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

66 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-08-22 22:08:07 -07:00
define(['appSettings', 'apphost', 'emby-checkbox', 'emby-select', 'emby-input'], function (appSettings, appHost) {
2016-10-22 22:11:46 -07:00
'use strict';
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();
2016-08-22 22:08:07 -07:00
page.querySelector('.selectAudioBitrate').value = appSettings.maxStaticMusicBitrate() || '';
2015-07-29 19:35:11 -07:00
}
2016-08-22 22:08:07 -07:00
function saveUser(page) {
2015-07-29 19:35:11 -07:00
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);
2016-08-22 22:08:07 -07:00
appSettings.maxStaticMusicBitrate(page.querySelector('.selectAudioBitrate').value || null);
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-08-22 22:08:07 -07:00
saveUser(view);
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
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-08-22 13:47:16 -07:00
if (appHost.supports('customsyncpath')) {
2016-06-19 09:53:53 -07:00
page.querySelector('.fldSyncPath').classList.remove('hide');
} else {
page.querySelector('.fldSyncPath').classList.add('hide');
}
2015-07-29 19:35:11 -07:00
});
2016-08-22 22:08:07 -07:00
view.addEventListener('viewbeforehide', function () {
saveUser(this);
});
2016-06-19 09:53:53 -07:00
};
2015-07-29 19:35:11 -07:00
2016-02-29 23:02:03 -07:00
});