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

95 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-02-29 23:02:03 -07:00
define(['appSettings'], function (appSettings) {
2015-07-29 19:35:11 -07:00
function loadForm(page, user) {
2016-02-29 23:02:03 -07:00
page.querySelector('#txtSyncPath').value = appSettings.syncPath();
page.querySelector('#chkWifi').checked = appSettings.syncOnlyOnWifi();
2015-07-29 19:35:11 -07:00
2016-02-29 23:02:03 -07:00
var uploadServers = appSettings.cameraUploadServers();
2015-09-26 07:51:26 -07:00
page.querySelector('.uploadServerList').innerHTML = ConnectionManager.getSavedServers().map(function (s) {
var checkedHtml = uploadServers.indexOf(s.Id) == -1 ? '' : ' checked';
var html = '<paper-checkbox' + checkedHtml + ' class="chkUploadServer" data-id="' + s.Id + '">' + s.Name + '</paper-checkbox>';
return html;
}).join('');
2015-07-29 19:35:11 -07:00
Dashboard.hideLoadingMsg();
}
function saveUser(page, user) {
2016-02-29 23:02:03 -07:00
appSettings.syncPath(page.querySelector('#txtSyncPath').value);
appSettings.syncOnlyOnWifi(page.querySelector('#chkWifi').checked);
2015-08-12 14:39:02 -07:00
2016-02-29 23:02:03 -07:00
appSettings.cameraUploadServers($(".chkUploadServer", page).get().filter(function (i) {
2015-09-27 08:00:57 -07:00
return i.checked;
}).map(function (i) {
return i.getAttribute('data-id');
}));
2015-07-29 19:35:11 -07:00
Dashboard.hideLoadingMsg();
2016-02-24 23:38:12 -07:00
require(['toast'], function (toast) {
toast(Globalize.translate('SettingsSaved'));
});
2015-07-29 19:35:11 -07:00
}
function onSubmit() {
var page = $(this).parents('.page')[0];
Dashboard.showLoadingMsg();
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
2015-12-14 08:43:03 -07:00
ApiClient.getUser(userId).then(function (user) {
2015-07-29 19:35:11 -07:00
saveUser(page, user);
});
// Disable default form submission
return false;
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#syncPreferencesPage", function () {
2015-07-29 19:35:11 -07:00
var page = this;
2015-08-08 09:16:34 -07:00
$('form', page).off('submit', onSubmit).on('submit', onSubmit);
2015-07-29 19:35:11 -07:00
$('.btnSelectSyncPath', page).on('click', function () {
require(['nativedirectorychooser'], function () {
2015-12-14 08:43:03 -07:00
NativeDirectoryChooser.chooseDirectory().then(function (path) {
2015-07-29 19:35:11 -07:00
$('#txtSyncPath', page).val(path);
});
});
});
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#syncPreferencesPage", function () {
2015-07-29 19:35:11 -07:00
var page = this;
Dashboard.showLoadingMsg();
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
2015-12-14 08:43:03 -07:00
ApiClient.getUser(userId).then(function (user) {
2015-07-29 19:35:11 -07:00
loadForm(page, user);
});
2015-09-11 09:26:06 -07:00
if (AppInfo.supportsSyncPathSetting) {
page.querySelector('.fldSyncPath').classList.remove('hide');
} else {
page.querySelector('.fldSyncPath').classList.add('hide');
}
2015-07-29 19:35:11 -07:00
});
2016-02-29 23:02:03 -07:00
});