GridDetailsWidget.js 4.6 KB

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