// 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/lang dojo/_base/array dojo/_base/html dojo/on dojo/has dojo/query dojo/Deferred dojo/promise/all dijit/_WidgetBase dijit/_TemplatedMixin esri/undoManager esri/OperationBase esri/tasks/RelationshipQuery esri/dijit/Popup esri/dijit/PopupMobile esri/graphicsUtils esri/dijit/PopupTemplate jimu/utils jimu/ConfigManager jimu/dijit/DropdownMenu jimu/LayerInfos/LayerInfos".split(" "),function(v,g,p,e,u,z,l,A,B,C,D,E,F,O,x,G,H,I,J,K,L,M){var q=v([C,D],{baseClass:"related-records-popup-projector",
templateString:"\x3cdiv\x3e\x3cdiv class\x3d'operation-box' data-dojo-attach-point\x3d'operationBox' style\x3d'display: none'\x3e\x3cdiv class\x3d'previos-btn feature-action' data-dojo-attach-point\x3d'previouBtn'data-dojo-attach-event\x3d'click:_onPreviouBtnClick'\x3e\x3c/div\x3e\x3cdiv class\x3d'operation-title' data-dojo-attach-point\x3d'operationTitle'\x3eabc\x3c/div\x3e\x3cdiv class\x3d'add-new-btn' data-dojo-attach-point\x3d'addNewBtn'\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d'content-box' data-dojo-attach-point\x3d'contentBox'\x3e\x3c/div\x3e\x3c/div\x3e",
popup:null,popupManager:null,undoManager:null,originalFeature:null,originalJimuLayerInfo:null,_temporaryData:null,postCreate:function(){this.undoManager=new E;this.layerInfosObj=M.getInstanceSync();var a=g.getObject("_wabProperties.referToFeatureLayerId",!1,this.originalFeature)||this.originalFeature.getLayer().id;this.originalJimuLayerInfo=this.layerInfosObj.getLayerInfoById(a);this._temporaryData={eventHandles:[],dijits:[]};window.isRTL?e.addClass(this.previouBtn,"icon-arrow-forward"):e.addClass(this.previouBtn,
"icon-arrow-back");a=this._createOperation({feature:this.originalFeature,oriJimuLayerInfo:this.originalJimuLayerInfo});this.showRelatedTables(a);this.popupUIController="esri.dijit.Popup"===this.popup.declaredClass?new q.PopupUIController(this):new q.PopupMobileUIController(this);this.popupUIController.addDomNode(this.domNode)},destroy:function(){this._clearPage();this.undoManager.destroy();this.popupUIController.destroy();this.inherited(arguments)},_getRelatedTableInfoArray:function(a){a=a.data.oriJimuLayerInfo;
var b=new A;a.getRelatedTableInfoArray().then(g.hitch(this,function(c){b.resolve(c)}));return b},_getRelatedRecordsByRelatedQuery:function(a){return a.oriJimuLayerInfo.getRelatedRecords(a.feature,a.destJimuLayerInfo,a.relationshipIndex)},_ignoreCaseToGetFieldObject:function(a,b){var c=null;b&&a&&a.fields&&p.some(a.fields,function(d){if(d.name.toLowerCase()===b.toLowerCase())return c=d,!0});return c},getLocaleDateTime:function(a){return J.localizeDate(new Date(a),{fullYear:!0,formatLength:"medium"})},
_getDisplayTitleOfRelatedRecord:function(a,b,c){var d=a.getInfoTemplate();return(a="popupTitle"===c&&d?"function"===typeof d.title?d.title(b):d.title:this._getDisplayTitleFromPopup(a,b,c))?a:" "},_getDisplayTitleFromPopup:function(a,b,c){(a=this._getPopupTemplateWithOnlyDisplayField(a,c))?(b.setInfoTemplate(a),c=this.popupUIController.getDisplayTitle(b),b.setInfoTemplate(null)):c=b.attributes[c];return c},_getPopupTemplateWithOnlyDisplayField:function(a,b){a=a.getPopupInfo()||a._getDefaultPopupInfo(a.layerObject);
var c={title:"",fieldInfos:[],description:"",showAttachments:!1,mediaInfos:[]};try{a&&a.fieldInfos&&b&&p.some(a.fieldInfos,function(d){return d.fieldName.toLowerCase()===b.toLowerCase()?(d=g.clone(d),d.visible=!0,c.fieldInfos.push(d),!0):!1},this)}catch(d){console.error(d)}return new I(c)},_canShowRelatedData:function(a){var b=!0;(a=a.getPopupInfo())&&a.relatedRecordsInfo&&(b=!1!==a.relatedRecordsInfo.showRelatedRecords);return b},setPopupContent:function(a){this._clearPage();a.data.destJimuLayerInfo?
a.data.relatedFeature||this.showRelatedRecords(a):this.showFeature(a);this.undoManager.peekUndo()?this.popupUIController.changeRefDomNode():this.popupUIController.revertRefDomNode()},showFeature:function(a){var b=a.data,c=b.oriJimuLayerInfo.layerObject,d=g.getObject("_wabProperties.originalLayerName",!1,c)||b.oriJimuLayerInfo.title;c=g.getObject("_wabProperties.popupInfo.displayFieldOfRelatedRecordList",!1,c);var f=this._getDisplayTitleOfRelatedRecord(b.oriJimuLayerInfo,b.feature,c);"popupTitle"!==
c&&(f=d+": "+f);this._setOperationTitle(f);g.setObject("_wabProperties.popupInfo.operationDataForListRelatedRecords",null,b.oriJimuLayerInfo.layerObject);b.oriJimuLayerInfo.loadInfoTemplate().then(g.hitch(this,function(k){b.oriJimuLayerInfo.layerObject.infoTemplate||a.data.feature.setInfoTemplate(k);this.popupUIController.setFeature(a.data.feature);b.oriJimuLayerInfo.layerObject.infoTemplate||a.data.feature.setInfoTemplate(null)}));this.showRelatedTables(a);this.popupManager.initPopupMenu([a.data.feature]);
this.popupUIController.updateZoomToBtn([a.data.feature])},showRelatedRecords:function(a){var b=a.data,c=g.getObject("_wabProperties.originalLayerName",!1,b.destJimuLayerInfo.layerObject)||b.destJimuLayerInfo.title;this._setOperationTitle(c);this._clearPage();g.setObject("_wabProperties.popupInfo.operationDataForListRelatedRecords",b,b.destJimuLayerInfo.layerObject);g.setObject("_wabProperties.popupInfo.originalFeature",this.originalFeature,b.destJimuLayerInfo.layerObject);g.setObject("_wabProperties.popupInfo.layerForActionWithEmptyFeatures",
b.destJimuLayerInfo.layerObject,this.popup);this._getRelatedRecordsByRelatedQuery(b).then(g.hitch(this,function(d){0<d.length?this._setTitle(window.jimuNls.popup.relatedRecords):this._setTitle(window.jimuNls.popup.noRelatedRecotds,"font-normal");var f=this._showFieldSelector(b.destJimuLayerInfo);p.forEach(d,function(k,m){k._layer=b.destJimuLayerInfo.layerObject;var r=this._getDisplayTitleOfRelatedRecord(b.destJimuLayerInfo,k,f);m=e.create("div",{"class":"item record-item "+(0===m%2?"oddLine":"evenLine"),
innerHTML:r},this.contentBox);m.relatedRecord=k;m=u(m,"click",g.hitch(this,function(){this._addOperation(a);var n=this._createOperation({feature:k,oriJimuLayerInfo:b.destJimuLayerInfo,relationshipIndex:b.relationshipIndex});this.setPopupContent(n)}));this._temporaryData.eventHandles.push(m)},this);this.popupManager.initPopupMenu(d);this.popupUIController.updateZoomToBtn(d)}));this.popupUIController.setContent(this.domNode)},showRelatedTables:function(a){this._canShowRelatedData(a.data.oriJimuLayerInfo)&&
this._getRelatedTableInfoArray(a).then(g.hitch(this,function(b){0<b.length&&this._setTitle(window.jimuNls.popup.relatedTables);var c={};p.forEach(b,function(f){void 0===c[f.id]?c[f.id]=0:c[f.id]++},this);var d={};p.forEach(b,function(f,k){void 0===d[f.id]?d[f.id]=0:d[f.id]++;var m='\x3cdiv title\x3d"'+f.title+'"\x3e'+f.title+"\x3c/div\x3e",r=e.create("div",{"class":"item table-item "+(0===k%2?"oddLine":"evenLine"),innerHTML:m},this.contentBox),n=d[f.id];if(0<c[f.id]){k=a.data.oriJimuLayerInfo.getLayerObject();
var w=f.getLayerObject();B({oriLayerObject:k,relatedLayerObject:w}).then(g.hitch(this,function(h){h=a.data.oriJimuLayerInfo.getOriRelationshipByDestLayer(h.oriLayerObject,h.relatedLayerObject,n);h=h.name||h.id;r.innerHTML=m+('\x3cdiv class\x3d"relationshipName" title\x3d"'+h+'"\x3e('+h+")\x3c/div\x3e")}))}k=u(r,"click",g.hitch(this,function(){f.getLayerObject().then(g.hitch(this,function(){this._addOperation(a);var h=this._createOperation({feature:a.data.feature,oriJimuLayerInfo:a.data.oriJimuLayerInfo,
destJimuLayerInfo:f,relationshipIndex:n});this.setPopupContent(h)}))}));this._temporaryData.eventHandles.push(k)},this)}))},_createOperation:function(a){return new q.Operation({feature:a.feature||null,oriJimuLayerInfo:a.oriJimuLayerInfo||null,destJimuLayerInfo:a.destJimuLayerInfo||null,relatedFeature:a.relatedFeature||null,relationshipIndex:a.relationshipIndex||0},this)},_addOperation:function(a){this.undoManager.add(a)},_onPreviouBtnClick:function(){this.undoManager.undo()},_clearPage:function(){e.empty(this.contentBox);
p.forEach(this._temporaryData.eventHandles,function(a){a&&a.remove&&a.remove()},this);this._temporaryData.eventHandles=[];p.forEach(this._temporaryData.dijits,function(a){a&&a.destroy&&a.destroy()},this);this._temporaryData.dijits=[]},_setTitle:function(a,b){a&&e.create("div",{"class":"title-box "+(b?b:""),innerHTML:a},this.contentBox)},_setOperationTitle:function(a){e.setAttr(this.operationTitle,"innerHTML",a);e.setAttr(this.operationTitle,"title",a)},_showFieldSelector:function(a){var b="objecid",
c=l(".title-box",this.contentBox)[0],d=a.layerObject,f=[];if(!c||!a)return b;var k=a.getPopupInfo();k&&k.title&&f.push({label:window.jimuNls.popup.saveAsPopupTitle,value:"popupTitle"});var m=[];k&&k.fieldInfos?p.forEach(k.fieldInfos,function(h){var t={};h.visible&&(t.name=h.fieldName,t.alias=h.label,m.push(t))}):m=d.fields;p.forEach(m,function(h){"globalid"!==h.name.toLowerCase()&&"shape"!==h.name.toLowerCase()&&f.push({label:h.alias||h.name,value:h.name})});c=(new L({items:f})).placeAt(c);c.domNode.title=
window.jimuNls.popup.chooseFieldTip;var r=g.getObject("_wabProperties.popupInfo.displayFieldOfRelatedRecordList",!1,d),n=this._ignoreCaseToGetFieldObject(a.layerObject,a.layerObject.displayField||a.layerObject.objectIdField),w=K.getInstance().getAppConfig();r?b=r:"2.3"===w.configWabVersion&&n&&n.name?b=n.name:k&&k.title?b="popupTitle":n&&n.name?b=n.name:0<f.length&&(b=f[0].value);b&&(c.setHighlightValue(b),g.setObject("_wabProperties.popupInfo.displayFieldOfRelatedRecordList",b,d));this._temporaryData.dijits.push(c);
a=u(c,"click-item",g.hitch(this,function(h,t){l(".item.record-item",this.contentBox).forEach(g.hitch(this,function(y){g.setObject("_wabProperties.popupInfo.displayFieldOfRelatedRecordList",t,d);var N=this._getDisplayTitleOfRelatedRecord(h,y.relatedRecord,t);y.innerHTML=N}))},a));this._temporaryData.eventHandles.push(a);return b}});q.Operation=v([F],{constructor:function(a,b){this.data=a;this.relatedRecordsPopupProjector=b},performUndo:function(){this.relatedRecordsPopupProjector.setPopupContent(this)}});
q.PopupUIController=v([],{constructor:function(a){this.rrPopupProjector=a;this.popup=a.popup;this.initTempPopup();this._initTempPopupForDisplayTitle();this._initZoomToBtn();this._setScrollable()},initTempPopup:function(){this._tempPopup=new x({},e.create("div"))},_initTempPopupForDisplayTitle:function(){this._tempPopupForDisplayTitle=new x({},e.create("div"));this._tempPopupForDisplayTitle.show()},destroy:function(){this._tempPopup.destroy();this._tempPopupForDisplayTitle.destroy();this._zoomToBtnClickHandle&&
this._zoomToBtnClickHandle.remove&&this._zoomToBtnClickHandle.remove();this._zoomToBtnANode&&e.destroy(this._zoomToBtnANode);this.toucemoveScrollHandle&&this.toucemoveScrollHandle.remove&&this.toucemoveScrollHandle.remove()},addDomNode:function(a){setTimeout(g.hitch(this,function(){var b=this._getRefDomNode();b&&e.place(a,b,"after")}),1)},setFeature:function(a){this._tempPopup.setFeatures([a]);if(a=l(".esriViewPopup",this._tempPopup.domNode)[0])this.setContent(a),e.place(this.rrPopupProjector.domNode,
a,"after"),this._unsetScrollable()},setContent:function(a){var b=l(".related-records-popup-projector").parent()[0];b&&b.removeChild(this.rrPopupProjector.domNode);this.popup.setContent(a);this._unsetScrollable()},_setScrollable:function(){var a=l(".contentPane",this.popup.domNode)[0];z("esri-touch")&&a&&(this.toucemoveScrollHandle=u(a,"touchmove",g.hitch(this,function(b){b.preventDefault();l(".esriViewPopup",this.popup.domNode)[0]&&(b=a.firstChild,b instanceof Text&&(b=a.childNodes[1]),this.rrPopupProjector.domNode&&
e.setStyle(this.rrPopupProjector.contentBox,{"-webkit-transition-property":"-webkit-transform","-webkit-transform":"translate("+b._currentX+"px, "+b._currentY+"px)"}))})))},_unsetScrollable:function(){e.setStyle(this.rrPopupProjector.contentBox,{"-webkit-transition-property":"none","-webkit-transform":"none"});e.setStyle(this.rrPopupProjector.domNode,{"-webkit-transition-property":"none","-webkit-transform":"none"})},getDisplayTitle:function(a){this._tempPopupForDisplayTitle.setFeatures([a]);return(a=
l("td.attrValue",this._tempPopupForDisplayTitle.domNode)[0])&&a.innerHTML},_getRefDomNode:function(){return this._getViewPopupDomNode()},_getViewPopupDomNode:function(){return l(".esriViewPopup",this.popup.domNode)[0]},_setPopupTitleInBody:function(){this.rrPopupProjector.undoManager.peekUndo()?this._tempPopup.set("titleInBody",!1):this._tempPopup.set("titleInBody",!0)},_initZoomToBtn:function(){var a=l(".actionList",this.popup.domNode)[0];this._oldZoomToBtnANdoe=l(".action",a)[0];this._zoomToBtnANode=
e.create("a",{"class":"action",style:"display: none",href:"javascript:void(0)"},a);this._zoomToBtn=e.create("span",{innerHTML:window.jimuNls.common.zoomTo},this._zoomToBtnANode);this._showOldZoomToBtn()},_hideZoomToBtn:function(){this._zoomToBtnANode&&e.setStyle(this._zoomToBtnANode,"display","none")},_showZoomToBtn:function(){this._zoomToBtnANode&&e.setStyle(this._zoomToBtnANode,"display","inline-block")},_hideOldZoomToBtn:function(){this._oldZoomToBtnANdoe&&e.setStyle(this._oldZoomToBtnANdoe,"display",
"none")},_showOldZoomToBtn:function(){this._oldZoomToBtnANdoe&&e.setStyle(this._oldZoomToBtnANdoe,"display","inline-block")},updateZoomToBtn:function(a){this._hideOldZoomToBtn();!a||1>a.length||!a[0].geometry?this._hideZoomToBtn():(this._showZoomToBtn(),this._zoomToBtnClickHandle&&this._zoomToBtnClickHandle.remove&&this._zoomToBtnClickHandle.remove(),this._zoomToBtnClickHandle=u(this._zoomToBtn,"click",g.hitch(this,function(){var b=null;try{b=H.graphicsExtent(a)}catch(c){console.error(c)}b&&(this.rrPopupProjector.popupManager.mapManager.map.setExtent(b),
this.popup.hide())})))},changeRefDomNode:function(){e.setStyle(this.rrPopupProjector.operationBox,"display","block");e.addClass(this.rrPopupProjector.domNode,"second-page-mode");var a=this._getViewPopupDomNode();a&&e.addClass(a,"second-page-mode")},revertRefDomNode:function(){e.setStyle(this.rrPopupProjector.operationBox,"display","none");e.removeClass(this.rrPopupProjector.domNode,"second-page-mode");this._hideZoomToBtn();this._showOldZoomToBtn()}});q.PopupMobileUIController=v([q.PopupUIController],
{initTempPopup:function(){this._tempPopup=new G({},e.create("div"))},setFeature:function(a){this._tempPopup.setFeatures([a]);a=l(".esriMobileInfoView.esriMobilePopupInfoView",this._tempPopup.domNode)[0];if(a=l(".esriViewPopup",a)[0])this.setContent(a),e.place(this.rrPopupProjector.domNode,a,"after")},updateZoomToBtn:function(){},_initZoomToBtn:function(){},_getRefDomNode:function(){return l(".esriMobilePopupInfoView .esriMobileInfoViewItem")[1]},_getViewPopupDomNode:function(){var a=l(".esriMobileInfoView.esriMobilePopupInfoView")[0];
return l(".esriViewPopup",a)[0]}});return q});