// 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/RelatedTableCharts/setting/LayerChooser.html":'\x3cdiv style\x3d"width: 100%; height: 100%;"\x3e\r\n    \x3cdiv class\x3d"esriCTLayerSelectorDiv"\x3e\r\n        \x3cdiv class\x3d"esriCTLayerChooserContainer row"\x3e\r\n            \x3cdiv class\x3d"esriCTlabel esriCTLabelContainer" title\x3d"${nls.layerChooser.selectPolygonLayerLabel}"\x3e\r\n                ${nls.layerChooser.selectPolygonLayerLabel}\r\n            \x3c/div\x3e\r\n            \x3cdiv class\x3d"esriCTLayerField"\x3e\r\n                \x3cdiv data-dojo-attach-point\x3d"itemSelectDiv"\x3e\r\n                \x3c/div\x3e\r\n                \x3cdiv class\x3d"esriCTHint"\x3e\r\n                    ${nls.layerChooser.selectPolygonLayerHintText}\r\n                \x3c/div\x3e\r\n            \x3c/div\x3e\r\n        \x3c/div\x3e\r\n        \x3cdiv class\x3d"esriCTLayerChooserContainer row"\x3e\r\n            \x3cdiv class\x3d"esriCTlabel esriCTLabelContainer" title\x3d"${nls.layerChooser.selectRelatedTableLayerLabel}"\x3e\r\n                ${nls.layerChooser.selectRelatedTableLayerLabel}\r\n            \x3c/div\x3e\r\n            \x3cdiv class\x3d"esriCTLayerField"\x3e\r\n                \x3cselect data-dojo-attach-point\x3d"relationshipSelect" style\x3d"width: 232px;" data-dojo-type\x3d"dijit/form/Select"\x3e\r\n                \x3c/select\x3e\r\n                \x3cdiv class\x3d"esriCTHint"\x3e\r\n                    ${nls.layerChooser.selectRelatedTableLayerHintText}\r\n                \x3c/div\x3e\r\n            \x3c/div\x3e\r\n        \x3c/div\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"buttonsDiv" class\x3d"buttonsDiv"\x3e\r\n        \x3cdiv class\x3d"button-container button-container-absolute" style\x3d"padding: 0px;"\x3e\r\n            \x3cdiv class\x3d"jimu-btn jimu-float-trailing jimu-leading-margin1 jimu-state-disabled"\r\n                data-dojo-attach-point\x3d"okButton" tabindex\x3d"0"\x3e\r\n                ${nls.ok}\x3c/div\x3e\r\n            \x3cdiv class\x3d"jimu-btn jimu-float-trailing jimu-leading-margin1" data-dojo-attach-point\x3d"cancelButton" tabindex\x3d"0"\x3e\r\n                ${nls.cancel}\x3c/div\x3e\r\n        \x3c/div\x3e\r\n    \x3c/div\x3e\r\n\x3c/div\x3e\r\n'}});
define("dojo/_base/declare jimu/BaseWidgetSetting dijit/_WidgetsInTemplateMixin dojo/_base/lang dojo/_base/array dojo/promise/all dojo/Deferred dojo/on dojo/dom-class dojo/text!./LayerChooser.html jimu/dijit/LayerChooserFromMap jimu/dijit/LayerChooserFromMapWithDropbox esri/request jimu/dijit/Message dojo/domReady!".split(" "),function(p,q,r,e,k,t,u,m,n,v,l,w,x,y){return p([q,r],{baseClass:"jimu-widget-RelatedTableCharts-setting",templateString:v,selectRouteURL:null,agolFlag:!1,serviceFlag:!1,_numberFieldTypes:["esriFieldTypeSmallInteger",
"esriFieldTypeInteger","esriFieldTypeSingle","esriFieldTypeDouble"],startup:function(){this.inherited(arguments)},postCreate:function(){this._createPolygonChooserArgs();this.own(m(this.cancelButton,"click",e.hitch(this,function(a){this.onCancleClick(a)})));this.own(m(this.okButton,"click",e.hitch(this,this._onOKButtonClicked)))},_getGeometryType:function(a){switch(a){case "esriGeometryPolygon":return"polygon";case "esriGeometryPolyline":return"polyline";case "esriGeometryPoint":return"point";default:return"*"}},
_createPolygonChooserArgs:function(){var a=[];a.push(this.geometryType);a=l.createFeaturelayerFilter(a,!1);var f=l.createQueryableLayerFilter();a={multiple:!1,createMapResponse:this.map.webMapResponse,showLayerTypes:["FeatureLayer"],filter:l.andCombineFilters([a,f])};a=new l(a);a=new w({layerChooser:a});a.placeAt(this.itemSelectDiv);a.startup();this.own(m(a,"selection-change",e.hitch(this,this._createRelatedTableOptions)))},_createRelatedTableOptions:function(a){var f=[];if(a&&0<a.length){this.polygonLayer=
a[0];this.polygonLayerInfo={url:this.polygonLayer.url,geometryType:this._getGeometryType(this.polygonLayer.geometryType),supportsDistinct:!1};this.polygonLayer.advancedQueryCapabilities&&this.polygonLayer.advancedQueryCapabilities.supportsDistinct&&(this.polygonLayerInfo.supportsDistinct=!0);this.polygonLayer.fields&&(this.polygonLayerInfo.fields=e.clone(this.polygonLayer.fields));this.polygonLayerInfo.layerId=this.polygonLayer.layerId?this.polygonLayer.layerId:this.polygonLayer.url.substr(this.polygonLayer.url.lastIndexOf("/")+
1,this.polygonLayer.url.length);var c=this.polygonLayer.url.substr(0,this.polygonLayer.url.lastIndexOf("/")+1);this.polygonLayerInfo.baseURL=c;this.polygonLayerInfo=e.mixin(this.polygonLayerInfo,this._getLayerDetailsFromMap(c,this.polygonLayerInfo.layerId));this.relatedTableInfo=[];var b=[];k.forEach(this.polygonLayer.relationships,e.hitch(this,function(d){var h=new u;b.push(h);x({url:c+d.relatedTableId,content:{f:"json"},handleAs:"json"}).then(e.hitch(this,function(g){h.resolve(g)}),e.hitch(this,
function(){h.resolve()}))}));t(b).then(e.hitch(this,function(d){var h,g;for(g=0;g<d.length;g++)d[g].fields&&(h=k.some(d[g].fields,e.hitch(this,function(z){return 0<=this._numberFieldTypes.indexOf(z.type)})))&&(h={url:c+d[g].id,baseURL:c,relationShipId:this.polygonLayer.relationships[g].id,layerId:d[g].id,title:this.polygonLayer.relationships[g].name},h.fields=e.clone(d[g].fields),h=e.mixin(h,this._getLayerDetailsFromMap(c,d[g].id)),h=e.mixin(h,this._getLayerDetailsFromMapTables(c,d[g].id)),h.title&&
(this.relatedTableInfo[f.length]=h,f.push({label:this.relatedTableInfo[f.length].title,value:f.length})));0<f.length?(this.relationshipSelect.options.length=0,f[0].selected=!0,this.relationshipSelect.addOption(f),n.remove(this.okButton,"jimu-state-disabled")):this._resetRelatedLayerSelector()}),e.hitch(this,function(){this._resetRelatedLayerSelector()}))}else this._resetRelatedLayerSelector()},_resetRelatedLayerSelector:function(){this.relationshipSelect.value="";this.relationshipSelect.options.length=
0;this.relationshipSelect.addOption({value:"",label:"",selected:!0});n.add(this.okButton,"jimu-state-disabled")},_getLayerDetailsFromMap:function(a,f){var c={};this.map&&this.map.webMapResponse&&this.map.webMapResponse.itemInfo&&this.map.webMapResponse.itemInfo.itemData&&this.map.webMapResponse.itemInfo.itemData.operationalLayers&&k.forEach(this.map.webMapResponse.itemInfo.itemData.operationalLayers,e.hitch(this,function(b){b.layerObject&&("ArcGISMapServiceLayer"===b.layerType||"ArcGISTiledMapServiceLayer"===
b.layerType?a.substring(0,a.length-1)===b.url&&(k.forEach(b.resourceInfo.layers,e.hitch(this,function(d){d.id===parseInt(f,10)&&(c.title=d.name)})),k.forEach(b.layers,e.hitch(this,function(d){d.id===parseInt(f,10)&&(d.name&&(c.title=d.name),c.popupInfo=d.popupInfo,d.layerDefinition&&d.layerDefinition.definitionExpression&&(c.definitionExpression=d.layerDefinition.definitionExpression))}))):b.url.replace(/.*?:\/\//g,"")===(a+f).replace(/.*?:\/\//g,"")&&(c.title=b.title,c.popupInfo=b.popupInfo,b.layerDefinition&&
b.layerDefinition.definitionExpression&&(c.definitionExpression=b.layerDefinition.definitionExpression)))}));return c},_getLayerDetailsFromMapTables:function(a,f){var c={};this.map&&this.map.webMapResponse&&this.map.webMapResponse.itemInfo&&this.map.webMapResponse.itemInfo.itemData&&this.map.webMapResponse.itemInfo.itemData.tables&&k.forEach(this.map.webMapResponse.itemInfo.itemData.tables,e.hitch(this,function(b){b.url.replace(/.*?:\/\//g,"")===(a+f).replace(/.*?:\/\//g,"")&&(c.title=b.title,c.popupInfo=
b.popupInfo,b.layerDefinition&&b.layerDefinition.definitionExpression&&(c.definitionExpression=b.layerDefinition.definitionExpression))}));return c},_onOKButtonClicked:function(){if(!n.contains(this.okButton,"jimu-state-disabled"))if(this.polygonLayerInfo){if(""===this.relationshipSelect.value)return this._errorMessage(this.nls.layerChooser.errorInSelectingRelatedLayer),!1;var a={polygonLayerInfo:this.polygonLayerInfo,relatedLayerInfo:this.relatedTableInfo[this.relationshipSelect.value]};this.onOkClick(a)}else return this._errorMessage(this.nls.layerChooser.errorInSelectingPolygonLayer),
!1},_errorMessage:function(a){(new y({message:a})).message=a},onOkClick:function(a){return a},onCancleClick:function(a){return a}})});