// 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/Query/SingleQueryResult.html":'\x3cdiv\x3e\r\n  \x3cdiv class\x3d"features-result" data-dojo-attach-point\x3d"featuresResultDiv"\x3e\r\n    \x3cdiv role\x3d"button" tabindex\x3d"0" class\x3d"popup-menu-button query-result-action-button" data-dojo-attach-point\x3d"btnFeatureAction" data-dojo-attach-event\x3d"click:_onBtnMenuClicked,keydown:_onBtnMenuKeydown"\x3e\x3c/div\x3e\r\n    \x3cdiv tabindex\x3d"0" class\x3d"results-number" data-dojo-attach-point\x3d"resultsNumberDiv"\x3e\r\n      \x3cdiv class\x3d"number-container"\x3e\r\n        \x3cdiv\x3e${nls.displayedFeatures}:\x3c/div\x3e\r\n        \x3cspan data-dojo-attach-point\x3d"numSpan"\x3e\x3c/span\x3e\r\n      \x3c/div\x3e\r\n      \x3cdiv class\x3d"action-container"\x3e\r\n        \x3cdiv role\x3d"button" tabindex\x3d"0" data-dojo-attach-point\x3d"loadMoreIcon" class\x3d"icon load-more-button query-hidden" title\x3d"${nls.loadMore}" data-dojo-attach-event\x3d"onclick:_onLoadMoreClicked,onkeydown:_onLoadMoreKeydown"\x3e\x3c/div\x3e\r\n        \x3cdiv role\x3d"button" tabindex\x3d"0" data-dojo-attach-point\x3d"expandedListIcon" class\x3d"icon expand-list" data-dojo-attach-event\x3d"onclick:_onExpandClicked,onkeydown:_onExpandKeydown"\x3e\x3c/div\x3e\r\n      \x3c/div\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv class\x3d"results-container" data-dojo-attach-point\x3d"resultsContainer" data-dojo-attach-event\x3d"onscroll:_onResultsScroll" onselectstart\x3d"return false;"\x3e\r\n      \x3ctable data-dojo-attach-point\x3d"resultsTable" valign\x3d"top" class\x3d"results-table" data-dojo-attach-event\x3d"onclick:_onResultsTableClicked,onkeydown:_onResultsTableKeydown" cellpadding\x3d"0" cellspacing\x3d"0" \x3e\r\n        \x3ctbody data-dojo-attach-point\x3d"resultsTbody"\x3e\x3c/tbody\x3e\r\n      \x3c/table\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n  \x3cdiv class\x3d"multiple-related-records-section not-visible" data-dojo-attach-point\x3d"multipleRelatedRecordsDiv"\x3e\r\n    \x3ctable class\x3d"related-records-header multiple-related-records-header"\x3e\r\n      \x3ctbody\x3e\r\n        \x3ctr\x3e\r\n          \x3ctd class\x3d"first-td"\x3e\r\n            \x3cdiv role\x3d"button" tabindex\x3d"0" aria-label\x3d"${nls.back}" class\x3d"back-arrow feature-action icon-arrow-back"  data-dojo-attach-point\x3d"multipleRelatedRecordsResultBackBtn" data-dojo-attach-event\x3d"onclick:_onBtnMultipleRelatedBackClicked,onkeydown:_onBtnMultipleRelatedBackKeydown"\x3e\x3c/div\x3e\r\n          \x3c/td\x3e\r\n          \x3ctd class\x3d"middle-td"\x3e\r\n            \x3cselect data-dojo-type\x3d"jimu/dijit/formSelect" aria-label\x3d"${nls.relatedLayer}" data-dojo-attach-point\x3d"relatedLayersSelect" data-dojo-attach-event\x3d"change:_onRelatedLayersSelectChanged" style\x3d"width:100%;"\x3e\x3c/select\x3e\r\n          \x3c/td\x3e\r\n          \x3ctd class\x3d"last-td"\x3e\x3c/td\x3e\r\n        \x3c/tr\x3e\r\n      \x3c/tbody\x3e\r\n    \x3c/table\x3e\r\n  \x3c/div\x3e\r\n  \x3cdiv class\x3d"single-related-records-section not-visible" data-dojo-attach-point\x3d"singleRelatedRecordsResultDiv"\x3e\r\n    \x3ctable role\x3d"title" tabindex\x3d"0" class\x3d"related-records-header single-related-records-header" data-dojo-attach-point\x3d"singleRelatedRecordsResultTitle" data-a11y-label-by\x3d"single-related-records-title"  data-dojo-attach-event\x3d"onkeydown:_onBtnSingleRelatedTitleKeydown"\x3e\r\n      \x3ctbody\x3e\r\n        \x3ctr\x3e\r\n          \x3ctd class\x3d"first-td"\x3e\r\n            \x3cdiv role\x3d"button" tabindex\x3d"0" aria-label\x3d"${nls.back}" class\x3d"back-arrow feature-action icon-arrow-back" data-dojo-attach-point\x3d"singleRelatedRecordsResultBackBtn" data-dojo-attach-event\x3d"onclick:_onBtnSingleRelatedBackClicked,onkeydown:_onBtnSingleRelatedBackKeydown"\x3e\x3c/div\x3e\r\n          \x3c/td\x3e\r\n          \x3ctd class\x3d"middle-td"\x3e\r\n            \x3cdiv class\x3d"related-records-title jimu-ellipsis" data-dojo-attach-point\x3d"relatedTitleDiv" data-a11y-label-id\x3d"single-related-records-title"\x3e\x3c/div\x3e\r\n          \x3c/td\x3e\r\n          \x3ctd class\x3d"last-td"\x3e\x3c/td\x3e\r\n        \x3c/tr\x3e\r\n      \x3c/tbody\x3e\r\n    \x3c/table\x3e\r\n  \x3c/div\x3e\r\n  \x3cdiv data-dojo-attach-point\x3d"shelter" data-dojo-type\x3d"jimu/dijit/LoadingIndicator" data-dojo-props\x3d"hidden:true"\x3e\x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare dijit/_WidgetBase jimu/dijit/BindLabelPropsMixin dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/Evented dojo/text!./SingleQueryResult.html dojo/_base/lang dojo/on dojo/keys dojo/_base/query dojo/_base/html dojo/_base/array dojo/Deferred esri/lang esri/tasks/QueryTask esri/tasks/FeatureSet esri/dijit/PopupTemplate esri/dijit/PopupRenderer esri/tasks/RelationshipQuery jimu/utils jimu/symbolUtils jimu/dijit/Popup jimu/dijit/Message jimu/dijit/FeatureActionPopupMenu jimu/BaseFeatureAction jimu/dijit/SymbolChooser jimu/LayerInfos/LayerInfos jimu/FeatureActionManager ./SingleQueryLoader ./RelatedRecordsResult jimu/dijit/LoadingIndicator jimu/dijit/formSelect".split(" "),
function(N,O,P,Q,R,S,T,g,z,m,v,e,q,F,U,V,C,W,X,Y,t,G,Z,aa,ba,D,ca,da,ea,fa,H){return N([O,P,Q,R,S],{baseClass:"single-query-result",templateString:T,singleQueryLoader:null,featureLayer:null,singleRelatedRecordsResult:null,multipleRelatedRecordsResult:null,popupMenu:null,map:null,nls:null,currentAttrs:null,queryWidget:null,_lastFeatureClass:"jimu-table-row-last",_lastFeatureArrowClass:"popup-title-icon",_lastRelatedClass:"related-table-btn-last",postMixInProperties:function(){this.inherited(arguments);
this.isRenderIdForAttrs=!0;var a=window.jimuNls.common;this.nls.back=a.back;this.nls.expand=a.expand.split(" $")[0];this.nls.collapse=a.collapse.split(" $")[0]},getCurrentAttrs:function(){return this.singleQueryLoader?this.singleQueryLoader.getCurrentAttrs():null},postCreate:function(){this.inherited(arguments);this.singleQueryLoader=new fa(this.map,this.currentAttrs);this.popupMenu=ba.getInstance();this.featureActionManager=ea.getInstance();this.btnFeatureAction.title=window.jimuNls.featureActions.featureActions;
this._initExpandListIcon();this.own(z(this.multipleRelatedRecordsDiv,"keydown",g.hitch(this,function(a){a.keyCode===m.ESCAPE&&a.target!==this.multipleRelatedRecordsResultBackBtn&&(a.stopPropagation(),this.multipleRelatedRecordsResultBackBtn.focus())})));this.own(z(this.singleRelatedRecordsResultDiv,"keydown",g.hitch(this,function(a){a.keyCode===m.ESCAPE&&a.target!==this.singleRelatedRecordsResultBackBtn&&(a.stopPropagation(),this.singleRelatedRecordsResultBackBtn.focus())})))},_initExpandListIcon:function(){var a=
this.getCurrentAttrs();(a=a&&a.config)&&a.defaultExpand?(e.addClass(this.expandedListIcon,"expanded"),this.expandedListIcon.title=this.nls.collapseAll,e.addClass(this.resultsTbody,"expanded")):(e.addClass(this.expandedListIcon,"folded"),this.expandedListIcon.title=this.nls.expandAll,e.addClass(this.resultsTbody,"folded"))},destroy:function(){this.emit("features-update",{taskIndex:this.currentAttrs.queryTr.taskIndex});this.queryWidget=null;var a=this.getCurrentAttrs();a&&a.query&&(a.query.resultLayer&&
a.query.resultLayer.getMap()&&this.map.removeLayer(a.query.resultLayer),a.query.resultLayer=null);this.inherited(arguments)},_isValidNumber:function(a){return"number"===typeof a&&!isNaN(a)},zoomToLayer:function(){var a=this.getCurrentAttrs(),b=a.query.resultLayer;b&&!this._isTable(a.layerInfo)&&(a=q.filter(b.graphics,g.hitch(this,function(c){return(c=c.geometry)?"point"===c.type?this._isValidNumber(c.x)&&this._isValidNumber(c.y):"multipoint"===c.type?c.points&&0<c.points.length?q.every(c.points,g.hitch(this,
function(d){return d?this._isValidNumber(d[0])&&this._isValidNumber(d[1]):!1})):!1:!0:!1})),0<a.length&&(a=t.toFeatureSet(a),t.zoomToFeatureSet(this.map,a)))},_emitFeaturesUpdate:function(){this.emit("features-update",{taskIndex:this.currentAttrs.queryTr.taskIndex,features:this.currentAttrs.query.resultLayer.graphics})},executeQueryForFirstTime:function(){var a=new F;this._clearResultPage();this._hideResultsNumberDiv();var b=this.getCurrentAttrs(),c=b.query.resultLayer,d=g.hitch(this,function(l){if(this.domNode){this.shelter.hide();
var k=b.query.allCount;this._updateNumSpan(b.query.foundedNum,k);0<k&&(this._addResultItems(l,c),this._addResultLayerToMap(c),this.zoomToLayer());a.resolve(k);this._emitFeaturesUpdate()}}),f=g.hitch(this,function(l){console.error(l);this.domNode&&(this.shelter.hide(),c&&this.map.removeLayer(c),c=null,this._showQueryErrorMsg(),a.reject(l))});this.shelter.show();3!==b.queryType&&this._showResultsNumberDiv();this.singleQueryLoader.executeQueryForFirstTime().then(d,f);return a},getResultLayer:function(){var a=
this.getCurrentAttrs();return g.getObject("query.resultLayer",!1,a)},showResultLayer:function(){var a=this.getResultLayer();a&&a.show()},hideResultLayer:function(){var a=this.getResultLayer();a&&a.hide()},showLayer:function(){this.showResultLayer();this.multipleRelatedRecordsResult&&this.multipleRelatedRecordsResult.showLayer();this.singleRelatedRecordsResult&&this.singleRelatedRecordsResult.showLayer()},hideLayer:function(){this.hideResultLayer();this.multipleRelatedRecordsResult&&this.multipleRelatedRecordsResult.hideLayer();
this.singleRelatedRecordsResult&&this.singleRelatedRecordsResult.hideLayer()},_addResultLayerToMap:function(a){0>this.map.graphicsLayerIds.indexOf(a.id)&&this.map.addLayer(a)},_showResultsNumberDiv:function(){e.setStyle(this.resultsNumberDiv,"display","flex")},_hideResultsNumberDiv:function(){e.setStyle(this.resultsNumberDiv,"display","none")},_updateNumSpan:function(a,b){a>b&&(a=b);this._updateLoadMoreVisible(a<b);a=t.localizeNumber(a);b=t.localizeNumber(b);this.numSpan.innerHTML=a+"/"+b},_isTable:function(a){return"Table"===
a.type},_onResultsScroll:function(){t.isScrollToBottom(this.resultsContainer)&&this._continueQuery()},_continueQuery:function(){var a=this.getCurrentAttrs(),b=a.query.allCount,c=a.query.foundedNum;if(!(c>=b)){var d=a.query.resultLayer,f=g.hitch(this,function(k){this.domNode&&(this._updateLoadMoreState(!1),this.shelter.hide(),c=a.query.foundedNum,this._updateNumSpan(c,b),this._addResultItems(k,d),this.zoomToLayer(),this._emitFeaturesUpdate(),this.emit("features-layout-update"))}),l=g.hitch(this,function(k){console.error(k);
this.domNode&&(this._updateLoadMoreState(!1),this._showQueryErrorMsg(),this.shelter.hide())});this.shelter.show();this._updateLoadMoreState(!0);this.singleQueryLoader.executeQueryWhenScrollToBottom().then(f,l)}},_clearResultPage:function(){this._hideInfoWindow();this._unSelectResultTr();e.empty(this.resultsTbody);this._updateNumSpan(0,0)},_unSelectResultTr:function(){this.resultTr&&e.removeClass(this.resultTr,"jimu-state-active");this.resultTr=null},_selectResultTr:function(a){this._unSelectResultTr();
(this.resultTr=a)&&e.addClass(this.resultTr,"jimu-state-active")},_addResultItems:function(a,b){var c=this.getCurrentAttrs(),d=c.config.url,f=c.config.objectIdField,l=this._getCurrentRelationships(),k=g.clone(c.config.popupInfo);k.mediaInfos=[];var n=new W(k),h=!0;b.renderer||(h=!1);var p=this._isWebMapShowRelatedRecordsEnabled();this._featuresNum=a.length;q.forEach(a,g.hitch(this,function(r,A){var B="";B=0===A%2?"even":"odd";b.add(r);this._createQueryResultItem({resultLayer:b,feature:r,trClass:B,
popupTemplate2:n,relationships:l,objectIdField:f,url:d,relationshipPopupTemplates:c.relationshipPopupTemplates,shouldCreateSymbolNode:h,isWebMapShowRelatedRecordsEnabled:p},A)}))},_updateLoadMoreVisible:function(a){a?e.removeClass(this.loadMoreIcon,"query-hidden"):e.addClass(this.loadMoreIcon,"query-hidden")},_updateLoadMoreState:function(a){a?e.addClass(this.loadMoreIcon,"loading"):e.removeClass(this.loadMoreIcon,"loading")},_onLoadMoreClicked:function(){this._continueQuery()},_onLoadMoreKeydown:function(a){a.keyCode!==
m.ENTER&&a.keyCode!==m.SPACE||this._onLoadMoreClicked()},_clearPopItemClass:function(){var a=v(".query-result-item-table .popup-td.expanded",this.resultsTbody),b=v(".query-result-item-table .popup-td.folded",this.resultsTbody);a&&a.length&&a.removeClass("expanded");b&&b.length&&b.removeClass("folded")},_onExpandClicked:function(){var a=this.nls.expand;this._clearPopItemClass();e.hasClass(this.resultsTbody,"expanded")?(e.addClass(this.expandedListIcon,"folded"),e.removeClass(this.resultsTbody,"expanded"),
e.addClass(this.resultsTbody,"folded"),this.expandedListIcon.title=this.nls.expandAll):(e.removeClass(this.expandedListIcon,"folded"),e.addClass(this.resultsTbody,"expanded"),e.removeClass(this.resultsTbody,"folded"),this.expandedListIcon.title=this.nls.collapseAll,a=this.nls.collapse);for(var b=v(".popup-title-icon",this.resultsTbody),c=0;c<b.length;c++)e.setAttr(b[c],"aria-label",a);this.emit("features-layout-update")},_onExpandKeydown:function(a){a.keyCode!==m.ENTER&&a.keyCode!==m.SPACE||this._onExpandClicked()},
_getPopupTitle:function(a,b){if(a)return"function"===typeof a.title?a.title(b):a.title},_createQueryResultItem:function(a,b){var c="",d="",f="";b===this._featuresNum-1&&(c=" "+this._lastFeatureClass,d=" "+this._lastRelatedClass,f='data-lastArrow\x3d"true"');var l=a.resultLayer,k=a.feature,n=a.trClass,h=a.popupTemplate2,p=a.relationships,r=a.objectIdField,A=a.url,B=a.relationshipPopupTemplates,w=a.shouldCreateSymbolNode;a=a.isWebMapShowRelatedRecordsEnabled;if(k&&k.attributes){var ha=this._getPopupTitle(h,
k);c=e.toDom('\x3ctr role\x3d"button" tabindex\x3d"0" class\x3d"jimu-table-row jimu-table-row-separator query-result-item'+c+'"  cellpadding\x3d"0" cellspacing\x3d"0"\x3e\x3ctd\x3e\x3ctable class\x3d"query-result-item-table"\x3e\x3ctbody\x3e\x3ctr\x3e\x3ctd class\x3d"symbol-td"\x3e\x3c/td\x3e\x3ctd class\x3d"popup-td expanded"\x3e\x3cdiv class\x3d"popup-title-container"\x3e\x3cdiv class\x3d"popup-title"\x3e'+ha+'\x3c/div\x3e\x3cdiv role\x3d"button" tabindex\x3d"0" aria-label\x3d"'+this.nls.collapse+
'" '+f+' class\x3d"popup-title-icon"\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d"popup-content"\x3e\x3c/div\x3e\x3c/td\x3e\x3c/tr\x3e\x3c/tbody\x3e\x3c/table\x3e\x3c/td\x3e\x3c/tr\x3e');e.addClass(c,n);e.place(c,this.resultsTbody);c.feature=k;n=v(".symbol-td",c)[0];if(w)try{var x=l.renderer;if(x){var I=x.getSymbol(k);if(I){var J=G.createSymbolNode(I,{width:32,height:32});J&&e.place(J,n)}}}catch(y){console.error(y)}else e.destroy(n);var K=v(".popup-td .popup-content",c)[0];l=h.title;w=h.info&&h.info.title;
h.title=null;w&&(h.info.title=null);x=new X({template:h,graphic:k,chartTheme:h.chartTheme});e.place(x.domNode,K);x.startup();h.title=l;w&&(h.info.title=w);if(r&&p&&0<p.length&&a){var ia=k.attributes[r];q.forEach(p,g.hitch(this,function(y,u){var L=this._getRelationshipLayerInfo(y.relatedTableId),M=L.name,ja=B[y.relatedTableId],E="related-table-btn";b===this._featuresNum-1&&u===p.length-1&&(E=E+" "+d);u=e.create("div",{"class":E,role:"button",tabindex:"0",innerHTML:M},K);u.queryStatus="unload";u.url=
A;u.layerName=M;u.objectId=ia;u.relationship=y;u.relationshipLayerInfo=L;u.relationshipPopupTemplate=ja}))}}},_onBtnMultipleRelatedBackClicked:function(){this._showFeaturesResultDiv()},_onBtnMultipleRelatedBackKeydown:function(a){a.keyCode===m.ENTER||a.keyCode===m.SPACE||a.keyCode===m.ESCAPE?(a.stopPropagation(),this._onBtnMultipleRelatedBackClicked(),this.btnFeatureAction.focus()):a.keyCode===m.TAB&&a.shiftKey&&(a.preventDefault(),this.multipleRelatedRecordsResult.lastFocusItem.focus())},_onBtnSingleRelatedBackClicked:function(){this._showFeaturesResultDiv()},
_onBtnSingleRelatedBackKeydown:function(a){a.keyCode===m.ENTER||a.keyCode===m.SPACE||a.keyCode===m.ESCAPE?(a.stopPropagation(),this._onBtnSingleRelatedBackClicked(),this._currentRelatedRecord.focus()):a.keyCode===m.TAB&&a.shiftKey&&a.stopPropagation()},_onBtnSingleRelatedTitleKeydown:function(a){a.keyCode===m.TAB&&a.shiftKey&&(a.preventDefault(),this.singleRelatedRecordsResult.lastFocusItem.focus())},_showFeaturesResultDiv:function(){this.multipleRelatedRecordsResult&&this.multipleRelatedRecordsResult.destroy();
this.multipleRelatedRecordsResult=null;this.singleRelatedRecordsResult&&this.singleRelatedRecordsResult.destroy();this.singleRelatedRecordsResult=null;e.addClass(this.multipleRelatedRecordsDiv,"not-visible");e.addClass(this.singleRelatedRecordsResultDiv,"not-visible");e.removeClass(this.featuresResultDiv,"not-visible");this.emit("hide-related-records")},_showMultipleRelatedRecords:function(){this.singleRelatedRecordsResult&&this.singleRelatedRecordsResult.destroy();this.singleRelatedRecordsResult=
null;e.addClass(this.featuresResultDiv,"not-visible");e.addClass(this.singleRelatedRecordsResultDiv,"not-visible");e.removeClass(this.multipleRelatedRecordsDiv,"not-visible");this.emit("show-related-records");var a=this._getCurrentRelationships();this.relatedLayersSelect.removeOption(this.relatedLayersSelect.getOptions());q.forEach(a,g.hitch(this,function(b){var c=this._getRelationshipLayerInfo(b.relatedTableId);this.relatedLayersSelect.addOption({value:b.id+"",label:c.name,relationship:b,relationshipLayerInfo:c,
relationshipPopupTemplate:this.currentAttrs.relationshipPopupTemplates[b.relatedTableId]})}));this._onRelatedLayersSelectChanged()},_onRelatedLayersSelectChanged:function(){var a=this.relatedLayersSelect.get("value"),b=this.relatedLayersSelect.getOptions(a);if(b){this.multipleRelatedRecordsResult&&this.multipleRelatedRecordsResult.destroy();this.multipleRelatedRecordsResult=new H({map:this.map,layerDefinition:b.relationshipLayerInfo,nls:this.nls,config:this.currentAttrs.config});this.multipleRelatedRecordsResult.placeAt(this.multipleRelatedRecordsDiv);
this.multipleRelatedRecordsResult.lastFocusItem=this.multipleRelatedRecordsResultBackBtn;this.multipleRelatedRecordsResultBackBtn.focus();this.own(z(this.multipleRelatedRecordsResult,"focus-result-header",g.hitch(this,function(){this.multipleRelatedRecordsResultBackBtn.focus()})));var c=this.currentAttrs.config.url;this.shelter.show();var d=g.hitch(this,function(f){console.error(f);this.domNode&&this.shelter.hide()});this.singleQueryLoader.getObjectIdsForAllRelatedRecordsAction().then(g.hitch(this,
function(f){this._queryRelatedRecords(c,f,b.relationship.id).then(g.hitch(this,function(l){if(this.domNode){this.shelter.hide();var k=[];q.forEach(f,g.hitch(this,function(p){(p=l[p])&&p.features&&0<p.features.length&&(k=k.concat(p.features))}));var n=b.relationshipLayerInfo,h=new C;h.fields=g.clone(n.fields);h.features=k;h.geometryType=n.geometryType;h.fieldAliases={};q.forEach(h.fields,g.hitch(this,function(p){var r=p.name;h.fieldAliases[r]=p.alias||r}));this.multipleRelatedRecordsResult.setResult(b.relationshipPopupTemplate,
h)}}),d)}),d)}},_showSingleRelatedRecordsDiv:function(){this.multipleRelatedRecordsResult&&this.multipleRelatedRecordsResult.destroy();this.multipleRelatedRecordsResult=null;e.addClass(this.featuresResultDiv,"not-visible");e.addClass(this.multipleRelatedRecordsDiv,"not-visible");e.removeClass(this.singleRelatedRecordsResultDiv,"not-visible");this.emit("show-related-records")},_onSingleRelatedTableButtonClicked:function(a){this.singleRelatedRecordsResult&&this.singleRelatedRecordsResult.destroy();
this.singleRelatedRecordsResult=null;var b=a.url,c=a.layerName,d=a.objectId,f=a.relationship,l=a.relationshipLayerInfo,k=a.relationshipPopupTemplate;this.singleRelatedRecordsResult=new H({map:this.map,layerDefinition:l,nls:this.nls,config:this.currentAttrs.config});this.singleRelatedRecordsResult.placeAt(this.singleRelatedRecordsResultDiv);this.singleRelatedRecordsResultTitle.lastFocusItem=this.singleRelatedRecordsResultBackBtn;this.own(z(this.singleRelatedRecordsResult,"focus-result-header",g.hitch(this,
function(){this.singleRelatedRecordsResultTitle.focus()})));this._showSingleRelatedRecordsDiv();var n=g.hitch(this,function(){var h=new C;h.fields=g.clone(l.fields);h.features=a.relatedFeatures;h.geometryType=l.geometryType;h.fieldAliases={};q.forEach(h.fields,g.hitch(this,function(p){var r=p.name;h.fieldAliases[r]=p.alias||r}));this.singleRelatedRecordsResult.setResult(k,h);this.relatedTitleDiv.innerHTML=c;this.singleRelatedRecordsResultTitle.focus();this._currentRelatedRecord=a});"unload"===a.queryStatus?
(a.queryStatus="loading",this.shelter.show(),this._queryRelatedRecords(b,[d],f.id).then(g.hitch(this,function(h){this.domNode&&(this.shelter.hide(),h=(h=(h=h&&h[d])&&h.features)||[],a.relatedFeatures=h,a.queryStatus="loaded",n())}),g.hitch(this,function(h){this.domNode&&(this.shelter.hide(),console.error(h),a.queryStatus="unload",n())}))):"loaded"===a.queryStatus&&n()},_queryRelatedRecords:function(a,b,c){a=new V(a);var d=new Y;d.objectIds=b;d.relationshipId=c;d.outFields=["*"];d.returnGeometry=!0;
d.outSpatialReference=this.map.spatialReference;return a.executeRelationshipQuery(d)},_getCurrentRelationships:function(){return this.getCurrentAttrs().queryTr.layerInfo.relationships||[]},_getRelationshipInfo:function(a){for(var b=this._getCurrentRelationships(),c=0;c<b.length;c++)if(b[c].id===a)return b[c];return null},_getRelationshipLayerInfo:function(a){return this.getCurrentAttrs().relationshipLayerInfos[a]},_tryLocaleNumber:function(a){var b=a;if(U.isDefined(a)&&isFinite(a))try{var c=t.localizeNumber(a);
"string"===typeof c&&(b=c)}catch(d){console.error(d)}return b+""},_showQueryErrorMsg:function(a){new aa({message:a||this.nls.queryError})},_onSinglePopupExpandIconClicked:function(a){var b=this.nls.expand,c=a.parentNode.parentNode;if(c){var d=e.hasClass(this.resultsTbody,"expanded");e.hasClass(c,"expanded")||e.hasClass(c,"folded")?e.hasClass(c,"expanded")?(e.removeClass(c,"expanded"),e.addClass(c,"folded")):(e.addClass(c,"expanded"),e.removeClass(c,"folded"),b=this.nls.collapse):d?(e.addClass(c,"folded"),
e.removeClass(c,"expanded")):(e.addClass(c,"expanded"),e.removeClass(c,"folded"),b=this.nls.collapse);e.setAttr(a,"aria-label",b);"true"===e.getAttr(a,"data-lastArrow")&&this.emit("features-layout-update")}},_onResultsTableKeydown:function(a){a.keyCode!==m.ENTER&&a.keyCode!==m.SPACE||this._onResultsTableClicked(a)},_onResultsTableClicked:function(a){a=a.target||a.srcElement;if(e.isDescendant(a,this.resultsTable))if(e.hasClass(a,"popup-title-icon"))this._onSinglePopupExpandIconClicked(a);else if(e.hasClass(a,
"related-table-btn"))this._onSingleRelatedTableButtonClicked(a);else if(a=e.hasClass(a,"query-result-item")?a:t.getAncestorDom(a,g.hitch(this,function(f){return e.hasClass(f,"query-result-item")}),this.resultsTbody)){this._selectResultTr(a);e.addClass(a,"jimu-state-active");a=a.feature;var b=a.geometry;if(b){var c=b.type;if("point"===c)var d=b;else"multipoint"===c?1===b.points.length?d=b.getPoint(0):1<b.points.length&&(d=b.getPoint(0)):"polyline"===c?(d=b.getExtent(),d=d.expand(1.4),d=d.getCenter()):
"polygon"===c?(d=b.getExtent(),d=d.expand(1.4),d=d.getCenter()):"extent"===c&&(d=b.expand(1.4),d=d.getCenter());b=t.toFeatureSet(a);t.zoomToFeatureSet(this.map,b);"function"===typeof this.map.infoWindow.setFeatures&&this.map.infoWindow.setFeatures([a]);"function"===typeof this.map.infoWindow.reposition&&this.map.infoWindow.reposition();this.map.infoWindow.show(d)}}},_hideInfoWindow:function(){this.map&&this.map.infoWindow&&(this.map.infoWindow.hide(),"function"===typeof this.map.infoWindow.setFeatures&&
this.map.infoWindow.setFeatures([]))},_getDisplayedFields:function(a,b){a=g.clone(a);if(b&&!b.readFromWebMap){var c=[];q.map(b.fieldInfos,function(f){f.visible&&c.push(f.fieldName)});b=b.title.substring(1,b.title.length-1).split("}{");var d=c.concat(b);a=q.filter(a,function(f){return d.includes(f.name)})}return a},_getFeatureSet:function(){var a=this.currentAttrs.query.resultLayer,b=null,c=this.currentAttrs.config&&this.currentAttrs.config.popupInfo;c&&(b=c.fieldInfos);var d=new C;d.fields=this._getDisplayedFields(a.fields,
c);d.features=[].concat(a.graphics);d.geometryType=a.geometryType;d.fieldAliases={};q.forEach(d.fields,g.hitch(this,function(f){var l=f.name;f=this._getFieldAliasByPopupInfo(f,b);d.fieldAliases[l]=f}));return d},_getFieldAliasByPopupInfo:function(a,b){var c=a.name;a=a.alias||c;b&&b.length&&(b=b.filter(function(d){return d.fieldName===c})[0])&&(a=b.label);return a},_onBtnMenuClicked:function(a){var b=e.position(a.target||a.srcElement),c=this._getFeatureSet(),d=this.getCurrentAttrs();this.featureActionManager.getSupportedActions(c,
d.query.resultLayer).then(g.hitch(this,function(f){q.forEach(f,g.hitch(this,function(n){n.data=c}));if(!d.config.enableExport){var l=["ExportToCSV","ExportToFeatureCollection","ExportToGeoJSON","SaveToMyContent"];f=q.filter(f,g.hitch(this,function(n){return 0>l.indexOf(n.name)}))}f=q.filter(f,g.hitch(this,function(n){return"CreateLayer"!==n.name}));var k=new D({name:"RemoveQueryResult",iconClass:"icon-close",label:this.nls.removeThisResult,iconFormat:"svg",map:this.map,onExecute:g.hitch(this,this._removeResult)});
k.name="RemoveQueryResult";k.data=c;f.push(k);(k=this._getRelatedTableAction(c))&&f.push(k);(k=this._getSymbolAction(c))&&f.push(k);this.popupMenu.setActions(f);this.popupMenu._setFocusedNodeBeforeOpen();this.popupMenu.show(b)}))},_onBtnMenuKeydown:function(a){a.keyCode!==m.ENTER&&a.keyCode!==m.SPACE||this._onBtnMenuClicked(a)},_getObjectIdField:function(){return this.currentAttrs.config.objectIdField},_getSymbolAction:function(a){var b=null;this.currentAttrs.query.resultLayer.renderer&&this.currentAttrs.config.canModifySymbol&&
(b=new D({name:"ChangeSymbol",label:this.nls.changeSymbol,data:a&&a.features,iconClass:"icon-edit-symbol",iconFormat:"svg",map:this.map,onExecute:g.hitch(this,this._showSymbolChooser)}));return b},_showSymbolChooser:function(){var a=this.currentAttrs.query.resultLayer,b=a.renderer,c={};(b=b.defaultSymbol||b.symbol)?c.symbol=b:(a=t.getSymbolTypeByGeometryType(a.geometryType),c.type=a);var d=new ca(c),f=new Z({width:380,autoHeight:!0,titleLabel:this.nls.changeSymbol,content:d,onClose:g.hitch(this,function(){d.destroy();
f=d=null}),buttons:[{label:window.jimuNls.common.ok,onClick:g.hitch(this,function(){var l=d.getSymbol();this._updateSymbol(l);f.close()})},{label:window.jimuNls.common.cancel,onClick:g.hitch(this,function(){f.close()})}]})},_updateSymbol:function(a){var b=this.currentAttrs.query.resultLayer;q.forEach(b.graphics,function(c){c.setSymbol(a)});b.redraw();b=v(".symbol",this.resultsTable);q.forEach(b,g.hitch(this,function(c){var d=c.parentElement;e.destroy(c);(c=G.createSymbolNode(a,{width:32,height:32}))&&
e.place(c,d)}))},_getRelatedTableAction:function(a){var b=null,c=a&&a.features,d=this._getCurrentRelationships();this._getObjectIdField()&&0<c.length&&d&&0<d.length&&this._isWebMapShowRelatedRecordsEnabled()&&(b=new D({iconClass:"icon-show-related-record",icon:"",data:a,label:this.nls.showAllRelatedRecords,onExecute:g.hitch(this,function(){this._showMultipleRelatedRecords();var f=new F;f.resolve();return f}),getIcon:function(){return""}}));return b},_isWebMapShowRelatedRecordsEnabled:function(){var a=
this.currentAttrs.config.popupInfo;return a.relatedRecordsInfo?!1!==a.relatedRecordsInfo.showRelatedRecords:!0},_removeResult:function(){this.queryWidget.removeSingleQueryResult(this);this._hideInfoWindow()},_getAvailableWidget:function(a){return(a=this.queryWidget.appConfig.getConfigElementsByName(a)[0])&&a.visible?a:null},_openAttributeTable:function(){var a=this._getAvailableWidget("AttributeTable");if(a){var b=da.getInstanceSync().getLayerInfoById(this.currentAttrs.query.resultLayer.id);this.queryWidget.widgetManager.triggerWidgetOpen(a.id).then(g.hitch(this,
function(){this.queryWidget.publishData({target:"AttributeTable",layer:b})}))}}})});