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

166 lines
4.2 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2014-10-11 13:38:13 -07:00
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 || '');
2016-04-15 12:20:04 -07:00
$('#chkSubfolder', page).checked(config.EnableCameraUploadSubfolders);
2014-10-11 18:46:02 -07:00
2014-10-11 13:38:13 -07:00
loadDeviceList(page, devices, config);
}
function loadDeviceList(page, devices, config) {
var html = '';
2016-04-15 12:20:04 -07:00
html += '<div class="paperCheckboxListLabel">';
2014-10-11 13:38:13 -07:00
html += Globalize.translate('LabelEnableCameraUploadFor');
2016-04-15 12:20:04 -07:00
html += '</div>';
html += '<div class="paperCheckboxList paperList">';
2014-10-11 13:38:13 -07:00
var index = 0;
html += devices.map(function (d) {
var deviceHtml = '';
2016-04-15 12:20:04 -07:00
var isChecked = config.EnabledCameraUploadDevices.indexOf(d.Id) != -1;
var checkedHtml = isChecked ? ' checked="checked"' : '';
2014-10-11 13:38:13 -07:00
2016-04-15 12:20:04 -07:00
var label = d.Name;
2014-10-11 18:46:02 -07:00
if (d.AppName) {
2016-04-15 12:20:04 -07:00
label += ' - ' + d.AppName;
2014-10-11 18:46:02 -07:00
}
2016-04-15 12:20:04 -07:00
deviceHtml += '<paper-checkbox class="chkDevice" data-id="' + d.Id + '"' + checkedHtml + '>' + label + '</paper-checkbox>';
2014-10-11 13:38:13 -07:00
index++;
return deviceHtml;
}).join('');
2016-04-15 12:20:04 -07:00
html += '</div>';
2014-10-11 13:38:13 -07:00
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
}));
2015-12-14 08:43:03 -07:00
Promise.all([promise1, promise2]).then(function (responses) {
2014-10-11 13:38:13 -07:00
2015-12-14 08:43:03 -07:00
load(page, responses[1].Items, responses[0]);
2014-10-11 13:38:13 -07:00
Dashboard.hideLoadingMsg();
});
}
function save(page) {
2015-12-14 08:43:03 -07:00
ApiClient.getNamedConfiguration("devices").then(function (config) {
2014-10-11 13:38:13 -07:00
config.CameraUploadPath = $('#txtUploadPath', page).val();
2016-04-15 12:20:04 -07:00
config.EnabledCameraUploadDevices = $('.chkDevice', page).get().filter(function (c) {
return c.checked;
}).map(function (c) {
2014-10-11 13:38:13 -07:00
return c.getAttribute('data-id');
});
2014-10-11 18:46:02 -07:00
config.EnableCameraUploadSubfolders = $('#chkSubfolder', page).checked();
2015-12-14 08:43:03 -07:00
ApiClient.updateNamedConfiguration("devices", config).then(Dashboard.processServerConfigurationUpdateResult);
2014-10-11 13:38:13 -07:00
});
}
2015-06-07 21:47:19 -07:00
function onSubmit() {
var form = this;
var page = $(form).parents('.page');
save(page);
return false;
}
2016-04-12 23:02:07 -07:00
function getTabs() {
return [
{
href: 'syncactivity.html',
name: Globalize.translate('TabSyncJobs')
},
{
href: 'devicesupload.html',
name: Globalize.translate('TabCameraUpload')
},
{
href: 'syncsettings.html',
name: Globalize.translate('TabSettings')
}];
}
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
2016-04-12 23:02:07 -07:00
LibraryMenu.setTabs('syncadmin', 1, getTabs);
2014-10-11 13:38:13 -07:00
var page = this;
loadData(page);
});
});