2016-03-18 21:26:17 -07:00
|
|
|
|
define(['jQuery'], function ($) {
|
2014-05-07 11:38:50 -07:00
|
|
|
|
|
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-03-19 15:31:00 -07:00
|
|
|
|
$('#chkSkipIfGraphicalSubsPresent', page).checked(config.SkipIfEmbeddedSubtitlesPresent);
|
2016-02-19 19:45:12 -07:00
|
|
|
|
$('#chkSkipIfAudioTrackPresent', page).checked(config.SkipIfAudioTrackMatches);
|
2016-04-06 21:09:32 -07:00
|
|
|
|
$('#chkRequirePerfectMatch', page).checked(config.RequirePerfectMatch);
|
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
|
|
|
|
}
|
|
|
|
|
|
2016-03-06 11:09:20 -07:00
|
|
|
|
$('.downloadLanguages', page).html(html);
|
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
|
|
|
|
|
2016-03-19 15:31:00 -07:00
|
|
|
|
config.SkipIfEmbeddedSubtitlesPresent = $('#chkSkipIfGraphicalSubsPresent', form).checked();
|
2015-06-08 14:32:20 -07:00
|
|
|
|
config.SkipIfAudioTrackMatches = $('#chkSkipIfAudioTrackPresent', form).checked();
|
2016-04-06 21:09:32 -07:00
|
|
|
|
config.RequirePerfectMatch = $('#chkRequirePerfectMatch', 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
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|