PackageMapDetailsWidget.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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/PackageMapDetailsWidget",
  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. "hpcc/PackageSourceWidget",
  32. "dojo/text!../templates/PackageMapDetailsWidget.html",
  33. "dijit/layout/BorderContainer",
  34. "dijit/layout/TabContainer",
  35. "dijit/layout/ContentPane",
  36. "dijit/form/Button",
  37. "dijit/Toolbar",
  38. "dijit/TooltipDialog",
  39. "dijit/TitlePane"
  40. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, dom, domAttr, domClass, topic,
  41. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  42. WsPackageMaps, PackageSourceWidget, template) {
  43. return declare("PackageMapDetailsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  44. templateString: template,
  45. baseClass: "PackageMapDetailsWidget",
  46. i18n: lang.mixin(nlsCommon, nlsSpecific),
  47. borderContainer: null,
  48. tabContainer: null,
  49. validateWidget: null,
  50. validateWidgetLoaded: false,
  51. xmlWidget: null,
  52. xmlWidgetLoaded: false,
  53. initalized: false,
  54. tabId: "",
  55. packageMap: "",
  56. target: "",
  57. process: "",
  58. active: false,
  59. buildRendering: function (args) {
  60. this.inherited(arguments);
  61. },
  62. postCreate: function (args) {
  63. this.inherited(arguments);
  64. this.borderContainer = registry.byId(this.id + "BorderContainer");
  65. this.tabContainer = registry.byId(this.id + "TabContainer");
  66. this.validateWidget = registry.byId(this.id + "Validate");
  67. this.xmlWidget = registry.byId(this.id + "XML");
  68. var context = this;
  69. this.tabContainer.watch("selectedChildWidget", function (name, oval, nval) {
  70. if (nval.id == context.id + "Validate" && !context.validateWidgetLoaded) {
  71. context.validateWidgetLoaded = true;
  72. context.validateWidget.init({
  73. target: context.target,
  74. process: context.process,
  75. packageMap: context.packageMap
  76. });
  77. } else if (nval.id == context.id + "XML" && !context.xmlWidgetLoaded) {
  78. context.xmlWidgetLoaded = true;
  79. context.xmlWidget.init({
  80. target: context.target,
  81. process: context.process,
  82. packageMap: context.packageMap
  83. });
  84. }
  85. });
  86. },
  87. startup: function (args) {
  88. this.inherited(arguments);
  89. },
  90. resize: function (args) {
  91. this.inherited(arguments);
  92. this.borderContainer.resize();
  93. },
  94. layout: function (args) {
  95. this.inherited(arguments);
  96. },
  97. init: function (params) {
  98. if (this.initalized)
  99. return;
  100. this.initalized = true;
  101. this.tabId = params.tabId;
  102. this.packageMap = params.packageMap;
  103. this.target = params.target;
  104. this.process = params.process;
  105. this.active = params.active;
  106. if (params.packageMap) {
  107. registry.byId(this.id + "Summary").set("title", params.packageMap);
  108. domAttr.set(this.id + "PMID", "innerHTML", params.packageMap);
  109. domAttr.set(this.id + "Target", "value", params.target);
  110. domAttr.set(this.id + "Process", "value", params.process);
  111. if (params.active == true)
  112. domClass.add(this.id + "StateIdImage", "iconRunning");
  113. else
  114. domClass.add(this.id + "StateIdImage", "iconArchived");
  115. }
  116. this.refreshActionState();
  117. },
  118. refreshActionState: function () {
  119. registry.byId(this.id + "Activate").set("disabled", this.active);
  120. registry.byId(this.id + "Deactivate").set("disabled", !this.active);
  121. domAttr.set(this.id + "StateIdImage", "title", this.active? this.i18n.Active:this.i18n.NotActive);
  122. },
  123. showErrors: function (errMsg, errStack) {
  124. dojo.publish("hpcc/brToaster", {
  125. Severity: "Error",
  126. Source: errMsg,
  127. Exceptions: [{ Message: errStack }]
  128. });
  129. },
  130. _onActivate: function (event) {
  131. var context = this;
  132. var packageMaps = [];
  133. packageMaps[0] = {Target:this.target,
  134. Process:this.process,Id:this.packageMap};
  135. WsPackageMaps.activatePackageMap(packageMaps, {
  136. load: function (response) {
  137. domClass.replace(context.id + "StateIdImage", "iconRunning");
  138. context.active = true;
  139. context.refreshActionState();
  140. },
  141. error: function (errMsg, errStack) {
  142. context.showErrors(errMsg, errStack);
  143. }
  144. });
  145. },
  146. _onDeactivate: function (event) {
  147. var context = this;
  148. var packageMaps = [];
  149. packageMaps[0] = {Target:this.target,
  150. Process:this.process,Id:this.packageMap};
  151. WsPackageMaps.deactivatePackageMap(packageMaps, {
  152. load: function (response) {
  153. domClass.replace(context.id + "StateIdImage", "iconArchived");
  154. context.active = false;
  155. context.refreshActionState();
  156. },
  157. error: function (errMsg, errStack) {
  158. context.showErrors(errMsg, errStack);
  159. }
  160. });
  161. },
  162. _onDelete: function (event) {
  163. if (confirm(this.i18n.DeleteThisPackage)) {
  164. var context = this;
  165. var packageMaps = [];
  166. packageMaps[0] = {Target:this.target,
  167. Process:this.process,Id:this.packageMap};
  168. WsPackageMaps.deletePackageMap(packageMaps, {
  169. load: function (response) {
  170. topic.publish("packageMapDeleted", context.tabId);
  171. },
  172. error: function (errMsg, errStack) {
  173. context.showErrors(errMsg, errStack);
  174. }
  175. });
  176. }
  177. }
  178. });
  179. });