// 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
define("dojo/_base/kernel dojo/_base/declare dojo/_base/Deferred dojo/on dojo/has dojo/aspect dgrid/List dojo/has!touch?dgrid/util/touch put-selector/put dojo/query dojo/_base/sniff".split(" "),function(y,z,A,k,g,m,l,r,t){function u(a,b){b=a.unselectable=b?"on":"";a=a.getElementsByTagName("*");for(var c=a.length;--c;)"INPUT"!==a[c].tagName&&"TEXTAREA"!==a[c].tagName&&(a[c].unselectable=b)}function v(a,b){var c=a.bodyNode,d=b?"text":21>g("ff")?"-moz-none":"none";n&&"msUserSelect"!==n?c.style[n]=d:
g("dom-selectstart")?b||a._selectstartHandle?b&&a._selectstartHandle&&(a._selectstartHandle.remove(),delete a._selectstartHandle):a._selectstartHandle=k(c,"selectstart",function(f){var e=f.target&&f.target.tagName;"INPUT"!==e&&"TEXTAREA"!==e&&f.preventDefault()}):(u(c,!b),b||a._unselectableHandle)?b&&a._unselectableHandle&&(a._unselectableHandle.remove(),delete a._unselectableHandle):a._unselectableHandle=m.after(a,"renderRow",function(f){u(f,!0);return f})}g.add("dom-comparedocumentposition",function(a,
b,c){return!!c.compareDocumentPosition});g.add("pointer",function(a){return"PointerEvent"in a?"pointer":"MSPointerEvent"in a?"MSPointer":!1});g.add("css-user-select",function(a,b,c){a=c.style;b=["Khtml","O","ms","Moz","Webkit"];c=b.length;var d="userSelect";do if("undefined"!==typeof a[d])return d;while(c--&&(d=b[c]+"UserSelect"));return!1});g.add("dom-selectstart","undefined"!==typeof document.onselectstart);var p=g("mac")?"metaKey":"ctrlKey",n=g("css-user-select"),w=(l=g("pointer"))&&"MS"===l.slice(0,
2),x=l?l+(w?"Down":"down"):"mousedown",q=l?l+(w?"Up":"up"):"mouseup";"WebkitUserSelect"===n&&"undefined"!==typeof document.documentElement.style.msUserSelect&&(n=!1);return z("dgrid.Selection",null,{selectionDelegate:".dgrid-cell.dgrid-cell-padding.dgrid-column-selectionHandle.field-selectionHandle.selection-handle-column",selectionEvents:x+","+q+",dgrid-cellfocusin",selectionTouchEvents:g("touch")?r.tap:null,deselectOnRefresh:!0,allowSelectAll:!1,selection:{},selectionMode:"extended",allowTextSelection:void 0,
_selectionTargetType:"rows",create:function(){this.selection={};return this.inherited(arguments)},postCreate:function(){this.inherited(arguments);this._initSelectionEvents();var a=this.selectionMode;this.selectionMode="";this._setSelectionMode(a)},destroy:function(){this.inherited(arguments);this._selectstartHandle&&this._selectstartHandle.remove();this._unselectableHandle&&this._unselectableHandle.remove();this._removeDeselectSignals&&this._removeDeselectSignals()},_setSelectionMode:function(a){a!=
this.selectionMode&&(this.clearSelection(),this.selectionMode=a,this._selectionHandlerName="_"+a+"SelectionHandler",this._setAllowTextSelection(this.allowTextSelection))},setSelectionMode:function(a){y.deprecated("setSelectionMode(...)",'use set("selectionMode", ...) instead',"dgrid 0.4");this.set("selectionMode",a)},_setAllowTextSelection:function(a){"undefined"!==typeof a?v(this,a):v(this,"none"===this.selectionMode);this.allowTextSelection=a},_handleSelect:function(a,b){if(this[this._selectionHandlerName]&&
this.allowSelect(this.row(b))&&("dgrid-cellfocusin"!==a.type||"mousedown"!==a.parentType)&&(a.type!==q||b==this._waitForMouseUp)){this._waitForMouseUp=null;this._selectionTriggerEvent=a;if(!a.keyCode||!a.ctrlKey||32==a.keyCode)if(!a.shiftKey&&a.type===x&&this.isSelected(b))this._waitForMouseUp=b;else this[this._selectionHandlerName](a,b);this._selectionTriggerEvent=null}},_singleSelectionHandler:function(a,b){a=a.keyCode?a.ctrlKey:a[p];this._lastSelected===b?this.select(b,null,!a||!this.isSelected(b)):
(this.clearSelection(),this.select(b),this._lastSelected=b)},_multipleSelectionHandler:function(a,b){var c=this._lastSelected,d=a.keyCode?a.ctrlKey:a[p];if(!a.shiftKey){var f=d?null:!0;c=null}this.select(b,c,f);c||(this._lastSelected=b)},_extendedSelectionHandler:function(a,b){(2===a.button?this.isSelected(b):a.keyCode?a.ctrlKey:a[p])||this.clearSelection(null,!0);this._multipleSelectionHandler(a,b)},_toggleSelectionHandler:function(a,b){this.select(b,null,null)},_initSelectionEvents:function(){var a=
this,b=this.contentNode,c=this.selectionDelegate;this._selectionEventQueues={deselect:[],select:[]};g("touch")&&!g("pointer")&&this.selectionTouchEvents?(k(b,r.selector(c,this.selectionTouchEvents),function(d){a._handleSelect(d,this);a._ignoreMouseSelect=this}),k(b,k.selector(c,this.selectionEvents),function(d){a._ignoreMouseSelect!==this?a._handleSelect(d,this):d.type===q&&(a._ignoreMouseSelect=null)})):k(b,k.selector(c,this.selectionEvents),function(d){a._handleSelect(d,this)});this.addKeyHandler&&
this.addKeyHandler(32,function(d){a._handleSelect(d,d.target)});if(this.allowSelectAll)this.on("keydown",function(d){d[p]&&65==d.keyCode&&!/\bdgrid-input\b/.test(d.target.className)&&(d.preventDefault(),a[a.allSelected?"clearSelection":"selectAll"]())});this._setStore&&m.after(this,"_setStore",function(){a._updateDeselectionAspect()});this._updateDeselectionAspect()},_updateDeselectionAspect:function(){function a(e,h,B){e=h||e&&e[b.idProperty||"id"];if(null!=e&&(h=(e=b.row(e))&&b.selection[e.id]))b[B](e,
null,h)}var b=this,c=this.store;this._removeDeselectSignals&&this._removeDeselectSignals();if(c&&c.notify){var d=m.before(c,"notify",function(e,h){e||a(e,h,"deselect")});var f=m.after(c,"notify",function(e,h){a(e,h,"select")},!0);this._removeDeselectSignals=function(){d.remove();f.remove()}}else d=m.before(this,"removeRow",function(e,h){h||(e=this.row(e))&&e.id in this.selection&&this.deselect(e)}),this._removeDeselectSignals=function(){d.remove()}},allowSelect:function(a){return!0},_fireSelectionEvent:function(a){var b=
this._selectionEventQueues[a],c=this._selectionTriggerEvent;var d={bubbles:!0,grid:this};c&&(d.parentType=c.type);d[this._selectionTargetType]=b;this._selectionEventQueues[a]=[];k.emit(this.contentNode,"dgrid-"+a,d)},_fireSelectionEvents:function(){var a=this._selectionEventQueues,b;for(b in a)a[b].length&&this._fireSelectionEvent(b)},_select:function(a,b,c){"undefined"===typeof c&&(c=!0);a.element||(a=this.row(a));if(!1===c||this.allowSelect(a)){var d=this.selection;var f=!!d[a.id];null===c&&(c=
!f);var e=a.element;c||this.allSelected?d[a.id]=c:delete this.selection[a.id];e&&(c?t(e,".dgrid-selected"+(this.addUiClasses?".ui-state-active":"")):t(e,"!dgrid-selected!ui-state-active"));c!==f&&e&&this._selectionEventQueues[(c?"":"de")+"select"].push(a);if(b)if(b.element||(b=this.row(b)),b){if(b=b.element)for(d=this._determineSelectionDirection(e,b),d||(b=document.getElementById(b.id),d=this._determineSelectionDirection(e,b));a.element!=b&&(a=this[d](a));)this._select(a,null,c)}else this._lastSelected=
e,console.warn("The selection range has been reset because the beginning of the selection is no longer in the DOM. If you are using OnDemandList, you may wish to increase farOffRemoval to avoid this, but note that keeping more nodes in the DOM may impact performance.")}},_determineSelectionDirection:g("dom-comparedocumentposition")?function(a,b){a=b.compareDocumentPosition(a);return a&1?!1:2===a?"down":"up"}:function(a,b){return 1>b.sourceIndex?!1:b.sourceIndex>a.sourceIndex?"down":"up"},select:function(a,
b,c){this._select(a,b,c);this._fireSelectionEvents()},deselect:function(a,b){this.select(a,b,!1)},clearSelection:function(a,b){this.allSelected=!1;for(var c in this.selection)a!==c&&this._select(c,null,!1);b||(this._lastSelected=null);this._fireSelectionEvents()},selectAll:function(){this.allSelected=!0;this.selection={};for(var a in this._rowIdToObject){var b=this.row(this._rowIdToObject[a]);this._select(b.id,null,!0)}this._fireSelectionEvents()},isSelected:function(a){if("undefined"===typeof a||
null===a)return!1;a.element||(a=this.row(a));return a.id in this.selection?!!this.selection[a.id]:this.allSelected&&(!a.data||this.allowSelect(a))},refresh:function(){this.deselectOnRefresh&&this.clearSelection();this._lastSelected=null;return this.inherited(arguments)},renderArray:function(){var a=this,b=this.inherited(arguments);A.when(b,function(c){var d=a.selection,f,e;for(f=0;f<c.length;f++){var h=a.row(c[f]);(e=h.id in d?d[h.id]:a.allSelected)&&a._select(h,null,e)}a._fireSelectionEvents()});
return b}})});