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

105 lines
3.6 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
$('#chkSubtitlesMovies', page).checked(config.SubtitleOptions.DownloadMovieSubtitles).checkboxradio("refresh");
$('#chkSubtitlesEpisodes', page).checked(config.SubtitleOptions.DownloadEpisodeSubtitles).checkboxradio("refresh");
2014-05-07 19:16:11 -07:00
$('#chkSkipIfGraphicalSubsPresent', page).checked(config.SubtitleOptions.SkipIfGraphicalSubtitlesPresent).checkboxradio("refresh");
$('#chkSkipIfAudioTrackPresent', page).checked(config.SubtitleOptions.SkipIfAudioTrackMatches).checkboxradio("refresh");
2014-05-07 11:38:50 -07:00
$('#txtOpenSubtitleUsername', page).val(config.SubtitleOptions.OpenSubtitlesUsername);
$('#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) {
var html = '<div data-role="controlgroup" data-corners="false" style="margin:0;">';
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");
var langs = config.SubtitleOptions.DownloadLanguages || [];
$('.chkLang', page).each(function () {
this.checked = langs.indexOf(this.getAttribute('data-lang')) != -1;
}).checkboxradio('refresh');
}
2014-05-07 11:38:50 -07:00
$(document).on('pageshow', "#metadataSubtitlesPage", function () {
Dashboard.showLoadingMsg();
var page = this;
var promise1 = ApiClient.getServerConfiguration();
2014-05-07 13:16:57 -07:00
var promise2 = ApiClient.getCultures();
2014-05-07 11:38:50 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
loadPage(page, response1[0], response2[0]);
});
});
function metadataSubtitlesPage() {
var self = this;
self.onSubmit = function () {
Dashboard.showLoadingMsg();
var form = this;
ApiClient.getServerConfiguration().done(function (config) {
config.SubtitleOptions.DownloadMovieSubtitles = $('#chkSubtitlesMovies', form).checked();
config.SubtitleOptions.DownloadEpisodeSubtitles = $('#chkSubtitlesEpisodes', form).checked();
2014-05-07 19:16:11 -07:00
config.SubtitleOptions.SkipIfGraphicalSubtitlesPresent = $('#chkSkipIfGraphicalSubsPresent', form).checked();
config.SubtitleOptions.SkipIfAudioTrackMatches = $('#chkSkipIfAudioTrackPresent', form).checked();
2014-05-07 11:38:50 -07:00
config.SubtitleOptions.OpenSubtitlesUsername = $('#txtOpenSubtitleUsername', form).val();
2014-05-07 13:38:19 -07:00
var newPassword = $('#txtOpenSubtitlePassword', form).val();
if (newPassword) {
config.SubtitleOptions.OpenSubtitlesPasswordHash = newPassword;
}
2014-05-07 11:38:50 -07:00
2014-05-07 13:16:57 -07:00
config.SubtitleOptions.DownloadLanguages = $('.chkLang:checked', form).get().map(function (c) {
return c.getAttribute('data-lang');
});
2014-05-07 11:38:50 -07:00
ApiClient.updateServerConfiguration(config).done(Dashboard.processServerConfigurationUpdateResult);
});
// Disable default form submission
return false;
};
}
window.MetadataSubtitlesPage = new metadataSubtitlesPage();
})(jQuery, document, window);