diff --git a/Jellyfin.Plugin.SkinManager/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.SkinManager/Configuration/PluginConfiguration.cs index 3b216ec..40cdd61 100644 --- a/Jellyfin.Plugin.SkinManager/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.SkinManager/Configuration/PluginConfiguration.cs @@ -1,14 +1,18 @@ using MediaBrowser.Model.Plugins; +using System; +using System.Collections.Generic; namespace Jellyfin.Plugin.SkinManager.Configuration { public class PluginConfiguration : BasePluginConfiguration { - public string selectedCss { get; set; } + public string selectedSkin { get; set; } + public string[] options { get; set; } public PluginConfiguration() { - selectedCss = ""; + selectedSkin = ""; + options = Array.Empty(); } } } diff --git a/Jellyfin.Plugin.SkinManager/Configuration/configurationpage.html b/Jellyfin.Plugin.SkinManager/Configuration/configurationpage.html index a8a6d69..72b3971 100644 --- a/Jellyfin.Plugin.SkinManager/Configuration/configurationpage.html +++ b/Jellyfin.Plugin.SkinManager/Configuration/configurationpage.html @@ -44,8 +44,7 @@ }); function loadSkins(){ var cssOptions = document.getElementById("cssOptions"); - var skinVersions = document.getElementById("skinVersions"); - var versionDescription = document.getElementById("versionDescription"); + data.forEach(element => { var opt = document.createElement("option"); opt.appendChild(document.createTextNode(element.name)); @@ -53,6 +52,7 @@ cssOptions.appendChild(opt); }); updateSelectors(); + loadConfig(); preloadPreviews(); } @@ -105,41 +105,44 @@ return html; } - function getCheckBox ( option) { + function getCheckBox ( option,saved) { var html = ""; + var checked = saved=="true"?'checked="checked"' : ""; var id = "chkFolder" ; var name = option.name; var css = option.css; var description = option.description; //html += ''; - html += '
'+description+'
' + html += '
'+description+'
' return html; } - function getColorPicker ( option) { + function getColorPicker ( option,saved) { var html = ""; var id = "favcolor" ; var name = option.name; var defaultValue = option.default==undefined?"#000000":option.default; + defaultValue = saved == undefined?defaultValue:saved; var css = option.css; var description = option.description; var mode = option.mode; html += '
'+description+'
'; return html; } - function getNumber(option){ + function getNumber(option,saved){ var html = ""; var id = "number" ; var name = option.name; var css = option.css; var step = option.step==undefined?1:option.step; var defaultValue = option.default; + defaultValue = saved == undefined?defaultValue:saved; var description = option.description; //html += '
'; html += '
'+description+'
' return html; } - function getSelector(option){ + function getSelector(option,saved){ var html = ""; var id = "selector" ; var name = option.name; @@ -147,20 +150,21 @@ var defaultValue = option.default; var description = option.description; //html += '
'; - html += '
' + html += '
' return html; } - function getOptions(option){ + function getOptions(option,saved){ var html = ""; var selections = option.selections var css = option.css; selections.forEach(element=>{ - var name = element.name; - html+= '' + var name = element.name; + var selected = saved==name?'selected="selected"' : ""; + html+= '' }) return html; } - function getSlider(option){ + function getSlider(option,saved){ var html = ""; var id = "slider" ; @@ -168,6 +172,7 @@ var css = option.css; var step = option.step==undefined?1:option.step; var defaultValue = option.default; + defaultValue = saved == undefined?defaultValue:saved; var description = option.description; html += '
'+description+'
' return html @@ -261,12 +266,141 @@ }) } + var config = undefined; + + function loadConfig(){ + + var pluginId = "e9ca8b8e-ca6d-40e7-85dc-58e536df8eb3"; + + ApiClient.getPluginConfiguration(pluginId).then(function (savedConfig) { + config = savedConfig; + + if (!config) { + config.selectedSkin =""; + config.options = []; + } + loadSavedOptions() + }); + } + + function loadSavedOptions(){ + var skin = undefined; + data.forEach(element=> { + if(element.defaultCss == config.selectedSkin){ + skin = element + } + }) + if(skin == undefined){ + return; + } + var count = 0; + for (let option of document.getElementById("cssOptions").options){ + if(option.value == config.selectedSkin ){ + document.getElementById("cssOptions").selectedIndex = count; + } + count ++; + } + + var options = skin.options; + var savedOptions = config.options; + var html = ""; + html += '
'; + options.forEach(element=>{ + var savedValue = undefined; + var count = 0; + savedOptions.forEach(savedOption => { + if(element.css == savedOption){ + savedValue = savedOptions[count+1]; + } + count ++; + }) + if(element.type == "checkBox"){ + html += getCheckBox(element,savedValue); + }else if(element.type == "colorPicker"){ + html += getColorPicker(element,savedValue); + }else if(element.type == "number"){ + html += getNumber(element,savedValue); + }else if(element.type == "selector"){ + html += getSelector(element,savedValue); + }else if(element.type == "slider"){ + html += getSlider(element,savedValue); + }else if(element.type == "section"){ + html += getSection(element,savedValue); + } + }); + html += loadPreviews(skin); + html += '
'; + $('#options').html(html).trigger('create'); + } + + function saveConfig(){ + var pluginId = "e9ca8b8e-ca6d-40e7-85dc-58e536df8eb3"; + config.selectedSkin = $('#cssOptions').val(); + + var options = []; + var count = 0; + data[document.getElementById("cssOptions").selectedIndex].options.forEach(option => { + options[count] = option.css; + options[count +1 ] = getValue(option); + count += 2; + }); + config.options = options; + + ApiClient.getPluginConfiguration(pluginId).then(function (oldConfig){ + oldConfig = config; + ApiClient.updatePluginConfiguration(pluginId,oldConfig).then(function (res){ + Dashboard.processPluginConfigurationUpdateResult(res);}); + }); + } + + function getValue(option){ + var result = ""; + switch(option.type){ + + case "checkBox": + document.getElementsByClassName("checkbox emby-checkbox").forEach(element =>{ + if(option.css == element.getAttribute("data-css")){ + result = element.checked?"true":"false"; + + } + }) + + case "number": + document.getElementsByClassName("number emby-input").forEach(element =>{ + if(option.css == element.getAttribute("data-css")){ + result = element.value; + } + }) + case "colorPicker": + document.getElementsByClassName("color").forEach(element =>{ + if(option.css == element.getAttribute("data-css")){ + result = element.value; + } + }) + case "slider": + document.getElementsByClassName("slider").forEach(element =>{ + if(option.css == element.getAttribute("data-css")){ + result = element.value; + } + }) + case "selector": + document.getElementsByClassName("selector emby-select-withcolor emby-select").forEach(element =>{ + if(option.css == element.getAttribute("data-css")){ + result = element.selectedOptions[0].innerText;; + } + }) + + } + return result; + } + - function setSkin() { + function setSkin() { + saveConfig() ApiClient.getServerConfiguration().then(function (config) { ApiClient.updateServerConfiguration(config).then(function() { ApiClient.getNamedConfiguration('branding').then(function(brandingConfig) { @@ -299,7 +433,6 @@ }; $('#configPage').on('pageshow', function () { Dashboard.showLoadingMsg(); - loadSavedConfig(); ApiClient.getPluginConfiguration(plugin.guid).then(function (config) { $('#cssOptions').val(config.selectedCss).change(); Dashboard.hideLoadingMsg();