2017-01-27 22:16:59 -05:00
|
|
|
define(["dialogHelper","jQuery","components/libraryoptionseditor/libraryoptionseditor","emby-input","emby-select","paper-icon-button-light","listViewStyle","formDialogStyle"],function(dialogHelper,$,libraryoptionseditor){"use strict";function onSubmit(){if(0==pathInfos.length)return require(["alert"],function(alert){alert({text:Globalize.translate("PleaseAddAtLeastOneFolder"),type:"error"})}),!1;var form=this,dlg=$(form).parents(".dialog")[0],name=$("#txtValue",form).val(),type=$("#selectCollectionType",form).val();"mixed"==type&&(type=null);var libraryOptions=libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions"));return libraryOptions.PathInfos=pathInfos,ApiClient.addVirtualFolder(name,type,currentOptions.refresh,libraryOptions).then(function(){hasChanges=!0,dialogHelper.close(dlg)},function(){require(["toast"],function(toast){toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"))})}),!1}function getCollectionTypeOptionsHtml(collectionTypeOptions){return collectionTypeOptions.filter(function(i){return i.isSelectable!==!1}).map(function(i){return'<option value="'+i.value+'">'+i.name+"</option>"}).join("")}function initEditor(page,collectionTypeOptions){$("#selectCollectionType",page).html(getCollectionTypeOptionsHtml(collectionTypeOptions)).val("").on("change",function(){var value=this.value,dlg=$(this).parents(".dialog")[0];if(libraryoptionseditor.setContentType(dlg.querySelector(".libraryOptions"),"mixed"==value?"":value),value?dlg.querySelector(".libraryOptions").classList.remove("hide"):dlg.querySelector(".libraryOptions").classList.add("hide"),"mixed"!=value){var index=this.selectedIndex;if(index!=-1){var name=this.options[index].innerHTML.replace("*","").replace("&","&");$("#txtValue",dlg).val(name);var folderOption=collectionTypeOptions.filter(function(i){return i.value==value})[0];$(".collectionTypeFieldDescription",dlg).html(folderOption.message||"")}}}),$(".btnAddFolder",page).on("click",onAddButtonClick),$("form",page).off("submit",onSubmit).on("submit",onSubmit)}function onAddButtonClick(){var page=$(this).parents(".dlg-librarycreator")[0];require(["directorybrowser"],function(directoryBrowser){var picker=new directoryBrowser;picker.show({enableNetworkSharePath:!0,callback:function(path,networkSharePath){path&&addMediaLocation(page,path,networkSharePath),picker.close()}})})}function getFolderHtml(pathInfo,index){var html="";html+='<div class="listItem lnkPath">',html+='<i class="listItemIcon md-icon">folder</i>';var cssClass=pathInfo.NetworkPath?"listItemBody two-line":"listItemBody";return html+='<div class="'+cssClass+'">',html+='<div class="listItemBodyText">'+pathInfo.Path+"</div>",pathInfo.NetworkPath&&(html+='<div class="listItemBodyText secondary">'+pathInfo.NetworkPath+"</div>"),html+="</div>",html+='<button is="paper-icon-button-light"" class="listItemButton btnRemovePath" data-index="'+index+'"><i class="md-icon">remove_circle</i></button>',html+="</div>"}function renderPaths(page){var foldersHtml=pathInfos.map(getFolderHtml).join(""),folderList=page.querySelector(".folderList");folderList.innerHTML=foldersHtml,foldersHtml?folderList.classList.remove("hide"):folderList.classList.add("hide"),$(page.querySelectorAll(".btnRemovePath")).on("click",onRemoveClick)}function addMediaLocation(page,path,networkSharePath){if(0==pathInfos.filter(function(p){return p.Path.toLowerCase()==path.toLowerCase()}).length){var pathInfo={Path:path};networkSharePath&&(pathInfo.NetworkPath=networkSharePath),pathInfos.push(pathInfo),renderPaths(page)}}function onRemoveClick(){var button=this,index=parseInt(button.getAttribute("data-index")),location=pathInfos[index];pathInfos=pathInfos.filter(function(p){return p.Path.toLowerCase()!=location.toLowerCase()});var page=$(this).parents(".dlg-librarycreator")[0];renderPaths(page)}function onDialogClosed(){Dashboard.hideLoadingMsg(),currentDeferred.resolveWith(null,[hasChanges])}function initLibraryOptions(dlg){libraryoptionseditor.embed(dlg.querySelector(".libraryOptions")).then(function(){$("#selectCollectionType",dlg).trigger("change")})}f
|