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');
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-07 11:38:50 -07:00
|
|
|
|
$(document).on('pageshow', "#metadataSubtitlesPage", function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
|
var promise1 = ApiClient.getNamedConfiguration("subtitles");
|
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;
|
|
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
|
ApiClient.getNamedConfiguration("subtitles").done(function (config) {
|
2014-05-07 11:38:50 -07:00
|
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
|
config.DownloadMovieSubtitles = $('#chkSubtitlesMovies', form).checked();
|
|
|
|
|
config.DownloadEpisodeSubtitles = $('#chkSubtitlesEpisodes', form).checked();
|
2014-05-07 11:38:50 -07:00
|
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
|
config.SkipIfGraphicalSubtitlesPresent = $('#chkSkipIfGraphicalSubsPresent', form).checked();
|
|
|
|
|
config.SkipIfAudioTrackMatches = $('#chkSkipIfAudioTrackPresent', form).checked();
|
2014-05-07 11:38:50 -07:00
|
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
|
config.OpenSubtitlesUsername = $('#txtOpenSubtitleUsername', form).val();
|
2014-05-07 11:38:50 -07:00
|
|
|
|
|
2014-05-07 13:38:19 -07:00
|
|
|
|
var newPassword = $('#txtOpenSubtitlePassword', form).val();
|
|
|
|
|
|
|
|
|
|
if (newPassword) {
|
2014-08-10 15:13:17 -07:00
|
|
|
|
config.OpenSubtitlesPasswordHash = newPassword;
|
2014-05-07 13:38:19 -07:00
|
|
|
|
}
|
2014-05-07 11:38:50 -07:00
|
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
|
config.DownloadLanguages = $('.chkLang:checked', form).get().map(function (c) {
|
2014-05-07 13:16:57 -07:00
|
|
|
|
|
|
|
|
|
return c.getAttribute('data-lang');
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
|
ApiClient.updateNamedConfiguration("subtitles", config).done(Dashboard.processServerConfigurationUpdateResult);
|
2014-05-07 11:38:50 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Disable default form submission
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.MetadataSubtitlesPage = new metadataSubtitlesPage();
|
|
|
|
|
|
|
|
|
|
})(jQuery, document, window);
|