TargetSelectWidget.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. require([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/_base/array",
  20. "dojo/_base/xhr",
  21. "dojo/data/ItemFileReadStore",
  22. "dojo/on",
  23. "dijit/form/Select",
  24. "dijit/registry",
  25. "hpcc/WsTopology",
  26. "hpcc/WsWorkunits",
  27. "hpcc/FileSpray"
  28. ], function (declare, lang, arrayUtil, xhr, ItemFileReadStore, on,
  29. Select, registry,
  30. WsTopology, WsWorkunits, FileSpray) {
  31. return declare("TargetSelectWidget", [Select], {
  32. loading: false,
  33. defaultValue: "",
  34. // Implementation ---
  35. init: function (params) {
  36. if (this.initalized)
  37. return;
  38. this.initalized = true;
  39. this.loading = true;
  40. this.options = [];
  41. if (params.Target) {
  42. this.defaultValue = params.Target;
  43. this.set("value", params.Target);
  44. }
  45. if (params.includeBlank) {
  46. this.includeBlank = params.includeBlank;
  47. this.options.push({
  48. label: " ",
  49. value: ""
  50. });
  51. }
  52. if (params.Groups === true) {
  53. this.loadGroups();
  54. } else if (params.DropZones === true) {
  55. this.loadDropZones();
  56. } else if (params.WUState === true) {
  57. this.loadWUState();
  58. } else if (params.DFUState === true) {
  59. this.loadDFUState();
  60. } else if (params.ECLSamples === true) {
  61. this.loadECLSamples();
  62. } else {
  63. this.loadTargets();
  64. }
  65. if (params.callback) {
  66. this.callback = params.callback;
  67. }
  68. if (params.includeBlank) {
  69. }
  70. },
  71. _setValueAttr: function (target) {
  72. if (target === null)
  73. target = "";
  74. this.inherited(arguments);
  75. if (this.callback) {
  76. this.callback(this.value, this._getRowAttr());
  77. }
  78. },
  79. _getValueAttr: function () {
  80. if (this.loading)
  81. return this.defaultValue;
  82. return this.value;
  83. },
  84. _getRowAttr: function () {
  85. var context = this;
  86. var retVal = null;
  87. arrayUtil.forEach(this.options, function (item, idx) {
  88. if (context.value === item.value) {
  89. retVal = item;
  90. return false;
  91. }
  92. });
  93. return retVal;
  94. },
  95. _postLoad: function () {
  96. if (this.defaultValue == "") {
  97. this.defaultValue = this.options[0].value;
  98. }
  99. this.set("value", this.defaultValue);
  100. this.loading = false;
  101. },
  102. loadDropZones: function () {
  103. var context = this;
  104. WsTopology.TpServiceQuery({
  105. load: function (response) {
  106. if (lang.exists("TpServiceQueryResponse.ServiceList.TpDropZones.TpDropZone", response)) {
  107. var targetData = response.TpServiceQueryResponse.ServiceList.TpDropZones.TpDropZone;
  108. for (var i = 0; i < targetData.length; ++i) {
  109. context.options.push({
  110. label: targetData[i].Name,
  111. value: targetData[i].Name,
  112. machine: targetData[i].TpMachines.TpMachine[0]
  113. });
  114. }
  115. context._postLoad();
  116. }
  117. }
  118. });
  119. },
  120. loadGroups: function () {
  121. var context = this;
  122. WsTopology.TpGroupQuery({
  123. load: function (response) {
  124. if (lang.exists("TpGroupQueryResponse.TpGroups.TpGroup", response)) {
  125. var targetData = response.TpGroupQueryResponse.TpGroups.TpGroup;
  126. for (var i = 0; i < targetData.length; ++i) {
  127. context.options.push({
  128. label: targetData[i].Name,
  129. value: targetData[i].Name
  130. });
  131. }
  132. context._postLoad();
  133. }
  134. }
  135. });
  136. },
  137. loadWUState: function() {
  138. for (var key in WsWorkunits.States) {
  139. this.options.push({
  140. label: WsWorkunits.States[key],
  141. value: WsWorkunits.States[key]
  142. });
  143. }
  144. this._postLoad();
  145. },
  146. loadDFUState: function () {
  147. for (var key in FileSpray.States) {
  148. this.options.push({
  149. label: FileSpray.States[key],
  150. value: FileSpray.States[key]
  151. });
  152. }
  153. this._postLoad();
  154. },
  155. LogicalFileSearchType: function() {
  156. this.options.push({
  157. label: "Created",
  158. value: "Created"
  159. });
  160. this.options.push({
  161. label: "Used",
  162. value: "Referenced"
  163. });
  164. this._postLoad();
  165. },
  166. loadTargets: function () {
  167. var context = this;
  168. WsTopology.TpLogicalClusterQuery({
  169. }).then(function (response) {
  170. if (lang.exists("TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster", response)) {
  171. var targetData = response.TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster;
  172. for (var i = 0; i < targetData.length; ++i) {
  173. context.options.push({
  174. label: targetData[i].Name,
  175. value: targetData[i].Name
  176. });
  177. }
  178. if (!context.includeBlank && context._value == "") {
  179. if (response.TpLogicalClusterQueryResponse["default"]) {
  180. context._value = response.TpLogicalClusterQueryResponse["default"].Name;
  181. } else {
  182. context._value = context.options[0].value;
  183. }
  184. }
  185. }
  186. context._postLoad();
  187. });
  188. },
  189. loadECLSamples: function () {
  190. var sampleStore = new ItemFileReadStore({
  191. url: "ecl/ECLPlaygroundSamples.json"
  192. });
  193. this.setStore(sampleStore);
  194. var context = this;
  195. this.on("change", function (evt) {
  196. var filename = this.get("value");
  197. xhr.get({
  198. url: "ecl/" + filename,
  199. handleAs: "text",
  200. load: function (eclText) {
  201. context.onNewSelection(eclText);
  202. },
  203. error: function () {
  204. }
  205. });
  206. });
  207. context._postLoad();
  208. }
  209. });
  210. });