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

102 lines
3.4 KiB
JavaScript
Raw Normal View History

2014-05-07 11:38:50 -07:00
(function ($, document, window) {
2014-05-07 13:16:57 -07:00
function loadPage(page, config, languages) {
2014-05-07 11:38:50 -07:00
2014-08-10 15:13:17 -07:00
$('#chkSubtitlesMovies', page).checked(config.DownloadMovieSubtitles).checkboxradio("refresh");
$('#chkSubtitlesEpisodes', page).checked(config.DownloadEpisodeSubtitles).checkboxradio("refresh");
2014-05-07 11:38:50 -07:00
2014-08-10 15:13:17 -07:00
$('#chkSkipIfGraphicalSubsPresent', page).checked(config.SkipIfGraphicalSubtitlesPresent).checkboxradio("refresh");
$('#chkSkipIfAudioTrackPresent', page).checked(config.SkipIfAudioTrackMatches).checkboxradio("refresh");
2014-05-07 11:38:50 -07:00
2014-08-10 15:13:17 -07:00
$('#txtOpenSubtitleUsername', page).val(config.OpenSubtitlesUsername);
2014-05-07 11:38:50 -07:00
$('#txtOpenSubtitlePassword', page).val('');
2014-05-07 13:16:57 -07:00
populateLanguages(page, config, languages);
2014-05-07 11:38:50 -07:00
Dashboard.hideLoadingMsg();
}
2014-05-07 13:16:57 -07:00
function populateLanguages(page, config, languages) {
2015-02-27 10:43:06 -07:00
var html = '<div data-role="controlgroup" style="margin:0;">';
2014-05-07 13:16:57 -07:00
for (var i = 0, length = languages.length; i < length; i++) {
var culture = languages[i];
var id = "chkSubtitleLanguage" + i;
html += '<label style="font-size:13px;" for="' + id + '">' + culture.DisplayName + '</label>';
html += '<input class="chkLang" data-lang="' + culture.ThreeLetterISOLanguageName.toLowerCase() + '" type="checkbox" id="' + id + '" />';
}
html += '</div>';
$('.downloadLanguages', page).html(html).trigger("create");
2014-08-10 15:13:17 -07:00
var langs = config.DownloadLanguages || [];
2014-05-07 13:16:57 -07:00
$('.chkLang', page).each(function () {
this.checked = langs.indexOf(this.getAttribute('data-lang')) != -1;
}).checkboxradio('refresh');
}
2015-06-08 14:32:20 -07:00
function onSubmit() {
2014-05-07 11:38:50 -07:00
Dashboard.showLoadingMsg();
2015-06-08 14:32:20 -07:00
var form = this;
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
ApiClient.getNamedConfiguration("subtitles").done(function (config) {
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
config.DownloadMovieSubtitles = $('#chkSubtitlesMovies', form).checked();
config.DownloadEpisodeSubtitles = $('#chkSubtitlesEpisodes', form).checked();
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
config.SkipIfGraphicalSubtitlesPresent = $('#chkSkipIfGraphicalSubsPresent', form).checked();
config.SkipIfAudioTrackMatches = $('#chkSkipIfAudioTrackPresent', form).checked();
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
config.OpenSubtitlesUsername = $('#txtOpenSubtitleUsername', form).val();
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
var newPassword = $('#txtOpenSubtitlePassword', form).val();
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
if (newPassword) {
config.OpenSubtitlesPasswordHash = newPassword;
}
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
config.DownloadLanguages = $('.chkLang:checked', form).get().map(function (c) {
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
return c.getAttribute('data-lang');
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
});
ApiClient.updateNamedConfiguration("subtitles", config).done(Dashboard.processServerConfigurationUpdateResult);
});
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
// Disable default form submission
return false;
}
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
$(document).on('pageinitdepends', "#metadataSubtitlesPage", function () {
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
$('.metadataSubtitlesForm').off('submit', onSubmit).on('submit', onSubmit);
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
}).on('pageshowready', "#metadataSubtitlesPage", function () {
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
Dashboard.showLoadingMsg();
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
var page = this;
2014-05-07 13:16:57 -07:00
2015-06-08 14:32:20 -07:00
var promise1 = ApiClient.getNamedConfiguration("subtitles");
var promise2 = ApiClient.getCultures();
2014-05-07 13:16:57 -07:00
2015-06-08 14:32:20 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
2014-05-07 13:16:57 -07:00
2015-06-08 14:32:20 -07:00
loadPage(page, response1[0], response2[0]);
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
});
2014-05-07 11:38:50 -07:00
2015-06-08 14:32:20 -07:00
});
2014-05-07 11:38:50 -07:00
})(jQuery, document, window);