//>>built
define("dgrid/tree",["dojo/_base/declare","dojo/_base/array","dojo/_base/Deferred","dojo/_base/lang","dojo/has","dojo/query","dojo/on","dojo/aspect","./Grid","dojo/has!touch?./util/touch","put-selector/put"],function(_1,_2,_3,_4,_5,_6,on,_7,_8,_9,_a){_4.getObject("dgrid.tree",true);return (dgrid.tree=function(_b){var _c=_b.renderCell||_8.defaultRenderCell;var _d,_e;if(!_b){_b={};}_b.shouldExpand=_b.shouldExpand||function(_f,_10,_11){return _11;};_7.after(_b,"init",function(){var _12=_b.grid,_13=".dgrid-content .dgrid-column-"+_b.id,_14,_15=[],tr,_16;if(!_12.store){throw new Error("dgrid tree column plugin requires a store to operate.");}if(!_b.renderExpando){_b.renderExpando=function(_17,_18,_19){var dir=this.grid.isRTL?"right":"left",cls=".dgrid-expando-icon",_1a;if(_18){cls+=".ui-icon.ui-icon-triangle-1-"+(_19?"se":"e");}_1a=_a("div"+cls+"[style=margin-"+dir+": "+(_17*(this.indentWidth||9))+"px; float: "+dir+"]");_1a.innerHTML="&nbsp;";return _1a;};}_15.push(_12.on(_b.expandOn||".dgrid-expando-icon:click,"+_13+":dblclick,"+_13+":keydown",function(_1b){var row=_12.row(_1b);if((!_12.store.mayHaveChildren||_12.store.mayHaveChildren(row.data))&&(_1b.type!="keydown"||_1b.keyCode==32)&&!(_1b.type=="dblclick"&&_e&&_e.count>1&&row.id==_e.id&&_1b.target.className.indexOf("dgrid-expando-icon")>-1)){_12.expand(row);}if(_1b.target.className.indexOf("dgrid-expando-icon")>-1){if(_e&&_e.id==_12.row(_1b).id){_e.count++;}else{_e={id:_12.row(_1b).id,count:1};}}}));if(_5("touch")){_15.push(_12.on(_9.selector(_13,_9.dbltap),function(){_12.expand(this);}));}if(!_12._expanded){_12._expanded={};}_15.push(_7.after(_12,"insertRow",function(_1c){var row=this.row(_1c),_1d=_b.shouldExpand(row,_d,this._expanded[row.id]);if(_1d){this.expand(_1c,true,true);}return _1c;}));_15.push(_7.before(_12,"removeRow",function(_1e,_1f){var _20=_1e.connected;if(_20){_6(">.dgrid-row",_20).forEach(function(_21){_12.removeRow(_21,true);});if(!_1f){_a(_20,"!");}}}));if(_b.collapseOnRefresh){_15.push(_7.after(_12,"cleanup",function(){this._expanded={};}));}_12._calcRowHeight=function(_22){var _23=_22.connected;return _22.offsetHeight+(_23?_23.offsetHeight:0);};_12.expand=function(_24,_25,_26){var row=_24.element?_24:_12.row(_24);_24=row.element;_24=_24.className.indexOf("dgrid-expando-icon")>-1?_24:_6(".dgrid-expando-icon",_24)[0];if(_24&&_24.mayHaveChildren){var _27=_25===undefined?!this._expanded[row.id]:_25;_24.className="dgrid-expando-icon ui-icon ui-icon-triangle-1-"+(_27?"se":"e");var _28=_24.preloadNode,_29=row.element,_2a,_2b;if(!_28){_2a=_29.connected=_a("div.dgrid-tree-container");_28=_24.preloadNode=_a(_29,"+",_2a,"div.dgrid-preload");var _2c=function(_2d){return _12.store.getChildren(row.data,_2d);};_2c.level=_24.level;if(_b.allowDuplicates){_2b={parentId:row.id};}_3.when(_12.renderQuery?_12._trackError(function(){return _12.renderQuery(_2c,_28,_2b);}):_12.renderArray(_2c(_2b),_28,{query:_2c}),function(){if(_12._expanded[row.id]){var _2e=_2a.scrollHeight;_2a.style.height=_2e?_2e+"px":"auto";}});var _2f=function(_30){var _31=this.style.height;if(_31){this.style.display=_31=="0px"?"none":"block";}if(_30){_a(this,".dgrid-tree-resetting");setTimeout(function(){_a(_2a,"!dgrid-tree-resetting");});_14=true;}else{if(!_14){_14=false;}}this.style.height="";};on(_2a,"transitionend,webkitTransitionEnd,oTransitionEnd,MSTransitionEnd",_2f);if(!_14){setTimeout(function(){_2f.call(_2a);},600);}}_2a=_29.connected;_2a.hidden=!_27;var _32=_2a.style,_33;if(_14===false||_26){_32.display=_27?"block":"none";_32.height="";}else{if(_27){_32.display="block";_33=_2a.scrollHeight;_32.height="0px";}else{_a(_2a,".dgrid-tree-resetting");_32.height=_2a.scrollHeight+"px";}setTimeout(function(){_a(_2a,"!dgrid-tree-resetting");_32.height=_27?(_33?_33+"px":"auto"):"0px";});}if(_27){this._expanded[row.id]=true;}else{delete this._expanded[row.id];}}};_7.after(_b,"destroy",function(){_2.forEach(_15,function(l){l.remove();});delete _12.expand;delete _12._calcRowHeight;});});_b.renderCell=function(_34,_35,td,_36){var _37=_b.grid,_38=Number(_36&&_36.query&&_36.query.level)+1,_39=!_37.store.mayHaveChildren||_37.store.mayHaveChildren(_34),_3a=_36.parentId,_3b,_3c;_38=_d=isNaN(_38)?0:_38;_3b=_b.renderExpando(_38,_39,_37._expanded[(_3a?_3a+"-":"")+_37.store.getIdentity(_34)]);_3b.level=_38;_3b.mayHaveChildren=_39;_3c=_c.call(_b,_34,_35,td,_36);if(_3c&&_3c.nodeType){_a(td,_3b);_a(td,_3c);}else{td.insertBefore(_3b,td.firstChild);}};return _b;});});