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;
|
|
|
|
|
|
2014-06-30 10:40:46 -07:00
|
|
|
|
var isChecked = config.DownloadingChannels.indexOf(channel.Id) != -1 ? ' checked="checked"' : '';
|
2014-06-02 12:32:41 -07:00
|
|
|
|
|
2014-08-18 19:49:16 -07:00
|
|
|
|
html += '<input class="chkChannelDownload" type="checkbox" name="' + id + '" id="' + id + '" data-channelid="' + channel.Id + '"' + isChecked + '>';
|
2014-06-02 12:32:41 -07:00
|
|
|
|
html += '<label for="' + id + '">' + channel.Name + '</label>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
$('.channelDownloadingList', page).html(html).trigger('create');
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 21:50:21 -07:00
|
|
|
|
function loadPage(page, config, allChannelFeatures, supporterInfo) {
|
|
|
|
|
|
|
|
|
|
if (supporterInfo.IsMBSupporter) {
|
|
|
|
|
$('#txtDownloadSizeLimit', page).attr('max', '100');
|
|
|
|
|
} else {
|
|
|
|
|
$('#txtDownloadSizeLimit', page).attr('max', '.5');
|
|
|
|
|
}
|
2014-06-02 12:32:41 -07:00
|
|
|
|
|
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) {
|
2014-06-15 16:30:04 -07:00
|
|
|
|
return i.SupportsContentDownloading;
|
2014-06-02 12:32:41 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
populateDownloadList(page, config, downloadableList);
|
2014-06-01 12:41:35 -07:00
|
|
|
|
|
2014-06-30 10:40:46 -07:00
|
|
|
|
$('#selectChannelResolution', page).val(config.PreferredStreamingWidth || '')
|
2014-06-01 12:41:35 -07:00
|
|
|
|
.selectmenu("refresh");
|
|
|
|
|
|
2014-06-30 10:40:46 -07:00
|
|
|
|
$('#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
|
|
|
|
|
2014-06-30 10:40:46 -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;
|
|
|
|
|
|
2014-06-30 10:40:46 -07:00
|
|
|
|
var promise1 = ApiClient.getNamedConfiguration("channels");
|
2014-07-01 22:16:59 -07:00
|
|
|
|
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Channels/Features"));
|
2014-09-17 21:50:21 -07:00
|
|
|
|
var promise3 = Dashboard.getPluginSecurityInfo();
|
2014-06-02 12:32:41 -07:00
|
|
|
|
|
2014-09-17 21:50:21 -07:00
|
|
|
|
$.when(promise1, promise2, promise3).done(function (response1, response2, response3) {
|
2014-06-01 12:41:35 -07:00
|
|
|
|
|
2014-06-02 12:32:41 -07:00
|
|
|
|
var config = response1[0];
|
|
|
|
|
var allFeatures = response2[0];
|
2014-09-17 21:50:21 -07:00
|
|
|
|
var supporterInfo = response3;
|
2014-06-02 12:32:41 -07:00
|
|
|
|
|
2014-09-17 21:50:21 -07:00
|
|
|
|
loadPage(page, config, allFeatures, supporterInfo);
|
2014-06-01 12:41:35 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function onSubmit() {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var form = this;
|
|
|
|
|
|
2014-06-30 10:40:46 -07:00
|
|
|
|
ApiClient.getNamedConfiguration("channels").done(function (config) {
|
2014-06-01 12:41:35 -07:00
|
|
|
|
|
|
|
|
|
// This should be null if empty
|
2014-06-30 10:40:46 -07:00
|
|
|
|
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
|
|
|
|
|
2014-06-30 10:40:46 -07:00
|
|
|
|
config.DownloadPath = $('#txtCachePath', form).val() || null;
|
2014-06-02 12:32:41 -07:00
|
|
|
|
|
2014-06-30 10:40:46 -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
|
|
|
|
|
2014-07-03 19:22:57 -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);
|