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

105 lines
2.9 KiB
JavaScript
Raw Normal View History

define(['appSettings', 'jQuery'], 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-05-17 10:44:17 -07:00
var syncPath = page.querySelector('#txtSyncPath').value;
appSettings.syncPath(syncPath);
2016-02-29 23:02:03 -07:00
appSettings.syncOnlyOnWifi(page.querySelector('#chkWifi').checked);
2015-08-12 14:39:02 -07:00
2016-05-17 10:44:17 -07:00
var 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');
2016-05-17 10:44:17 -07:00
});
appSettings.cameraUploadServers(cameraUploadServers);
2015-09-27 08:00:57 -07:00
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'));
});
2016-05-17 10:44:17 -07:00
if (cameraUploadServers.length || syncPath) {
if (window.MainActivity) {
MainActivity.authorizeStorage();
}
}
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
});