define(["jQuery","apphost","scripts/taskbutton","loading","cardStyle"],function($,appHost,taskButton,loading){"use strict";function changeCollectionType(page,virtualFolder){require(["alert"],function(alert){alert({title:Globalize.translate("HeaderChangeFolderType"),text:Globalize.translate("HeaderChangeFolderTypeHelp")})})}function addVirtualFolder(page){require(["medialibrarycreator"],function(medialibrarycreator){(new medialibrarycreator).show({collectionTypeOptions:getCollectionTypeOptions().filter(function(f){return!f.hidden}),refresh:shouldRefreshLibraryAfterChanges(page)}).then(function(hasChanges){hasChanges&&reloadLibrary(page)})})}function editVirtualFolder(page,virtualFolder){require(["medialibraryeditor"],function(medialibraryeditor){(new medialibraryeditor).show({refresh:shouldRefreshLibraryAfterChanges(page),library:virtualFolder}).then(function(hasChanges){hasChanges&&reloadLibrary(page)})})}function deleteVirtualFolder(page,virtualFolder){var msg=Globalize.translate("MessageAreYouSureYouWishToRemoveMediaFolder");virtualFolder.Locations.length&&(msg+="

"+Globalize.translate("MessageTheFollowingLocationWillBeRemovedFromLibrary")+"

",msg+=virtualFolder.Locations.join("
")),require(["confirm"],function(confirm){confirm(msg,Globalize.translate("HeaderRemoveMediaFolder")).then(function(){var refreshAfterChange=shouldRefreshLibraryAfterChanges(page);ApiClient.removeVirtualFolder(virtualFolder.Name,refreshAfterChange).then(function(){reloadLibrary(page)})})})}function renameVirtualFolder(page,virtualFolder){require(["prompt"],function(prompt){prompt({label:Globalize.translate("LabelNewName"),confirmText:Globalize.translate("ButtonRename")}).then(function(newName){if(newName&&newName!=virtualFolder.Name){var refreshAfterChange=shouldRefreshLibraryAfterChanges(page);ApiClient.renameVirtualFolder(virtualFolder.Name,newName,refreshAfterChange).then(function(){reloadLibrary(page)})}})})}function showCardMenu(page,elem,virtualFolders){var card=$(elem).parents(".card")[0],index=parseInt(card.getAttribute("data-index")),virtualFolder=virtualFolders[index],menuItems=[];menuItems.push({name:Globalize.translate("ButtonChangeContentType"),id:"changetype",ironIcon:"videocam"}),menuItems.push({name:Globalize.translate("ButtonEditImages"),id:"editimages",ironIcon:"photo"}),menuItems.push({name:Globalize.translate("ButtonManageFolders"),id:"edit",ironIcon:"folder_open"}),menuItems.push({name:Globalize.translate("ButtonRemove"),id:"delete",ironIcon:"remove"}),menuItems.push({name:Globalize.translate("ButtonRename"),id:"rename",ironIcon:"mode_edit"}),require(["actionsheet"],function(actionsheet){actionsheet.show({items:menuItems,positionTo:elem,callback:function(resultId){switch(resultId){case"changetype":changeCollectionType(page,virtualFolder);break;case"edit":editVirtualFolder(page,virtualFolder);break;case"editimages":editImages(page,virtualFolder);break;case"rename":renameVirtualFolder(page,virtualFolder);break;case"delete":deleteVirtualFolder(page,virtualFolder)}}})})}function reloadLibrary(page){loading.show(),ApiClient.getVirtualFolders().then(function(result){reloadVirtualFolders(page,result)})}function shouldRefreshLibraryAfterChanges(page){return $(page).is("#mediaLibraryPage")}function reloadVirtualFolders(page,virtualFolders){var html="";virtualFolders.push({Name:Globalize.translate("ButtonAddMediaLibrary"),icon:"add_circle",Locations:[],showType:!1,showLocations:!1,showMenu:!1,showNameWithIcon:!0});for(var i=0,length=virtualFolders.length;i',html+='
',html+='
',html+='
',html+='
';var imgUrl="";if(virtualFolder.PrimaryImageItemId&&(imgUrl=ApiClient.getScaledImageUrl(virtualFolder.PrimaryImageItemId,{type:"Primary"})),imgUrl?html+='
":virtualFolder.showNameWithIcon||(html+='
',html+=''+(virtualFolder.icon||getIcon(virtualFolder.CollectionType))+"",html+="
"),!imgUrl&&virtualFolder.showNameWithIcon&&(html+='

',html+=''+(virtualFolder.icon||getIcon(virtualFolder.CollectionType))+"",virtualFolder.showNameWithIcon&&(html+='
',html+=virtualFolder.Name,html+="
"),html+="

"),html+="
",html+="
",html+='
',virtualFolder.showMenu!==!1){var moreIcon="dots-horiz"==appHost.moreIcon?"":"";html+='
',html+='",html+="
"}html+="
",html+=virtualFolder.showNameWithIcon?" ":virtualFolder.Name,html+="
";var typeName=getCollectionTypeOptions().filter(function(t){return t.value==virtualFolder.CollectionType})[0];return typeName=typeName?typeName.name:Globalize.translate("FolderTypeUnset"),html+="
",html+=virtualFolder.showType===!1?" ":typeName,html+="
",virtualFolder.showLocations===!1?(html+="
",html+=" ",html+="
"):virtualFolder.Locations.length?1==virtualFolder.Locations.length?(html+="
",html+=virtualFolder.Locations[0],html+="
"):(html+="
",html+=Globalize.translate("NumLocationsValue",virtualFolder.Locations.length),html+="
"):(html+="
",html+=Globalize.translate("NumLocationsValue",virtualFolder.Locations.length),html+="
"),html+="
",html+="
",html+=""}function getTabs(){return[{href:"library.html",name:Globalize.translate("HeaderLibraries")},{href:"librarydisplay.html",name:Globalize.translate("TabDisplay")},{href:"metadataimages.html",name:Globalize.translate("TabMetadata")},{href:"metadatanfo.html",name:Globalize.translate("TabNfoSettings")},{href:"librarysettings.html",name:Globalize.translate("TabAdvanced")}]}window.WizardLibraryPage={next:function(){loading.show();var apiClient=ApiClient;apiClient.ajax({type:"POST",url:apiClient.getUrl("System/Configuration/MetadataPlugins/Autoset")}).then(function(){loading.hide(),Dashboard.navigate("wizardsettings.html")})}},pageClassOn("pageshow","mediaLibraryPage",function(){var page=this;reloadLibrary(page)}),pageIdOn("pageshow","mediaLibraryPage",function(){LibraryMenu.setTabs("librarysetup",0,getTabs);var page=this;taskButton({mode:"on",progressElem:page.querySelector(".refreshProgress"),taskKey:"RefreshLibrary",button:page.querySelector(".btnRefresh")})}),pageIdOn("pagebeforehide","mediaLibraryPage",function(){var page=this;taskButton({mode:"off",progressElem:page.querySelector(".refreshProgress"),taskKey:"RefreshLibrary",button:page.querySelector(".btnRefresh")})})});