EventScheduleWorkunitWidget.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/i18n",
  20. "dojo/i18n!./nls/common",
  21. "dojo/i18n!./nls/EventScheduleWorkunitWidget",
  22. "dojo/dom",
  23. "dojo/dom-form",
  24. "dojo/_base/array",
  25. "dojo/on",
  26. "dijit/registry",
  27. "dijit/Menu",
  28. "dijit/MenuItem",
  29. "dgrid/Grid",
  30. "dgrid/Keyboard",
  31. "dgrid/Selection",
  32. "dgrid/selector",
  33. "dgrid/extensions/ColumnResizer",
  34. "dgrid/extensions/DijitRegistry",
  35. "dgrid/extensions/Pagination",
  36. "hpcc/_TabContainerWidget",
  37. "hpcc/TargetSelectWidget",
  38. "hpcc/WUDetailsWidget",
  39. "hpcc/WsWorkunits",
  40. "hpcc/ESPUtil",
  41. "hpcc/FilterDropDownWidget",
  42. "dojo/text!../templates/EventScheduleWorkunitWidget.html",
  43. "dijit/layout/BorderContainer",
  44. "dijit/layout/TabContainer",
  45. "dijit/layout/ContentPane",
  46. "dijit/Toolbar",
  47. "dijit/form/Form",
  48. "dijit/form/Button",
  49. "dijit/ToolbarSeparator",
  50. "dijit/form/TextBox",
  51. "dijit/form/DropDownButton",
  52. "dijit/TooltipDialog",
  53. "dojox/layout/TableContainer"
  54. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, dom, domForm, arrayUtil, on,
  55. registry, Menu, MenuItem,
  56. Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  57. _TabContainerWidget, TargetSelectWidget, WUDetailsWidget, WsWorkunits, ESPUtil, FilterDropDownWidget,
  58. template) {
  59. return declare("EventScheduleWorkunitWidget", [_TabContainerWidget], {
  60. i18n: lang.mixin(nlsCommon, nlsSpecific),
  61. templateString: template,
  62. baseClass: "EventScheduleWorkunitWidget",
  63. eventTab: null,
  64. eventGrid: null,
  65. filter: null,
  66. clusterTargetSelect: null,
  67. postCreate: function (args) {
  68. this.inherited(arguments);
  69. this.filter = registry.byId(this.id + "Filter");
  70. this.eventTab = registry.byId(this.id + "_EventScheduledWorkunits");
  71. this.clusterTargetSelect = registry.byId(this.id + "ClusterTargetSelect");
  72. },
  73. startup: function (args) {
  74. this.inherited(arguments);
  75. this.initContextMenu();
  76. },
  77. init: function (params) {
  78. var context = this;
  79. if (this.inherited(arguments))
  80. return;
  81. this.clusterTargetSelect.init({
  82. Targets: true,
  83. includeBlank: true,
  84. Target: params.Cluster
  85. });
  86. this.initEventGrid();
  87. this.selectChild(this.eventTab, true);
  88. this.filter.on("clear", function (evt) {
  89. context.refreshGrid();
  90. });
  91. this.filter.on("apply", function (evt) {
  92. context.refreshGrid();
  93. });
  94. },
  95. initTab: function () {
  96. var currSel = this.getSelectedChild();
  97. if (currSel && !currSel.initalized) {
  98. if (currSel.id == this.eventTab.id) {
  99. } else {
  100. currSel.init(currSel.params);
  101. }
  102. }
  103. },
  104. addMenuItem: function (menu, details) {
  105. var menuItem = new MenuItem(details);
  106. menu.addChild(menuItem);
  107. return menuItem;
  108. },
  109. initContextMenu: function ( ) {
  110. var context = this;
  111. var pMenu = new Menu({
  112. targetNodeIds: [this.id + "EventGrid"]
  113. });
  114. this.menuOpen = this.addMenuItem(pMenu, {
  115. label: this.i18n.Open,
  116. onClick: function () { context._onOpen(); }
  117. });
  118. this.menuDeschedule = this.addMenuItem(pMenu, {
  119. label: this.i18n.Deschedule,
  120. onClick: function () { context._onDeschedule(); }
  121. });
  122. pMenu.startup();
  123. },
  124. initEventGrid: function (params) {
  125. var context = this;
  126. var store = WsWorkunits.CreateEventScheduleStore();
  127. this.eventGrid = new declare([Grid, Pagination, Selection, ColumnResizer, Keyboard, DijitRegistry, ESPUtil.GridHelper])({
  128. allowSelectAll: true,
  129. deselectOnRefresh: false,
  130. store: store,
  131. query: this.getFilter(),
  132. rowsPerPage: 50,
  133. pagingLinks: 1,
  134. pagingTextBox: true,
  135. firstLastArrows: true,
  136. pageSizeOptions: [25, 50, 100],
  137. columns: {
  138. col1: selector({ width: 27, selectorType: 'checkbox' }),
  139. Wuid: {
  140. label: this.i18n.Workunit, width: 180, sortable: true,
  141. formatter: function (Wuid) {
  142. return "<a href='#' class='" + context.id + "WuidClick'>" + Wuid + "</a>";
  143. }
  144. },
  145. Cluster: { label: this.i18n.Cluster, width: 108, sortable: true },
  146. JobName: { label: this.i18n.JobName, sortable: true },
  147. EventName: { label: this.i18n.EventName, width: 90, sortable: true },
  148. EventText: { label: this.i18n.EventText, sortable: true }
  149. }
  150. },
  151. this.id + "EventGrid");
  152. this.eventGrid.set("noDataMessage", "<span class='dojoxGridNoData'>" + this.i18n.NoScheduledEvents + "</span>");
  153. on(document, "." + context.id + "WuidClick:click", function (evt) {
  154. if (context._onRowDblClick) {
  155. var item = context.eventGrid.row(evt).data;
  156. context._onRowDblClick(item);
  157. }
  158. });
  159. this.eventGrid.on(".dgrid-row:dblclick", function (evt) {
  160. if (context._onRowDblClick) {
  161. var item = context.eventGrid.row(evt).data;
  162. context._onRowDblClick(item);
  163. }
  164. });
  165. this.eventGrid.on(".dgrid-row:contextmenu", function (evt) {
  166. if (context._onRowContextMenu) {
  167. var item = context.eventGrid.row(evt).data;
  168. var cell = context.eventGrid.cell(evt);
  169. var colField = cell.column.field;
  170. var mystring = "item." + colField;
  171. context._onRowContextMenu(item, colField, mystring);
  172. }
  173. });
  174. this.eventGrid.onSelectionChanged(function (event) {
  175. context.refreshActionState();
  176. });
  177. this.eventGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  178. context.refreshActionState();
  179. });
  180. this.eventGrid.startup();
  181. this.refreshActionState();
  182. },
  183. refreshActionState: function () {
  184. var selection = this.eventGrid.getSelected();
  185. var hasSelection = selection.length > 0;
  186. registry.byId(this.id + "Deschedule").set("disabled", !hasSelection);
  187. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  188. },
  189. _onRefresh: function (params) {
  190. this.refreshGrid();
  191. },
  192. _onOpen: function (event) {
  193. var selections = this.eventGrid.getSelected();
  194. var firstTab = null;
  195. for (var i = selections.length - 1; i >= 0; --i) {
  196. var tab = this.ensurePane(this.id + "_" + selections[i].Wuid, selections[i]);
  197. if (i == 0) {
  198. firstTab = tab;
  199. }
  200. }
  201. if (firstTab) {
  202. this.selectChild(firstTab, true);
  203. }
  204. },
  205. _onDeschedule: function (event) {
  206. if (confirm(this.i18n.DescheduleSelectedWorkunits)) {
  207. var context = this;
  208. var selection = this.eventGrid.getSelected();
  209. WsWorkunits.WUAction(selection, "Deschedule").then(function (response) {
  210. context.refreshGrid(response);
  211. });
  212. }
  213. },
  214. refreshGrid: function (args) {
  215. this.eventGrid.set("query", this.getFilter());
  216. },
  217. _onRowDblClick: function (item) {
  218. var wuTab = this.ensurePane(this.id + "_" + item.Wuid, item);
  219. this.selectChild(wuTab);
  220. },
  221. getFilter: function(){
  222. return this.filter.toObject();
  223. },
  224. ensurePane: function (id, params) {
  225. id = id.split(".").join("x");
  226. var retVal = registry.byId(id);
  227. if (!retVal) {
  228. retVal = new WUDetailsWidget({
  229. id: id,
  230. title: params.Wuid,
  231. closable: true,
  232. params: {
  233. Wuid: params.Wuid
  234. }
  235. });
  236. this.addChild(retVal, 1);
  237. }
  238. return retVal;
  239. }
  240. });
  241. });