GridDetailsWidget.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/store/Memory",
  19. "dojo/store/Observable",
  20. "dijit/registry",
  21. "hpcc/_TabContainerWidget",
  22. "dojo/text!../templates/GridDetailsWidget.html",
  23. "dijit/layout/TabContainer",
  24. "dijit/layout/BorderContainer",
  25. "dijit/Toolbar",
  26. "dijit/form/Button",
  27. "dijit/ToolbarSeparator",
  28. "dijit/layout/ContentPane"
  29. ], function (declare, Memory, Observable,
  30. registry,
  31. _TabContainerWidget,
  32. template) {
  33. return declare("GridDetailsWidget", [_TabContainerWidget], {
  34. templateString: template,
  35. baseClass: "GridDetailsWidget",
  36. gridTitle: "Change Me",
  37. idProperty: "Change Me",
  38. store: null,
  39. grid: null,
  40. postCreate: function (args) {
  41. this.inherited(arguments);
  42. this.gridTab = registry.byId(this.id + "_Grid");
  43. },
  44. startup: function (args) {
  45. this.inherited(arguments);
  46. var context = this;
  47. var store = new Memory({
  48. idProperty: this.idProperty,
  49. data: []
  50. });
  51. this.store = Observable(store);
  52. this.grid = this.createGrid(this.id + "Grid");
  53. this.grid.on(".dgrid-row:dblclick", function (evt) {
  54. if (context._onRowDblClick) {
  55. var row = context.grid.row(evt).data;
  56. context._onRowDblClick(row);
  57. }
  58. });
  59. this.grid.on(".dgrid-row:contextmenu", function (evt) {
  60. if (context._onRowContextMenu) {
  61. }
  62. });
  63. this.grid.onSelectionChanged(function (event) {
  64. context._refreshActionState();
  65. });
  66. this.grid.onContentChanged(function (object, removedFrom, insertedInto) {
  67. context._refreshActionState();
  68. });
  69. this.grid.startup();
  70. },
  71. // Hitched actions ---
  72. _onRefresh: function (event) {
  73. this.refreshGrid();
  74. },
  75. _onOpen: function (event, params) {
  76. var selections = this.grid.getSelected();
  77. var firstTab = null;
  78. for (var i = 0; i < selections.length; ++i) {
  79. var tab = this.ensurePane(selections[i], params);
  80. if (i == 0) {
  81. firstTab = tab;
  82. }
  83. }
  84. if (firstTab) {
  85. this.selectChild(firstTab);
  86. }
  87. },
  88. _onRowDblClick: function (row) {
  89. var tab = this.ensurePane(row);
  90. this.selectChild(tab);
  91. },
  92. initTab: function () {
  93. var currSel = this.getSelectedChild();
  94. if (currSel && !currSel.initalized) {
  95. if (currSel.hpcc) {
  96. currSel.init(currSel.hpcc.params);
  97. }
  98. currSel.initalized = true;
  99. }
  100. },
  101. getDetailID: function (row, params) {
  102. return this.id + "_" + "Detail" + row[this.idProperty];
  103. },
  104. ensurePane: function (row, params) {
  105. var id = this.getDetailID(row, params);
  106. var retVal = registry.byId(id);
  107. if (!retVal) {
  108. retVal = this.createDetail(id, row, params);
  109. this.addChild(retVal);
  110. }
  111. return retVal;
  112. },
  113. _refreshActionState: function () {
  114. var selection = this.grid.getSelected();
  115. this.refreshActionState(selection);
  116. },
  117. refreshActionState: function (selection) {
  118. registry.byId(this.id + "Open").set("disabled", !selection.length);
  119. }
  120. });
  121. });