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

139 lines
3.3 KiB
JavaScript
Raw Normal View History

2014-01-29 13:57:17 -07:00
(function ($, document, window) {
2014-01-29 22:20:18 -07:00
var currentConfig;
function remove(page, index) {
2014-05-30 12:23:56 -07:00
Dashboard.confirm(Globalize.translate('MessageConfirmPathSubstitutionDeletion'), Globalize.translate('HeaderConfirmDeletion'), function (result) {
2014-01-29 22:20:18 -07:00
if (result) {
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);
});
});
}
});
}
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) {
var mapHtml = '<tr>';
mapHtml += '<td style="vertical-align:middle;">';
mapHtml += map.From;
mapHtml += '</td>';
mapHtml += '<td style="vertical-align:middle;">';
mapHtml += map.To;
mapHtml += '</td>';
2015-09-06 12:09:36 -07:00
mapHtml += '<td>';
mapHtml += '<paper-icon-button data-index="' + index + '" icon="delete" class="btnDeletePath"></paper-icon-button>';
mapHtml += '</td>';
2014-01-29 22:20:18 -07:00
mapHtml += '</tr>';
index++;
return mapHtml;
});
var elem = $('.tbodyPathSubstitutions', page).html(html.join('')).parents('table').table('refresh').trigger('create');
$('.btnDeletePath', elem).on('click', function () {
remove(page, parseInt(this.getAttribute('data-index')));
});
if (config.PathSubstitutions.length) {
$('#tblPaths', page).show();
} else {
$('#tblPaths', page).hide();
}
}
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
2014-01-29 22:20:18 -07:00
reloadPathMappings(page, config);
2014-01-29 13:57:17 -07:00
Dashboard.hideLoadingMsg();
}
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
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#libraryPathMappingPage", function () {
2014-01-29 13:57:17 -07:00
2015-06-08 14:32:20 -07:00
$('.libraryPathMappingForm').off('submit', onSubmit).on('submit', onSubmit);
2014-01-29 13:57:17 -07:00
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#libraryPathMappingPage", function () {
2014-01-29 13:57:17 -07:00
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
})(jQuery, document, window);