TargetSelectWidget.js 7.9 KB

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