// 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/json dojo/Deferred esri/graphicsUtils esri/IdentityManager jimu/portalUtils jimu/portalUrlUtils jimu/Role jimu/dijit/Message ../BaseFeatureAction jimu/dijit/Popup jimu/dijit/AddItemForm".split(" "),function(n,d,p,q,r,t,l,u,v,w,m,x,y,z){return n(x,{name:"SaveToMyContent",iconClass:"icon-save",isFeatureSupported:function(b){return 0>=b.features.length||!b.features[0].geometry?!1:!0},onExecute:function(b,a){this.checkPrivilege().then(d.hitch(this,
function(c){if(c)var e=new z({appConfig:this.appConfig}),h=new y({content:e,titleLabel:window.jimuNls.featureActions.SaveToMyContent,width:525,height:220,buttons:[{label:window.jimuNls.common.ok,onClick:d.hitch(this,function(){e.showBusy();h.disableButton(0);e.validate().then(d.hitch(this,function(k){k.valid?this._addItem(b,a,e):(e.hideBusy(),h.enableButton(0))}))})},{label:window.jimuNls.common.cancel,classNames:["jimu-btn-vacation"],onClick:d.hitch(this,function(){h.close()})}]});else new m({message:window.jimuNls.noEditPrivileges})}))},
checkPrivilege:function(){var b=v.getStandardPortalUrl(this.appConfig.portalUrl),a=u.getPortal(b);if(a){if(a.haveSignIn())return this._hasPrivilege(a);l.useSignInPage=!1;return a.signIn().then(d.hitch(this,function(){l.useSignInPage=!0;return this._hasPrivilege(a)}),d.hitch(this,function(){l.useSignInPage=!0}))}b=new r;b.resolve(!1);return b},_hasPrivilege:function(b){return b.loadSelfInfo().then(d.hitch(this,function(a){if(a&&a.user){var c=new w({id:a.user.roleId?a.user.roleId:a.user.role,role:a.user.role});
a.user.privileges&&c.setPrivileges(a.user.privileges);return c.canCreateItem()&&c.canPublishFeatures()}return!1}),function(){return!1})},_addItem:function(b,a,c){var e=c.getName(),h=c.getFolderId(),k=c.popup;a=a||{};var f={name:a.name||a.id,type:a.type||"Feature Layer",displayField:a.displayField,description:a.description,copyrightText:a.copyright,geometryType:a.geometryType||b.geometryType,fields:a.fields||b.fields,objectIdField:a.objectIdField};b.features[0].geometry&&(a=t.graphicsExtent(b.features),
f.initialExtent=a,f.fullExtent=a,f.extent=a);!f.objectIdField&&f.fields&&p.some(f.fields,function(g){if("esriFieldTypeOID"===g.type)return f.objectIdField=g.name,!0});b={layers:[{layerDefinition:f,featureSet:b.toJson()}]};c.addItem({name:e,title:e,type:"Feature Collection",typeKeywords:"WAB_created",text:q.stringify(b)},h).then(d.hitch(this,function(g){!0===g.success?k.close():(c.hideBusy(),k.enableButton(0),new m({message:g.error?g.error.message:""}))}),function(g){c.hideBusy();k.enableButton(0);
new m({message:g.message})})}})});