// 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/declare dojo/_base/html dijit/_WidgetBase jimu/dijit/Message jimu/dijit/Filter dgrid/OnDemandGrid ../dgrid/Selection dgrid/extensions/ColumnHider dgrid/extensions/ColumnResizer dgrid/extensions/ColumnReorder dgrid/Keyboard dijit/Menu dijit/MenuItem dijit/PopupMenuItem dijit/Toolbar dijit/form/Button dijit/DropDownMenu dijit/form/ToggleButton dijit/form/DropDownButton dojo/Deferred dojo/when dojo/Evented dojo/touch dojo/store/Memory esri/config esri/lang esri/request esri/tasks/RelationParameters esri/tasks/RelationshipQuery esri/layers/FeatureLayer esri/tasks/QueryTask esri/tasks/query esri/tasks/ProjectParameters esri/geometry/Multipoint esri/geometry/geometryEngine esri/geometry/normalizeUtils esri/IdentityManager dojo/_base/lang dojo/on dojo/aspect dojo/_base/array jimu/dijit/LoadingIndicator jimu/dijit/FieldStatistics jimu/dijit/Popup jimu/dijit/CheckBox jimu/SelectionManager jimu/CSVUtils jimu/utils jimu/ArcadeUtils ../utils dojo/query dojo/string dojo/topic dojo/keys dojo/has".split(" "),
function(N,m,R,G,S,T,U,V,W,X,Y,O,A,Z,aa,I,ba,ca,da,B,ea,fa,ha,C,J,w,ia,P,ja,K,F,D,ka,la,ma,na,oa,g,r,pa,p,L,qa,ra,sa,ta,ua,E,va,x,H,wa,Q,y,M){return N([R,fa],{baseClass:"jimu-widget-attributetable-feature-table",_defaultFeatureCount:2E3,_defaultBatchCount:25,_batchCount:0,_filterObj:null,_currentDef:null,_requestStatus:"initial",parent:null,map:null,matchingMap:!1,layerInfo:null,configedInfo:null,footerHeight:25,layer:null,loading:null,grid:null,footer:null,selectedRowsLabel:null,selectionRows:null,
nls:null,_dblClickResult:null,actived:!1,showSelected:!1,tableCreated:!1,_relatedQuery:!1,_relatedQueryIds:null,_selectionHandles:null,_selectionResults:null,_normalizedExtent:null,GRID_FAR_OFF_REMOVAL:{DEFAULT:2E3,RESELECTION:Infinity,INFINITY:Infinity},constructor:function(a){a=a||{};this.set("parent",a.parent||null);this.set("map",a.map||null);this.set("matchingMap",!!a.matchingMap);this.set("layerInfo",a.layerInfo||null);this.set("layer",a.layer||null);this.set("configedInfo",a.configedInfo||
null);this.set("relatedOriginalInfo",a.relatedOriginalInfo||null);this.set("relationship",a.relationship||null);this.set("prevRelationship",null);this.set("syncSelection",!!a.syncSelection||!0)},postCreate:function(){this.inherited(arguments);this._relatedQueryIds=[];this.createToolbar();this.loading=new L;this.loading.placeAt(this.domNode);this.selectionManager=ta.getInstance();this._selectionResults=[];this.selectionRows=[];this._normalizedExtent=null;m.setAttr(this.domNode,"data-layerinfoid",g.getObject("layerInfo.id",
!1,this));this.get("map")&&(this.own(r(this.map.root,ha.release,g.hitch(this,function(){this._clickMap=!0}))),this.own(r(this.map,"extent-change",g.hitch(this,"_onExtentChange"))));this.own(r(window,"resize",g.hitch(this,this._resize)));this.layerInfo&&this.own(r(this.layerInfo,"filterChanged",g.hitch(this,this._handleFilterChange)))},startup:function(){this.inherited(arguments);this.toolbarHeight=parseInt(m.getStyle(this.toolbar.domNode,"height"),10)||0},setLayerDefinition:function(a){this._layerDefinition=
a},getLayerDefinition:function(){return this._getLayerDifinition()},getFilterableFields:function(){if(this._layerDefinition&&this.configedInfo){var a=g.clone(this._layerDefinition);return this._getFilterableFields(a.fields,this.configedInfo.layer.fields)}return[]},getFilterObj:function(){return this._filterObj},setFilterObj:function(a){this._filterObj=a},showRefreshing:function(a){a?this._toggleLoading(!0):this._toggleLoading(!1)},active:function(){this.actived=!0},deactive:function(){this.actived=
!1},cancelThread:function(){"fulfilled"!==this._requestStatus&&this._currentDef&&(this._currentDef.cancel({canceledBySelf:!0}),this._requestStatus="canceled")},isCanceled:function(){return"canceled"===this._requestStatus},createToolbar:function(){var a=new aa({},m.create("div")),b=new ba;this.showSelectedRecordsMenuItem=new A({label:this.nls.showSelectedRecords,iconClass:"esriAttributeTableSelectPageImage",onClick:g.hitch(this,this.toggleSelectedRecords)});b.addChild(this.showSelectedRecordsMenuItem);
var c=this.layerInfo&&this.layerInfo.layerObject&&this.layerInfo.layerObject.relationships,d=new O;this.showRelatedRecordsMenuItem=new Z({label:this.nls.showRelatedRecords,iconClass:"esriAttributeTableSelectAllImage",popup:d});if(c&&0<c.length){var e=p.map(c,g.hitch(this,function(f){return this.parent&&this.parent.getRelationShipInfo(f)}));p.forEach(c,g.hitch(this,function(f){var k=this.parent&&this.parent.getRelationShipInfo(f),l=0;k&&(p.some(e,function(h){h&&h.name===k.name&&l++;if(1<l)return!1}),
d.addChild(new A({label:k.name+(1<l?f&&'\x3cbr\x3e\x3cspan style\x3d"opacity: 0.4"\x3e\x26lpar;'+f.name+"\x26rpar;\x3c/span\x3e":""),onClick:g.hitch(this,this.onShowRelatedRecordsClick,f)})))}))}b.addChild(this.showRelatedRecordsMenuItem);this.filterMenuItem=new A({label:this.nls.filter,iconClass:"esriAttributeTableFilterImage",onClick:g.hitch(this,this.onFilterMenuItemClick)});b.addChild(this.filterMenuItem);this.toggleColumnsMenuItem=new A({label:this.nls.columns,iconClass:"esriAttributeTableColumnsImage",
onClick:g.hitch(this,this.onToggleColumnsClick)});b.addChild(this.toggleColumnsMenuItem);this.hideExportButton||(this.exportCSVMenuItem=new A({label:this.nls.exportFiles,showLabel:!0,iconClass:"esriAttributeTableExportImage",onClick:g.hitch(this,this.onExportCSVClick)}),b.addChild(this.exportCSVMenuItem));this.selectionMenu=new da({label:this.nls.options,iconClass:"esriAttributeTableOptionsImage",dropDown:b});a.addChild(this.selectionMenu);this.matchingCheckBox=new ca({checked:this.matchingMap?!0:
!1,showLabel:!0,label:this.nls.filterByExtent,onChange:g.hitch(this,function(f){this.set("matchingMap",f);this._onMatchingCheckBoxChange(f)})});a.addChild(this.matchingCheckBox);this.zoomButton=new I({label:this.nls.zoomto,iconClass:"esriAttributeTableZoomImage",onClick:g.hitch(this,this.zoomTo)});a.addChild(this.zoomButton);this.clearSelectionButton=new I({label:this.nls.clearSelection,iconClass:"esriAttributeTableClearImage",onClick:g.hitch(this,this.clearSelection,!0,!0)});a.addChild(this.clearSelectionButton);
this.refreshButton=new I({label:this.nls.refresh,showLabel:!0,iconClass:"esriAttributeTableRefreshImage",onClick:g.hitch(this,this.refresh)});a.addChild(this.refreshButton);m.place(a.domNode,this.domNode);this.toolbar=a;this.own(r(this,"data-loaded,row-click,clear-selection",g.hitch(this,"changeToolbarStatus")));this.parent&&Q.publish(this.parent.id+"_toolbar_created",{toolbar:this.toolbar,context:this})},startQuery:function(a){this.cancelThread();this._requestStatus="processing";this._toggleLoading();
a&&a.length?this.queryByStoreObjectIds=a:(this._relatedQuery=!1,this._relatedQueryIds=[],this.queryByStoreObjectIds=null);this._currentDef=this._getLayerObject();this._currentDef.then(g.hitch(this,function(b){this.domNode&&(this.layer=b,(b=!this.layerInfo.isTable&&this.matchingMap&&this.map.extent||null)&&b.spatialReference&&b.spatialReference.isWebMercator()?(this._currentDef=na.normalizeCentralMeridian([b],null,g.hitch(this,function(c){return c[0]}))).then(g.hitch(this,function(c){this._doQuery(c,
a);this._normalizedExtent=c}),g.hitch(this,function(c){c&&"Request canceled"!==c.message&&console.error(c);this.changeToolbarStatus();this._toggleLoading(!1)})):this._doQuery(b,a))}),g.hitch(this,function(b){console.error(b);this.changeToolbarStatus();this._toggleLoading(!1)}))},queryRecordsByRelationship:function(a){var b=a&&a.layer,c=a&&a.selectedIds;a&&a.relationship&&(this.set("prevRelationship",this.relationship),this.set("relationship",a.relationship));a&&a.relatedOriginalInfo&&this.set("relatedOriginalInfo",
a.relatedOriginalInfo);var d=this.relationship;a=this.prevRelationship;b&&d&&c&&0<c.length&&(!E.isEqual(this._relatedQueryIds,c)||!E.isEqual(d,a))&&g.getObject("relatedOriginalInfo.layerObject.url",!1,this)?(this._toggleLoading(!0),this._requestStatus="processing",this._relatedQuery=!0,this.matchingCheckBox.set("checked",!1),this.cancelThread(),this._currentDef=this._getLayerObject(),this._currentDef.then(g.hitch(this,function(e){if(this.domNode){this.layer=e;var f=[],k=this.layer;p.forEach(k.fields,
function(l){w.isDefined(l.show)&&!0!==l.show&&!("esriFieldTypeOID"===l.type||w.isDefined(k.objectIdField)&&l.name===k.objectIdField)||x.arcade.isArcadeExpressionField(l)||f.push(l.name)});e=new ja;e.objectIds=c;e.outFields=f.length?f:["*"];e.relationshipId=d.id;e.returnGeometry="esriGeometryPoint"===this.layer.geometryType;(this._currentDef=b.queryRelatedFeatures(e,function(l){return l})).then(g.hitch(this,function(l){if(this.domNode){var h={displayFieldName:d.objectIdField,fields:k.fields,features:[],
fieldAliases:null},n={},t=function(v){var z=v.attributes[this.layer.objectIdField];n[z]||(n[z]=!0,h.features.push(v))},q;for(q in l){var u=l[q];p.forEach(u&&u.features,t,this)}m.destroy(this.tipNode);0<h.features.length?(this.grid||(this._removeTable(),m.place(this.loading.domNode,this.domNode)),l=this._getOutFieldsFromLayerInfos(this.layer.objectIdField),this.queryExecute(l,h.features.length,!1,h)):(this.tipNode=m.toDom("\x3cdiv\x3e"+this.nls.noRelatedRecords+"\x3c/div\x3e"),this._removeTable(),
m.place(this.tipNode,this.domNode),m.place(this.loading.domNode,this.domNode));this._relatedQueryIds=c;this.emit("data-loaded");this._toggleLoading(!1)}}),g.hitch(this,function(l){l&&"Request canceled"!==l.message&&console.error(l);m.destroy(this.tipNode);this.tipNode=m.toDom("\x3cdiv\x3e"+this.nls.noRelatedRecords+"\x3c/div\x3e");this._removeTable();m.place(this.tipNode,this.domNode);m.place(this.loading.domNode,this.domNode);this._toggleLoading(!1);this.changeToolbarStatus()}))}}),g.hitch(this,
function(e){console.error(e);this._toggleLoading(!1);this.changeToolbarStatus()}))):this._toggleLoading(!1)},getSelectedRows:function(){return this.tableCreated?this.selectionRows:[]},zoomTo:function(){this._zoomToSelected()},toggleSelectedRecords:function(){this._relatedQuery&&!this.showSelected&&0===this.getSelectedRows().length?(this._relatedQuery=!1,this._relatedQueryIds=[],this.layerInfo&&!this.layerInfo.isTable&&this.matchingCheckBox.set("checked",!0),this.startQuery(),this.showSelectedRecordsMenuItem.set("label",
this.nls.showSelectedRecords),this.showSelected=!1,this.emit("show-all-records",{layerInfoId:this.layerInfo.id})):this.tableCreated&&(this.showSelected?(this.showAllSelectedRecords(),this.showSelectedRecordsMenuItem.set("label",this.nls.showSelectedRecords),this.showSelected=!1,this.emit("show-all-records",{layerInfoId:this.layerInfo.id})):(this.showSelectedRecords(),this.showSelectedRecordsMenuItem.set("label",this.nls.showAllRecords),this.showSelected=!0,this.emit("show-selected-records",{layerInfoId:this.layerInfo.id})))},
onShowRelatedRecordsClick:function(a){var b=this.getSelectedRows();0<b.length?this.emit("show-related-records",{layerInfoId:this.layerInfo.id,objectIds:b,relationshipObj:a}):this._getFeatureIds(this.layer&&this.layer.objectIdField,this.matchingMap&&this._normalizedExtent).then(g.hitch(this,function(c){console.log(c);this.emit("show-related-records",{layerInfoId:this.layerInfo.id,objectIds:c,relationshipObj:a})}))},onFilterMenuItemClick:function(){this.showRefreshing(!0);this.getLayerDefinition().then(g.hitch(this,
function(a){if(this.domNode){a=g.clone(a);var b=this.getFilterableFields();a.fields=b;var c=new S({widgetId:this.widgetId,noFilterTip:this.nls.noFilterTip,style:"width:100%;",featureLayerId:this.layerInfo.id,runtime:!0});b=this._getFilterPopupSize();this._filterPopup=new ra({titleLabel:this.nls.filter,width:b.w,height:b.h,content:c,autoHeight:!0,buttons:[{label:this.nls.ok,onClick:g.hitch(this,function(){var d=c.toJson();d&&d.expr?(this.setFilterObj(d),this.clearSelection(!1),this.startQuery(),this._filterPopup.close(),
this._filterPopup=null,this.emit("apply-filter",{layerInfoId:this.layerInfo.id,expr:d.expr})):new G({message:this.nls.setFilterTip})})},{label:this.nls.cancel}]});c.startup();m.addClass(this._filterPopup.domNode,"widget-at-filter-popup");b=this.getFilterObj();c.build({url:this.layer.url,partsObj:b,layerDefinition:this.layer||a,featureLayerId:this.layer.id})}}),g.hitch(this,function(a){this.domNode&&console.error(a)})).always(g.hitch(this,function(){this.showRefreshing(!1)}));this.emit("show-filter",
{layerInfoId:this.layerInfo.id})},_getFilterPopupSize:function(){var a={w:720,h:485};window.appInfo.isRunInMobile&&(a={w:window.innerWidth,h:window.innerHeight});return a},_resize:function(){if(this._filterPopup){var a=this._getFilterPopupSize();this._filterPopup.resize(a)}},onToggleColumnsClick:function(){this.toggleColumns();this.emit("toggle-columns",{layerInfoId:this.layerInfo.id})},onExportCSVClick:function(){var a=this._getRichTextFields(),b=this._getExportCSVPopupMessage(a),c=new G({"class":this.baseClass+
"-popup",message:b,titleLabel:this.nls.exportFiles,autoHeight:!0,buttons:[{label:this.nls.ok,onClick:g.hitch(this,function(){var d=b._check;c.domNode&&(c.domNode.className+=" is-loading",(new L).placeAt(c.domNode));this.exportToCSV(null,"undefined"===typeof d||d.checked?null:a).then(function(){c.close()},function(e){console.error("Error exporting CSV for Attribute Table");c.close()})})},{label:this.nls.cancel}]});this.emit("export-csv",{layerInfoId:this.layerInfo.id})},_getExportCSVPopupMessage:function(a){var b=
document.createElement("div");b.className="message-wrapper";b.appendChild(document.createTextNode(this.nls.exportMessage));if(a.length){var c=document.createElement("div");c.className="input-row";var d=new sa({label:this.nls.keepRichTextLabel,checked:!0}),e=document.createElement("a");e.className="hint-button";e.href="#";e.role="button";e.appendChild(document.createTextNode(this.nls.whatsThis));c.appendChild(d.domNode);c.appendChild(e);b.appendChild(c);b._check=d;this.own(r(e,"click",g.hitch(this,
function(f){f.preventDefault();f={"class":this.baseClass+"-popup",message:this._getRichTextMessage(a)};window.appInfo.isRunInMobile||(f.width=500);new G(f)})))}return b},_getRichTextMessage:function(a){if(!a||a.hasOwnProperty("length")&&!a.length)return"";for(var b=document.createElement("div"),c="",d=0,e=a.length;d<e;d++)c+="\x3cmark\x3e"+a[d].fieldName+"\x3c/mark\x3e";a="\x3cp\x3e"+wa.substitute(this.nls.richTextMessage.explanatoryText.line1,{layerName:"\x3cstrong\x3e"+this.layer.name+"\x3c/strong\x3e"})+
"\x3c/p\x3e";a=a+('\x3cdiv class\x3d"tags"\x3e'+c+"\x3c/div\x3e\x3cp\x3e")+(this.nls.richTextMessage.explanatoryText.line2+"\x3c/p\x3e\x3cp\x3e"+this.nls.richTextMessage.explanatoryText.line3+"\x3c/p\x3e\x3ch3\x3e"+this.nls.richTextMessage.example.label+'\x3c/h3\x3e\x3cdiv class\x3d"example-block"\x3e\x3cpre\x3e\x3cu\x3eArcGIS\x3c/u\x3e \x3cfont color\x3d"#31aacd"\x3eWeb AppBuilder\x3c/font\x3e\x3c/pre\x3e'+this.nls.richTextMessage.example.scenarios.first+'\x3cpre\x3e\x26ltu\x26gtArcGIS\x26lt/u\x26gt \x26ltfont color\x3d"#31aacd"\x26gtWeb AppBuilder\x26lt/font\x26gt\x3c/pre\x3e'+
this.nls.richTextMessage.example.scenarios.second+"\x3cpre\x3eArcGIS Web AppBuilder\x3c/pre\x3e\x3c/div\x3e");b.innerHTML=a;return b},_getRichTextFields:function(){var a=this.layerInfo&&this.layerInfo.getPopupInfo&&this.layerInfo.getPopupInfo();a=a&&a.fieldInfos;var b=[];if(a)for(var c=0,d=a.length;c<d;c++){var e=a[c];e.stringFieldOption&&"richtext"===e.stringFieldOption&&b.push(e)}return b},onSelectionComplete:function(){var a=this.layer&&this.layer.getSelectedFeatures();a&&(0===a.length?this.clearSelection(!1,
0<this._selectionResults.length):this._selectBySelf(a)||(this.clearSelection(!1),this._updateSelectRowsByFeatures(a)))},onSelectionClear:function(){this.clearSelection(!1,!0);this._setFarOffRemoval(this.GRID_FAR_OFF_REMOVAL.DEFAULT)},changeToolbarStatus:function(){if(this.tableCreated){var a=this.getSelectedRows();this.showSelected?this.showSelectedRecordsMenuItem.set("label",this.nls.showAllRecords):this.showSelectedRecordsMenuItem.set("label",this.nls.showSelectedRecords);this.tableCreated&&a&&
0<a.length&&this.layer&&this.layer.objectIdField?(this.showSelectedRecordsMenuItem.set("disabled",!1),this.clearSelectionButton.set("disabled",!1)):(this.showSelectedRecordsMenuItem.set("disabled",!0),this.clearSelectionButton.set("disabled",!0));this._relatedQuery&&(this.showSelectedRecordsMenuItem.set("disabled",!1),this.tableCreated&&a&&0===a.length&&this.showSelectedRecordsMenuItem.set("label",this.nls.showAllRecords));this.showRelatedRecordsMenuItem.set("disabled",!0);if(this.layerInfo&&this.isSupportQueryToServer()&&
this.layer&&this.layer.objectIdField){this._relatedDef&&!this._relatedDef.isFulfilled()&&this._relatedDef.cancel();var b=this.layerInfo.getRelatedTableInfoArray();this._relatedDef=b;b.then(g.hitch(this,function(c){this.domNode&&this.tableCreated&&c&&0<c.length&&this.showRelatedRecordsMenuItem.set("disabled",!1)}))}this.tableCreated&&this.isSupportQueryToServer()&&!this._relatedQuery?this.filterMenuItem.set("disabled",!1):this.filterMenuItem.set("disabled",!0);this.matchingCheckBox.set("disabled",
!1);this.tableCreated?this.toggleColumnsMenuItem.set("disabled",!1):this.toggleColumnsMenuItem.set("disabled",!0);this.hideExportButton||(a&&0<a.length?this.exportCSVMenuItem.set("label",this.nls.exportSelected):this.exportCSVMenuItem.set("label",this.nls.exportAll),this.tableCreated?this.exportCSVMenuItem.set("disabled",!1):this.exportCSVMenuItem.set("disabled",!0));this.layerInfo.isShowInMap()?this.tableCreated&&a&&0<a.length?this.zoomButton.set("disabled",!1):this.zoomButton.set("disabled",!0):
this.zoomButton.set("disabled",!0);this.layerInfo.isTable&&(this.matchingCheckBox.set("disabled",!0),this.zoomButton.set("disabled",!0))}else this._relatedQuery?(this.showSelectedRecordsMenuItem.set("disabled",!1),this.showSelectedRecordsMenuItem.set("label",this.nls.showAllRecords)):this.showSelectedRecordsMenuItem.set("disabled",!0),this.showRelatedRecordsMenuItem.set("disabled",!0),this.matchingCheckBox.set("disabled",!0),this.filterMenuItem.set("disabled",!0),this.toggleColumnsMenuItem.set("disabled",
!0),this.hideExportButton||this.exportCSVMenuItem.set("disabled",!0),this.zoomButton.set("disabled",!0)},showSelectedRecords:function(){if(this.tableCreated){var a=this.layer.objectIdField,b=this.getSelectedRows();0<b.length&&this.grid&&(this.grid.store instanceof C?this.grid.set("query",g.hitch(this,function(c){return"number"===typeof c&&-1<b.indexOf(c)||-1<b.indexOf(c[a])?!0:!1})):this.grid.set("query",function(){return b}))}},showAllSelectedRecords:function(){if(this.tableCreated&&this.showSelected){this.grid.set("query",
{});var a=this.getSelectedRows();this._updateSelectRowsByIds(a)}},clearSelection:function(a,b){this.tableCreated&&(this.grid.clearSelection(),this.selectionRows=[],a&&this.grid.set("query",{}),b&&(this._selectionResults=[],this.layer&&0<this.layer.getSelectedFeatures().length&&this.selectionManager.clearSelection(this.layer)),this._closePopup(),this.setSelectedNumber(),this.showSelected=!1,this.emit("clear-selection"))},refresh:function(){this.grid&&this.grid.clearSelection();this._relatedQuery||
this.startQuery();this.emit("refresh",{layerInfoId:this.layerInfo.id})},exportToCSV:function(a,b){if(!this.layerInfo||!this.layer||!this.tableCreated){var c=new B;c.reject();return c}return this.getSelectedRowsData().then(g.hitch(this,function(d){var e=this.layer.objectIdField,f=[],k=this.layer.fullExtent.spatialReference.equals(this.map.extent.spatialReference),l=this._hasArcadeExpressionFields(),h=x.getSortbyFields(this.grid,this.layer);if(k||!this.layer.url){var n=p.map(this._getTableSelectedIds(),
g.hitch(this,function(v){for(var z=0,xa=d.length;z<xa;z++)if(d[z]&&d[z][e]===v)return d[z];return{}}))||[];0===n.length&&this.isSelectionMode()&&n.push({});f=n;0===n.length&&this.grid.store instanceof C&&(f={},h&&h instanceof Array&&(f.sort=p.map(h,function(v){v=v.split(/ +/);return{attribute:v[0],descending:"DESC"===v[1]}})),f=g.clone(this.grid.store.query({},f)));f.length&&this._appendXY(f)}var t=this._getTableSelectedIds(),q=this.parent&&this.parent.tabContainer.selectedChildWidget.params.viewInTableFlag;
n=[];if(t=!f.length&&q&&!t.length)n=g.clone(this.grid.store.data),!k&&this.layer.url||!n.length||this._appendXY(n);q={};var u=this.getOutFields(!!f.length);q.datas=t?n:f;q.fromClient=!1;q.withGeometry="esriGeometryPoint"===this.layer.geometryType;q.outFields=u;q.formatNumber=!1;q.formatDate=!0;q.formatCodedValue=!0;q.popupInfo=this.layerInfo.getPopupInfo();q.objectIds=!k&&0<this.getSelectedRows().length&&this._getExportObjectIds();q.outSpatialReference=!k&&g.clone(this.layer.fullExtent.spatialReference);
q.richTextFieldsToClear=b;l&&(q.arcadeExpressions={expressionInfos:this.layerInfo.getPopupInfo().expressionInfos,layerDefinition:E.getFeatureLayerDefinition(this.layer)});q.orderByFields=h;if(!q.objectIds||q.objectIds instanceof Array&&0===q.objectIds.length)this.matchingMap&&this.layerInfo&&!this.layerInfo.isTable&&(q.geometry=this._currentExtent),q.start=0,q.num=this.layer.maxRecordCount||1E3,q.filterExpression=this.layerInfo.getFilter&&this.layerInfo.getFilter();return ua.exportCSVFromFeatureLayer(a||
this.configedInfo.name,this.layer,q)}))},toggleColumns:function(){this.tableCreated&&this.grid._toggleColumnHiderMenu()},changeHeight:function(a){this.grid&&0<=a-this.toolbarHeight-this.footerHeight&&m.setStyle(this.grid.domNode,"height",a-this.toolbarHeight-this.footerHeight+"px")},isSupportQueryToServer:function(){var a=this.layer&&"esri.layers.CSVLayer"===this.layer.declaredClass,b=this.layer&&"esri.layers.StreamLayer"===this.layer.declaredClass;return this.layer&&this.layer.url&&this.configedInfo.layer.url&&
!a&&!b},isSupportQueryOnClient:function(){var a=this.layer&&"esri.layers.CSVLayer"===this.layer.declaredClass,b=this.layer&&"esri.layers.StreamLayer"===this.layer.declaredClass;return!(this.layer&&this.layer.url&&this.configedInfo.layer.url)||a||b},destroy:function(){this._destroyed||(this.layer=this.configedInfo=this.layerInfo=null,this._selectionHandles&&p.forEach(this._selectionHandles,function(a){a&&a.remove&&a.remove()}),this._closePopup(),this._filterPopup&&this._filterPopup.domNode&&(this._filterPopup.close(),
this._filterPopup=null),this._dblClickResult=null,this.grid&&this.grid.destroy(),this.prevRelationship=this.relationship=this.nls=this.map=null,this._currentDef&&!this._currentDef.isFulfilled()&&this._currentDef.cancel({canceledBySelf:!0}),this._relatedDef&&!this._relatedDef.isFulfilled()&&this._relatedDef.cancel({canceledBySelf:!0}),this.inherited(arguments))},_selectBySelf:function(a){a=a||[];if(a.length!==this._selectionResults.length)return!1;var b=this.layer.objectIdField;return p.every(this._selectionResults,
function(c){return a.some(function(d){return c.attributes[b]===d.attributes[b]})})},_updateSelectRowsByFeatures:function(a){var b=p.map(a,g.hitch(this,function(c){return c.attributes[this.layer.objectIdField]}));this._updateSelectRowsByIds(b);this._selectionResults=a},_updateSelectRowsByIds:function(a){this.grid&&this.tableCreated&&(this.selectionRows=a,p.forEach(a,g.hitch(this,function(b){this.grid.select(b)})),this.setSelectedNumber(),this.changeToolbarStatus())},_removeTable:function(){this.grid&&
this.grid.domNode&&(this.grid.destroy(),this.grid=null);this.footer&&(m.destroy(this.footer),this.selectedRowsLabel=this.footer=null);this.tableCreated=!1},_onMatchingCheckBoxChange:function(a){this.tableCreated&&!this._relatedQuery&&(this.cancelThread(),this.queryByStoreObjectIds=null,this.startQuery());if("fulfilled"===this._requestStatus&&this.tableCreated&&this._relatedQuery)if(a)this.queryByStoreObjectIds=p.map(this.grid.store.data,g.hitch(this,function(c){return c[this.layer.objectIdField]})),
this.startQuery(this.queryByStoreObjectIds);else{var b=this._relatedQueryIds;this._relatedQueryIds=[];this.queryRecordsByRelationship({layer:this.relatedOriginalInfo.layerObject,selectedIds:b})}a||(this._currentExtent=null)},_closePopup:function(){var a=this.map.infoWindow.getSelectedFeature(),b=a&&this._dblClickResult&&a===this._dblClickResult;a=a&&a._layer===this.layer;this.domNode&&(b||a)&&(this.map.infoWindow.hide(),this._dblClickResult=null)},_getLayerObject:function(){function a(b){this._selectionHandles&&
p.forEach(this._selectionHandles,function(c){c&&c.remove&&c.remove()});this._selectionHandles=[];this._selectionHandles.push(r(b,"selection-complete",g.hitch(this,"onSelectionComplete")));this._selectionHandles.push(r(b,"selection-clear",g.hitch(this,"onSelectionClear")))}return(this._currentDef=this.layerInfo.getLayerObject()).then(g.hitch(this,function(b){var c=new B;"esri.layers.ArcGISImageServiceLayer"===b.declaredClass||"esri.layers.ArcGISImageServiceVectorLayer"===b.declaredClass?(b=new K(b.url),
this.own(r(b,"load",g.hitch(this,function(d){g.hitch(this,a)(d.layer);c.resolve(d.layer)})))):(g.hitch(this,a)(b),c.resolve(b));return c}))},_getLayerDifinition:function(){return this._layerDefinition?ea(g.clone(this._layerDefinition)):ia({url:this.layer.url,content:{f:"json"},handleAs:"json",callbackParamName:"callback"}).then(g.hitch(this,function(a){this.setLayerDefinition(a);return this.getLayerDefinition()}))},_getFilterableFields:function(a,b){return p.filter(a,function(c){return p.some(b,function(d){return c.name===
d.name&&(d.show||!w.isDefined(d.show))&&g.mixin(c,d)})})},_getExportObjectIds:function(){var a=this._getTableSelectedIds()||[];if(0===a.length&&this.grid.store instanceof C){var b=this.layer.objectIdField;this.grid.store.query(function(c){a.push(c[b])})}return a},_doQuery:function(a,b){if(this.layer){var c=this.layer.objectIdField;this.isSupportQueryToServer()?this._queryToServer(a,c,b):this.isSupportQueryOnClient()&&this._queryOnClient(a,c,b)}},_queryOnClient:function(a,b,c){var d={};d.features=
"esri.layers.StreamLayer"===this.layer.declaredClass?this.layer.getLatestObservations():p.filter(this.layer.graphics,g.hitch(this,function(h){return!h.wabIsTemp}));c&&0<c.length&&(d.features=p.filter(d.features,function(h){return-1<c.indexOf(h.attributes[this.layer.objectIdField])},this));var e=this.layer.fields,f=this.configedInfo.layer.fields;d.fields=f?p.filter(f,g.hitch(this,function(h){w.isDefined(h.show)||(h.show=!0);h.name!==b||"esriFieldTypeOID"!==h.type&&"esriFieldTypeInteger"!==h.type||
(h._pk=!0);for(var n=0,t=e.length;n<t;n++)e[n].name!==h.name||h.type||(h.type=e[n].type);return h.show||h._pk})):p.filter(e,g.hitch(this,function(h){w.isDefined(h.show)||(h.show=!0);h.name!==b||"esriFieldTypeOID"!==h.type&&"esriFieldTypeInteger"!==h.type||(h._pk=!0);return h.show||h._pk}));f=[];for(var k=d.features.length,l=0;l<k;l++)d&&d.features&&d.features[l]&&d.features[l].geometry&&f.push(d.features[l].geometry);a&&J.defaults.geometryService&&0<f.length?a.spatialReference.equals(f[0].spatialReference)?
(d.features=p.filter(d.features,g.hitch(this,function(h){if(h&&h.geometry)return ma.intersects(a,h.geometry)})),this.queryExecute(d.fields,d.features.length,!1,d,a)):(k=new P,k.geometries1=f,k.geometries2=[a],k.relation=P.SPATIAL_REL_INTERSECTION,(this._currentDef=J.defaults.geometryService.relation(k,g.hitch(this,function(h){return h}))).then(g.hitch(this,function(h,n){for(var t=n.length,q=[],u=0;u<t;u++)q.push(h.features[n[u].geometry1Index]);h.features=q;this.queryExecute(h.fields,h.features.length,
!1,h,a)},d),g.hitch(this,function(h){h&&"Request canceled"!==h.message&&console.error(h);this.changeToolbarStatus();this._toggleLoading(!1)}))):this.queryExecute(d.fields,d.features.length,!1,d,a)},_queryToServer:function(a,b,c){this._getFeatureCount(a,c).then(g.hitch(this,function(d){if(this.domNode)if(c)this._queryFeatureLayer(a,b,d,!1,c);else{var e=this.layer,f=w.isDefined(e.maxRecordCount)?e.maxRecordCount:1E3;this._batchCount=Math.min(f,this._defaultBatchCount);if(d<=f||!this.layer.objectIdField)this._queryFeatureLayer(a,
b,d,!1);else{var k=this._getOutFieldsFromLayerInfos(b),l={fields:this.layer.fields};this.layer._recordCounts=d;e.advancedQueryCapabilities&&e.advancedQueryCapabilities.supportsPagination?this.queryExecute(k,d,!0,l,a):this._getFeatureIds(b,a).then(g.hitch(this,function(h){this.domNode&&(this.layer._objectIds=h,this.queryExecute(k,d,!0,l,a))}),g.hitch(this,function(h){console.error(h);this.changeToolbarStatus()}))}}}),g.hitch(this,function(d){console.error(d);this.changeToolbarStatus()}))},_getFeatureCount:function(a,
b){var c=new B,d=new F(this.configedInfo.layer.url),e=new D;e.returnGeometry=!1;e.where=this._getLayerFilterExpression();b&&(e.where+=" AND "+this.layer.objectIdField+" IN ("+b.join()+")");a&&(e.geometry=a);(this._currentDef=d.executeForCount(e,g.hitch(this,function(f){return f}))).then(g.hitch(this,function(f){c.resolve(f)}),g.hitch(this,function(f){f&&"Request canceled"!==f.message&&(console.error(f),console.log("Could not get feature count."));this._toggleLoading(!1);c.reject(f)}));return c},_queryFeatureLayer:function(a,
b,c,d,e){var f=new F(this.configedInfo.layer.url),k=new D;k.where=this._getLayerFilterExpression();e&&b&&(k.where+=" AND "+b+" IN ("+e.join()+")");var l=this._getOutFieldsFromLayerInfos(b),h=(e=this._hasArcadeExpressionFields())&&this._hasArcadeExpressionWithGeometry();if(0<l.length&&!e){var n=[];p.forEach(l,function(t){n.push(t.name)});k.outFields=n}else k.outFields=["*"];a&&(k.geometry=a,k.spatialRelationship=D.SPATIAL_REL_INTERSECTS);k.outSpatialReference=g.clone(this.map.spatialReference);k.returnGeometry=
"esriGeometryPoint"===this.layer.geometryType||h;b&&(k.orderByFields=[b+" ASC"]);(this._currentDef=f.execute(k,g.hitch(this,function(t){return t}))).then(g.hitch(this,function(t){this.queryExecute(l,c,d,t,a)}),g.hitch(this,function(t){t&&"Request canceled"!==t.message&&console.error(t);this.changeToolbarStatus();this._toggleLoading(!1)}))},_getFeatureIds:function(a,b){var c=new B,d=new F(this.configedInfo.layer.url),e=new D;e.returnGeometry=!1;e.returnIdsOnly=!0;e.where=this._getLayerFilterExpression();
if(this.layer._orderByFields||a)e.orderByFields=this.layer._orderByFields||[a+" ASC"];b&&(e.geometry=b);(this._currentDef=d.executeForIds(e,g.hitch(this,function(f){return f}))).then(g.hitch(this,function(f){c.resolve(f)}),g.hitch(this,function(f){f&&"Request canceled"!==f.message&&(console.error(f),console.log("Could not get feature Ids"));c.resolve([])}));return c},queryExecute:function(a,b,c,d,e){var f=[];f=null;var k={};if(this.domNode){d.fields=this._processExecuteFields(this.layer.fields,a);
c?f=x.generateCacheStore(this.layer,b,this._batchCount,this._getLayerFilterExpression(),e):(f=p.map(d.features,g.hitch(this,function(q){var u=g.clone(q.attributes);return g.mixin(u,{geometry:q.geometry})})),f=x.generateMemoryStore(f,this.layer.objectIdField));a=this.layer.typeIdField;k=this.layer.types;var l=g.getObject("advancedQueryCapabilities.supportsOrderBy",!1,this.layer),h=g.getObject("advancedQueryCapabilities.supportsPagination",!1,this.layer),n=g.getObject("advancedQueryCapabilities.supportsStatistics",
!1,this.layer),t=x.arcade.getExpressionInfosFromLayerInfo(this.layerInfo);t=va.compileExpressions(t);k=x.generateColumnsFromFields(this.grid&&this.grid.columns,this.map,this.layerInfo,t,d.fields,a,k,l&&h||!c,n,this.layer);this.layer.hasAttachments&&this.layer.objectIdField&&this.configedInfo.showAttachments&&(k.attachmentsColumn=this.formatAttachmentsColumn());c=20+100*d.fields.length<m.getMarginBox(this.domNode).w;this.createTable(k,f,b,c);b=this.grid.domNode.querySelectorAll(".dgrid-header .dgrid-column-selectionHandle");
0<b.length&&b[0].setAttribute("role","presentation");this._currentExtent=e;e=this.layer.getSelectedFeatures();this.selectionRows&&0<this.selectionRows.length?this._updateSelectRowsByIds(this.selectionRows):e&&0<e.length?this._updateSelectRowsByFeatures(e):this.grid.clearSelection();this.changeToolbarStatus();this.emit("data-loaded")}},formatAttachmentsColumn:function(){var a={label:this.nls.attachments,className:"attachments-column",hidden:!1,unhidable:!0,field:"at-show-attachments",sortable:!1,_cache:{sortable:!1,
statistics:!1}};a.renderCell=g.hitch(this,function(b,c,d){var e=b[this.layer.objectIdField];this.layer.queryAttachmentInfos(e,g.hitch(this,function(f){var k=p.map(f,g.hitch(this,function(h){var n=h.name&&/\.(png|jpg|jpeg|gif)$/gi.test(h.name)?"image-type":"file-type",t=oa.findCredential(this.layer.url);return'\x3cli class\x3d"'+n+'"\x3e\x3ca class\x3d"jimu-ellipsis" target\x3d"_blank" href\x3d"'+(this.layer.url+"/"+e+"/attachments/"+h.id+(t?"?token\x3d"+t.token:""))+'"\x3e'+h.name+"\x3c/a\x3e\x3c/li\x3e"})),
l="";0<f.length&&(l=" "+this.nls.files);l='\x3cdiv class\x3d"attachment-infos"\x3e\x3cdiv class\x3d"show-attachments-div"\x3e\x3cspan class\x3d"show-attachments"\x3e'+f.length+l+'\x3c/span\x3e\x3c/div\x3e\x3cdiv class\x3d"attachment-popup"\x3e\x3cdiv class\x3d"attachment-popup-header"\x3e\x3cspan\x3e'+k.length+"\x26nbsp;"+this.nls.files+'\x3c/span\x3e\x3cspan class\x3d"close jimu-float-trailing"\x3e\x3c/span\x3e\x3c/div\x3e\x3cul class\x3d"attachment-popup-content"\x3e'+k.join("")+"\x3c/ul\x3e\x3c/div\x3e\x3c/div\x3e";
l=m.toDom(l);0<f.length&&(f=H(".show-attachments-div",l)[0],m.addClass(f,"has-attachments"));d.appendChild(l);this.own(r(d,"click",g.hitch(this,function(h){h=h&&h.target;if(m.hasClass(h,"show-attachments-div")||m.hasClass(h,"show-attachments")||m.hasClass(h,"close")){h=this._visibleAttachmentPopup;var n=H(".attachment-popup",d)[0];n&&0<k.length&&m.toggleClass(n,"show");m.hasClass(n,"show")?this._visibleAttachmentPopup=n:this._visibleAttachmentPopup=null;h&&h!==n&&m.toggleClass(h,"show")}})))}),g.hitch(this,
function(f){console.error(f)}))});return a},createTable:function(a,b,c,d){if(this.grid)this.grid.set("store",b),this.grid.set("columns",a),this.grid.refresh();else{var e={},f=new L;m.setStyle(f.domNode,"max-width","100vw");e.columns=a;e.store=b;e.keepScrollPosition=!0;e.farOffRemoval=this.GRID_FAR_OFF_REMOVAL.DEFAULT;M("chrome")||(e.pagingDelay=1E3);e.allowTextSelection=this.allowTextSelection;e.deselectOnRefresh=!1;e.loadingMessage=f.domNode&&f.domNode.outerHTML;this.layer.objectIdField||(e.minRowsPerPage=
this.layer.maxRecordCount||1E3,e.maxRowsPerPage=this.layer.maxRecordCount||1E3,e.selectionMode="none");this.grid=new (N([T,U,V,W,X,Y]))(e,m.create("div"));m.place(this.grid.domNode,this.domNode);this.grid.startup();this.tipNode&&m.destroy(this.tipNode);this.own(r(this.ownerDocument,"keydown",g.hitch(this,function(k){this.allowTextSelection&&this.grid&&this.grid.allowTextSelection&&k.shiftKey&&this.grid._setAllowTextSelection(!1)})));this.own(r(this.ownerDocument,"keyup",g.hitch(this,function(){this.allowTextSelection&&
this.grid&&!this.grid.allowTextSelection&&this.grid._setAllowTextSelection(!0)})));this.own(r(this.ownerDocument,"keydown",g.hitch(this,function(k){this.tableCreated&&(k.keyCode===y.SHIFT||(M("mac")?k.keyCode===y.META:k.keyCode===y.CTRL)&&this.isSelectionMode())&&(this._setFarOffRemoval(this.GRID_FAR_OFF_REMOVAL.INFINITY),r.once(this.ownerDocument,"keyup",g.hitch(this,function(l){!this.tableCreated||l.keyCode!==y.SHIFT&&(M("mac")?l.keyCode!==y.META:l.keyCode!==y.CTRL)||(this.isSelectionMode()?this._setFarOffRemoval(this.GRID_FAR_OFF_REMOVAL.RESELECTION):
this._setFarOffRemoval(this.GRID_FAR_OFF_REMOVAL.DEFAULT))})))})));this.layer.objectIdField&&(this.own(r(this.grid,".dgrid-header .dgrid-cell:click",g.hitch(this,this._onHeaderClick))),this.own(r(this.grid,"dgrid-columnstatechange",g.hitch(this,this._onColumnStateChange))),this.own(r(this.grid,".selection-handle-column:click",g.hitch(this,this._onSelectionHandleClick)),r(this.grid,".selection-handle-column:keydown",g.hitch(this,function(k){k.keyCode!==y.ENTER&&k.keyCode!==y.SPACE||this._onSelectionHandleClick()}))),
this.own(r(this.grid,".dgrid-row:dblclick",g.hitch(this,this._onDblclickRow)),r(this.grid,"dgrid-sort",g.hitch(this,function(k){this.emit("sort",k)})),r(this.grid,"dgrid-refresh-complete",g.hitch(this,function(k){this.parent&&Q.publish(this.parent.id+"_table_created",{grid:k.grid,context:this})}))),a=this.map.getLayer(this.layer.id),this.syncSelection&&a&&this.own(r(a,"click",g.hitch(this,this._onFeaturelayerClick))))}this.grid.get("sort")[0]||(this.configedInfo&&this.configedInfo.sortField?this.grid.set("sort",
this.configedInfo.sortField,this.configedInfo.isDescending):this.layer.objectIdField&&this.grid.set("sort",this.layer.objectIdField,!1));this.getParent()&&(a=H(".dgrid-scroller",this.grid.domNode)[0],e=H(".dgrid-header",this.grid.domNode)[0],b=m.getComputedStyle(a),e=m.getMarginBox(e),b=parseInt(b.marginTop,10),isFinite(b)&&e&&b<e.h&&m.setStyle(a,"marginTop",e.h+"px"));d?m.addClass(this.domNode,"auto-width"):m.removeClass(this.domNode,"auto-width");this.footer?m.empty(this.footer):this.footer=m.create("div",
{id:this.parent.id+"_"+this.id+"_footer","class":this.parent.baseClass+"-feature-table-footer",tabindex:"-1"},this.domNode);c=m.create("div",{"class":"dgrid-status self-footer",innerHTML:c+"\x26nbsp;"+(this.layerInfo.isTable?this.nls.records:this.nls.features)+"\x26nbsp;"},this.footer);this.selectedRowsLabel=m.create("div",{"class":"dgrid-status self-footer",id:this.id+"_Selected_Rows_Label",innerHTML:"0\x26nbsp;"+this.nls.selected+"\x26nbsp;",style:{display:this.layer.objectIdField?"":"none"}},c,
"after");c=m.getStyle(this.domNode,"height");this.changeHeight(c);this._requestStatus="fulfilled";this.tableCreated=!0;m.place(this.loading.domNode,this.grid.domNode);this._toggleLoading(!1)},getSelectedRowsData:function(){var a=new B,b=this._getTableSelectedIds()||[];if(!this.grid||!b.length)return a.resolve(null),a;this.grid.store instanceof C?(b=g.clone(this.grid.store.data),a.resolve(b)):this.grid.store.query(b,{_export_count:b.length}).then(g.hitch(this,function(c){c=c&&g.clone(this.grid.store._entityData||
this.grid.store.data);a.resolve(c)}));return a},_appendXY:function(a){a&&"esriGeometryPoint"===this.layer.geometryType&&p.forEach(a,function(b){var c=b.geometry;c&&"point"===c.type&&("x"in b?b._x=c.x:b.x=c.x,"y"in b?b._y=c.y:b.y=c.y);delete b.geometry})},getOutFields:function(a){var b=null;b=this._getOutFieldsFromLayerInfos(this.layer.objectIdField);b=this._processExecuteFields(this.layer.fields,b);b=this._getVisibleFields(b);b=g.clone(b);a&&(a="",a=-1!==b.indexOf("x")?"_x":"x",b.push({name:a,alias:a,
format:{digitSeparator:!1,places:6},show:!0,type:"esriFieldTypeDouble"}),a=-1!==b.indexOf("y")?"_y":"y",b.push({name:a,alias:a,format:{digitSeparator:!1,places:6},show:!0,type:"esriFieldTypeDouble"}));return b},setSelectedNumber:function(){if(this.selectedRowsLabel&&this.grid){var a=this.getSelectedRows(),b=0;if(this.grid.store instanceof C){var c=p.map(this.grid.store.data,function(d){return d[this.layer.objectIdField]},this);p.forEach(a,function(d){-1<c.indexOf(d)&&b++})}else b=a.length;this.selectedRowsLabel.innerHTML=
"\x26nbsp;\x26nbsp;"+b+" "+this.nls.selected+"\x26nbsp;\x26nbsp;"}},_setSelection:function(a){this._selectionResults=a=a||[];this.selectionManager.setSelection(this.layer,a)},_zoomToExtentByFeatures:function(a){return this.getExtent(a).then(g.hitch(this,function(b){if(b&&this.domNode){var c=null;if("point"===b.type){var d=this.map.getNumLevels(),e=this.map.getLevel();c=this.map.getMaxZoom();0<d?(e===c?d=e:(d=e+4,d>c&&(d=c)),c=this.map.centerAndZoom(b,d)):c=this.map.centerAndZoom(b,1/Math.pow(2,4)*
2)}else c=this.map.setExtent(b.expand(2));return c.then(function(){return b})}}))},_showMapInfoWindowByFeatures:function(a,b){if(b&&0!==b.length&&this.domNode){var c=this.map.infoWindow,d=this.layerInfo.isPopupEnabled()&&this.layerInfo.getInfoTemplate();if(c&&c.setFeatures&&1===b.length&&d){p.forEach(b,g.hitch(this,function(f){f._layer=this.layerInfo.layerObject;f.setInfoTemplate(d)}));c.setFeatures(b);var e=null;e="point"===a.type?b[0].geometry:a.getCenter();c.show(e,{closetFirst:!0});this._dblClickResult=
b[0];this.syncWithMapInfowindow(this._dblClickResult)}}},selectFeatures:function(a,b){if(b&&0<b.length){if("rowclick"===a||"selectall"===a)this._setSelection(b);else if("zoom"===a||"row-dblclick"===a){var c=E.graphicsExtent(b),d=E.toFeatureSet(b),e=r(this.map,"zoom-end, pan-end",g.hitch(this,function(){e.remove();"row-dblclick"===a&&this.domNode&&this._showMapInfoWindowByFeatures(c,b)}));E.zoomToFeatureSet(this.map,d).then(null,function(f){f&&(console.error(f.message),e&&e.remove())})}this.setSelectedNumber();
this.onFeatureSelectionChange()}else this.onFeatureSelectionChange(),this._popupMessage(this.nls.dataNotAvailable)},syncWithMapInfowindow:function(a){var b=this.map.infoWindow,c=g.isArray(a)?a:[a];r.once(b,"hide",g.hitch(this,function(){d&&d.remove&&(d.remove(),d=null)}));var d=pa.after(b,"show",g.hitch(this,function(){var e=b.getSelectedFeature();e=e&&c[0]===e;var f=-1;b.features&&(f=b.features.indexOf(c[0]));!e&&-1<f?b.select(f):this.domNode&&!e&&d&&d.remove&&(d.remove(),d=null)}))},getGraphicsFromLocalFeatureLayer:function(a){for(var b=
[],c,d,e=a.length,f=this.layer.graphics.length,k=this.layer.objectIdField,l=0;l<e;l++)for(var h=0;h<f;h++)if(c=this.layer.graphics[h].attributes[k]+"",d=a[l]+"",c===d){b.push(this.layer.graphics[h]);break}return b},getExtent:function(a){var b=new B,c,d=a.length;if(1===d&&a[0].geometry&&"point"===a[0].geometry.type)var e=a[0].geometry;else if(1!==d||a[0].geometry)for(var f=0;f<d;f++)a[f].geometry?"point"===a[f].geometry.type?(c||(c=new la(a[f].geometry.spatialReference)),c.addPoint(a[f].geometry),
f===d-1&&(e=c.getExtent())):e=e?e.union(a[f].geometry.getExtent()):a[f].geometry.getExtent():console.error("unable to get geometry of the reocord: ",a[f]);else return b.reject(Error("AttributeTable.getExtent:: extent was not projected.")),b;if(!e||!e.spatialReference)return b.reject(Error("AttributeTable.getExtent:: extent was not projected.")),b;a=this.map.spatialReference;e.spatialReference.equals(a)?b.resolve(e):(c=new ka,c.geometries=[e],c.outSR=a,J.defaults.geometryService.project(c,g.hitch(this,
function(k){this.domNode&&(k&&k.length?b.resolve(k[0]):b.reject(Error("AttributeTable.getExtent:: extent was not projected.")))}),g.hitch(this,function(k){k||(k=Error("AttributeTable.getExtent:: extent was not projected."));b.reject(k)})));return b},_onFeaturelayerClick:function(a,b){if(this.actived){var c=g.getObject("graphic",!1,a),d=g.getObject("graphic.attributes",!1,a);d&&c&&c._layer===this.layer&&((c=this.map.infoWindow.getSelectedFeature())&&c._layer===this.layer&&!b&&this.map.infoWindow.hide(),
b=d[this.layer.objectIdField],this.showSelected&&this.toggleSelectedRecords(),this._getIndexOfIdInGrid(b).then(g.hitch(this,function(e){-1!==e&&(this.grid.scrollTo({x:0,y:this.grid.rowHeight*e}),this.map.infoWindow.features&&(e=this.map.infoWindow.features.indexOf(a.graphic),this.map.infoWindow.select(e)),r.once(this.map.infoWindow,"selection-change",g.hitch(this,function(){var f=this.map.infoWindow.getSelectedFeature(),k=g.getObject("_layer",!1,f);f!==a.graphic&&k===this.layer&&this._onFeaturelayerClick({graphic:f},
!0)})),this.syncWithMapInfowindow(a.graphic))})))}},_getIndexOfIdInGrid:function(a){var b=new B,c=-1,d=g.getObject("store.objectIds",!1,this.grid);c=null;c=this.grid.get("sort")[0];if(this._relatedQuery)return b.resolve(-1),b;if(this.grid.store instanceof C)a=this.grid.store.get(a),d=this.grid.store.data,a?c&&c.attribute&&w.isDefined(c.descending)?(d=g.clone(d),c=function(e,f){return function(k,l){return k[e]===l[e]?0:k[e]<l[e]?f?1:-1:f?-1:1}}(c.attribute,c.descending),d.sort(c),d=p.map(d,function(e){return e[this.layer.objectIdField]},
this),c=d.indexOf(a[this.layer.objectIdField])):c=d.indexOf(a):c=-1,b.resolve(c);else if(d&&0<d.length)c=d.indexOf(a),b.resolve(c);else{d=new D;d.returnGeometry=!1;d.where=this._getLayerFilterExpression()+" AND "+this.layer.objectIdField+" \x3c "+a;if(c&&(c.attribute!==this.layer.objectIdField||c.descending))return b.resolve(-1),b;this.matchingMap&&!this._relatedQuery&&this._currentExtent&&(d.geometry=this._currentExtent);(this._currentDef=this.layer.queryCount(d)).then(g.hitch(this,function(e){b.resolve(e)}),
g.hitch(this,function(e){b.reject(e)}))}return b},_zoomToSelected:function(){if(this.configedInfo&&this.tableCreated){var a=this.getSelectedRows();this._goToFeatures(a,"zoom")}},_goToFeatures:function(a,b){if(0!==a.length){var c=this.getGraphicsFromLocalFeatureLayer(a);this.isSupportQueryToServer()&&a.length!==c.length?this._queryFeaturesByIds(a,b):this.selectFeatures(b,c)}},_onDblclickRow:function(a){this.layerInfo&&this.layerInfo.isShowInMap()&&(a=[this.grid.row(a).id],this._goToFeatures(a,"row-dblclick"))},
_queryFeaturesByIds:function(a,b){var c=new D;c.objectIds=a;c.returnGeometry=!0;c.outSpatialReference=g.clone(this.map.spatialReference);c.outFields=["*"];a=this.layer;var d="esri.layers.CSVLayer"===a.declaredClass;a.url&&!d?(new F(a.url)).execute(c,g.hitch(this,function(e){this.selectFeatures(b,e.features)}),g.hitch(this,this._errorSelectFeatures)):a.selectFeatures(c,K.SELECTION_NEW,g.hitch(this,this.selectFeatures,b),g.hitch(this,this._errorSelectFeatures))},_onHeaderClick:function(a){var b=this.grid.cell(a),
c=b.column,d=b.element.getBoundingClientRect();this._showColumnMenu(c,b,a.target,{x:a.pageX||d.x+.5*d.width,y:a.pageY||d.y+d.height})},_showColumnMenu:function(a,b,c,d){var e=g.getObject("_cache",!1,a);if(e&&(e.sortable||e.statistics)){var f=new O({});m.addClass(f.domNode,"jimu-widget-attributetable-feature-menu");var k=this;if(e.sortable){var l=["iconSortAscending","iconSortDescending"];p.forEach([this.nls.sortAsc,this.nls.sortDes],function(h,n){h=new A({label:h,iconClass:l[n],baseClass:"menuItemClass",
onClick:function(){0===n?k.grid.set("sort",a.field,!1):1===n&&k.grid.set("sort",a.field,!0)}});f.addChild(h)})}e.statistics&&(e=new A({label:this.nls.statistics,iconClass:"iconTableStatistics",baseClass:"menuItemClass",onClick:g.hitch(this,function(){var h={layer:this.layer,filterExpression:this._getLayerFilterExpression(),fieldNames:[a.field]};this.matchingMap&&(h.geometry=this._currentExtent);if(this.showSelected){var n=this._getSelectedIds();h.filterExpression+=" AND "+this.layer.objectIdField+
" IN ("+n.join()+")"}else this.queryByStoreObjectIds&&0<this.queryByStoreObjectIds.length&&(h.filterExpression+=" AND "+this.layer.objectIdField+" IN ("+this.queryByStoreObjectIds.join()+")");this.fieldStatistics=new qa;this.fieldStatistics.showContentAsPopup(h)})}),f.addChild(e));e=f.getChildren();f.startup();f._openMyself({target:c,delegatedTarget:b,iframe:null,coords:d});this.own(r(f,"Close",g.hitch(this,function(){var h=this.get("columnMenu");h&&(h.destroyRecursive(),this.set("columnMenu",null))})));
this.set("columnMenu",f);1>e.length&&r.emit(f,"Close")}},_onColumnStateChange:function(a){if(a&&a.grid&&a.grid.columns){var b=0,c;for(c in a.grid.columns)a.grid.columns[c].hidden||b++;20+100*b-1<m.getMarginBox(this.domNode).w?m.addClass(this.domNode,"auto-width"):m.removeClass(this.domNode,"auto-width")}},_onSelectionHandleClick:function(){var a=this._getSelectedIds();this.selectionRows=a;this._closePopup();this.layerInfo.isTable||(0<a.length?this._goToFeatures(a,"rowclick"):(this.onFeatureSelectionChange(),
this._setSelection([])));this.setSelectedNumber();1===this.getSelectedRows().length&&this._setFarOffRemoval(this.GRID_FAR_OFF_REMOVAL.RESELECTION);this.emit("row-click",{table:this,selectedIds:a})},_onExtentChange:function(a){var b=g.getObject("delta.x",!1,a),c=g.getObject("delta.y",!1,a);a=this._clickMap&&!a.levelChange?isFinite(b)&&isFinite(c)&&(0<Math.abs(b)||0<Math.abs(c)):!0;this._clickMap=!1;a&&this.matchingMap&&this.actived&&this.layerInfo&&!this.layerInfo.isTable&&this.startQuery(this.queryByStoreObjectIds)},
_getLayerFilterExpression:function(){var a=this.layerInfo.getFilter();return a?a:"1\x3d1"},_getOutFieldsFromLayerInfos:function(a){var b=this.configedInfo.layer.fields,c=this.layerInfo.getPopupInfo(),d=c&&c.fieldInfos,e=[];b&&p.forEach(b,g.hitch(this,function(f){if(!w.isDefined(f.show)&&(f.show=!0,d))for(var k=0,l=d.length;k<l;k++){var h=d[k];h.fieldName===f.name&&(f.show=h.visible)}f.name!==a||"esriFieldTypeOID"!==f.type&&"esriFieldTypeInteger"!==f.type&&f.type||(f._pk=!0);(f.show||f._pk)&&e.push(f)}));
return e},_processExecuteFields:function(a,b){if(a&&0<a.length){var c=[];if(!b.length)return a;for(var d=0,e=b.length;d<e;d++)for(var f=0;f<a.length;f++)b[d].name!==a[f].name||b[d].type!==a[f].type&&b[d].type||(a[f]=g.mixin(a[f],b[d]),c.push(a[f]));return c}return b},_getVisibleFields:function(a){var b=[];if(this.grid&&this.grid.columns){for(var c in this.grid.columns){var d=this.grid.columns[c];d&&d.hidden&&b.push(d.field)}return p.filter(a,function(e){if(0>b.indexOf(e.name))return e})}return a},
_getSelectedIds:function(){var a=[],b=this.grid.selection,c;for(c in b)b[c]&&(isFinite(c)?a.push(parseInt(c,10)):a.push(c));return a},_getTableSelectedIds:function(){var a=[],b=this.getSelectedRows();if(this.grid)if(this.grid.store instanceof C){var c=p.map(this.grid.store.data,function(d){return d[this.layer.objectIdField]},this);p.forEach(b,function(d){-1<c.indexOf(d)&&a.push(parseInt(d,10))})}else a=b;return a},isSelectionMode:function(){var a=this.getSelectedRows();return this.tableCreated&&a&&
0<a.length&&this.layer&&this.layer.objectIdField?!0:!1},_errorSelectFeatures:function(a){console.error(a)},_popupMessage:function(a){var b=new G({message:a,buttons:[{label:this.nls.ok,onClick:g.hitch(this,function(){b.close()})}]});this._toggleLoading(!1)},_hasArcadeExpressionFields:function(){return this.layerInfo.getPopupInfo()&&this.layerInfo.getPopupInfo().expressionInfos&&p.some(this.configedInfo.layer.fields,function(a){return x.arcade.isArcadeExpressionField(a)})},_hasArcadeExpressionWithGeometry:function(){var a=
this.layerInfo.getPopupInfo()&&this.layerInfo.getPopupInfo().expressionInfos,b=x.arcade.parseArcadeExpressions(a);return b?p.some(Object.keys(b),function(c){return b[c].usesGeometry}):!1},_toggleLoading:function(a){void 0===a?this.loading.hidden?this.loading.show():this.loading.hide():a?this.loading.show():this.loading.hide()},_setFarOffRemoval:function(a){this.tableCreated&&!isNaN(a)&&this.grid.set("farOffRemoval",a)},_handleFilterChange:function(){var a=this.layer.getSelectedFeatures(),b=this.layer.objectIdField;
if(a&&0<a.length){var c=p.map(a,function(e){return e.attributes[b]}),d=new D;d.where=b+" in ("+c.join(",")+") AND "+this.layerInfo.getFilter();(new F(this.layer.url)).executeForIds(d).then(g.hitch(this,function(e){p.forEach(a,function(f){e&&0<=e.indexOf(f.attributes[b])?f.show():f.hide()});this.selectionManager._isLayerNeedDisplayLayer(this.layer)&&this.selectionManager._updateDisplayLayer(this.layer,a,K.SELECTION_NEW)}),g.hitch(this,function(e){console.error(e)}))}}})});