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

150 lines
3.8 KiB
JavaScript
Raw Normal View History

2014-10-11 13:38:13 -07:00
(function () {
function load(page, devices, config) {
if (devices.length) {
$('.noDevices', page).hide();
$('.devicesUploadForm', page).show();
} else {
$('.noDevices', page).show();
$('.devicesUploadForm', page).hide();
}
$('#txtUploadPath', page).val(config.CameraUploadPath || '');
2014-10-11 18:46:02 -07:00
$('#chkSubfolder', page).checked(config.EnableCameraUploadSubfolders).checkboxradio('refresh');
2014-10-11 13:38:13 -07:00
loadDeviceList(page, devices, config);
}
function loadDeviceList(page, devices, config) {
var html = '';
html += '<fieldset data-role="controlgroup">';
html += '<legend>';
html += Globalize.translate('LabelEnableCameraUploadFor');
html += '</legend>';
var index = 0;
html += devices.map(function (d) {
var deviceHtml = '';
var id = "chk" + index;
deviceHtml += '<label for="' + id + '">';
deviceHtml += d.Name;
2014-10-11 18:46:02 -07:00
if (d.AppName) {
deviceHtml += '<br/><span>' + d.AppName + '</span>';
}
2014-10-11 13:38:13 -07:00
deviceHtml += '</label>';
var isChecked = config.EnabledCameraUploadDevices.indexOf(d.Id) != -1;
var checkedHtml = isChecked ? ' checked="checked"' : '';
deviceHtml += '<input type="checkbox" id="' + id + '" class="chkDevice" data-id="' + d.Id + '"' + checkedHtml + ' />';
index++;
return deviceHtml;
}).join('');
html += '</fieldset>';
html += '<div class="fieldDescription">';
html += Globalize.translate('LabelEnableCameraUploadForHelp');
html += '</div>';
$('.devicesList', page).html(html).trigger('create');
}
function loadData(page) {
Dashboard.showLoadingMsg();
var promise1 = ApiClient.getNamedConfiguration("devices");
var promise2 = ApiClient.getJSON(ApiClient.getUrl('Devices', {
SupportsContentUploading: true
}));
$.when(promise1, promise2).done(function (response1, response2) {
2014-12-12 20:56:30 -07:00
load(page, response2[0].Items, response1[0]);
2014-10-11 13:38:13 -07:00
Dashboard.hideLoadingMsg();
});
}
function save(page) {
ApiClient.getNamedConfiguration("devices").done(function (config) {
config.CameraUploadPath = $('#txtUploadPath', page).val();
config.EnabledCameraUploadDevices = $('.chkDevice:checked', page).get().map(function (c) {
return c.getAttribute('data-id');
});
2014-10-11 18:46:02 -07:00
config.EnableCameraUploadSubfolders = $('#chkSubfolder', page).checked();
2014-10-11 13:38:13 -07:00
ApiClient.updateNamedConfiguration("devices", config).done(Dashboard.processServerConfigurationUpdateResult);
});
}
2015-06-07 21:47:19 -07:00
function onSubmit() {
var form = this;
var page = $(form).parents('.page');
save(page);
return false;
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#devicesUploadPage", function () {
2014-10-11 13:38:13 -07:00
var page = this;
$('#btnSelectUploadPath', page).on("click.selectDirectory", function () {
2015-10-13 12:22:45 -07:00
require(['directorybrowser'], function (directoryBrowser) {
2014-10-11 13:38:13 -07:00
2015-10-13 12:22:45 -07:00
var picker = new directoryBrowser();
2014-10-11 13:38:13 -07:00
2015-10-13 12:22:45 -07:00
picker.show({
2014-10-11 13:38:13 -07:00
2015-10-13 12:22:45 -07:00
callback: function (path) {
2014-10-11 13:38:13 -07:00
2015-10-13 12:22:45 -07:00
if (path) {
$('#txtUploadPath', page).val(path);
}
picker.close();
},
header: Globalize.translate('HeaderSelectUploadPath')
});
2014-10-11 13:38:13 -07:00
});
});
2015-06-07 21:47:19 -07:00
$('.devicesUploadForm').off('submit', onSubmit).on('submit', onSubmit);
2014-10-11 13:38:13 -07:00
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#devicesUploadPage", function () {
2014-10-11 13:38:13 -07:00
var page = this;
loadData(page);
});
})();