PackageMapDetailsWidget.js 7.1 KB

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