// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
require({cache:{"url:widgets/BusinessAnalyst/esriAnalystX/widgets/SelectableTreeGrid/templates/SelectableTreeGrid.html":'\x3cdiv class\x3d"esriMapsAnalystXNonSelectable"\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"gridContainer"\x3e\x3c/div\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"selectionCounter" class\x3d"esriMapsAnalystXSelectableTreeCounter"\x3e\x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare dojo/aspect dojo/Evented dojo/dom-class dojo/dom-construct dojo/dom-style dojo/on dojo/query dijit/Tooltip dijit/_WidgetBase ../../dijit/_TemplatedMixin dgrid/OnDemandGrid dgrid/tree esri/dijit/geoenrichment/utils/KeyboardUtil esri/dijit/geoenrichment/TriStateItem ../../dijit/utils/DgridUtil ../../dijit/utils/DomUtil ../../dijit/utils/MouseUtil ../../dijit/tooltips/TooltipUtil dojo/text!./templates/SelectableTreeGrid.html xstyle/css!./css/SelectableTreeGrid.css".split(" "),function(r,
p,w,h,t,u,m,x,v,y,z,A,B,C,D,E,n,F,G,H){var J=r(null,{_selectedRowInfos:null,_lastSelectedRowInfo:null,_outsideHandler:null,_isSelectionFrozen:!1,keepSelectionOnOutsideClick:!1,_previouslySelectedRowsByNode:null,constructor:function(){this._previouslySelectedRowsByNode=new WeakMap},buildRendering:function I(){this._selectedRowInfos={};this.inherited(I,arguments)},postCreate:function e(){this.inherited(e,arguments);h.add(this.domNode,"esriMapsAnalystXNonSelectable")},_reselectSingleNode:function(e){this.selectSingleRow(this._previouslySelectedRowsByNode.get(e),
e)},selectSingleRow:function(e,a){this.unselectAllRows();this._selectRow(e,a)},_selectRow:function(e,a){h.add(e,this.selectedRowClass);h.add(e,"row-level-"+this._getNodeLevel(a));var b=this.tree.getIdentity(a),c={row:e,node:a,nodeId:b,index:a.parent&&a.parent.children.indexOf(a)};this._lastSelectedRowInfo=this._selectedRowInfos[b]=c;this._previouslySelectedRowsByNode.set(a,e);var d=this;this._outsideHandler=this._outsideHandler||m(document.body,"click",function(){F.isMouseOver(d.domNode)||d._isSelectionFrozen||
d.keepSelectionOnOutsideClick||d.unselectAllRows()})},_unselectRow:function(e,a){delete this._selectedRowInfos[this.tree.getIdentity(a)];h.remove(e,this.selectedRowClass)},unselectAllRows:function(){for(var e in this._selectedRowInfos)h.remove(this._selectedRowInfos[e].row,this.selectedRowClass);this._selectedRowInfos={};this._lastSelectedRowInfo=null;this._outsideHandler&&this._outsideHandler.remove();this._outsideHandler=null},getSelectedRowNodes:function(){return this._getSelectedNodesRows().nodes},
selectRowNodes:function(e){var a=this;e&&e.forEach(function(b){var c=a.grid.row(b);c&&c.element&&a._selectRow(c.element,b)})},freezeRowSelection:function(){this._isSelectionFrozen=!0},unfreezeRowSelection:function(){this._isSelectionFrozen=!1},_getSelectedNodesRows:function(){var e=[],a=[],b=[],c;for(c in this._selectedRowInfos)b.push(this._selectedRowInfos[c]);b.sort(function(d,f){return d.index-f.index});b.forEach(function(d){e.push(d.node);a.push(d.row)});return{nodes:e,rows:a}},_emitSelectedRowsEvent:function(){var e=
this._getSelectedNodesRows();if(e.nodes.length)this.onRowsSelected(e.nodes,e.rows)}});return r([y,z,w,J],{templateString:H,tree:null,grid:null,gridClass:"",highlightSelected:!0,firstColumns:null,additionalColumns:null,showRootCheckbox:!0,showCheckboxColumn:!0,showHeader:!0,labelColumnField:"label",gridParams:null,keepContentUnderScroll:void 0,hideInvisibleExpandoIcons:!1,expandOnNodeClick:!1,checkLimit:0,checkLimitMessage:null,checkLimitMessageTimeout:5E3,handleMultipleCheck:!1,enableRowSelection:!1,
enableMultipleRowSelection:!1,allowSelectionFromManyParents:!1,selectedRowFilter:null,selectedRowClass:"row-selected",enableHeaderLabelToggleClick:!0,defaultExpand:null,fitParentSize:!1,renderAllRows:!1,rowPostProcessor:null,_rootCheckbox:null,_checkboxes:null,_lastCheckedNode:null,updateSelectionCountDiv:function(e,a){},getLabel:function(e,a){return e.label},postCreate:function a(){this.inherited(a,arguments);this._createGrid()},resize:function(){this.grid.resize();this._updateCheckboxState(this._rootCheckbox);
for(var a in this._checkboxes)this._updateCheckboxState(this._checkboxes[a]);this._emitSelectionChanged()},setWidth:function(a){this.grid&&this.grid.domNode&&u.set(this.grid.domNode,"width",a+"px")},setHeight:function(a){this.grid&&this.grid.domNode&&u.set(this.grid.domNode,"height",a+"px")},row:function(a){return this.grid.row(a)},cell:function(a){return this.grid.cell(a)},_labelColumn:null,_createGrid:function(){var a=this;this._checkboxes={};var b={label:this.getLabel(this.tree.root,!0),sortable:!1,
field:this.labelColumnField,renderCell:this._renderLabel.bind(this),renderHeaderCell:this._renderLabelHeader.bind(this,this.tree.root)},c;if(this.additionalColumns&&this.additionalColumns.length&&(c=this.additionalColumns.filter(function(f){return f.field===a.labelColumnField})[0])){for(var d in b)void 0===c[d]&&(c[d]=b[d]);b=c}b.indentWidth=b.indentWidth||16;this._labelColumn=b=this._prepareTreeColumn(b);d=[];this.firstColumns&&(d=d.concat(this.firstColumns));this.showCheckboxColumn&&d.push({label:"",
field:"checkbox",sortable:!1,renderCell:this._renderCheckboxForColumn.bind(this),renderHeaderCell:this._renderCheckboxForColumn.bind(this,this.tree.root)});c||d.push(b);this.additionalColumns&&(d=d.concat(this.additionalColumns));b=["esriMapsAnalystXSelectableTreeGrid"];this.gridClass&&b.push(this.gridClass);this.fitParentSize&&b.push("fitParentSize");b=Object.assign({class:b.join(" "),keepScrollPosition:!0,store:this.tree,columns:d},this.gridParams);this.grid=this._createGridObject(b,this.gridContainer);
this.own(this.grid);this.grid._expanded=this.defaultExpand||this.grid._expanded||{};E.oddEvenFix(this.grid);this.own(m(this.tree,"updated",this._onStoreUpdated.bind(this)));this._addKeepScrollHandlers();this._addGridHandlers();this.renderAllRows&&(this.grid.minRowsPerPage=1E4,this.grid.maxRowsPerPage=10250);this.grid.startup();G.autoTooltip(this.domNode);this.showHeader||h.add(this.domNode,"esriMapsAnalystXGridNoHeader");m(this.grid.domNode,".dgrid-expando-icon:click,.dgrid-content .dgrid-column-labelColumn:dblclick,.dgrid-content .dgrid-column-labelColumn:keydown",
function(f){(f=a.grid.row(f))&&a.onExpandChangedUser(f.data)})},_createGridObject:function(a,b){return new A(a,b)},onRowInserted:function(a,b){},_addGridHandlers:function(){function a(c,d){b.enableRowSelection&&d.parent&&(!b.selectedRowFilter||b.selectedRowFilter(d))&&(h.add(c,"esriMapsAnalystXClickable"),m(c,"click",function(f){setTimeout(function(){if(!b._isSelectionFrozen){if(f.shiftKey&&b.enableMultipleRowSelection){if(b._lastSelectedRowInfo&&b._lastSelectedRowInfo.row.parentNode&&b._lastSelectedRowInfo.node.parent===
d.parent){var l=n.getChildIndex(b._lastSelectedRowInfo.row.parentNode,b._lastSelectedRowInfo.row),g=n.getChildIndex(c.parentNode,c),k=l<=g?b._lastSelectedRowInfo.row:c;l=l<=g?c:b._lastSelectedRowInfo.row;g=k;if(k.id!==l.id){do{k=b.grid.row(g).data;b._selectRow(g,k);if(g.id===l.id)break;g=g.nextSibling}while(g)}}else b.selectSingleRow(c,d);n.stealFocus()}else C.isCtrl(f)&&b.enableMultipleRowSelection?b._lastSelectedRowInfo&&b._lastSelectedRowInfo.row.parentNode&&b._lastSelectedRowInfo.node.parent===
d.parent||b.allowSelectionFromManyParents?b._selectedRowInfos[d.id]?b._unselectRow(c,d):b._selectRow(c,d):b.selectSingleRow(c,d):b.selectSingleRow(c,d);b._emitSelectedRowsEvent()}})}))}var b=this;this.own(p.after(this.grid,"insertRow",function(c){var d=c&&b.grid._rowIdToObject[c.id];if(c){if(d&&b.hideInvisibleExpandoIcons&&(!d.children||!d.children.length)){var f=x(".dgrid-expando-icon",c)[0];f&&(f.style.width="0")}n[d&&!1===d.visible?"hide":"show"](c);a(c,d)}d&&(b._updateRowHighlighting(d,c),b.onRowInserted(c,
d));b.rowPostProcessor&&b.rowPostProcessor(c,d);return c}))},_addKeepScrollHandlers:function(){function a(c){if(!b.grid.contentNode)return c;if(b.fitParentSize){var d=n.hasScrollbars(b.grid.bodyNode);b.grid.headerNode.style[b.isLeftToRight()?"right":"left"]=d.w?"":"0px";b._lastContentWidth=b.grid.contentNode.style.width||b._lastContentWidth||"";b.grid.contentNode.style.width=d.h?b._lastContentWidth:""}else b.keepContentUnderScroll?b.grid.contentNode.style.width=b.grid.headerNode.firstChild.offsetWidth+
"px":!1===b.keepContentUnderScroll&&(b.grid.contentNode.style.width="");return c}var b=this;if(this.fitParentSize||void 0!==this.keepContentUnderScroll)p.before(this.grid,"refresh",function(){b.hideCheckLimitMessage();b._lastCheckedNode=null}),p.after(this.grid,"resize",a),p.after(this.grid,"refresh",a)},_getNodeLevel:function(a){var b=-1;for(a=a&&a.parent;a;)b++,a=a.parent;return b},_prepareTreeColumn:function(a){return this._wrapTreeColumn(B(a))},_wrapTreeColumn:function(a){return a},_onStoreUpdated:function(){this._checkboxes=
{};this._refreshGrid();this._rootCheckbox&&this._updateCheckboxState(this._rootCheckbox);this._emitSelectionChanged()},_emitSelectionChanged:function(a){var b=this.tree.root.selectCount;this.updateSelectionCountDiv(this.selectionCounter,b);this.emit("SelectionChanged",{selected:b,toggledTreeNode:a})},refresh:function(){this._refreshGrid();this.refreshCheckboxes()},_isRefreshSuspended:!1,setRefreshSuspended:function(a){this._isRefreshSuspended=a},_refreshGrid:function(){if(!this._isRefreshSuspended){var a=
this.grid.getScrollPosition();this.grid.refresh();this.grid.scrollTo(a);for(var b in this._selectedRowInfos)this.grid.row(this._selectedRowInfos[b].node).element&&this._selectRow(this.grid.row(this._selectedRowInfos[b].node).element,this._selectedRowInfos[b].node)}},getScrollPosition:function(){return this.grid&&this.grid.getScrollPosition()},setScrollPosition:function(a){return this.grid&&this.grid.scrollTo(a)},_renderCheckbox:function(a){if(!a.leafCount&&a!==this.tree.root||!this.showCheckboxColumn||
!1===a.selectable&&void 0===a.indepSelection)return document.createTextNode("");var b=new D(null,{class:"esriStyleInTable"});b.autoToggle=!1;b.node=a;this._updateCheckboxState(b,a);!1===a.enabled&&b.set("disabled",!0);a===this.tree.root?(this._rootCheckbox=b,n[this.showRootCheckbox?"show":"hide"](b.domNode)):this._checkboxes[this.tree.getIdentity(a)]=b;b.onClick=this._onCheckboxClick.bind(this,a,b);return b},_renderCheckboxForColumn:function(a){return(a=this._renderCheckbox(a))&&a.domNode},refreshCheckboxes:function(){this._rootCheckbox&&
this._updateCheckboxState(this._rootCheckbox);for(var a in this._checkboxes)this._updateCheckboxState(this._checkboxes[a])},clearLastCheckInfo:function(){this._lastCheckedNode=null},_onCheckboxClick:function(a,b,c){c.stopPropagation();this.hideCheckLimitMessage();var d=this.handleMultipleCheck&&("function"!==typeof this.handleMultipleCheck||this.handleMultipleCheck(a));d&&c.shiftKey&&this._tryToggleMultipleNodes(this._lastCheckedNode,a,b||c)?this._lastCheckedNode=a:(this._lastCheckedNode=d?a:null,
this._toggleNodeSelection(a,b||c),this.refreshCheckboxes())},_tryToggleMultipleNodes:function(a,b,c){if(!a||a===b||a.parent!==b.parent)return!1;var d=b.parent.children,f=d.indexOf(a);b=d.indexOf(b);a=f<b?1:-1;var l=[],g=[];for(f+=a;;f+=a){var k=d[f];((void 0===k.indepSelection?k.selected:k.indepSelection)?l:g).push(k);if(f===b)break}l.forEach(function(q){this._toggleNodeSelection(q,c)},this);g.every(function(q){return this._toggleNodeSelection(q,c)},this);this.refreshCheckboxes();return!0},_toggleNodeSelection:function(a,
b){var c=void 0===a.indepSelection?!a.selected:!a.indepSelection;if(c&&this.checkLimit){var d=this.getSelectedNodes().length,f="function"===typeof this.checkLimit?this.checkLimit(this.tree,d):this.checkLimit;if(d>=f)if(void 0===a.indepSelection&&a.children&&!1!==this.tree.getSelectionState(a))c=!1;else return this.showCheckLimitMessage(b),!1}d=!0;void 0===a.indepSelection?(d=this.tree.changeSelect(a,c,f),!d&&this.showCheckLimitMessage(b)):a.indepSelection=c;this._emitSelectionChanged(a);return d},
_checkLimitHandler:null,showCheckLimitMessage:function(a){if(this.checkLimitMessage){var b=a&&(a.domNode||a.target);b&&(v.show(this.checkLimitMessage,b,["above","below"]),a=function(){b&&v.hide(b);b=null},setTimeout(a,this.checkLimitMessageTimeout),this._checkLimitHandler=a,this.onCheckLimitReached(a))}},hideCheckLimitMessage:function(){this._checkLimitHandler&&this._checkLimitHandler();this._checkLimitHandler=null},onCheckLimitReached:function(a){},_updateCheckboxState:function(a){if(a){var b=this._getNodeSelection(a.node);
a.set("checked",b);this._updateRowHighlighting(a.node,null,b)}},_getNodeSelection:function(a){return void 0!==a.indepSelection?a.indepSelection:this.tree.getSelectionState(a)},_updateRowHighlighting:function(a,b,c){this.highlightSelected&&a&&(c=void 0!==c?c:this._getNodeSelection(a),(b=b||this.grid&&this.row(a).element)&&(!0!==c||void 0===a.indepSelection&&!1===a.selectable?h.remove(b,"selected"):h.add(b,"selected")))},_renderLabel:function(a,b,c){b=this._renderLabelNode(a,c);this._provideLabelClickAction(b,
c,a);return b},_provideLabelClickAction:function(a,b,c){var d=this.expandOnNodeClick&&c.children?c.children.length&&(a=b,function(){this.toggleExpand(c);this.onExpandChangedUser(c)}.bind(this)):!1!==c.enabled&&this.showCheckboxColumn?this._onCheckboxClick.bind(this,c,null):null;d&&(h.add(a,"esriMapsAnalystXClickable"),m(a,"click",function(f){f.stopPropagation();d(f)}))},_renderLabelNode:function(a){return t.create("div",{class:"esriMapsAnalystXSelectableTreeLabel TrimWithEllipses",innerHTML:this.getLabel(a)})},
_renderLabelHeader:function(a){var b=t.create("div",{class:"esriMapsAnalystXSelectableTreeLabel TrimWithEllipses",innerHTML:this.getLabel(a)||this._labelColumn&&this._labelColumn.label||""});this.enableHeaderLabelToggleClick&&this.showRootCheckbox&&(h.add(b,"esriMapsAnalystXClickable"),m(b,"click",this._onCheckboxClick.bind(this,a,null)));return b},onRowsSelected:function(a,b){},isNodeSelected:function(a){return a&&(a.selected||a.indepSelection)},getSelectedNodes:function(){var a=this.tree.getSelectedNodes(!1),
b=this._getIndepSelectedNodes();return a.concat(b)},_getIndepSelectedNodes:function(){function a(c){c&&(c.indepSelection&&b.push(c),c.children&&c.children.forEach(a))}var b=[];a(this.tree.root);return b},getSelectedState:function(){if(!this.tree)return null;var a={normalSelection:{},indepSelection:{}},b=this.tree.getSelectedNodes(!1);b&&b.forEach(function(c){a.normalSelection[c.id]=!0});(b=this._getIndepSelectedNodes())&&b.forEach(function(c){a.indepSelection[c.id]=!0});return a},setSelectedState:function(a){if(this.tree){this.tree.changeSelect(this.tree.root,
!1);if(a){for(var b in a.normalSelection){var c=this.tree.get(b);c&&this.tree.changeSelect(c,!0)}for(b in a.indepSelection)if(c=this.tree.get(b))c.indepSelection=!0}this.refreshCheckboxes()}},setNodeSelected:function(a,b,c){a&&(void 0!==a.indepSelection?a.indepSelection=b:this.tree.changeSelect(a,b),!1!==c&&this.refreshCheckboxes())},isExpanded:function(a){a="string"===typeof a?a:a[this.tree.idProperty];return this.grid._expanded&&this.grid._expanded[a]},setExpanded:function(a,b,c){a="string"==typeof a?
a:a[this.tree.idProperty];void 0!==a&&(!1!==c?(c=this.grid.row(a))&&c.element&&this.grid.expand(a,b):this.grid._expanded[a]=b)},toggleExpand:function(a){this.setExpanded(a,!this.isExpanded(a))},getExpandedState:function(){return Object.assign({},this.grid._expanded)},setExpandedState:function(a){this.grid._expanded=a||{}},onExpandChangedUser:function(a){},destroy:function(){this.unselectAllRows();this.inherited(arguments)}})});