PackageMapValidateWidget.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2013 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/PackageMapValidateWidget",
  22. "dojo/dom",
  23. "dojo/dom-attr",
  24. "dojo/dom-class",
  25. "dojo/topic",
  26. "dijit/layout/_LayoutWidget",
  27. "dijit/_TemplatedMixin",
  28. "dijit/_WidgetsInTemplateMixin",
  29. "dijit/registry",
  30. "hpcc/WsPackageMaps",
  31. "dojo/text!../templates/PackageMapValidateWidget.html",
  32. "dijit/form/Form",
  33. "dijit/form/Button",
  34. "dijit/form/RadioButton",
  35. "dijit/form/Select",
  36. "dijit/form/SimpleTextarea"
  37. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, dom, domAttr, domClass, topic,
  38. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  39. WsPackageMaps, template) {
  40. return declare("PackageMapValidateWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  41. templateString: template,
  42. baseClass: "PackageMapValidateWidget",
  43. i18n: lang.mixin(nlsCommon, nlsSpecific),
  44. validateForm: null,
  45. targetSelect: null,
  46. packageContent: null,
  47. validateResult: null,
  48. validateButton: null,
  49. targets: null,
  50. processes: new Array(),
  51. initalized: false,
  52. buildRendering: function (args) {
  53. this.inherited(arguments);
  54. },
  55. postCreate: function (args) {
  56. this.inherited(arguments);
  57. this.validateForm = registry.byId(this.id + "ValidatePM");
  58. this.targetSelect = registry.byId(this.id + "TargetSelect");
  59. this.processSelect = registry.byId(this.id + "ProcessSelect");
  60. this.packageContent = registry.byId(this.id + "Package");
  61. this.validateButton = registry.byId(this.id + "Validate");
  62. this.validateResult = registry.byId(this.id + "ValidateResult");
  63. },
  64. startup: function (args) {
  65. this.inherited(arguments);
  66. },
  67. resize: function (args) {
  68. this.inherited(arguments);
  69. },
  70. layout: function (args) {
  71. this.inherited(arguments);
  72. },
  73. init: function (params) {
  74. if (this.initalized)
  75. return;
  76. this.initalized = true;
  77. this.validateResult.set('style', 'visibility:hidden');
  78. if (params.targets == undefined)
  79. return;
  80. this.initSelection(params.targets);
  81. },
  82. initSelections: function (targets) {
  83. this.targets = targets;
  84. if (this.targets.length > 0) {
  85. for (var i = 0; i < this.targets.length; ++i)
  86. this.targetSelect.options.push({label: this.targets[i].Name, value: this.targets[i].Name});
  87. this.targetSelect.set("value", this.targets[0].Name);
  88. if (this.targets[0].Processes != undefined)
  89. this.updateProcessSelections(this.targets[0].Name);
  90. }
  91. },
  92. addProcessSelections: function (processes) {
  93. for (var i = 0; i < processes.length; ++i) {
  94. var process = processes[i];
  95. if ((this.processes != null) && (this.processes.indexOf(process) != -1))
  96. continue;
  97. this.processes.push(process);
  98. this.processSelect.options.push({label: process, value: process});
  99. }
  100. },
  101. updateProcessSelections: function (targetName) {
  102. this.processSelect.removeOption(this.processSelect.getOptions());
  103. this.processSelect.options.push({label: this.i18n.ANY, value: '' });
  104. for (var i = 0; i < this.targets.length; ++i) {
  105. var target = this.targets[i];
  106. if ((target.Processes != undefined) && ((targetName == '') || (targetName == target.Name)))
  107. this.addProcessSelections(target.Processes.Item);
  108. }
  109. this.processSelect.set("value", '');
  110. },
  111. addArrayToText: function (arrayTitle, arrayItems, text) {
  112. if ((arrayItems.Item != undefined) && (arrayItems.Item.length > 0)) {
  113. text += arrayTitle + ":\n";
  114. for (i=0;i<arrayItems.Item.length;i++)
  115. text += " " + arrayItems.Item[i] + "\n";
  116. text += "\n";
  117. }
  118. return text;
  119. },
  120. validateResponseToText: function (response) {
  121. var text = "";
  122. if (!lang.exists("Errors", response) || (response.Errors.length < 1))
  123. text += this.i18n.NoErrorFound;
  124. else
  125. text = this.addArrayToText(this.i18n.Errors, response.Errors, text);
  126. if (!lang.exists("Warnings", response) || (response.Warnings.length < 1))
  127. text += this.i18n.Warnings;
  128. else
  129. text = this.addArrayToText(this.i18n.Warnings, response.Warnings, text);
  130. text += "\n";
  131. text = this.addArrayToText(this.i18n.QueriesNoPackage, response.queries.Unmatched, text);
  132. text = this.addArrayToText(this.i18n.PackagesNoQuery, response.packages.Unmatched, text);
  133. text = this.addArrayToText(this.i18n.FilesNoPackage, response.files.Unmatched, text);
  134. return text;
  135. },
  136. _onChangeTarget: function (event) {
  137. this.processes.length = 0;
  138. this.targetSelected = this.targetSelect.getValue();
  139. this.updateProcessSelections(this.targetSelected);
  140. },
  141. _onValidate: function (event) {
  142. var request = { target: this.targetSelect.getValue() };
  143. var type = this.validateForm.attr('value').ValidateType;
  144. if (type == 'ActivePM') {
  145. request['active'] = true;
  146. request['process'] = this.processSelect.getValue();
  147. } else {
  148. var content = this.packageContent.getValue();
  149. if (content == '') {
  150. alert(this.i18n.PackageContentNotSet);
  151. return;
  152. }
  153. request['content'] = content;
  154. }
  155. var context = this;
  156. this.validateResult.setValue("");
  157. this.validateButton.set("disabled", true);
  158. WsPackageMaps.validatePackage(request, {
  159. load: function (response) {
  160. var responseText = context.validateResponseToText(response);
  161. if (responseText == '')
  162. context.validateResult.setValue(context.i18n.Empty);
  163. else {
  164. responseText = context.i18n.ValidateResult + responseText;
  165. context.validateResult.setValue(responseText);
  166. }
  167. context.validateResult.set('style', 'visibility:visible');
  168. context.validateButton.set("disabled", false);
  169. },
  170. error: function (errMsg, errStack) {
  171. context.showErrors(errMsg, errStack);
  172. context.validateButton.set("disabled", false);
  173. }
  174. });
  175. },
  176. showErrors: function (errMsg, errStack) {
  177. dojo.publish("hpcc/brToaster", {
  178. Severity: "Error",
  179. Source: errMsg,
  180. Exceptions: [{ Message: errStack }]
  181. });
  182. }
  183. });
  184. });