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

134 lines
4.0 KiB
JavaScript
Raw Normal View History

2014-06-01 12:41:35 -07:00
(function ($, document, window) {
2014-06-02 12:32:41 -07:00
function populateDownloadList(page, config, downloadableList) {
if (downloadableList.length) {
$('.channelDownloading', page).show();
} else {
$('.channelDownloading', page).hide();
}
var html = '';
html += '<div data-role="controlgroup">';
for (var i = 0, length = downloadableList.length; i < length; i++) {
var channel = downloadableList[i];
var id = 'chkChannelDownload' + i;
var isChecked = config.DownloadingChannels.indexOf(channel.Id) != -1 ? ' checked="checked"' : '';
2014-06-02 12:32:41 -07:00
html += '<input class="chkChannelDownload" type="checkbox" name="' + id + '" id="' + id + '" data-channelid="' + channel.Id + '" data-mini="true"' + isChecked + '>';
html += '<label for="' + id + '">' + channel.Name + '</label>';
}
html += '</div>';
$('.channelDownloadingList', page).html(html).trigger('create');
}
function loadPage(page, config, allChannelFeatures) {
2014-06-02 19:01:30 -07:00
if (allChannelFeatures.length) {
$('.noChannelsHeader', page).hide();
} else {
$('.noChannelsHeader', page).show();
}
2014-06-02 12:32:41 -07:00
var downloadableList = allChannelFeatures.filter(function (i) {
return i.SupportsContentDownloading;
2014-06-02 12:32:41 -07:00
});
populateDownloadList(page, config, downloadableList);
2014-06-01 12:41:35 -07:00
$('#selectChannelResolution', page).val(config.PreferredStreamingWidth || '')
2014-06-01 12:41:35 -07:00
.selectmenu("refresh");
$('#txtDownloadAge', page).val(config.MaxDownloadAge || '');
2014-08-14 06:24:30 -07:00
$('#txtDownloadSizeLimit', page).val(config.DownloadSizeLimit || '');
2014-06-02 12:32:41 -07:00
$('#txtCachePath', page).val(config.DownloadPath || '');
2014-06-02 12:32:41 -07:00
2014-06-01 12:41:35 -07:00
Dashboard.hideLoadingMsg();
}
2014-06-02 12:32:41 -07:00
$(document).on('pageinit', "#channelSettingsPage", function () {
var page = this;
$('#btnSelectCachePath', page).on("click.selectDirectory", function () {
var picker = new DirectoryBrowser(page);
picker.show({
callback: function (path) {
if (path) {
$('#txtCachePath', page).val(path);
}
picker.close();
},
header: Globalize.translate('HeaderSelectChannelDownloadPath'),
instruction: Globalize.translate('HeaderSelectChannelDownloadPathHelp')
});
});
}).on('pageshow', "#channelSettingsPage", function () {
2014-06-01 12:41:35 -07:00
Dashboard.showLoadingMsg();
var page = this;
var promise1 = ApiClient.getNamedConfiguration("channels");
2014-07-01 22:16:59 -07:00
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Channels/Features"));
2014-06-02 12:32:41 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
2014-06-01 12:41:35 -07:00
2014-06-02 12:32:41 -07:00
var config = response1[0];
var allFeatures = response2[0];
loadPage(page, config, allFeatures);
2014-06-01 12:41:35 -07:00
});
});
function onSubmit() {
Dashboard.showLoadingMsg();
var form = this;
ApiClient.getNamedConfiguration("channels").done(function (config) {
2014-06-01 12:41:35 -07:00
// This should be null if empty
config.PreferredStreamingWidth = $('#selectChannelResolution', form).val() || null;
config.MaxDownloadAge = $('#txtDownloadAge', form).val() || null;
2014-08-14 06:24:30 -07:00
config.DownloadSizeLimit = $('#txtDownloadSizeLimit', form).val() || null;
2014-06-02 12:32:41 -07:00
config.DownloadPath = $('#txtCachePath', form).val() || null;
2014-06-02 12:32:41 -07:00
config.DownloadingChannels = $('.chkChannelDownload:checked', form)
2014-06-02 12:32:41 -07:00
.get()
.map(function(i) {
return i.getAttribute('data-channelid');
});
2014-06-01 12:41:35 -07:00
ApiClient.updateNamedConfiguration("channels", config).done(Dashboard.processServerConfigurationUpdateResult);
2014-06-01 12:41:35 -07:00
});
// Disable default form submission
return false;
}
window.ChannelSettingsPage = {
onSubmit: onSubmit
};
})(jQuery, document, window);