GridDetailsWidget.js 4.7 KB

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