//>>built
define("dojox/grid/enhanced/plugins/NestedSorting","dojo/_base/declare,dojo/_base/array,dojo/_base/connect,dojo/_base/lang,dojo/_base/html,dojo/_base/event,dojo/_base/window,dojo/keys,dojo/query,dojo/string,../_Plugin,../../EnhancedGrid".split(","),function(o,m,r,j,c,n,p,q,i,l,s,t){o=o("dojox.grid.enhanced.plugins.NestedSorting",s,{name:"nestedSorting",_currMainSort:"none",_currRegionIdx:-1,_a11yText:{dojoxGridDescending:"&#9662;",dojoxGridAscending:"&#9652;",dojoxGridAscendingTip:"&#1784;",dojoxGridDescendingTip:"&#1783;",
dojoxGridUnsortedTip:"x"},constructor:function(){this._sortDef=[];this._sortData={};this._headerNodes={};this._excludedColIdx=[];this.nls=this.grid._nls;this.grid.setSortInfo=function(){};this.grid.setSortIndex=j.hitch(this,"_setGridSortIndex");this.grid.getSortIndex=function(){};this.grid.getSortProps=j.hitch(this,"getSortProps");this.grid.sortFields&&this._setGridSortIndex(this.grid.sortFields,null,!0);this.connect(this.grid.views,"render","_initSort");this.initCookieHandler();this.grid.plugin("rearrange")?
this.subscribe("dojox/grid/rearrange/move/"+this.grid.id,j.hitch(this,"_onColumnDnD")):this.connect(this.grid.layout,"moveColumn","_onMoveColumn")},onStartUp:function(){this.inherited(arguments);this.connect(this.grid,"onHeaderCellClick","_onHeaderCellClick");this.connect(this.grid,"onHeaderCellMouseOver","_onHeaderCellMouseOver");this.connect(this.grid,"onHeaderCellMouseOut","_onHeaderCellMouseOut")},_onMoveColumn:function(a,b,f,d,c){var h=this._getCurrentRegion(),k=this._headerNodes[h&&this._getRegionHeader(h).getAttribute("idx")],
a=this._sortData,b={},g;if(h)this._blurRegion(h),this._currRegionIdx=m.indexOf(this._getRegions(),k.firstChild);if(d<f)for(g in a)g=parseInt(g,10),(c=a[g])&&(g>=d&&g<f?b[g+1]=c:g==f?b[d]=c:b[g]=c);else if(d>f+1)for(g in c||d++,a)g=parseInt(g,10),(c=a[g])&&(g>f&&g<d?b[g-1]=c:g==f?b[d-1]=c:b[g]=c);this._sortData=b;this._initSort(!1)},_onColumnDnD:function(a,b){if("col"===a){var c={},d=this._sortData,e,h=this._getCurrentRegion();this._blurRegion(h);h=this._getRegionHeader(h).getAttribute("idx");for(e in b)d[e]&&
(c[b[e]]=d[e],delete d[e]),e===h&&(h=b[e]);for(e in c)d[e]=c[e];c=this._headerNodes[h];this._currRegionIdx=m.indexOf(this._getRegions(),c.firstChild);this._initSort(!1)}},_setGridSortIndex:function(a,b,c){if(j.isArray(a)){for(var d,e,b=0;b<a.length;b++)if(d=a[b],e=this.grid.getCellByField(d.attribute),!e||e.nosort||!this.grid.canSort(e.index,e.field))return;this.clearSort();m.forEach(a,function(a,b){e=this.grid.getCellByField(a.attribute);this.setSortData(e.index,"index",b);this.setSortData(e.index,
"order",a.descending?"desc":"asc")},this)}else{if(isNaN(a)||void 0===b)return;this.setSortData(a,"order",b?"asc":"desc")}this._updateSortDef();c||this.grid.sort()},getSortProps:function(){return this._sortDef.length?this._sortDef:null},_initSort:function(a){var b=this.grid,f=b.domNode,d=this._sortDef.length;c.toggleClass(f,"dojoxGridSorted",!!d);c.toggleClass(f,"dojoxGridSingleSorted",1===d);c.toggleClass(f,"dojoxGridNestSorted",1<d);if(0<d)this._currMainSort=this._sortDef[0].descending?"desc":"asc";
var e,h=this._excludedCoIdx=[];this._headerNodes=i("th",b.viewsHeaderNode).forEach(function(a){e=parseInt(a.getAttribute("idx"),10);("none"===c.style(a,"display")||b.layout.cells[e].nosort||b.canSort&&!b.canSort(e,b.layout.cells[e].field))&&h.push(e)});this._headerNodes.forEach(this._initHeaderNode,this);this._initFocus();a&&this._focusHeader()},_initHeaderNode:function(a){c.toggleClass(a,"dojoxGridSortNoWrap",!0);var b=i(".dojoxGridSortNode",a)[0];b&&c.toggleClass(b,"dojoxGridSortNoWrap",!0);if(0<=
m.indexOf(this._excludedCoIdx,a.getAttribute("idx")))c.addClass(a,"dojoxGridNoSort");else{if(i(".dojoxGridSortBtn",a).length){var b=i(".dojoxGridSortBtnSingle",a)[0],f=i(".dojoxGridSortBtnNested",a)[0];b.className="dojoxGridSortBtn dojoxGridSortBtnSingle";f.className="dojoxGridSortBtn dojoxGridSortBtnNested";f.innerHTML="1";c.removeClass(a,"dojoxGridCellShowIndex");c.removeClass(a.firstChild,"dojoxGridSortNodeSorted");c.removeClass(a.firstChild,"dojoxGridSortNodeAsc");c.removeClass(a.firstChild,"dojoxGridSortNodeDesc");
c.removeClass(a.firstChild,"dojoxGridSortNodeMain");c.removeClass(a.firstChild,"dojoxGridSortNodeSub")}else this._connects=m.filter(this._connects,function(a){return a._sort?(r.disconnect(a),!1):!0}),b=c.create("a",{className:"dojoxGridSortBtn dojoxGridSortBtnNested",title:l.substitute(this.nls.sortingState,[this.nls.nestedSort,this.nls.ascending]),innerHTML:"1"},a.firstChild,"last"),b.onmousedown=n.stop,b=c.create("a",{className:"dojoxGridSortBtn dojoxGridSortBtnSingle",title:l.substitute(this.nls.sortingState,
[this.nls.singleSort,this.nls.ascending])},a.firstChild,"last"),b.onmousedown=n.stop;this._updateHeaderNodeUI(a)}},_onHeaderCellClick:function(a){this._focusRegion(a.target);c.hasClass(a.target,"dojoxGridSortBtn")&&(this._onSortBtnClick(a),n.stop(a),this._focusRegion(this._getCurrentRegion()))},_onHeaderCellMouseOver:function(a){if(a.cell&&!(1<this._sortDef.length)&&!(this._sortData[a.cellIndex]&&0===this._sortData[a.cellIndex].index)){for(var b in this._sortData)if(this._sortData[b]&&0===this._sortData[b].index){c.addClass(this._headerNodes[b],
"dojoxGridCellShowIndex");break}if(c.hasClass(p.body(),"dijit_a11y")){b=a.cell.index;var f=a.cellNode,a=i(".dojoxGridSortBtnSingle",f)[0],f=i(".dojoxGridSortBtnNested",f)[0];c.hasClass(this.grid.domNode,"dojoxGridSingleSorted")||c.hasClass(this.grid.domNode,"dojoxGridNestSorted");var d=f.getAttribute("orderIndex");if(null===d||void 0===d)f.setAttribute("orderIndex",f.innerHTML),d=f.innerHTML;f.innerHTML=this.isAsc(b)?d+this._a11yText.dojoxGridDescending:this.isDesc(b)?d+this._a11yText.dojoxGridUnsortedTip:
d+this._a11yText.dojoxGridAscending;if("none"===this._currMainSort)a.innerHTML=this._a11yText.dojoxGridAscending;else if("asc"===this._currMainSort)a.innerHTML=this._a11yText.dojoxGridDescending;else if("desc"===this._currMainSort)a.innerHTML=this._a11yText.dojoxGridUnsortedTip}}},_onHeaderCellMouseOut:function(){for(var a in this._sortData)if(this._sortData[a]&&0===this._sortData[a].index){c.removeClass(this._headerNodes[a],"dojoxGridCellShowIndex");break}},_onSortBtnClick:function(a){var b=a.cell.index;
if(c.hasClass(a.target,"dojoxGridSortBtnSingle"))this._prepareSingleSort(b);else if(c.hasClass(a.target,"dojoxGridSortBtnNested"))this._prepareNestedSort(b);else return;n.stop(a);this._doSort(b)},_doSort:function(a){!this._sortData[a]||!this._sortData[a].order?this.setSortData(a,"order","asc"):this.isAsc(a)?this.setSortData(a,"order","desc"):this.isDesc(a)&&this.removeSortData(a);this._updateSortDef();this.grid.sort();this._initSort(!0)},setSortData:function(a,b,c){var d=this._sortData[a];d||(d=this._sortData[a]=
{});d[b]=c},removeSortData:function(a){var b=this._sortData,c=b[a].index,d;delete b[a];for(d in b)b[d].index>c&&b[d].index--},_prepareSingleSort:function(a){var b=this._sortData,c;for(c in b)delete b[c];this.setSortData(a,"index",0);this.setSortData(a,"order","none"===this._currMainSort?null:this._currMainSort);if(!this._sortData[a]||!this._sortData[a].order)this._currMainSort="asc";else if(this.isAsc(a))this._currMainSort="desc";else if(this.isDesc(a))this._currMainSort="none"},_prepareNestedSort:function(a){var b=
this._sortData[a]?this._sortData[a].index:null;0===b||b||this.setSortData(a,"index",this._sortDef.length)},_updateSortDef:function(){this._sortDef.length=0;var a=this._sortData,b;for(b in a)this._sortDef[a[b].index]={attribute:this.grid.layout.cells[b].field,descending:"desc"===a[b].order}},_updateHeaderNodeUI:function(a){var b=this._getCellByNode(a),f=b.index,d=this._sortData[f],e=i(".dojoxGridSortNode",a)[0],h=i(".dojoxGridSortBtnSingle",a)[0],k=i(".dojoxGridSortBtnNested",a)[0];c.toggleClass(h,
"dojoxGridSortBtnAsc","asc"===this._currMainSort);c.toggleClass(h,"dojoxGridSortBtnDesc","desc"===this._currMainSort);h.title="asc"===this._currMainSort?l.substitute(this.nls.sortingState,[this.nls.singleSort,this.nls.descending]):"desc"===this._currMainSort?l.substitute(this.nls.sortingState,[this.nls.singleSort,this.nls.unsorted]):l.substitute(this.nls.sortingState,[this.nls.singleSort,this.nls.ascending]);var g=this;(function(){var a="Column "+(b.index+1)+" "+b.field,c="none",e="ascending";d&&
(c="asc"===d.order?"ascending":"descending",e="asc"===d.order?"descending":"none");var f=a+" - is sorted by "+c,i=a+" - is nested sorted by "+c,j=a+" - choose to sort by "+e,l=a+" - choose to nested sort by "+e;h.setAttribute("aria-label",f);k.setAttribute("aria-label",i);a=[g.connect(h,"onmouseover",function(){h.setAttribute("aria-label",j)}),g.connect(h,"onmouseout",function(){h.setAttribute("aria-label",f)}),g.connect(k,"onmouseover",function(){k.setAttribute("aria-label",l)}),g.connect(k,"onmouseout",
function(){k.setAttribute("aria-label",i)})];m.forEach(a,function(a){a._sort=!0})})();a=c.hasClass(p.body(),"dijit_a11y");if(d){if(d.index||0===d.index&&1<this._sortDef.length)k.innerHTML=d.index+1;c.addClass(e,"dojoxGridSortNodeSorted");if(this.isAsc(f)){if(c.addClass(e,"dojoxGridSortNodeAsc"),k.title=l.substitute(this.nls.sortingState,[this.nls.nestedSort,this.nls.descending]),a)e.innerHTML=this._a11yText.dojoxGridAscendingTip}else if(this.isDesc(f)&&(c.addClass(e,"dojoxGridSortNodeDesc"),k.title=
l.substitute(this.nls.sortingState,[this.nls.nestedSort,this.nls.unsorted]),a))e.innerHTML=this._a11yText.dojoxGridDescendingTip;c.addClass(e,0===d.index?"dojoxGridSortNodeMain":"dojoxGridSortNodeSub")}else if(k.innerHTML=this._sortDef.length+1,k.title=l.substitute(this.nls.sortingState,[this.nls.nestedSort,this.nls.ascending]),a)e.innerHTML=this._a11yText.dojoxGridUnsortedTip},isAsc:function(a){return"asc"===this._sortData[a].order},isDesc:function(a){return"desc"===this._sortData[a].order},_getCellByNode:function(a){var b;
for(b=0;b<this._headerNodes.length;b++)if(this._headerNodes[b]===a)return this.grid.layout.cells[b];return null},clearSort:function(){this._sortData={};this._sortDef.length=0},initCookieHandler:function(){this.grid.addCookieHandler&&this.grid.addCookieHandler({name:"sortOrder",onLoad:j.hitch(this,"_loadNestedSortingProps"),onSave:j.hitch(this,"_saveNestedSortingProps")})},_loadNestedSortingProps:function(a){this._setGridSortIndex(a)},_saveNestedSortingProps:function(){return this.getSortProps()},
_initFocus:function(){var a=this.focus=this.grid.focus;this._focusRegions=this._getRegions();if(!this._headerArea){var b=this._headerArea=a.getArea("header");b.onFocus=a.focusHeader=j.hitch(this,"_focusHeader");b.onBlur=a.blurHeader=a._blurHeader=j.hitch(this,"_blurHeader");b.onMove=j.hitch(this,"_onMove");b.onKeyDown=j.hitch(this,"_onKeyDown");b._regions=[];b.getRegions=null;this.connect(this.grid,"onBlur","_blurHeader")}},_focusHeader:function(a){-1===this._currRegionIdx?this._onMove(0,1,null):
this._focusRegion(this._getCurrentRegion());try{a&&n.stop(a)}catch(b){}return!0},_blurHeader:function(){this._blurRegion(this._getCurrentRegion());return!0},_onMove:function(a,b,f){var d=this._focusRegions[(this._currRegionIdx||0)+b];if(d)"none"===c.style(d,"display")||"hidden"===c.style(d,"visibility")?this._onMove(a,b+(0<b?1:-1),f):(this._focusRegion(d),a=this._getRegionView(d),a.scrollboxNode.scrollLeft=a.headerNode.scrollLeft)},_onKeyDown:function(a,b){if(b)switch(a.keyCode){case q.ENTER:case q.SPACE:(c.hasClass(a.target,
"dojoxGridSortBtnSingle")||c.hasClass(a.target,"dojoxGridSortBtnNested"))&&this._onSortBtnClick(a)}},_getRegionView:function(a){for(var b=a;b&&!c.hasClass(b,"dojoxGridHeader");)b=b.parentNode;return b?m.filter(this.grid.views.views,function(a){return a.headerNode===b})[0]||null:null},_getRegions:function(){var a=[],b=this.grid.layout.cells;this._headerNodes.forEach(function(f,d){"none"!==c.style(f,"display")&&(b[d].isRowSelector?a.push(f):i(".dojoxGridSortNode,.dojoxGridSortBtnNested,.dojoxGridSortBtnSingle",
f).forEach(function(b){b.setAttribute("tabindex",0);a.push(b)}))},this);return a},_focusRegion:function(a){if(a){var b=this._getCurrentRegion();b&&a!==b&&this._blurRegion(b);b=this._getRegionHeader(a);c.addClass(b,"dojoxGridCellSortFocus");c.hasClass(a,"dojoxGridSortNode")?c.addClass(a,"dojoxGridSortNodeFocus"):c.hasClass(a,"dojoxGridSortBtn")&&c.addClass(a,"dojoxGridSortBtnFocus");try{a.focus()}catch(f){}this.focus.currentArea("header");this._currRegionIdx=m.indexOf(this._focusRegions,a)}},_blurRegion:function(a){if(a){var b=
this._getRegionHeader(a);c.removeClass(b,"dojoxGridCellSortFocus");c.hasClass(a,"dojoxGridSortNode")?c.removeClass(a,"dojoxGridSortNodeFocus"):c.hasClass(a,"dojoxGridSortBtn")&&c.removeClass(a,"dojoxGridSortBtnFocus");a.blur()}},_getCurrentRegion:function(){return this._focusRegions?this._focusRegions[this._currRegionIdx]:null},_getRegionHeader:function(a){for(;a&&!c.hasClass(a,"dojoxGridCell");)a=a.parentNode;return a},destroy:function(){this._headerNodes=this._focusRegions=this._sortDef=this._sortData=
null;this.inherited(arguments)}});t.registerPlugin(o);return o});