TargetSelectWidget.js 7.9 KB

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