// 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/Bookmark/setting/Sync.html":'\x3cdiv class\x3d"sync"\x3e\r\n  \x3cdiv class\x3d"sync-setting-item"\x3e\r\n    \x3cdiv class\x3d"check" data-dojo-attach-point\x3d"isSyncWebmapNode"\x3e\x3c/div\x3e\r\n    \x3cdiv class\x3d"marks-table-div web-map" data-dojo-attach-point\x3d"webMapBookMarkerContainer"\x3e\x3c/div\x3e\r\n  \x3c/div\x3e\r\n\r\n  \x3cdiv class\x3d"sync-setting-item"\x3e\r\n    \x3cdiv class\x3d"check" data-dojo-attach-point\x3d"isSyncCustomNode"\x3e\x3c/div\x3e\r\n\r\n    \x3cdiv data-dojo-attach-point\x3d"customBtns" class\x3d"verticalCenter"\x3e\r\n      \x3c!--\x3cdiv class\x3d"custom-btns" data-dojo-attach-point\x3d"importBtn"\x3e${nls.import}\x3c/div\x3e--\x3e\r\n      \x3cdiv class\x3d"custom-btns create" data-dojo-attach-point\x3d"createNewBtn"\x3e${nls.create}\x3c/div\x3e\r\n    \x3c/div\x3e\r\n\r\n    \x3cdiv class\x3d"marks-table-div custom editing" data-dojo-attach-point\x3d"custombookMarkerContainer"\x3e\x3c/div\x3e\r\n  \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/keys jimu/BaseWidgetSetting dijit/_WidgetsInTemplateMixin dojo/on dojo/_base/html jimu/dijit/Popup jimu/dijit/Message ./Edit ./Import dojo/text!./Sync.html ../utils jimu/dijit/CheckBox libs/Sortable".split(" "),function(v,d,l,n,w,x,k,f,q,r,y,z,A,g,t,u){return v([w,x],{templateString:A,map:null,edit:null,popup:null,popupState:"",editIndex:null,startup:function(){this.webMapBookmarksNodes=u.create(this.webMapBookMarkerContainer,{sort:!1,
disabled:!0,animation:100});this.sortableBookMarkerNodes=u.create(this.custombookMarkerContainer,{handle:".drag-masker",sort:!0,disabled:!1,animation:100,onSort:d.hitch(this,function(){this.saveBookMarkersBySortable()})});this.isSyncWebmapCheckBox=new t({label:this.nls.alwaysSync,checked:!1},this.isSyncWebmapNode);this.isSyncWebmapCheckBox.startup();this.isSyncCustomCheckBox=new t({label:this.nls.configCustom,checked:!1},this.isSyncCustomNode);this.isSyncCustomCheckBox.startup();this.own(k(this.isSyncWebmapCheckBox,
"change",d.hitch(this,function(){!0===this.isSyncWebmapCheckBox.getValue()?this.showWebmapBookmarks():this.hideWebmapBookmarks()})));this.own(k(this.isSyncCustomCheckBox,"change",d.hitch(this,function(){!0===this.isSyncCustomCheckBox.getValue()?this.showCustomBookmarks():this.hideCustomBookmarks()})));this.own(k(this.createNewBtn,"click",d.hitch(this,function(){this.onAddBookmarkClick()})));this.hideWebmapBookmarks();this.hideCustomBookmarks();this.inherited(arguments)},showWebmapBookmarks:function(){f.removeClass(this.webMapBookMarkerContainer,
"hide");g.empty(this._bookmarksInWebmap);this._bookmarksInWebmap=g.readBookmarksInWebmap(this.map);this._bookmarksInWebmap=this.displayBookmarks({bookmarks:this._bookmarksInWebmap,syncMode:"webmap",bookmarksContainerNode:this.webMapBookMarkerContainer})},hideWebmapBookmarks:function(){f.addClass(this.webMapBookMarkerContainer,"hide")},showCustomBookmarks:function(){f.removeClass(this.customBtns,"hide");f.removeClass(this.custombookMarkerContainer,"hide");"undefined"===typeof this._customBookmarks&&
(g.empty(this._customBookmarks),this._customBookmarks=this.config.bookmarks2D,this._customBookmarks=this.displayBookmarks({bookmarks:this._customBookmarks,syncMode:"custom",bookmarksContainerNode:this.custombookMarkerContainer}))},hideCustomBookmarks:function(){f.addClass(this.customBtns,"hide");f.addClass(this.custombookMarkerContainer,"hide")},destroy:function(){this.webMapBookmarksNodes&&this.webMapBookmarksNodes.destroy&&(this.webMapBookmarksNodes.destroy(),this.webMapBookmarksNodes=null);this.sortableBookMarkerNodes&&
(this.sortableBookMarkerNodes.destroy(),this.sortableBookMarkerNodes=null);l.forEach(this._bookmarksInWebmap,function(a){a.itemNode&&a.itemNode.destroy()},this);this._bookmarksInWebmap=[];l.forEach(this._customBookmarks,function(a){a.itemNode&&a.itemNode.destroy()},this);this._customBookmarks=[];this.inherited(arguments)},setConfig:function(a){this.config=a;!0===this.config.syncMode.webmap&&this.isSyncWebmapCheckBox.setValue(!0);!0===this.config.syncMode.custom&&this.isSyncCustomCheckBox.setValue(!0)},
getConfig:function(){!0===this.isSyncWebmapCheckBox.getValue()?this.config.syncMode.webmap=!0:this.config.syncMode.webmap=!1;!0===this.isSyncCustomCheckBox.getValue()?this.config.syncMode.custom=!0:this.config.syncMode.custom=!1;var a=[];a=a.concat(this._customBookmarks);return{syncMode:this.config.syncMode,bookmarks:a}},displayBookmarks:function(a){var b=a.bookmarks,c=a.syncMode,m=a.bookmarksContainerNode||this.custombookMarkerContainer;g.empty(b);var h={};h="webmap"===c?{editBtn:!1,selectedBtn:!1,
deleteBtn:!1,renameBtn:!1}:{editBtn:!0,selectedBtn:!1,deleteBtn:!0,renameBtn:!1};l.forEach(b,function(e){if(e){h.layerInfosIcon=g.isWithLayerInfos(e);var p=g.createBookMarkNode(e,this.nls,this.folderUrl,h);e.itemNode=p;this.own(k(p,"thumbnail-click",d.hitch(this,d.partial(this._onBookmarkClick,e))));this.own(k(p,"delete",d.hitch(this,d.partial(this._onBookmarkDeleteImmediately,e))));this.own(k(p,"edit",d.hitch(this,d.partial(this._onBookmarkEdit,e))))}},this);b.forEach(d.hitch(this,function(e){e&&
e.itemNode&&e.itemNode.domNode&&f.place(e.itemNode.domNode,m,"last")}));return b},saveBookMarkersBySortable:function(){for(var a=this.sortableBookMarkerNodes.toArray(),b=[],c=0,m=a.length;c<m;c++){var h=g.findBookMarkByUID(a[c],this._customBookmarks);h&&b.push(h.bookmark)}this._customBookmarks=b;this.displayBookmarks({bookmarks:this._customBookmarks,syncMode:"custom"})},getBookmarkByName:function(a){for(var b=this._customBookmarks.length,c=0;c<b;c++)if(this._customBookmarks[c].displayName===a)return this.editIndex=
c,this._customBookmarks[c]},onAddBookmarkClick:function(){this.popupState="ADD";this._openEdit(this.nls.addBookmark,{name:"",thumbnail:"",extent:this.map.extent.toJson()})},_onBookmarkEdit:function(a){this.popupState="EDIT";this._openEdit(this.nls.edit,a)},_onBookmarkDeleteImmediately:function(a){(a=g.findBookMark(a,this._customBookmarks))&&a.bookmark&&(a.bookmark.itemNode&&a.bookmark.itemNode.destroy(),this._customBookmarks.splice(a.idx,1))},_openEdit:function(a,b){this.edit=new y({nls:this.nls,
folderUrl:this.folderUrl,portalUrl:this.appConfig.map.portalUrl,itemId:this.appConfig.map.itemId,mapOptions:this.appConfig.map.mapOptions});this.edit.setConfig(b||{});this.popup=new q({titleLabel:a,autoHeight:!0,content:this.edit,container:"main-page",width:600,buttons:[{label:this.nls.ok,key:n.ENTER,disable:!0,onClick:d.hitch(this,"_onEditOk",b)},{label:this.nls.cancel,classNames:["jimu-btn-vacation"],key:n.ESCAPE}],onClose:d.hitch(this,"_onEditClose")});f.addClass(this.popup.domNode,"widget-setting-popup");
this.edit.startup()},_onEditOk:function(a){var b=this.edit.getConfig(),c=null;if(b.name&&b.extent){"EDIT"===this.popupState&&(a=d.mixin(a,b));a=b.name;var m=g.getAutoRenameBeforeAdd(a,this._customBookmarks,!0);b.name=a;b.displayName=m;"ADD"===this.popupState?(this.addBookmark(b),c=!0):"EDIT"===this.popupState&&(this.saveBookMarkersBySortable(),c=!0);c?(this.popup.close(),this.popupState="",this.editIndex=null,c=!1):(b=l.mark(c.repeatFields,d.hitch(this,function(h){return h&&h.name})),new r({message:this.nls[c.errorCode]+
b.toString()}))}else new r({message:this.nls.warning})},_onEditClose:function(){this.popup=this.edit=null},addBookmark:function(a){var b=g.createBookMarkNode(a,this.nls,this.folderUrl,{editBtn:!0,changeImgBtn:!1});a.itemNode=b;this._customBookmarks.unshift(a);a.itemNode&&a.itemNode.domNode&&f.place(a.itemNode.domNode,this.custombookMarkerContainer,"last");this.saveBookMarkersBySortable()},onImport:function(){this.importWidget=new z({nls:this.nls,map:this.map,folderUrl:this.folderUrl});this.popup=
new q({titleLabel:this.nls.importTitle,autoHeight:!0,content:this.importWidget,container:"main-page",width:640,buttons:[{label:this.nls.ok,key:n.ENTER,disable:!0,onClick:d.hitch(this,"_onImportOk")},{label:this.nls.cancel,classNames:["jimu-btn-vacation"],key:n.ESCAPE}],onClose:d.hitch(this,"_onImportClose")});f.addClass(this.popup.domNode,"widget-setting-popup");this.importWidget.startup()},_onImportOk:function(){var a=this.importWidget.getConfig();l.forEach(a,function(b){this.addBookmark(b)},this);
this.popup.close()},_onImportClose:function(){this.importWidget.destroy()}})});