//>>built
define("dojox/grid/TreeGrid","dojo/_base/kernel ../main dojo/_base/declare dojo/_base/array dojo/_base/lang dojo/_base/event dojo/dom-attr dojo/dom-class dojo/query dojo/keys dijit/tree/ForestStoreModel ./DataGrid ./_Layout ./_FocusManager ./_RowManager ./_EditManager ./TreeSelection ./cells/tree ./_TreeView".split(" "),function(y,B,t,r,p,C,m,D,u,E,F,v,G,H,I,J,K,L){y.experimental("dojox.grid.TreeGrid");var M=t("dojox.grid._TreeAggregator",null,{cells:[],grid:null,childFields:[],constructor:function(a){this.cells=
a.cells||[];this.childFields=a.childFields||[];this.grid=a.grid;this.store=this.grid.store},_cacheValue:function(a,b,c){return a[b]=c},clearSubtotalCache:function(){this.store&&delete this.store._cachedAggregates},cnt:function(a,b,c){var d=0,e=this.store,f=this.childFields;f[b]?(c=e.getValues(c,f[b]),a.index<=b+1?d=c.length:r.forEach(c,function(g){d+=this.getForCell(a,b+1,g,"cnt")},this)):d=1;return d},sum:function(a,b,c){var d=0,e=this.store,f=this.childFields;f[b]?r.forEach(e.getValues(c,f[b]),
function(g){d+=this.getForCell(a,b+1,g,"sum")},this):d+=e.getValue(c,a.field);return d},value:function(a,b,c){},getForCell:function(a,b,c,d){var e=this.store;if(!e||!c||!e.isItem(c))return"";var f=e._cachedAggregates=e._cachedAggregates||{},g=e.getIdentity(c);f=f[g]=f[g]||[];a.getOpenState||(a=this.grid.getCell(a.layoutIndex+b+1));g=a.index;f=f[g]=f[g]||{};d=d||(a.parentCell?a.parentCell.aggregate:"sum")||"sum";a.field==e.getLabelAttributes()[0]&&(d="cnt");f=f[d]=f[d]||[];return void 0!=f[b]?f[b]:
(g=(a.parentCell&&a.parentCell.itemAggregates?a.parentCell.itemAggregates[a.idxInParent]:"")||"")&&e.hasAttribute(c,g)?this._cacheValue(f,b,e.getValue(c,g)):g?this._cacheValue(f,b,0):this._cacheValue(f,b,this[d](a,b,c))}});y=t("dojox.grid._TreeLayout",G,{_isCollapsable:!1,_getInternalStructure:function(a){var b=this.grid,c={type:"dojox.grid._TreeView",cells:[[]]},d=[],e=0,f=function(g,h){var q=[];r.forEach(g.children,function(l,k){if("children"in l)d.push(l.field),q[q.length-1].isCollapsable=!0,l.level=
h,q=q.concat(f(l,h+1));else{var w=q,z=w.push,A,x={};for(A in l)x[A]=l[A];x=p.mixin(x,{level:h,idxInParent:0<h?k:-1,parentCell:0<h?g:null});z.call(w,x)}});e=Math.max(e,h);return q};c.cells[0]=f({children:a[0].cells[0],itemAggregates:[]},0);b.aggregator=new M({cells:c.cells[0],grid:b,childFields:d});b.scroller&&b.defaultOpen&&(b.scroller.defaultRowHeight=b.scroller._origDefaultRowHeight*(2*e+1));return[c]},setStructure:function(a){var b=a,c=this.grid;c&&c.treeModel&&!r.every(b,function(d){return"cells"in
d})&&(b=arguments[0]=[{cells:[b]}]);1==b.length&&1==b[0].cells.length&&(c&&c.treeModel?(b[0].type="dojox.grid._TreeView",this._isCollapsable=!0,b[0].cells[0][this.grid.treeModel?this.grid.expandoCell:0].isCollapsable=!0):1===r.filter(b[0].cells[0],function(d){return"children"in d}).length&&(this._isCollapsable=!0));!this._isCollapsable||c&&c.treeModel||(arguments[0]=this._getInternalStructure(b));this.inherited(arguments)},addCellDef:function(a,b,c){var d=this.inherited(arguments);return p.mixin(d,
L)}});var n=t("dojox.grid.TreePath",null,{level:0,_str:"",_arr:null,grid:null,store:null,cell:null,constructor:function(a,b){p.isString(a)?(this._str=a,this._arr=r.map(a.split("/"),function(c){return parseInt(c,10)})):p.isArray(a)?(this._str=a.join("/"),this._arr=a.slice(0)):"number"==typeof a?(this._str=String(a),this._arr=[a]):(this._str=a._str,this._arr=a._arr.slice(0));this.level=this._arr.length-1;this.grid=b;this.store=this.grid.store;this.cell=b.treeModel?b.layout.cells[b.expandoCell]:b.layout.cells[this.level]},
item:function(){this._item||(this._item=this.grid.getItem(this._arr));return this._item},compare:function(a){if(p.isString(a)||p.isArray(a)){if(this._str==a||a.join&&this._str==a.join("/"))return 0;a=new n(a,this.grid)}else if(a instanceof n&&this._str==a._str)return 0;for(var b=0,c=this._arr.length<a._arr.length?this._arr.length:a._arr.length;b<c;b++){if(this._arr[b]<a._arr[b])return-1;if(this._arr[b]>a._arr[b])return 1}return this._arr.length<a._arr.length?-1:this._arr.length>a._arr.length?1:0},
isOpen:function(){return this.cell.openStates&&this.cell.getOpenState(this.item())},previous:function(){var a=this._arr.slice(0);if("0"==this._str)return null;var b=a.length-1;if(0===a[b])return a.pop(),new n(a,this.grid);a[b]--;return(new n(a,this.grid)).lastChild(!0)},next:function(){var a=this._arr.slice(0);if(this.isOpen())a.push(0);else{a[a.length-1]++;for(var b=this.level;0<=b;b--){var c=this.grid.getItem(a.slice(0,b+1));if(0<b)c||(a.pop(),a[b-1]++);else if(!c)return null}}return new n(a,this.grid)},
children:function(a){if(!this.isOpen()&&!a)return null;var b=[];if(a=this.grid.treeModel){var c=this.item(),d=a.store;if(!a.mayHaveChildren(c))return null;r.forEach(a.childrenAttrs,function(h){b=b.concat(d.getValues(c,h))})}else if(b=this.store.getValues(this.item(),this.grid.layout.cells[this.cell.level+1].parentCell.field),1<b.length&&this.grid.sortChildItems&&(a=this.grid.getSortProps())&&a.length){var e=a[0].attribute,f=this.grid;if(e&&b[0][e]){var g=!!a[0].descending;b=b.slice(0);b.sort(function(h,
q){return f._childItemSorter(h,q,e,g)})}}return b},childPaths:function(){var a=this.children();return a?r.map(a,function(b,c){return new n(this._str+"/"+c,this.grid)},this):[]},parent:function(){return 0===this.level?null:new n(this._arr.slice(0,this.level),this.grid)},lastChild:function(a){var b=this.children();if(!b||!b.length)return this;b=new n(this._str+"/"+String(b.length-1),this.grid);return a?b.lastChild(!0):b},toString:function(){return this._str}}),N=t("dojox.grid._TreeFocusManager",H,{setFocusCell:function(a,
b){a&&a.getNode(b)&&this.inherited(arguments)},isLastFocusCell:function(){if(this.cell&&this.cell.index==this.grid.layout.cellCount-1){var a=new n(this.grid.rowCount-1,this.grid);a=a.lastChild(!0);return this.rowIndex==a._str}return!1},next:function(){if(this.cell){var a=this.cell.index+1,b=this.grid.layout.cellCount-1,c=new n(this.rowIndex,this.grid);a>b&&((b=c.next())?(a=0,c=b):a--);if(this.grid.edit.isEditing()&&(b=this.grid.getCell(a),!this.isLastFocusCell()&&!b.editable)){this._focusifyCellNode(!1);
this.cell=b;this.rowIndex=c._str;this.next();return}this.setFocusIndex(c._str,a)}},previous:function(){if(this.cell){var a=(this.cell.index||0)-1,b=new n(this.rowIndex||0,this.grid);if(0>a){var c=b.previous();c?(a=this.grid.layout.cellCount-1,b=c):a=0}if(this.grid.edit.isEditing()&&(c=this.grid.getCell(a),!this.isFirstFocusCell()&&!c.editable)){this._focusifyCellNode(!1);this.cell=c;this.rowIndex=b._str;this.previous();return}this.setFocusIndex(b._str,a)}},move:function(a,b){if(this.isNavHeader())this.inherited(arguments);
else if(this.cell){var c=this.grid.scroller,d=this.rowIndex,e=new n(this.rowIndex,this.grid);if(a)if(0<a){e=e.next();var f=e._arr[0];f>c.getLastPageRow(c.page)&&this.grid.setScrollTop(this.grid.scrollTop+c.findScrollTop(f)-c.findScrollTop(d))}else 0>a&&(e=e.previous(),f=e._arr[0],f<=c.getPageRow(c.page)&&this.grid.setScrollTop(this.grid.scrollTop-c.findScrollTop(d)-c.findScrollTop(f)));c=this.grid.layout.cellCount-1;f=this.cell.index;for(var g=Math.min(c,Math.max(0,f+b)),h=this.grid.getCell(g),q=
0>b?-1:1;0<=g&&g<c&&h&&!0===h.hidden;)g+=q,h=this.grid.getCell(g);h&&!0!==h.hidden||(g=f);a&&this.grid.updateRow(d);this.setFocusIndex(e._str,g)}}});t=t("dojox.grid.TreeGrid",v,{defaultOpen:!0,sortChildItems:!1,openAtLevels:[],treeModel:null,expandoCell:0,aggregator:null,_layoutClass:y,createSelection:function(){this.selection=new K(this)},_childItemSorter:function(a,b,c,d){a=this.store.getValue(a,c);b=this.store.getValue(b,c);return a!=b?a<b==d?1:-1:0},_onNew:function(a,b){if(b&&b.item){var c=this.getItemIndex(b.item);
"string"==typeof c?this.updateRow(c.split("/")[0]):-1<c&&this.updateRow(c)}else this.inherited(arguments)},_onSet:function(a,b,c,d){this._checkUpdateStatus();this.aggregator&&this.aggregator.clearSubtotalCache();a=this.getItemIndex(a);"string"==typeof a?this.updateRow(a.split("/")[0]):-1<a&&this.updateRow(a)},_onDelete:function(a){this._cleanupExpandoCache(this._getItemIndex(a,!0),this.store.getIdentity(a),a);this.inherited(arguments)},_clearData:function(){this.inherited(arguments);this._by_idty_paths=
{}},_cleanupExpandoCache:function(a,b,c){},_addItem:function(a,b,c,d){!d&&this.model&&-1==r.indexOf(this.model.root.children,a)&&(this.model.root.children[b]=a);this.inherited(arguments)},getItem:function(a){var b=p.isArray(a);p.isString(a)&&a.indexOf("/")&&(a=a.split("/"),b=!0);b&&1==a.length&&(a=a[0],b=!1);if(!b)return v.prototype.getItem.call(this,a);b=this.store;var c=v.prototype.getItem.call(this,a[0]),d;if(this.aggregator){var e=this.aggregator.childFields||[];for(d=0;d<a.length-1&&c;d++)c=
e[d]?(b.getValues(c,e[d])||[])[a[d+1]]:null}else if(this.treeModel&&(e=this.treeModel.childrenAttrs||[],c))for(d=1,il=a.length;d<il&&c;d++){var f=0;for(jl=e.length;f<jl&&!(c=e[f]?(b.getValues(c,e[f])||[])[a[d]]:null);f++);}return c||null},_getItemIndex:function(a,b){if(!b&&!this.store.isItem(a))return-1;var c=this.inherited(arguments);return-1==c?(c=this.store.getIdentity(a),this._by_idty_paths[c]||-1):c},postMixInProperties:function(){!this.treeModel||"defaultOpen"in this.params||(this.defaultOpen=
!1);var a=this.defaultOpen;this.openAtLevels=r.map(this.openAtLevels,function(b){if("string"==typeof b)switch(b.toLowerCase()){case "true":return!0;case "false":return!1;default:return b=parseInt(b,10),isNaN(b)?a:b}return b});this._by_idty_paths={};this.inherited(arguments)},postCreate:function(){this.inherited(arguments);this.treeModel&&this._setModel(this.treeModel)},setModel:function(a){this._setModel(a);this._refresh(!0)},_setModel:function(a){if(a&&!(F&&a instanceof F))throw Error("dojox.grid.TreeGrid: treeModel must be an instance of dijit.tree.ForestStoreModel");
this.treeModel=a;D.toggle(this.domNode,"dojoxGridTreeModel",this.treeModel?!0:!1);this._setQuery(a?a.query:null);this._setStore(a?a.store:null)},createScroller:function(){this.inherited(arguments);this.scroller._origDefaultRowHeight=this.scroller.defaultRowHeight},createManagers:function(){this.rows=new I(this);this.focus=new N(this);this.edit=new J(this)},_setStore:function(a){this.inherited(arguments);this.treeModel&&!this.treeModel.root.children&&(this.treeModel.root.children=[]);this.aggregator&&
(this.aggregator.store=a)},getDefaultOpenState:function(a,b){var c,d=this.store;if(this.treeModel||!(a&&d&&d.isItem(b)&&(c=this.aggregator.childFields[a.level])))return this.defaultOpen;if(this.openAtLevels.length>a.level){var e=this.openAtLevels[a.level];if("boolean"==typeof e)return e;if("number"==typeof e)return d.getValues(b,c).length<=e}return this.defaultOpen},onStyleRow:function(a){if(this.layout._isCollapsable){var b=m.get(a.node,"dojoxTreeGridBaseClasses");b&&(a.customClasses=b);b=a;var c=
b.node.tagName.toLowerCase();b.customClasses+=(b.odd?" dojoxGridRowOdd":"")+(b.selected&&"tr"==c?" dojoxGridRowSelected":"")+(b.over&&"tr"==c?" dojoxGridRowOver":"");this.focus.styleRow(b);this.edit.styleRow(b)}else this.inherited(arguments)},styleRowNode:function(a,b){b&&("div"==b.tagName.toLowerCase()&&this.aggregator&&u("tr[dojoxTreeGridPath]",b).forEach(function(c){this.rows.styleRowNode(m.get(c,"dojoxTreeGridPath"),c)},this),this.rows.styleRowNode(a,b))},onCanSelect:function(a){var b=u("tr[dojoxTreeGridPath\x3d'"+
a+"']",this.domNode);return b.length&&D.contains(b[0],"dojoxGridSummaryRow")?!1:this.inherited(arguments)},onKeyDown:function(a){if(!a.altKey&&!a.metaKey)switch(a.keyCode){case E.UP_ARROW:this.edit.isEditing()||"0"==this.focus.rowIndex||(C.stop(a),this.focus.move(-1,0));break;case E.DOWN_ARROW:var b=new n(this.focus.rowIndex,this),c=new n(this.rowCount-1,this);c=c.lastChild(!0);this.edit.isEditing()||b.toString()==c.toString()||(C.stop(a),this.focus.move(1,0));break;default:this.inherited(arguments)}},
canEdit:function(a,b){return a.getNode(b)&&this._canEdit},doApplyCellEdit:function(a,b,c){var d=this.getItem(b),e=this.store.getValue(d,c);"number"==typeof e?a=isNaN(a)?a:parseFloat(a):"boolean"==typeof e?a="true"==a?!0:"false"==a?!1:a:e instanceof Date&&(e=new Date(a),a=isNaN(e.getTime())?a:e);this.store.setValue(d,c,a);this.onApplyCellEdit(a,b,c)}});t.markupFactory=function(a,b,c,d){var e=function(h){h=m.get(h,"width")||"auto";"auto"!=h&&"em"!=h.slice(-2)&&"%"!=h.slice(-1)&&(h=parseInt(h,10)+"px");
return h},f=function(h){var q;return"table"==h.nodeName.toLowerCase()&&0===u("\x3e colgroup",h).length&&1==(q=u("\x3e thead \x3e tr",h)).length?u("\x3e th",q[0]).map(function(l){var k={type:p.trim(m.get(l,"cellType")||""),field:p.trim(m.get(l,"field")||"")};k.type&&(k.type=p.getObject(k.type));var w=u("\x3e table",l)[0];w?(k.name="",k.children=f(w),m.has(l,"itemAggregates")?k.itemAggregates=r.map(m.get(l,"itemAggregates").split(","),function(z){return p.trim(z)}):k.itemAggregates=[],m.has(l,"aggregate")&&
(k.aggregate=m.get(l,"aggregate")),k.type=k.type||B.grid.cells.SubtableCell):(k.name=p.trim(m.get(l,"name")||l.innerHTML),m.has(l,"width")&&(k.width=e(l)),m.has(l,"relWidth")&&(k.relWidth=window.parseInt(m.get(l,"relWidth"),10)),m.has(l,"hidden")&&(k.hidden="true"==m.get(l,"hidden")),k.field=k.field||k.name,v.cell_markupFactory(d,l,k),k.type=k.type||B.grid.cells.Cell);k.type&&k.type.markupFactory&&k.type.markupFactory(l,k);return k}):[]};if(!a.structure){var g=f(b);g.length&&(a.structure=[{__span:Infinity,
cells:[g]}])}return v.markupFactory(a,b,c,d)};return t});