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
|
|
|
|
|
2016-02-19 19:45:12 -07:00
|
|
|
|
$('#chkSubtitlesMovies', page).checked(config.DownloadMovieSubtitles);
|
|
|
|
|
$('#chkSubtitlesEpisodes', page).checked(config.DownloadEpisodeSubtitles);
|
2014-05-07 11:38:50 -07:00
|
|
|
|
|
2016-02-19 19:45:12 -07:00
|
|
|
|
$('#chkSkipIfGraphicalSubsPresent', page).checked(config.SkipIfGraphicalSubtitlesPresent);
|
|
|
|
|
$('#chkSkipIfAudioTrackPresent', page).checked(config.SkipIfAudioTrackMatches);
|
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) {
|
|
|
|
|
|
2016-02-19 19:45:12 -07:00
|
|
|
|
var html = '';
|
2014-05-07 13:16:57 -07:00
|
|
|
|
|
|
|
|
|
for (var i = 0, length = languages.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var culture = languages[i];
|
|
|
|
|
|
2016-02-19 19:45:12 -07:00
|
|
|
|
html += '<paper-checkbox class="chkLang" data-lang="' + culture.ThreeLetterISOLanguageName.toLowerCase() + '">' + culture.DisplayName + '</paper-checkbox>';
|
2014-05-07 13:16:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-17 18:41:22 -07:00
|
|
|
|
$('.downloadLanguages', page).html(html).trigger('create');
|
2014-05-07 13:16:57 -07:00
|
|
|
|
|
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;
|
|
|
|
|
|
2016-02-19 19:45:12 -07:00
|
|
|
|
});
|
2014-05-07 13:16:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
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-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getNamedConfiguration("subtitles").then(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
|
|
|
|
|
2016-02-19 19:45:12 -07:00
|
|
|
|
config.DownloadLanguages = $('.chkLang', form).get().filter(function (c) {
|
|
|
|
|
|
|
|
|
|
return c.checked;
|
|
|
|
|
|
|
|
|
|
}).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
|
|
|
|
});
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.updateNamedConfiguration("subtitles", config).then(Dashboard.processServerConfigurationUpdateResult);
|
2015-06-08 14:32:20 -07:00
|
|
|
|
});
|
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-09-01 07:01:59 -07:00
|
|
|
|
$(document).on('pageinit', "#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-09-24 10:08:10 -07:00
|
|
|
|
}).on('pageshow', "#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-12-14 08:43:03 -07:00
|
|
|
|
Promise.all([promise1, promise2]).then(function (responses) {
|
2014-05-07 13:16:57 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
loadPage(page, responses[0], responses[1]);
|
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);
|