// 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/CostAnalysis/setting/AttributeSettings.html":'\x3cdiv class\x3d"esriCTMainAttributeSettingsContainer"\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"attributeSettingsAddFields" \r\n                class\x3d"esriCTBtnAddField esriCTEllipsis"\x3e\r\n                    \x3cspan class\x3d"esriCTBtnAddIcon"\x3e\x3c/span\x3e\r\n                    \x3cspan class\x3d"esriCTBtnAddLabel esriCTEllipsis"\x3e${nls.layerSettings.addFieldLabelTitle}\x3c/span\x3e\r\n    \x3c/div\x3e\r\n\r\n    \x3cdiv\x3e\r\n        \x3cdiv class\x3d"esriCTAttributeSettingsTable" data-dojo-attach-point\x3d"attributeSettingsTableNode"\x3e\x3c/div\x3e\r\n    \x3c/div\x3e\r\n\r\n\x3c/div\x3e'}});
define("dojo/_base/declare jimu/dijit/SimpleTable jimu/BaseWidget dojo/Evented dojo/_base/lang dojo/dom-class dijit/_WidgetsInTemplateMixin dojo/text!./AttributeSettings.html dojo/on dojo/query dijit/form/Select dojo/_base/array".split(" "),function(l,m,n,p,e,h,q,r,g,t,k,f){return l([n,p,q],{templateString:r,attributeSettingPopup:null,baseClass:"jimu-widget-cost-analysis-attribute-settings",_layerSettingsTable:null,_projectLayer:"",_entireFieldsArr:[],_selectedFieldsArr:[],_entireFieldObj:[],_projectFieldTypes:[],
validFieldTypes:"esriFieldTypeInteger esriFieldTypeSingle esriFieldTypeSmallInteger esriFieldTypeDouble esriFieldTypeString esriFieldTypeDate esriFieldTypeGUID".split(" "),constructor:function(a){e.mixin(this,a)},postMixInProperties:function(){this.nls.common={};e.mixin(this.nls.common,window.jimuNls.common)},postCreate:function(){this._entireFieldsArr=[];this._selectedFieldsArr=[];this._entireFieldObj=[];this._projectFieldTypes=[];this._layerSettingsTable=this.attributeSettingPopup=null;this._projectLayer=
this.projectLayer||this.config.projectSettings.projectLayer||"";this._projectLayerAttributeStore="";this.inherited(arguments);this._init()},_init:function(){this._clearData();this._fetchProjectLayerFieldTypes();this._addValidFields();this._createAttributeSettingsFieldsTable();this._attachEventsToElement();this._displayPreviousConfiguredFields()},_clearData:function(){this._entireFieldsArr=[];this._selectedFieldsArr=[];this._projectFieldTypes=[]},_fetchProjectLayerFieldTypes:function(){var a=this.map.getLayer(this._projectLayer).fields;
f.forEach(a,e.hitch(this,function(c){-1<this.validFieldTypes.indexOf(c.type)&&-1===this._projectFieldTypes.indexOf(c.type)&&this._projectFieldTypes.push(c.type)}))},_displayPreviousConfiguredFields:function(){this.selectedFields&&0<this.selectedFields.length&&(f.forEach(this.selectedFields,e.hitch(this,function(a){this._configuredField=a;this.attributeSettingsAddFields.click()})),this._configuredField=null)},_addValidFields:function(){f.forEach(this.featureLayer.fields,e.hitch(this,function(a){this._entireFieldObj[a.name]=
a;"esriFieldTypeGUID"===a.type?(this._entireFieldsArr.push(a.name),this._entireFieldObj[a.name]=e.clone(a),this.selectedFields&&this.selectedFields[a.name]&&(this._entireFieldObj[a.name].label=this.selectedFields[a.name].label)):-1<this.validFieldTypes.indexOf(a.type)&&-1<this._projectFieldTypes.indexOf(a.type)&&a.editable&&(this._entireFieldsArr.push(a.name),this._entireFieldObj[a.name]=e.clone(a),this.selectedFields&&this.selectedFields[a.name]&&(this._entireFieldObj[a.name].label=this.selectedFields[a.name].label))}));
0===this._entireFieldsArr.length&&this._disableAddFieldButton()},_disableAddFieldButton:function(){this._selectedFieldsArr.length===this._entireFieldsArr.length&&h.add(this.attributeSettingsAddFields,"esriCTDisabled")},_addFieldsRow:function(a){var c=this._attributeSettingsTable.addRow({});if(c.success&&c.tr){c=c.tr;var b=t(".simple-table-cell",c);var d=b[0];b=b[1];this._addFieldDropdown(a,d,c);this._addProjectFieldDropdown(b,c)}},_deleteFieldRow:function(a){h.remove(this.attributeSettingsAddFields,
"esriCTDisabled");var c=this._selectedFieldsArr.indexOf(a.fieldDropdownInstance.value);-1<c&&this._selectedFieldsArr.splice(c,1);this._addSelectedFieldInOtherDropdown(a.fieldDropdownInstance.value,null)},_addFieldDropdown:function(a,c,b){a=this._getDistinctFieldsOptionsObj(a);a=new k({"class":"esriCTFieldChooserDropdown",options:a});a.placeAt(c);a.startup();this._configuredField&&a.set("value",this._configuredField.layerField,!1);b.fieldDropdownInstance=a;this.own(g(a,"change",e.hitch(this,function(d){var u=
this._selectedFieldsArr[b.rowIndex];this._selectedFieldsArr[b.rowIndex]=d;this._addSelectedFieldInOtherDropdown(u,d);this._removeSelectedFieldFromOtherDropdown(d);b.projectFieldDropdownInstance.set("options",this._getProjectLayerFields(b));b.projectFieldDropdownInstance.set("value",b.projectFieldDropdownInstance.options[0])})));this._selectedFieldsArr.push(a.value);this._removeSelectedFieldFromOtherDropdown(a.value);this._disableAddFieldButton()},_addProjectFieldDropdown:function(a,c){var b=this._getProjectLayerFields(c);
b=new k({"class":"esriCTFieldChooserDropdown",options:b});b.placeAt(a);b.startup();this._configuredField&&b.set("value",this._configuredField.projectField,!1);c.projectFieldDropdownInstance=b;this.own(g(b,"change",e.hitch(this,function(){})))},_getProjectLayerFields:function(a){var c=[];a=a.fieldDropdownInstance.getValue();var b=this._getFieldType(a);this._projectLayer&&""!==this._projectLayer&&(a=this.map.getLayer(this._projectLayer).fields,c=[],f.forEach(a,e.hitch(this,function(d){b===d.type?c.push({label:d.alias||
d.name,value:d.name}):"esriFieldTypeString"===b&&"esriFieldTypeGlobalID"===d.type?c.push({label:d.alias||d.name,value:d.name}):"esriFieldTypeGUID"!==b||"esriFieldTypeGlobalID"!==d.type&&"esriFieldTypeGUID"!==d.type||c.push({label:d.alias||d.name,value:d.name})})));return c},_getFieldType:function(a){return this.featureLayer.getField(a).type},_getDistinctFieldsOptionsObj:function(a){var c=[];f.forEach(a,e.hitch(this,function(b){c.push({label:this._entireFieldObj[b].alias||this._entireFieldObj[b].name,
value:b})}));return c},_removeSelectedFieldFromOtherDropdown:function(a){var c=this._attributeSettingsTable.getRows();f.forEach(c,e.hitch(this,function(b){a!==b.fieldDropdownInstance.value&&b.fieldDropdownInstance.removeOption(a)}))},_addSelectedFieldInOtherDropdown:function(a,c){var b=this._attributeSettingsTable.getRows();f.forEach(b,e.hitch(this,function(d){c!==d.fieldDropdownInstance.value&&d.fieldDropdownInstance.addOption({label:this._entireFieldObj[a].alias||this._entireFieldObj[a].name,value:a})}))},
okButtonClicked:function(){var a=[];var c=this._attributeSettingsTable.getRows();0===c.length?this.selectedFields=null:(f.forEach(c,e.hitch(this,function(b){a.push({layerField:b.fieldDropdownInstance.value,projectField:b.projectFieldDropdownInstance.value})})),this.selectedFields=a);return this.selectedFields},_getDistinctFields:function(a,c){return a.filter(function(b){return 0>c.indexOf(b)})},_attachEventsToElement:function(){this.own(g(this.attributeSettingsAddFields,"click",e.hitch(this,function(){if(!h.contains(this.attributeSettingsAddFields,
"esriCTDisabled")){var a=this._getDistinctFields(this._entireFieldsArr,this._selectedFieldsArr);this._addFieldsRow(a)}})));this.own(g(this._attributeSettingsTable,"row-delete",e.hitch(this,function(a){this._deleteFieldRow(a)})))},onOkButtonClicked:function(){this.parentNode.attributeSettingPopup=this.attributeSettingPopup;this.attributeSettingPopup.hide()},onCancelButtonClicked:function(){this.attributeSettingPopup.hide()},_createAttributeSettingsFieldsTable:function(){this._attributeSettingsTable=
new m({fields:[{name:"layerAttributes",title:this.nls.layerSettings.layerAttributesHeaderTitle,type:"empty",editable:!1,width:"40%"},{name:"projectLayerAttributes",title:this.nls.layerSettings.projectLayerAttributesHeaderTitle,type:"empty",editable:!1,width:"40%"},{name:"Delete",title:this.nls.layerSettings.deleteColumnLabel,type:"actions",actions:["delete"],width:"20%"}],selectable:!0});this._attributeSettingsTable.placeAt(this.attributeSettingsTableNode);this._attributeSettingsTable.startup()}})});