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

162 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-08-05 12:34:10 -07:00
define(['jQuery', 'listViewStyle'], function ($) {
2014-01-29 13:57:17 -07:00
2014-01-29 22:20:18 -07:00
var currentConfig;
function remove(page, index) {
2016-02-22 12:12:06 -07:00
require(['confirm'], function (confirm) {
2014-01-29 22:20:18 -07:00
2016-02-22 12:12:06 -07:00
confirm(Globalize.translate('MessageConfirmPathSubstitutionDeletion'), Globalize.translate('HeaderConfirmDeletion')).then(function () {
2014-01-29 22:20:18 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getServerConfiguration().then(function (config) {
2014-01-29 22:20:18 -07:00
config.PathSubstitutions.splice(index, 1);
2015-12-14 08:43:03 -07:00
ApiClient.updateServerConfiguration(config).then(function () {
2014-01-29 22:20:18 -07:00
reload(page);
});
});
2016-02-22 12:12:06 -07:00
});
2014-01-29 22:20:18 -07: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 11:05:29 -07:00
var mapHtml = '';
2016-08-05 12:34:10 -07:00
mapHtml += '<div class="listItem">';
2014-01-29 22:20:18 -07:00
2016-08-05 12:34:10 -07:00
mapHtml += '<i class="listItemIcon md-icon">folder</i>';
2014-01-29 22:20:18 -07:00
2016-08-05 12:34:10 -07:00
mapHtml += '<div class="listItemBody three-line">';
2016-02-08 11:05:29 -07:00
2016-08-05 12:34:10 -07: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 11:05:29 -07:00
2016-08-05 12:34:10 -07:00
mapHtml += '</div>';
2014-01-29 22:20:18 -07:00
2016-08-05 12:34:10 -07: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 12:09:36 -07:00
2016-08-05 12:34:10 -07:00
mapHtml += '</div>';
2014-01-29 22:20:18 -07:00
index++;
return mapHtml;
2016-02-08 11:05:29 -07:00
}).join('');
if (config.PathSubstitutions.length) {
html = '<div class="paperList">' + html + '</div>';
}
var elem = $('.pathSubstitutions', page).html(html);
2014-01-29 22:20:18 -07:00
$('.btnDeletePath', elem).on('click', function () {
remove(page, parseInt(this.getAttribute('data-index')));
});
}
2014-01-29 13:57:17 -07:00
function loadPage(page, config) {
2014-01-29 22:20:18 -07:00
currentConfig = config;
2014-01-29 13:57:17 -07:00
2016-08-05 12:34:10 -07:00
reloadPathMappings(page, config);
Dashboard.hideLoadingMsg();
2014-01-29 13:57:17 -07:00
}
2014-01-29 22:20:18 -07:00
function reload(page) {
$('#txtFrom', page).val('');
$('#txtTo', page).val('');
2015-12-14 08:43:03 -07:00
ApiClient.getServerConfiguration().then(function (config) {
2014-01-29 22:20:18 -07:00
loadPage(page, config);
});
}
2015-06-08 14:32:20 -07:00
function onSubmit() {
2014-01-29 13:57:17 -07:00
Dashboard.showLoadingMsg();
2015-06-08 14:32:20 -07:00
var form = this;
var page = $(form).parents('.page');
2014-01-29 13:57:17 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getServerConfiguration().then(function (config) {
2014-01-29 13:57:17 -07:00
2015-06-08 14:32:20 -07:00
addSubstitution(page, config);
2015-12-14 08:43:03 -07:00
ApiClient.updateServerConfiguration(config).then(function () {
2014-01-29 13:57:17 -07:00
2015-06-08 14:32:20 -07:00
reload(page);
});
2014-01-29 13:57:17 -07:00
});
2015-06-08 14:32:20 -07:00
// Disable default form submission
return false;
}
2014-01-29 22:20:18 -07:00
2016-04-14 09:30:37 -07:00
function getTabs() {
return [
{
href: 'library.html',
name: Globalize.translate('TabFolders')
},
2016-06-03 22:51:33 -07:00
{
href: 'librarydisplay.html',
name: Globalize.translate('TabDisplay')
},
2016-04-14 09:30:37 -07:00
{
href: 'librarypathmapping.html',
name: Globalize.translate('TabPathSubstitution')
2016-04-14 19:39:39 -07:00
},
{
href: 'librarysettings.html',
name: Globalize.translate('TabAdvanced')
2016-04-14 09:30:37 -07:00
}];
}
2016-04-14 19:39:39 -07:00
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#libraryPathMappingPage", function () {
2014-01-29 13:57:17 -07:00
2016-01-05 09:46:01 -07:00
var page = this;
2015-06-08 14:32:20 -07:00
$('.libraryPathMappingForm').off('submit', onSubmit).on('submit', onSubmit);
2014-01-29 13:57:17 -07:00
2016-01-05 09:46:01 -07:00
page.querySelector('.labelFromHelp').innerHTML = Globalize.translate('LabelFromHelp', 'D:\\Movies');
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#libraryPathMappingPage", function () {
2014-01-29 13:57:17 -07:00
2016-06-03 22:51:33 -07:00
LibraryMenu.setTabs('librarysetup', 2, getTabs);
2015-06-08 14:32:20 -07:00
Dashboard.showLoadingMsg();
2014-01-29 13:57:17 -07:00
2015-06-08 14:32:20 -07:00
var page = this;
2014-01-29 13:57:17 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getServerConfiguration().then(function (config) {
2014-01-29 13:57:17 -07:00
2015-06-08 14:32:20 -07:00
loadPage(page, config);
2014-01-29 13:57:17 -07:00
2015-06-08 14:32:20 -07:00
});
2014-01-29 13:57:17 -07:00
2015-06-20 17:49:42 -07:00
}).on('pagebeforehide', "#libraryPathMappingPage", function () {
2014-01-29 13:57:17 -07:00
2015-06-08 14:32:20 -07:00
currentConfig = null;
2014-01-29 13:57:17 -07:00
2015-06-08 14:32:20 -07:00
});
2014-01-29 13:57:17 -07:00
});