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

161 lines
4 KiB
JavaScript
Raw Normal View History

2016-08-05 15:34:10 -04:00
define(['jQuery', 'listViewStyle'], function ($) {
2016-10-23 01:11:46 -04:00
'use strict';
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 = '';
2016-08-05 15:34:10 -04:00
mapHtml += '<div class="listItem">';
2014-01-30 00:20:18 -05:00
2016-08-05 15:34:10 -04:00
mapHtml += '<i class="listItemIcon md-icon">folder</i>';
2014-01-30 00:20:18 -05:00
2016-08-05 15:34:10 -04:00
mapHtml += '<div class="listItemBody three-line">';
2016-02-08 13:05:29 -05:00
2016-08-05 15:34:10 -04:00
mapHtml += "<h3 class='listItemBodyText'>" + map.From + "</h3>";
mapHtml += "<div class='listItemBodyText secondary'>" + Globalize.translate('HeaderTo') + "</div>";
mapHtml += "<div class='listItemBodyText secondary'>" + map.To + "</div>";
2016-02-08 13:05:29 -05:00
2016-08-05 15:34:10 -04:00
mapHtml += '</div>';
2014-01-30 00:20:18 -05:00
2016-08-05 15:34:10 -04:00
mapHtml += '<button type="button" is="paper-icon-button-light" data-index="' + index + '" class="btnDeletePath"><i class="md-icon">delete</i></button>';
2015-09-06 15:09:36 -04:00
2016-08-05 15:34:10 -04:00
mapHtml += '</div>';
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-08-05 15:34:10 -04:00
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',
2016-09-24 13:58:17 -04:00
name: Globalize.translate('HeaderLibraries')
2016-04-14 12:30:37 -04:00
},
2016-06-04 01:51:33 -04:00
{
href: 'librarydisplay.html',
name: Globalize.translate('TabDisplay')
},
2016-04-14 12:30:37 -04:00
{
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
2015-09-24 13:08:10 -04:00
}).on('pageshow', "#libraryPathMappingPage", function () {
2014-01-29 15:57:17 -05:00
2016-06-04 01:51:33 -04:00
LibraryMenu.setTabs('librarysetup', 2, 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
});