/******************************************************************************* * IBM Confidential * * OCO Source Materials * * A and PM: PD * * (c) Copyright IBM Corp. 2014 * * The source code for this program is not published or otherwise divested of * its trade secrets, irrespective of what has been deposited with the U.S. * Copyright Office. ******************************************************************************/ define([ "dojo/_base/declare", "dojo/dom", "dojo/dom-attr", "dojo/_base/array", "dojo/_base/lang", "dojo/string", "dojox/grid/EnhancedGrid", "dojox/grid/enhanced/plugins/IndirectSelection" ], function(declare, dom, domAttr, array, lang, string, EnhancedGrid){ var RowSelector = declare("pd/widgets/grid/cells/RowSelector", [dojox.grid.cells.RowSelector], { formatter: function(data, rowIndex, scope){ //overwrite dojo class scope.toggleRow(rowIndex, !(data == "true")); //bundle selector with hidden attribute. var self = scope; var baseClass = self.baseClass; var checked = self.getValue(rowIndex); var disabled = !!self.disabledMap[rowIndex]; if(checked){ baseClass += self.checkedClass; if(disabled){ baseClass += self.checkedDisabledClass; } }else if(disabled){ baseClass += self.disabledClass; } return ["
", "" + (checked ? self.checkedText : self.unCheckedText) + "", "
"].join(""); }, _toggleCheckedStyle: function(index, value){ this.inherited(arguments); var selector = this._getSelector(index); if(selector){ if (index == -1){ selector.setAttribute("title", this._getHeaderSelectorTooltip()); } } } }); var SingleRowSelector = declare("pd/widgets/grid/cells/pd/widgets/grid/cells/RowSelector", [dojox.grid.cells.SingleRowSelector, RowSelector], {}); var MultipleRowSelector = declare("pd/widgets/grid/cells/MultipleRowSelector", [dojox.grid.cells.MultipleRowSelector, RowSelector], { _selectRow: function(e){ this.inherited(arguments); //scroll to the selected column in preview if (this.grid.selection.selected[e.rowIndex]){ this.grid.pdToggleColumn({ index: e.rowIndex, hidden: false }); } }, _getHeaderSelectorTooltip: function () { // Summary: // Add a tooltip to header selector according to check state. return this.getValue(-1) ? PDMSG.IPT.IDS_IPT_TOOLTIP_EXCLUDE_ALL : PDMSG.IPT.IDS_IPT_TOOLTIP_INCLUDE_ALL; }, _addHeaderSelector: function(){ this.inherited(arguments); var headerCellNode = this.view.getHeaderCellNode(this.index); var divNode = dom.byId(this.grid.id + "_rowSelector_-1"); domAttr.set(divNode, "title", this._getHeaderSelectorTooltip()); domAttr.set(divNode, "role", "button"); } }); var IndirectSelection = declare("pd/widgets/grid/IndirectSelection", [dojox.grid.enhanced.plugins.IndirectSelection], { addRowSelectCell: function(option){ if(!this.grid.indirectSelection || this.grid.selectionMode == 'none'){ return; } var rowSelectCellAdded = false; var inValidFields = ['get', 'formatter', 'fields']; var defaultCellDef = { type: MultipleRowSelector, name: '', width:'30px', styles:'text-align: center;', noresize: true }; if(option.headerSelector){ option.name = ''; } if(this.grid.rowSelectCell){ this.grid.rowSelectCell.destroy(); } array.forEach(this.structure, function(view){ var cells = view.cells; if(cells && cells.length > 0 && !rowSelectCellAdded){ var firstRow = cells[0]; if(firstRow[0] && firstRow[0].isRowSelector){ rowSelectCellAdded = true; return; } var selectDef; var cellType = this.grid.selectionMode == 'single' ? SingleRowSelector : MultipleRowSelector; selectDef = lang.mixin(defaultCellDef, option, { type: cellType, editable: false, notselectable: true, filterable: false, navigatable: true, nosort: true }); array.forEach(inValidFields, function(field){ if(field in selectDef){ delete selectDef[field]; } }); if(cells.length > 1){ selectDef.rowSpan = cells.length; } array.forEach(this.cells, function(cell, i){ if(cell.index >= 0){ cell.index += 1; } }); var rowSelectCell = this.addCellDef(0, 0, selectDef); rowSelectCell.index = 0; firstRow.unshift(rowSelectCell); this.cells.unshift(rowSelectCell); this.grid.rowSelectCell = rowSelectCell; rowSelectCellAdded = true; } }, this); this.cellCount = this.cells.length; } }); EnhancedGrid.registerPlugin(IndirectSelection/*name:'indirectSelection'*/, {"preInit": true}); return IndirectSelection; });