// 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/SmartEditor/copy-features.html":'\x3cdiv class\x3d"esriCTSelectFeaturesContainer"\x3e\r\n  \x3cdiv style\x3d"height: 100%; width: 100%;"\x3e\r\n    \x3cdiv class\x3d"esriCTCopyFeaturesListTitle"\x3e${nls.copyFeatures.title}\x3c/div\x3e\r\n    \x3cdiv class\x3d"esriCTCopyFeaturesHint" data-dojo-attach-point\x3d"warningMessage" tabindex\x3d"0" role\x3d"presentation" aria-label\x3d"${nls.copyFeatures.multipleFeatureSaveWarning}"\x3e${nls.copyFeatures.multipleFeatureSaveWarning}\x3c/div\x3e\r\n    \x3cdiv style\x3d"width: 100; margin-bottom: 5px;" data-dojo-attach-point\x3d"applyEditsProgressParentNode"\x3e\x3c/div\x3e\r\n\t\x3cdiv class\x3d"esriCTCopyFeaturesListContent" data-dojo-attach-point\x3d"layerListTable"\x3e\x3c/div\x3e\r\n    \x3cdiv class\x3d"esriCTCopyFeaturesBtnContainer"\x3e\r\n      \x3cdiv tabindex\x3d"0" role\x3d"button" class\x3d"esriCTCopyFeaturesBtn jimu-btn" data-dojo-attach-point\x3d"createMultipleFeaturesBtn" aria-label\x3d"${nls.copyFeatures.createFeatures}" title\x3d"${nls.copyFeatures.createFeatures}"\x3e${nls.copyFeatures.createFeatures}\x3c/div\x3e\r\n      \x3cdiv tabindex\x3d"0" role\x3d"button" class\x3d"esriCTCopyFeaturesBtn jimu-btn" data-dojo-attach-point\x3d"createSingleFeatureBtn" aria-label\x3d"${nls.copyFeatures.createSingleFeature}"  title\x3d"${nls.copyFeatures.createSingleFeature}"\x3e${nls.copyFeatures.createSingleFeature}\x3c/div\x3e\r\n      \x3cdiv tabindex\x3d"0" role\x3d"button" class\x3d"esriCTCopyFeaturesBtn jimu-btn" data-dojo-attach-point\x3d"fieldsMatchingBtn" aria-label\x3d"${nls.fieldsMapping.popupTittle}"  title\x3d"${nls.fieldsMapping.popupTittle}"\x3e${nls.fieldsMapping.popupTittle}\x3c/div\x3e\r\n      \x3cdiv tabindex\x3d"0" role\x3d"button" class\x3d"esriCTCopyFeaturesBtn jimu-btn" data-dojo-attach-point\x3d"cancelBtn" aria-label\x3d"${nls.cancel}" title\x3d"${nls.cancel}"\x3e${nls.cancel}\x3c/div\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dijit/_WidgetBase dijit/_TemplatedMixin dojo/_base/declare dojo/Evented dojo/_base/lang dojo/_base/array dojo/dom-construct dojo/on dojo/query dojo/string dojo/keys jimu/dijit/CheckBox dojo/dom-class dojo/dom-attr ./highlightSymbolUtils esri/layers/GraphicsLayer dojo/text!./copy-features.html jimu/dijit/Message esri/tasks/query esri/tasks/QueryTask dojo/Deferred dojo/promise/all jimu/dijit/LoadingIndicator dijit/ProgressBar dojo/dom-style jimu/dijit/Popup ./fieldsMapping".split(" "),function(A,
B,C,D,f,l,q,p,v,w,r,E,m,k,F,G,H,x,I,J,y,z,K,L,u,N,M){return C([A,D,B],{templateString:H,layerLabel:null,featuresList:null,checkBoxNodes:{},layerCheckBoxNodes:{},featuresByLayerId:{},featureTitlesByLayerId:{},highlightGraphicsLayer:null,allChildCheckboxes:[],loading:null,fieldsMappingObj:null,layerOrderSequence:[],startup:function(){this.inherited(arguments);this.highlightGraphicsLayer=this._createNewGraphicsLayer("highlightGraphicsLayer");this.loading=new K({hidden:!0});this.loading.placeAt(this.parentDomNode)},
postCreate:function(){this.checkBoxNodes={};this.layerCheckBoxNodes={};this.featuresByLayerId={};this.featureTitlesByLayerId={};this.fieldsMappingObj=this.highlightGraphicsLayer=null;this.layerOrderSequence=[];this.applyEditsProgress=new L(null,this.applyEditsProgressParentNode);u.set(this.applyEditsProgress.domNode,"display","none");this.own(p(this.cancelBtn,"click",f.hitch(this,function(){this.cancelBtnClicked()})));this.own(p(this.cancelBtn,"keydown",f.hitch(this,function(a){a.keyCode!==r.ENTER&&
a.keyCode!==r.SPACE||this.cancelBtnClicked()})));this.own(p(this.createMultipleFeaturesBtn,"click",f.hitch(this,this._createMultipleFeaturesBtnClicked)));this.own(p(this.createMultipleFeaturesBtn,"keydown",f.hitch(this,function(a){a.keyCode!==r.ENTER&&a.keyCode!==r.SPACE||this._createMultipleFeaturesBtnClicked()})));this.own(p(this.createSingleFeatureBtn,"click",f.hitch(this,this._createSingleFeatureBtnClicked)));this.own(p(this.createSingleFeatureBtn,"keydown",f.hitch(this,function(a){a.keyCode!==
r.ENTER&&a.keyCode!==r.SPACE||this._createSingleFeatureBtnClicked()})));this.own(p(this.fieldsMatchingBtn,"click",f.hitch(this,this._fieldMatchingBtnClicked)));this.own(p(this.fieldsMatchingBtn,"keydown",f.hitch(this,function(a){a.keyCode!==r.ENTER&&a.keyCode!==r.SPACE||this._fieldMatchingBtnClicked()})))},selectFeaturesToCopy:function(a,c){this.allChildCheckboxes=[];if(a&&0<a.length){this.checkBoxNodes={};this.layerCheckBoxNodes={};this.featuresByLayerId={};this.featureTitlesByLayerId={};this.targetLayerDetails=
c;var b=this.targetLayerDetails.featureLayer.geometryType;this._changeWarningNote(b);this._showHideSingleFeatureButton(b);this._showHideMultipleFeatureButton(b);m.remove(this.mainNode,"esriCTHidden");c=new y;this._processSelectedFeatures(a,c).then(f.hitch(this,function(){q.empty(this.layerListTable);l.forEach(this.layerInfosObj.getLayerInfoArray(),f.hitch(this,function(d){if(this.featureTitlesByLayerId.hasOwnProperty(d.id)){d=d.id;var e=this.layerInfosObj.getLayerInfoById(d);e=e.title?e.title:e.name;
var h=q.create("div",{},this.layerListTable);var g=q.create("div",{"class":"esriCTHidden"});q.place(g,h,"last");this.layerCheckBoxNodes[d]=this._createListNode(e,h,!1,d,b);this.checkBoxNodes[d]||(this.checkBoxNodes[d]=[]);0<this.featureTitlesByLayerId[d].length&&(this._createFeatureEntries(d,h,b,g),this.layerOrderSequence.push(this.featureTitlesByLayerId[d].length));return!0}}));this._canExpandFirstLayerNode()&&v(".esriCTExpandCollapseNode",this.domNode)[0].click();this._highlightFeatures();this.updateSingleFeatureButtonText()}))}},
_canExpandFirstLayerNode:function(){var a=!1,c=[];c=Object.keys(this.layerCheckBoxNodes);this.layerCheckBoxNodes&&1===c.length?a=!0:1<c.length&&this.layerOrderSequence&&this.layerOrderSequence[0]&&10>=this.layerOrderSequence[0]&&(a=!0);return a},_processSelectedFeatures:function(a,c){var b={},d,e;this.featuresByLayerId={};this.featureTitlesByLayerId={};l.forEach(a,f.hitch(this,function(h){this.featuresByLayerId[h._layer.id]||(this.featuresByLayerId[h._layer.id]=[],this.featureTitlesByLayerId[h._layer.id]=
[]);this.featuresByLayerId[h._layer.id].push(h);var g=this.layerInfosObj.getLayerInfoById(h._layer.id).layerObject.objectIdField;g=h.getTitle()?h.getTitle():h.attributes[g];this.featureTitlesByLayerId[h._layer.id].push(g)}));this.loading.show();for(e in this.featuresByLayerId)e&&(a=this._getObjectIdFieldOfLayer(e),a=this._getSelectedFeatureObjectIds(this.featuresByLayerId[e],a),b[e]=this._getFeatureByChunks(e,a));z(b).then(f.hitch(this,function(h){for(d in h)d&&this._updateGeometryForSelectedFeature(d,
h);this._highlightFeatures();setTimeout(f.hitch(this,function(){this.loading.hide()}),1E3)}),f.hitch(this,function(){this.loading.hide();x({message:this.nls.copyFeatures.copyFeatureUpdateGeometryError})}));return c.resolve(null)},_getObjectIdFieldOfLayer:function(a){return this.layerInfosObj.getLayerInfoById(a).layerObject.objectIdField},_updateGeometryForSelectedFeature:function(a,c){var b=this._getObjectIdFieldOfLayer(a);l.forEach(this.featuresByLayerId[a],f.hitch(this,function(d){l.some(c[a],f.hitch(this,
function(e){if(e.attributes[b]===d.attributes[b])return d.geometry=e.geometry,!0}))}))},_getSelectedFeatureObjectIds:function(a,c){var b=[];l.forEach(a,f.hitch(this,function(d){b.push(d.attributes[c])}));return b},_getFeatureByChunks:function(a,c){var b=this.layerInfosObj.getLayerInfoById(a);var d=new y;var e=[];for(b=null===b.layerObject.url||""===b.layerObject.url?c.length:b.layerObject.maxRecordCount||999;0<c.length;)e.push(this._getSelectedFeatureGeometry(a,c.splice(0,b)));z(e).then(f.hitch(this,
function(h){var g=[];l.forEach(h,f.hitch(this,function(n){g=g.concat(n.features)}));d.resolve(g)}));return d.promise},_getSelectedFeatureGeometry:function(a,c){var b=this.layerInfosObj.getLayerInfoById(a);a=new J(b.getUrl());var d=new I;d.outFields=[b.layerObject.objectIdField];d.objectIds=c;d.returnGeometry=!0;d.outSpatialReference=this.map.spatialReference;return(null===b.layerObject.url||""===b.layerObject.url?b.layerObject.queryFeatures(d):a.execute(d)).promise},_createFeatureEntries:function(a,
c,b,d){l.forEach(this.featureTitlesByLayerId[a],f.hitch(this,function(e){e=this._createListNode(e,c,!0,a,b,d);this.checkBoxNodes[a].push(e);this.allChildCheckboxes.push(e)}))},_createListNode:function(a,c,b,d,e,h){var g=q.create("div",{"class":"jimu-widget-row esriCTCopyFeaturesNode"});var n=q.create("div",{"class":"jimu-float-leading checkBoxNode",style:"width: calc(100% - 20px)"},g);e="esriGeometryPoint"===e&&this.hideMultipleFeatureButton?!1:!0;n=new E({label:a,checked:e},n);k.set(n.domNode,"layerName",
a);b?(m.add(g,"esriCTCopyFeaturesChildNode"),k.set(n.domNode,"parentLayerId",d),p(n.domNode,"click",f.hitch(this,this._childNodeStateChanged)),k.set(h,"expandLayerId",d),q.place(g,h)):(this._updateParentCheckBoxLabel(n,a,this.featureTitlesByLayerId[d].length,d),b=q.create("div",{"class":"esriCTExpandCollapseNode collapsed",tabindex:"0",role:"button","aria-label":a,"aria-expanded":"false"}),q.place(b,g,"first"),k.set(n.domNode,"layerId",d),k.set(n.domNode,"layerName",a),k.set(b,"layerId",d),e||(this._updateParentCheckBoxLabel(n,
a,0,d),n.setStatus(!1)),p(n.domNode,"click",f.hitch(this,this._parentNodeStateChanged)),q.place(g,c,"first"),this.own(p(b,"click",f.hitch(this,function(t){this._expandButtonClicked(t)}))),this.own(p(b,"keydown",f.hitch(this,function(t){t.keyCode!==r.ENTER&&t.keyCode!==r.SPACE||this._expandButtonClicked(t)}))));return n},_expandButtonClicked:function(a){var c=k.get(a.currentTarget,"layerId");if(c=v("[expandLayerId\x3d"+c+"]",this.domNode)[0])m.contains(a.currentTarget,"expanded")?(m.replace(a.currentTarget,
"collapsed","expanded"),k.set(a.currentTarget,"aria-expanded","false"),m.add(c,"esriCTHidden")):(m.replace(a.currentTarget,"expanded","collapsed"),k.set(a.currentTarget,"aria-expanded","true"),m.remove(c,"esriCTHidden"))},_parentNodeStateChanged:function(a){a=k.get(a.currentTarget,"layerId");var c=this.layerCheckBoxNodes[a],b=k.get(c.domNode,"layerName");if(c.getStatus()){var d=this.checkBoxNodes[a],e=c.getValue();l.forEach(d,f.hitch(this,function(h){e?h.setValue(!0):h.setValue(!1)}));e?this._updateParentCheckBoxLabel(c,
b,this.featureTitlesByLayerId[a].length,a):this._updateParentCheckBoxLabel(c,b,0,a);this._highlightFeatures()}this.updateSingleFeatureButtonText()},_childNodeStateChanged:function(a){var c=k.get(a.currentTarget,"parentLayerId"),b=k.get(this.layerCheckBoxNodes[c].domNode,"layerName"),d=this.layerCheckBoxNodes[c],e=this.checkBoxNodes[c],h=!1;d.getStatus()||l.forEach(this.allChildCheckboxes,f.hitch(this,function(g){g.getValue()&&g.domNode!==a.currentTarget&&(g.setValue(!1),g=k.get(g.domNode,"parentLayerId"),
this._updateParentCheckBoxLabel(this.layerCheckBoxNodes[g],k.get(this.layerCheckBoxNodes[g].domNode,"layerName"),0,g))}));this._highlightFeatures();l.some(e,f.hitch(this,function(g){if(g.getValue())return h=!0}));d.setValue(h,!1);this.updateSingleFeatureButtonText();e=this.checkBoxNodes[c].filter(f.hitch(this,function(g){return!0===g.checked}));this._updateParentCheckBoxLabel(d,b,e.length,c)},_updateParentCheckBoxLabel:function(a,c,b,d){a.setLabel(w.substitute(this.nls.copyFeatures.layerLabel,{layerName:c,
selectedFeatures:b,totalFeatures:this.featureTitlesByLayerId[d].length}));k.set(a.domNode,"aria-label",w.substitute(this.nls.copyFeatures.layerAriaLabel,{layerName:c,selectedFeatures:b,totalFeatures:this.featureTitlesByLayerId[d].length}))},updateSingleFeatureButtonText:function(){var a=0;l.some(this.allChildCheckboxes,f.hitch(this,function(c){c.getValue()&&a++;if(1<a)return!0}));1===a||1===this.allChildCheckboxes.length?(k.set(this.createSingleFeatureBtn,"innerHTML",this.nls.copyFeatures.createOneSingleFeature),
k.set(this.createSingleFeatureBtn,"aria-label",this.nls.copyFeatures.createOneSingleFeature),k.set(this.createSingleFeatureBtn,"title",this.nls.copyFeatures.createOneSingleFeature),m.add(this.createMultipleFeaturesBtn,"esriCTCanCreateOnlyOneFeature"),"esriGeometryPoint"===this.targetLayerDetails.featureLayer.geometryType&&m.remove(this.createSingleFeatureBtn,"esriCTHidden")):(k.set(this.createSingleFeatureBtn,"innerHTML",this.nls.copyFeatures.createSingleFeature),k.set(this.createSingleFeatureBtn,
"aria-label",this.nls.copyFeatures.createSingleFeature),k.set(this.createSingleFeatureBtn,"title",this.nls.copyFeatures.createSingleFeature),m.remove(this.createMultipleFeaturesBtn,"esriCTCanCreateOnlyOneFeature"),"esriGeometryPoint"===this.targetLayerDetails.featureLayer.geometryType&&m.add(this.createSingleFeatureBtn,"esriCTHidden"))},cancelBtnClicked:function(){m.add(this.mainNode,"esriCTHidden");this.highlightGraphicsLayer.clear();this.emit("cancelBtnClicked")},_createMultipleFeaturesBtnClicked:function(){var a=
[],c;(c=this._getSelectedFeaturesForCopy())&&0<c.length&&(l.forEach(c,f.hitch(this,function(b){b&&b.geometry&&a.push(b)})),this.emit("createMultipleFeatures",a))},_createSingleFeatureBtnClicked:function(){var a;(a=this._getSelectedFeaturesForCopy())&&0<a.length&&this.emit("createSingleFeature",a)},_fieldMatchingBtnClicked:function(){var a=[],c={id:this.targetLayerDetails.featureLayer.id,fields:this.targetLayerDetails.fieldInfos,fieldValues:this.targetLayerDetails.fieldValues};l.forEach(this.layerInfosObj.getLayerInfoArray(),
f.hitch(this,function(b){if(this.featuresByLayerId.hasOwnProperty(b.id)){var d=b.id;var e=this.layerInfosObj.getLayerInfoById(d);b=this.editUtils.getFieldInfosFromWebmap(e)||e.layerObject.fields;e&&e.layerObject&&b&&(e=e.title?e.title:e.name,a.push({id:d,fields:b,name:e}))}}));this.fieldsMappingObj=new M({nls:this.nls,sourceLayerDetails:a,targetLayerDetails:c,fieldMappingDetails:this.fieldMappingDetails,usePresetValues:this.usePresetValues,overrideDefaultsByCopiedFeature:this.config.editor.overrideDefaultsByCopiedFeature});
this.own(p(this.fieldsMappingObj,"field-mapping-changed",f.hitch(this,function(b){this.fieldMappingDetails=b.fieldMappingDetails;this.config.editor.overrideDefaultsByCopiedFeature=b.overrideDefaultsByCopiedFeature})))},_getConfiguredFieldInfos:function(a,c){var b=[];l.forEach(c,function(d){var e=this._getFieldInfoByFieldName(a,d.fieldName);d=f.mixin(f.clone(e),d);b.push(d)},this);return b},_getFieldInfoByFieldName:function(a,c){var b={};l.some(a,function(d){if(d.name===c)return f.mixin(b,d),!0});
return b},_validateSelectedFeature:function(a){(!a||0>=a.length)&&x({message:this.nls.copyFeatures.selectFeatureToCopyMessage})},_getSelectedFeaturesForCopy:function(){var a,c=[];for(a in this.featuresByLayerId){var b=this._getSelectedFeaturesByLayerId(a);0<b.length&&(c=c.concat(b))}this._validateSelectedFeature(c);return c},_getSelectedFeaturesByLayerId:function(a){var c=[];l.forEach(this.checkBoxNodes[a],f.hitch(this,function(b,d){b.getValue()&&c.push(this.featuresByLayerId[a][d])}));return c},
_showHideSingleFeatureButton:function(a){"esriGeometryPoint"===a?m.add(this.createSingleFeatureBtn,"esriCTHidden"):m.remove(this.createSingleFeatureBtn,"esriCTHidden")},_showHideMultipleFeatureButton:function(a){"esriGeometryPoint"!==a&&this.hideMultipleFeatureButton?m.add(this.createMultipleFeaturesBtn,"esriCTHidden"):m.remove(this.createMultipleFeaturesBtn,"esriCTHidden")},_createNewGraphicsLayer:function(a){var c={};if(a+=this.widgetId)this.map._layers[a]&&this.map.removeLayer(this.map._layers[a]),
c={id:a};a=new G(c);this.map.addLayer(a);return a},_highlightFeatures:function(){this.highlightGraphicsLayer.clear();for(var a in this.featureTitlesByLayerId)this._highlightSingleLayerFeatures(a)},_highlightSingleLayerFeatures:function(a){var c=this.map.getLayer(a);a=this._getSelectedFeaturesByLayerId(a);l.forEach(a,f.hitch(this,function(b){b=F.getHighLightSymbol(b,c);this.highlightGraphicsLayer.add(b)}))},_changeWarningNote:function(a){a="esriGeometryPoint"===a&&this.hideMultipleFeatureButton?this.nls.copyFeatures.canNotSaveMultipleFeatureWarning:
"esriGeometryPoint"!==a&&this.hideMultipleFeatureButton?this.nls.copyFeatures.createOnlyOneMultipartFeatureWarning:this.nls.copyFeatures.multipleFeatureSaveWarning;k.set(this.warningMessage,"innerHTML",a);k.set(this.warningMessage,"aria-label",a)},setProgressPercentage:function(a){a=parseFloat(a.toFixed());0>=a?(this.applyEditsProgress.set({value:0}),u.set(this.applyEditsProgress.domNode,"display","block")):100<=a?(this.applyEditsProgress.set({value:100}),u.set(this.applyEditsProgress.domNode,"display",
"none")):this.applyEditsProgress.set({value:a})}})});