GridDetailsWidget.js 6.3 KB

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