GridDetailsWidget.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/store/Memory",
  20. "dojo/store/Observable",
  21. "dijit/registry",
  22. "dijit/Menu",
  23. "dijit/MenuItem",
  24. "dijit/MenuSeparator",
  25. "dijit/PopupMenuItem",
  26. "hpcc/_TabContainerWidget",
  27. "dojo/text!../templates/GridDetailsWidget.html",
  28. "dijit/layout/TabContainer",
  29. "dijit/layout/BorderContainer",
  30. "dijit/Toolbar",
  31. "dijit/form/Button",
  32. "dijit/ToolbarSeparator",
  33. "dijit/layout/ContentPane"
  34. ], function (declare, lang, Memory, Observable,
  35. registry, Menu, MenuItem, MenuSeparator, PopupMenuItem,
  36. _TabContainerWidget,
  37. template) {
  38. return declare("GridDetailsWidget", [_TabContainerWidget], {
  39. templateString: template,
  40. baseClass: "GridDetailsWidget",
  41. gridTitle: "Change Me",
  42. idProperty: "Change Me",
  43. store: null,
  44. toolbar: null,
  45. gridTab: null,
  46. grid: null,
  47. contextMenu: null,
  48. postCreate: function (args) {
  49. this.inherited(arguments);
  50. this.toolbar = registry.byId(this.id + "Toolbar");
  51. this.gridTab = registry.byId(this.id + "_Grid");
  52. },
  53. startup: function (args) {
  54. this.inherited(arguments);
  55. this.initGrid();
  56. this.initContextMenu();
  57. },
  58. // Hitched actions ---
  59. _onRefresh: function (event) {
  60. this.refreshGrid();
  61. },
  62. _onOpen: function (event, params) {
  63. var selections = this.grid.getSelected();
  64. var firstTab = null;
  65. for (var i = 0; i < selections.length; ++i) {
  66. var tab = this.ensurePane(selections[i], params);
  67. if (i == 0) {
  68. firstTab = tab;
  69. }
  70. }
  71. if (firstTab) {
  72. this.selectChild(firstTab);
  73. }
  74. },
  75. _onRowDblClick: function (row) {
  76. var tab = this.ensurePane(row);
  77. this.selectChild(tab);
  78. },
  79. // Implementation ---
  80. initGrid: function() {
  81. var context = this;
  82. var store = new Memory({
  83. idProperty: this.idProperty,
  84. data: []
  85. });
  86. this.store = Observable(store);
  87. this.grid = this.createGrid(this.id + "Grid");
  88. this.grid.on(".dgrid-row:dblclick", function (evt) {
  89. if (context._onRowDblClick) {
  90. var row = context.grid.row(evt).data;
  91. context._onRowDblClick(row);
  92. }
  93. });
  94. this.grid.on(".dgrid-row:contextmenu", function (evt) {
  95. if (context._onRowContextMenu) {
  96. }
  97. });
  98. this.grid.onSelectionChanged(function (event) {
  99. context._refreshActionState();
  100. });
  101. this.grid.onContentChanged(function (object, removedFrom, insertedInto) {
  102. context._refreshActionState();
  103. });
  104. if (!this.grid.get("noDataMessage")) {
  105. this.grid.set("noDataMessage", "<span class='dgridInfo'>Zero Rows...</span>");
  106. }
  107. if (!this.grid.get("loadingMessage")) {
  108. this.grid.set("loadingMessage", "<span class='dgridInfo'>Loading...</span>");
  109. }
  110. this.grid.startup();
  111. },
  112. appendMenuItem: function (menu, label, onClick) {
  113. var menuItem = new MenuItem({
  114. label: label,
  115. onClick: onClick
  116. });
  117. menu.addChild(menuItem);
  118. return menuItem;
  119. },
  120. appendContextMenuItem: function (label, onClick) {
  121. return this.appendMenuItem(this.contextMenu, label, onClick);
  122. },
  123. initContextMenu: function () {
  124. var context = this;
  125. this.contextMenu = new Menu({
  126. targetNodeIds: [this.id + "Grid"]
  127. });
  128. this.appendContextMenuItem("Refresh", function () {
  129. context._onRefresh();
  130. });
  131. this.contextMenu.addChild(new MenuSeparator());
  132. this.appendContextMenuItem("Open", function () {
  133. context._onOpen();
  134. });
  135. if (this.appendContextMenu) {
  136. this.appendContextMenu();
  137. }
  138. this.contextMenu.startup();
  139. },
  140. initTab: function () {
  141. var currSel = this.getSelectedChild();
  142. if (currSel) {
  143. if (!currSel.initalized) {
  144. if (currSel.hpcc) {
  145. currSel.init(currSel.hpcc.params);
  146. }
  147. currSel.initalized = true;
  148. } else if (currSel.refresh) {
  149. currSel.refresh(currSel.hpcc.refreshParams);
  150. }
  151. }
  152. },
  153. getDetailID: function (row, params) {
  154. return this.id + "_" + "Detail" + row[this.idProperty];
  155. },
  156. ensurePane: function (row, params) {
  157. var id = this.getDetailID(row, params);
  158. var retVal = registry.byId(id);
  159. if (!retVal) {
  160. retVal = this.createDetail(id, row, params);
  161. this.addChild(retVal);
  162. } else {
  163. lang.mixin(retVal.hpcc, {
  164. refreshParams: params
  165. });
  166. }
  167. return retVal;
  168. },
  169. _refreshActionState: function () {
  170. var selection = this.grid.getSelected();
  171. this.refreshActionState(selection);
  172. },
  173. refreshActionState: function (selection) {
  174. registry.byId(this.id + "Open").set("disabled", !selection.length);
  175. }
  176. });
  177. });