TargetSelectWidget.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. "dojo/dom",
  24. "dijit/form/Select",
  25. "dijit/registry",
  26. "hpcc/WsTopology",
  27. "hpcc/WsWorkunits",
  28. "hpcc/FileSpray"
  29. ], function (declare, lang, arrayUtil, xhr, ItemFileReadStore, on, dom,
  30. Select, registry,
  31. WsTopology, WsWorkunits, FileSpray) {
  32. return declare("TargetSelectWidget", Select, {
  33. loading: false,
  34. defaultValue: "",
  35. // Implementation ---
  36. init: function (params) {
  37. if (this.initalized)
  38. return;
  39. this.initalized = true;
  40. this.loading = true;
  41. this.options = [];
  42. if (params.Target) {
  43. this.defaultValue = params.Target;
  44. this.set("value", params.Target);
  45. }
  46. if (params.includeBlank) {
  47. this.includeBlank = params.includeBlank;
  48. this.options.push({
  49. label: " ",
  50. value: ""
  51. });
  52. }
  53. if (params.Groups === true) {
  54. this.loadGroups();
  55. } else if (params.DropZones === true) {
  56. this.loadDropZones();
  57. } else if (params.WUState === true) {
  58. this.loadWUState();
  59. } else if (params.DFUState === true) {
  60. this.loadDFUState();
  61. } else if (params.ECLSamples === true) {
  62. this.loadECLSamples();
  63. } else {
  64. this.loadTargets();
  65. }
  66. if (params.callback) {
  67. this.callback = params.callback;
  68. }
  69. if (params.includeBlank) {
  70. }
  71. },
  72. _setValueAttr: function (target) {
  73. if (target === null)
  74. target = "";
  75. this.inherited(arguments);
  76. if (this.callback) {
  77. this.callback(this.value, this._getRowAttr());
  78. }
  79. },
  80. _getValueAttr: function () {
  81. if (this.loading)
  82. return this.defaultValue;
  83. return this.value;
  84. },
  85. _getRowAttr: function () {
  86. var context = this;
  87. var retVal = null;
  88. arrayUtil.forEach(this.options, function (item, idx) {
  89. if (context.value === item.value) {
  90. retVal = item;
  91. return false;
  92. }
  93. });
  94. return retVal;
  95. },
  96. _postLoad: function () {
  97. if (this.defaultValue == "") {
  98. this.defaultValue = this.options[0].value;
  99. }
  100. this.set("value", this.defaultValue);
  101. this.loading = false;
  102. },
  103. loadDropZones: function () {
  104. var context = this;
  105. WsTopology.TpServiceQuery({
  106. load: function (response) {
  107. if (lang.exists("TpServiceQueryResponse.ServiceList.TpDropZones.TpDropZone", response)) {
  108. var targetData = response.TpServiceQueryResponse.ServiceList.TpDropZones.TpDropZone;
  109. for (var i = 0; i < targetData.length; ++i) {
  110. context.options.push({
  111. label: targetData[i].Name,
  112. value: targetData[i].Name,
  113. machine: targetData[i].TpMachines.TpMachine[0]
  114. });
  115. }
  116. context._postLoad();
  117. }
  118. }
  119. });
  120. },
  121. loadGroups: function () {
  122. var context = this;
  123. WsTopology.TpGroupQuery({
  124. load: function (response) {
  125. if (lang.exists("TpGroupQueryResponse.TpGroups.TpGroup", response)) {
  126. var targetData = response.TpGroupQueryResponse.TpGroups.TpGroup;
  127. for (var i = 0; i < targetData.length; ++i) {
  128. context.options.push({
  129. label: targetData[i].Name,
  130. value: targetData[i].Name
  131. });
  132. }
  133. context._postLoad();
  134. }
  135. }
  136. });
  137. },
  138. loadWUState: function() {
  139. for (var key in WsWorkunits.States) {
  140. this.options.push({
  141. label: WsWorkunits.States[key],
  142. value: WsWorkunits.States[key]
  143. });
  144. }
  145. this._postLoad();
  146. },
  147. loadDFUState: function () {
  148. for (var key in FileSpray.States) {
  149. this.options.push({
  150. label: FileSpray.States[key],
  151. value: FileSpray.States[key]
  152. });
  153. }
  154. this._postLoad();
  155. },
  156. LogicalFileSearchType: function() {
  157. this.options.push({
  158. label: "Created",
  159. value: "Created"
  160. });
  161. this.options.push({
  162. label: "Used",
  163. value: "Referenced"
  164. });
  165. this._postLoad();
  166. },
  167. loadTargets: function () {
  168. var context = this;
  169. WsTopology.TpLogicalClusterQuery({
  170. }).then(function (response) {
  171. if (lang.exists("TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster", response)) {
  172. var targetData = response.TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster;
  173. for (var i = 0; i < targetData.length; ++i) {
  174. context.options.push({
  175. label: targetData[i].Name,
  176. value: targetData[i].Name
  177. });
  178. }
  179. if (!context.includeBlank && context._value == "") {
  180. if (response.TpLogicalClusterQueryResponse.default) {
  181. context._value = response.TpLogicalClusterQueryResponse.default.Name;
  182. } else {
  183. context._value = context.options[0].value;
  184. }
  185. }
  186. }
  187. context._postLoad();
  188. });
  189. },
  190. loadECLSamples: function () {
  191. var sampleStore = new ItemFileReadStore({
  192. url: "ecl/ECLPlaygroundSamples.json"
  193. });
  194. this.setStore(sampleStore);
  195. var context = this;
  196. this.on("change", function (evt) {
  197. var filename = this.get("value");
  198. xhr.get({
  199. url: "ecl/" + filename,
  200. handleAs: "text",
  201. load: function (eclText) {
  202. context.onNewSelection(eclText);
  203. },
  204. error: function () {
  205. }
  206. });
  207. });
  208. context._postLoad();
  209. }
  210. });
  211. });