PreviewGrid.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*******************************************************************************
  2. * IBM Confidential
  3. *
  4. * OCO Source Materials
  5. *
  6. * A and PM: PD
  7. *
  8. * (c) Copyright IBM Corp. 2014
  9. *
  10. * The source code for this program is not published or otherwise divested of
  11. * its trade secrets, irrespective of what has been deposited with the U.S.
  12. * Copyright Office.
  13. ******************************************************************************/
  14. define([
  15. "dojo/_base/declare",
  16. "dojox/grid/EnhancedGrid",
  17. "dojo/_base/array",
  18. "dojo/query",
  19. "dojo/dom-style",
  20. "dojo/dom-attr",
  21. "dojo/_base/html",
  22. "dijit/Tooltip",
  23. "dojox/grid/enhanced/plugins/Selector"
  24. ],function(declare, EnhancedGrid, array, query, domStyle, domAttr, html){
  25. var PreviewGrid = declare("pd/widgets/PreviewGrid", [EnhancedGrid], {
  26. rowsPerPage: 60,
  27. keepRows: 120,
  28. autoHeight: false,
  29. plugins: {
  30. selector: {
  31. col: "single",
  32. row: "single",
  33. cell: "disabled"
  34. }
  35. },
  36. constructor: function() {
  37. this.selector = null;
  38. },
  39. postMixInProperties: function(){
  40. this.structure = this.store.objectStore.pdGetOriginalStructure();
  41. this.inherited(arguments);
  42. },
  43. pdToggleColumns: function(selection){
  44. for (var i=0; i<selection.length; i++) {
  45. this.pdToggleColumn(selection[i], i==(selection.length-1));
  46. }
  47. },
  48. pdToggleColumn: function(sel, needResize) {
  49. if (sel.hidden){
  50. this.selector.deselect("col", sel.index);
  51. }
  52. this.layout.cells[sel.index].hidden = sel.hidden;
  53. query(".pd_idx"+sel.index, pd_previewContainer.domNode).
  54. style("display", sel.hidden?"none":"table-cell");
  55. if (needResize) {
  56. this.resize();
  57. if (!sel.hidden){
  58. this.pdSelectColumn(sel.index);
  59. }
  60. }
  61. },
  62. pdSelectColumn: function(idx) {
  63. //scroll to the column according to the selection from ColumnGrid.
  64. var prevColFocusIdx = this.focus._colHeadFocusIdx;
  65. var colHeaderNode = this.focus._findHeaderCells()[idx];
  66. this.selector.clear();
  67. this.selector.select("col", idx);
  68. this.scrollToRow(0);
  69. if (prevColFocusIdx != null && prevColFocusIdx >= 0 && prevColFocusIdx != idx){
  70. html.toggleClass(this.focus._findHeaderCells()[prevColFocusIdx],
  71. this.focus.focusClass, false);
  72. }
  73. html.toggleClass(colHeaderNode, this.focus.focusClass, true);
  74. this.focus._colHeadNode = colHeaderNode;
  75. this.focus._colHeadFocusIdx = idx;
  76. this.focus._scrollHeader(idx);
  77. },
  78. canSort: function(colIndex, field){
  79. // summary:
  80. // Overwritten
  81. return false;
  82. },
  83. textSizeChanged: function(){
  84. //override
  85. },
  86. startup: function() {
  87. this.inherited(arguments);
  88. this.connect(this, "onCellMouseOver", this._pdShowTooltip);
  89. this.connect(this, "onHeaderCellMouseOver", this._pdShowHeaderTooltip);
  90. this.selector = this.pluginMgr.getPlugin("selector");
  91. },
  92. _pdShowHeaderTooltip: function(e) {
  93. var structure = this.structure[0];
  94. var msg = structure[e.cellIndex].name;
  95. if (msg) {
  96. domAttr.set(e.cellNode, "title", msg);
  97. }
  98. },
  99. _pdShowTooltip: function(e) {
  100. var item = e.grid.getItem(e.rowIndex);
  101. var msg = e.grid.store.getValue(item, e.cell.field);
  102. if (msg) {
  103. domAttr.set(e.cellNode, "title", msg);
  104. }
  105. },
  106. defaultUpdate: function(){
  107. //override the default one, so the table doesn't get rerendered.
  108. if(!this.domNode){return;}
  109. if(this.updating){
  110. this.invalidated.all = true;
  111. return;
  112. }
  113. this.prerender();
  114. }
  115. });
  116. PreviewGrid.markupFactory = EnhancedGrid.markupFactory;
  117. PreviewGrid.registerPlugin = EnhancedGrid.registerPlugin;
  118. return PreviewGrid;
  119. });