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

103 lines
3.1 KiB
JavaScript
Raw Normal View History

2016-06-19 09:53:53 -07:00
define(['appSettings'], function (appSettings) {
2015-07-29 19:35:11 -07:00
function loadForm(page, user) {
2016-06-13 21:06:57 -07:00
page.querySelector('#txtSyncPath').value = appSettings.syncPath() || '';
2016-02-29 23:02:03 -07:00
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';
2016-06-13 21:06:57 -07:00
var html = '<label><input type="checkbox" is="emby-checkbox"' + checkedHtml + ' class="chkUploadServer" data-id="' + s.Id + '"/><span>' + s.Name + '</span></label>';
2015-09-26 07:51:26 -07:00
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-06-19 09:53:53 -07:00
var chkUploadServer = page.querySelectorAll('.chkUploadServer');
var cameraUploadServers = [];
2015-09-27 08:00:57 -07:00
2016-06-19 09:53:53 -07:00
for (var i = 0, length = chkUploadServer.length; i < length; i++) {
if (chkUploadServer[i].checked) {
cameraUploadServers.push(chkUploadServer[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
}
2016-06-19 09:53:53 -07:00
return function (view, params) {
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
view.querySelector('form').addEventListener('submit', function (e) {
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
Dashboard.showLoadingMsg();
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
ApiClient.getUser(userId).then(function (user) {
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
saveUser(view, user);
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
});
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
// Disable default form submission
e.preventDefault();
return false;
});
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
view.querySelector('#btnSelectSyncPath').addEventListener('click', function () {
2015-07-29 19:35:11 -07:00
require(['nativedirectorychooser'], function () {
2015-12-14 08:43:03 -07:00
NativeDirectoryChooser.chooseDirectory().then(function (path) {
2016-06-13 12:02:48 -07:00
if (path) {
2016-06-19 09:53:53 -07:00
view.querySelector('#txtSyncPath').value = path;
2016-06-13 12:02:48 -07:00
}
2015-07-29 19:35:11 -07:00
});
});
});
2016-06-19 09:53:53 -07:00
view.addEventListener('viewshow', function () {
var page = this;
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
Dashboard.showLoadingMsg();
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
ApiClient.getUser(userId).then(function (user) {
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -07:00
loadForm(page, user);
});
2015-07-29 19:35:11 -07:00
2016-06-19 09:53:53 -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-06-19 09:53:53 -07:00
};
2015-07-29 19:35:11 -07:00
2016-02-29 23:02:03 -07:00
});