TargetSelectWidget.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. },
  77. _getValueAttr: function () {
  78. if (this.loading)
  79. return this.defaultValue;
  80. return this.value;
  81. },
  82. _postLoad: function () {
  83. if (this.defaultValue == "") {
  84. this.defaultValue = this.options[0].value;
  85. }
  86. this.set("value", this.defaultValue);
  87. this.loading = false;
  88. },
  89. loadDropZones: function () {
  90. var context = this;
  91. WsTopology.TpServiceQuery({
  92. load: function (response) {
  93. if (lang.exists("TpServiceQueryResponse.ServiceList.TpDropZones.TpDropZone", response)) {
  94. var targetData = response.TpServiceQueryResponse.ServiceList.TpDropZones.TpDropZone;
  95. for (var i = 0; i < targetData.length; ++i) {
  96. context.options.push({
  97. label: targetData[i].Name,
  98. value: targetData[i].Name,
  99. machine: targetData[i].TpMachines.TpMachine[0]
  100. });
  101. }
  102. context._postLoad();
  103. }
  104. }
  105. });
  106. },
  107. loadGroups: function () {
  108. var context = this;
  109. WsTopology.TpGroupQuery({
  110. load: function (response) {
  111. if (lang.exists("TpGroupQueryResponse.TpGroups.TpGroup", response)) {
  112. var targetData = response.TpGroupQueryResponse.TpGroups.TpGroup;
  113. for (var i = 0; i < targetData.length; ++i) {
  114. context.options.push({
  115. label: targetData[i].Name,
  116. value: targetData[i].Name
  117. });
  118. }
  119. context._postLoad();
  120. }
  121. }
  122. });
  123. },
  124. loadWUState: function() {
  125. for (var key in WsWorkunits.States) {
  126. this.options.push({
  127. label: WsWorkunits.States[key],
  128. value: WsWorkunits.States[key]
  129. });
  130. }
  131. this._postLoad();
  132. },
  133. loadDFUState: function () {
  134. for (var key in FileSpray.States) {
  135. this.options.push({
  136. label: FileSpray.States[key],
  137. value: FileSpray.States[key]
  138. });
  139. }
  140. this._postLoad();
  141. },
  142. LogicalFileSearchType: function() {
  143. this.options.push({
  144. label: "Created",
  145. value: "Created"
  146. });
  147. this.options.push({
  148. label: "Used",
  149. value: "Referenced"
  150. });
  151. this._postLoad();
  152. },
  153. loadTargets: function () {
  154. var context = this;
  155. WsTopology.TpLogicalClusterQuery({
  156. }).then(function (response) {
  157. if (lang.exists("TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster", response)) {
  158. var targetData = response.TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster;
  159. var has_hthor = false;
  160. for (var i = 0; i < targetData.length; ++i) {
  161. context.options.push({
  162. label: targetData[i].Name,
  163. value: targetData[i].Name
  164. });
  165. if (targetData[i].Name == "hthor") {
  166. has_hthor = true;
  167. }
  168. }
  169. if (!context.includeBlank && context._value == "") {
  170. if (has_hthor) {
  171. context._value = "hthor";
  172. } else {
  173. context._value = context.options[0].value;
  174. }
  175. }
  176. }
  177. context._postLoad();
  178. });
  179. },
  180. loadECLSamples: function () {
  181. var sampleStore = new ItemFileReadStore({
  182. url: "ecl/ECLPlaygroundSamples.json"
  183. });
  184. this.setStore(sampleStore);
  185. var context = this;
  186. this.on("change", function (evt) {
  187. var filename = this.get("value");
  188. xhr.get({
  189. url: "ecl/" + filename,
  190. handleAs: "text",
  191. load: function (eclText) {
  192. context.onNewSelection(eclText);
  193. },
  194. error: function () {
  195. }
  196. });
  197. });
  198. context._postLoad();
  199. }
  200. });
  201. });