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

96 lines
2.5 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2016-10-22 22:11:46 -07:00
'use strict';
2014-10-13 13:14:53 -07:00
function load(page, device, capabilities) {
if (capabilities.SupportsContentUploading) {
2016-08-21 11:33:17 -07:00
$('#fldCameraUploadPath', page).removeClass('hide');
2014-10-13 13:14:53 -07:00
} else {
2016-08-21 11:33:17 -07:00
$('#fldCameraUploadPath', page).addClass('hide');
2014-10-13 13:14:53 -07:00
}
$('#txtCustomName', page).val(device.CustomName || '');
2014-11-25 21:12:29 -07:00
$('#txtUploadPath', page).val(device.CameraUploadPath || '');
2014-10-30 21:57:24 -07:00
$('.reportedName', page).html(device.ReportedName || '');
2014-10-13 13:14:53 -07:00
}
function loadData(page) {
Dashboard.showLoadingMsg();
var id = getParameterByName('id');
var promise1 = ApiClient.getJSON(ApiClient.getUrl('Devices/Info', { Id: id }));
var promise2 = ApiClient.getJSON(ApiClient.getUrl('Devices/Capabilities', { Id: id }));
2015-12-14 08:43:03 -07:00
Promise.all([promise1, promise2]).then(function (responses) {
2014-10-13 13:14:53 -07:00
2015-12-14 08:43:03 -07:00
load(page, responses[0], responses[1]);
2014-10-13 13:14:53 -07:00
Dashboard.hideLoadingMsg();
});
}
function save(page) {
var id = getParameterByName('id');
ApiClient.ajax({
url: ApiClient.getUrl('Devices/Options', { Id: id }),
type: 'POST',
data: JSON.stringify({
CustomName: $('#txtCustomName', page).val(),
CameraUploadPath: $('#txtUploadPath', page).val()
}),
contentType: "application/json"
2015-12-14 08:43:03 -07:00
}).then(Dashboard.processServerConfigurationUpdateResult);
2014-10-13 13:14:53 -07:00
}
2015-05-15 08:46:20 -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', "#devicePage", function () {
2014-10-13 13:14:53 -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-13 13:14:53 -07:00
2015-10-13 12:22:45 -07:00
var picker = new directoryBrowser();
2014-10-13 13:14:53 -07:00
2015-10-13 12:22:45 -07:00
picker.show({
2014-10-13 13:14:53 -07:00
2015-10-13 12:22:45 -07:00
callback: function (path) {
2014-10-13 13:14:53 -07:00
2015-10-13 12:22:45 -07:00
if (path) {
$('#txtUploadPath', page).val(path);
}
picker.close();
},
header: Globalize.translate('HeaderSelectUploadPath')
});
2014-10-13 13:14:53 -07:00
});
});
2015-05-15 08:46:20 -07:00
$('.deviceForm').off('submit', onSubmit).on('submit', onSubmit);
2014-10-13 13:14:53 -07:00
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#devicePage", function () {
2014-10-13 13:14:53 -07:00
var page = this;
loadData(page);
});
});