jellyfin-web/dashboard-ui/scripts/metadataimagespage.js

1 line
14 KiB
JavaScript
Raw Normal View History

2017-05-17 20:18:08 -07:00
define(["jQuery","dom","loading","libraryMenu","listViewStyle"],function($,dom,loading,libraryMenu){"use strict";function populateLanguages(select){return ApiClient.getCultures().then(function(languages){var html="";html+="<option value=''></option>";for(var i=0,length=languages.length;i<length;i++){var culture=languages[i];html+="<option value='"+culture.TwoLetterISOLanguageName+"'>"+culture.DisplayName+"</option>"}select.innerHTML=html})}function populateCountries(select){return ApiClient.getCountries().then(function(allCountries){var html="";html+="<option value=''></option>";for(var i=0,length=allCountries.length;i<length;i++){var culture=allCountries[i];html+="<option value='"+culture.TwoLetterISORegionName+"'>"+culture.DisplayName+"</option>"}select.innerHTML=html})}function loadTabs(page,tabs){for(var html="",i=0,length=tabs.length;i<length;i++){var tab=tabs[i],isChecked=0==i?' selected="selected"':"";html+='<option value="'+tab.type+'"'+isChecked+">"+Globalize.translate(tab.name)+"</option>"}$("#selectItemType",page).html(html).trigger("change"),loading.hide()}function loadType(page,type){loading.show(),currentType=type;var promise1=ApiClient.getServerConfiguration(),promise2=ApiClient.getJSON(ApiClient.getUrl("System/Configuration/MetadataPlugins"));Promise.all([promise1,promise2]).then(function(responses){var config=responses[0],metadataPlugins=responses[1];config=config.MetadataOptions.filter(function(c){return c.ItemType==type})[0],config?(renderType(page,type,config,metadataPlugins),loading.hide()):ApiClient.getJSON(ApiClient.getUrl("System/Configuration/MetadataOptions/Default")).then(function(defaultConfig){config=defaultConfig,renderType(page,type,config,metadataPlugins),loading.hide()})})}function setVisibilityOfBackdrops(elem,visible){visible?(elem.show(),$("input",elem).attr("required","required")):(elem.hide(),$("input",elem).attr("required","").removeAttr("required"))}function renderType(page,type,config,metadataPlugins){var metadataInfo=metadataPlugins.filter(function(f){return type==f.ItemType})[0];setVisibilityOfBackdrops($(".backdropFields",page),metadataInfo.SupportedImageTypes.indexOf("Backdrop")!=-1),setVisibilityOfBackdrops($(".screenshotFields",page),metadataInfo.SupportedImageTypes.indexOf("Screenshot")!=-1),$(".imageType",page).each(function(){var imageType=this.getAttribute("data-imagetype"),container=dom.parentWithTag(this,"LABEL");metadataInfo.SupportedImageTypes.indexOf(imageType)==-1?container.classList.add("hide"):container.classList.remove("hide"),getImageConfig(config,imageType).Limit?this.checked=!0:this.checked=!1});var backdropConfig=getImageConfig(config,"Backdrop");$("#txtMaxBackdrops",page).val(backdropConfig.Limit),$("#txtMinBackdropDownloadWidth",page).val(backdropConfig.MinWidth);var screenshotConfig=getImageConfig(config,"Screenshot");$("#txtMaxScreenshots",page).val(screenshotConfig.Limit),$("#txtMinScreenshotDownloadWidth",page).val(screenshotConfig.MinWidth),renderMetadataLocals(page,type,config,metadataInfo),renderMetadataFetchers(page,type,config,metadataInfo),renderMetadataSavers(page,type,config,metadataInfo),renderImageFetchers(page,type,config,metadataInfo)}function getImageConfig(config,type){return config.ImageOptions.filter(function(i){return i.Type==type})[0]||{Type:type,MinWidth:"Backdrop"==type?1280:0,Limit:"Backdrop"==type?3:1}}function renderImageFetchers(page,type,config,metadataInfo){var plugins=metadataInfo.Plugins.filter(function(p){return"ImageFetcher"==p.Type}),html="";if(!plugins.length)return void $(".imageFetchers",page).html(html).hide();var i,length,plugin;for(html+='<h3 class="checkboxListLabel">'+Globalize.translate("LabelImageFetchers")+"</h3>",html+='<div class="checkboxList paperList checkboxList-paperList">',i=0,length=plugins.length;i<length;i++){plugin=plugins[i];var isChecked=config.DisabledImageFetchers.indexOf(plugin.Name)==-1?' checked="checked"':"";html+='<div class="listItem imageFetcherItem" data-pluginname="'+plugin.Name+'">',html+='<label class="listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" class="chkIma