123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /*******************************************************************************
- * 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 ["<div tabindex = -1 ", "id = '" + self.grid.id + "_rowSelector_" + rowIndex + "' ",
- "name = '" + self.grid.id + "_rowSelector' class = '" + baseClass + "' ",
- "role = 'button' aria-pressed = '" + checked + "' aria-disabled = '" + disabled +
- "' aria-label = '" + string.substitute(self.grid._nls["indirectSelection" + self.inputType], [rowIndex + 1]) + "'>",
- "<span class = '" + self.statusTextClass + "'>" + (checked ? self.checkedText : self.unCheckedText) + "</span>",
- "</div>"].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;
- });
|