PackageMapDetailsWidget.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. showErrorMessage: function (message) {
  119. dojo.publish("hpcc/brToaster", {
  120. message: message,
  121. type: "error",
  122. duration: -1
  123. });
  124. },
  125. showErrors: function (errMsg, errStack) {
  126. var message = "Unknown Error";
  127. if (errMsg != '')
  128. message = "<h3>" + errMsg + "</h3>";
  129. if (errStack != '')
  130. message += "<p>" + errStack + "</p>";
  131. this.showErrorMessage(message);
  132. },
  133. _onActivate: function (event) {
  134. var context = this;
  135. var packageMaps = [];
  136. packageMaps[0] = {Target:this.target,
  137. Process:this.process,Id:this.packageMap};
  138. WsPackageMaps.activatePackageMap(packageMaps, {
  139. load: function (response) {
  140. domClass.replace(context.id + "StateIdImage", "iconRunning");
  141. context.active = true;
  142. context.refreshActionState();
  143. },
  144. error: function (errMsg, errStack) {
  145. context.showErrors(errMsg, errStack);
  146. }
  147. });
  148. },
  149. _onDeactivate: function (event) {
  150. var context = this;
  151. var packageMaps = [];
  152. packageMaps[0] = {Target:this.target,
  153. Process:this.process,Id:this.packageMap};
  154. WsPackageMaps.deactivatePackageMap(packageMaps, {
  155. load: function (response) {
  156. domClass.replace(context.id + "StateIdImage", "iconArchived");
  157. context.active = false;
  158. context.refreshActionState();
  159. },
  160. error: function (errMsg, errStack) {
  161. context.showErrors(errMsg, errStack);
  162. }
  163. });
  164. },
  165. _onDelete: function (event) {
  166. if (confirm('Delete selected package?')) {
  167. var context = this;
  168. var packageMaps = [];
  169. packageMaps[0] = {Target:this.target,
  170. Process:this.process,Id:this.packageMap};
  171. WsPackageMaps.deletePackageMap(packageMaps, {
  172. load: function (response) {
  173. topic.publish("packageMapDeleted", context.tabId);
  174. },
  175. error: function (errMsg, errStack) {
  176. context.showErrors(errMsg, errStack);
  177. }
  178. });
  179. }
  180. }
  181. });
  182. });