1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/scripts/librarypathmapping.js

160 lines
4 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2014-01-29 15:57:17 -05:00
2014-01-30 00:20:18 -05:00
var currentConfig;
function remove(page, index) {
2016-02-22 14:12:06 -05:00
require(['confirm'], function (confirm) {
2014-01-30 00:20:18 -05:00
2016-02-22 14:12:06 -05:00
confirm(Globalize.translate('MessageConfirmPathSubstitutionDeletion'), Globalize.translate('HeaderConfirmDeletion')).then(function () {
2014-01-30 00:20:18 -05:00
2015-12-14 10:43:03 -05:00
ApiClient.getServerConfiguration().then(function (config) {
2014-01-30 00:20:18 -05:00
config.PathSubstitutions.splice(index, 1);
2015-12-14 10:43:03 -05:00
ApiClient.updateServerConfiguration(config).then(function () {
2014-01-30 00:20:18 -05:00
reload(page);
});
});
2016-02-22 14:12:06 -05:00
});
2014-01-30 00:20:18 -05:00
});
}
function addSubstitution(page, config) {
config.PathSubstitutions.push({
From: $('#txtFrom', page).val(),
To: $('#txtTo', page).val()
});
}
function reloadPathMappings(page, config) {
var index = 0;
var html = config.PathSubstitutions.map(function (map) {
2016-02-08 13:05:29 -05:00
var mapHtml = '';
mapHtml += '<paper-icon-item>';
2014-01-30 00:20:18 -05:00
2016-02-08 13:05:29 -05:00
mapHtml += '<paper-fab mini icon="folder" class="blue" item-icon></paper-fab>';
2014-01-30 00:20:18 -05:00
2016-02-08 13:05:29 -05:00
mapHtml += '<paper-item-body three-line>';
mapHtml += "<div>" + map.From + "</div>";
mapHtml += "<div secondary><b>" + Globalize.translate('HeaderTo') + "</b></div>";
mapHtml += "<div secondary>" + map.To + "</div>";
mapHtml += '</paper-item-body>';
2014-01-30 00:20:18 -05:00
2015-09-06 15:09:36 -04:00
mapHtml += '<paper-icon-button data-index="' + index + '" icon="delete" class="btnDeletePath"></paper-icon-button>';
2016-02-08 13:05:29 -05:00
mapHtml += '</paper-icon-item>';
2014-01-30 00:20:18 -05:00
index++;
return mapHtml;
2016-02-08 13:05:29 -05:00
}).join('');
if (config.PathSubstitutions.length) {
html = '<div class="paperList">' + html + '</div>';
}
var elem = $('.pathSubstitutions', page).html(html);
2014-01-30 00:20:18 -05:00
$('.btnDeletePath', elem).on('click', function () {
remove(page, parseInt(this.getAttribute('data-index')));
});
}
2014-01-29 15:57:17 -05:00
function loadPage(page, config) {
2014-01-30 00:20:18 -05:00
currentConfig = config;
2014-01-29 15:57:17 -05:00
2016-02-08 13:05:29 -05:00
require(['paper-fab', 'paper-item-body', 'paper-icon-item'], function () {
reloadPathMappings(page, config);
Dashboard.hideLoadingMsg();
});
2014-01-29 15:57:17 -05:00
}
2014-01-30 00:20:18 -05:00
function reload(page) {
$('#txtFrom', page).val('');
$('#txtTo', page).val('');
2015-12-14 10:43:03 -05:00
ApiClient.getServerConfiguration().then(function (config) {
2014-01-30 00:20:18 -05:00
loadPage(page, config);
});
}
2015-06-08 17:32:20 -04:00
function onSubmit() {
2014-01-29 15:57:17 -05:00
Dashboard.showLoadingMsg();
2015-06-08 17:32:20 -04:00
var form = this;
var page = $(form).parents('.page');
2014-01-29 15:57:17 -05:00
2015-12-14 10:43:03 -05:00
ApiClient.getServerConfiguration().then(function (config) {
2014-01-29 15:57:17 -05:00
2015-06-08 17:32:20 -04:00
addSubstitution(page, config);
2015-12-14 10:43:03 -05:00
ApiClient.updateServerConfiguration(config).then(function () {
2014-01-29 15:57:17 -05:00
2015-06-08 17:32:20 -04:00
reload(page);
});
2014-01-29 15:57:17 -05:00
});
2015-06-08 17:32:20 -04:00
// Disable default form submission
return false;
}
2014-01-30 00:20:18 -05:00
2016-04-14 12:30:37 -04:00
function getTabs() {
return [
{
href: 'library.html',
name: Globalize.translate('TabFolders')
},
{
href: 'librarypathmapping.html',
name: Globalize.translate('TabPathSubstitution')
2016-04-14 22:39:39 -04:00
},
{
href: 'librarysettings.html',
name: Globalize.translate('TabAdvanced')
2016-04-14 12:30:37 -04:00
}];
}
2016-04-14 22:39:39 -04:00
2015-09-01 10:01:59 -04:00
$(document).on('pageinit', "#libraryPathMappingPage", function () {
2014-01-29 15:57:17 -05:00
2016-01-05 11:46:01 -05:00
var page = this;
2015-06-08 17:32:20 -04:00
$('.libraryPathMappingForm').off('submit', onSubmit).on('submit', onSubmit);
2014-01-29 15:57:17 -05:00
2016-01-05 11:46:01 -05:00
page.querySelector('.labelFromHelp').innerHTML = Globalize.translate('LabelFromHelp', 'D:\\Movies');
2015-09-24 13:08:10 -04:00
}).on('pageshow', "#libraryPathMappingPage", function () {
2014-01-29 15:57:17 -05:00
2016-04-14 12:30:37 -04:00
LibraryMenu.setTabs('librarysetup', 1, getTabs);
2015-06-08 17:32:20 -04:00
Dashboard.showLoadingMsg();
2014-01-29 15:57:17 -05:00
2015-06-08 17:32:20 -04:00
var page = this;
2014-01-29 15:57:17 -05:00
2015-12-14 10:43:03 -05:00
ApiClient.getServerConfiguration().then(function (config) {
2014-01-29 15:57:17 -05:00
2015-06-08 17:32:20 -04:00
loadPage(page, config);
2014-01-29 15:57:17 -05:00
2015-06-08 17:32:20 -04:00
});
2014-01-29 15:57:17 -05:00
2015-06-20 20:49:42 -04:00
}).on('pagebeforehide', "#libraryPathMappingPage", function () {
2014-01-29 15:57:17 -05:00
2015-06-08 17:32:20 -04:00
currentConfig = null;
2014-01-29 15:57:17 -05:00
2015-06-08 17:32:20 -04:00
});
2014-01-29 15:57:17 -05:00
});