Selector.js
2.95 KB
//>>built
define("dojo/_base/declare dojo/_base/lang dojo/_base/sniff dojo/dom-construct dojo/dom-class ./Selection".split(" "),function(k,h,l,m,n,p){return k(p,{postCreate:function(){this.inherited(arguments);this.on(".dgrid-selector:click,.dgrid-selector:keydown",h.hitch(this,"_handleSelectorClick"));this.on("dgrid-select",h.hitch(this,"_changeSelectorInput",!0));this.on("dgrid-deselect",h.hitch(this,"_changeSelectorInput",!1))},_defaultRenderSelectorInput:function(a,b,c,g){var e=a.grid;n.add(c,"dgrid-selector");
return c.input=m.create("input",{"aria-checked":b,checked:b,disabled:!e.allowSelect(e.row(g)),tabIndex:isNaN(a.tabIndex)?-1:a.tabIndex,type:a.selector},c)},_configureSelectorColumn:function(a){var b=this,c=a.selector;this._selectorColumns.push(a);this._selectorSingleRow=this._selectorSingleRow||"radio"===a.selector;var g="function"===typeof c?c:this._defaultRenderSelectorInput;a.sortable=!1;a.renderCell=function(c,d,f){d=(d=c&&b.row(c))&&b.selection[d.id];g(a,!!d,f,c)};a.renderHeaderCell=function(c){var d=
"label"in a?a.label:a.field||"";"radio"!==a.selector&&b.allowSelectAll?(a._selectorHeaderCheckbox=g(a,!1,c,{}),b._hasSelectorHeaderCheckbox=!0):c.appendChild(document.createTextNode(d))}},_handleSelectorClick:function(a){if("INPUT"!==a.target.nodeName||"keydown"!==a.type||32!==a.keyCode){var b=this.cell(a).row;if("click"===a.type||32===a.keyCode||!l("opera")&&13===a.keyCode||0===a.keyCode){this._selectionTriggerEvent=a;if(b){if(this.allowSelect(b)){var c=this._lastSelected&&this.row(this._lastSelected);
this._selectorSingleRow?c&&c.id===b.id||(this.clearSelection(),this.select(b,null,!0),this._lastSelected=b.element):b&&(a.shiftKey?this._changeSelectorInput(!0,{rows:[b]}):c=null,c=a.shiftKey?c:null,this.select(c||b,b,c?void 0:null),this._lastSelected=b.element)}}else this[this.allSelected?"clearSelection":"selectAll"]();this._selectionTriggerEvent=null}}},_changeSelectorInput:function(a,b){this._selectorColumns.length&&this._updateRowSelectors(a,b);this._hasSelectorHeaderCheckbox&&this._updateHeaderCheckboxes()},
_updateRowSelectors:function(a,b){b=b.rows;for(var c=b.length,g=this._selectorColumns.length,e=0;e<c;e++)for(var d=0;d<g;d++){var f=this.cell(b[e],this._selectorColumns[d].id).element;f&&(f=(f.contents||f).input)&&!f.disabled&&(f.checked=a,f.setAttribute("aria-checked",a))}},_updateHeaderCheckboxes:function(){for(var a=this._selectorColumns.length,b=0;b<a;b++){var c="false",g,e,d=this._selectorColumns[b]._selectorHeaderCheckbox;if(d){g=this.selection;e=!1;for(var f in g)if(g[f]!=this.allSelected){e=
!0;break}d.indeterminate=e;d.checked=this.allSelected;e?c="mixed":this.allSelected&&(c="true");d.setAttribute("aria-checked",c)}}},configStructure:function(){this.inherited(arguments);var a=this.columns;this._selectorColumns=[];this._hasSelectorHeaderCheckbox=this._selectorSingleRow=!1;for(var b in a)a[b].selector&&this._configureSelectorColumn(a[b])},_handleSelect:function(a){var b=this.cell(a).column;b&&b.selector||this.inherited(arguments)}})});