2015-07-29 19:35:11 -07:00
|
|
|
|
(function ($, window, document) {
|
|
|
|
|
|
|
|
|
|
function loadForm(page, user) {
|
|
|
|
|
|
2015-08-10 17:14:15 -07:00
|
|
|
|
page.querySelector('#txtSyncPath').value = AppSettings.syncPath();
|
2015-08-12 14:39:02 -07:00
|
|
|
|
page.querySelector('#chkWifi').checked = AppSettings.syncOnlyOnWifi();
|
2015-07-29 19:35:11 -07:00
|
|
|
|
|
2015-09-26 07:51:26 -07:00
|
|
|
|
var uploadServers = AppSettings.cameraUploadServers();
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
2015-08-10 17:14:15 -07:00
|
|
|
|
AppSettings.syncPath(page.querySelector('#txtSyncPath').value);
|
2015-08-12 14:39:02 -07:00
|
|
|
|
AppSettings.syncOnlyOnWifi(page.querySelector('#chkWifi').checked);
|
|
|
|
|
|
2015-09-27 08:00:57 -07:00
|
|
|
|
AppSettings.cameraUploadServers($(".chkUploadServer", page).get().filter(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.checked;
|
|
|
|
|
|
|
|
|
|
}).map(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.getAttribute('data-id');
|
|
|
|
|
}));
|
|
|
|
|
|
2015-07-29 19:35:11 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
Dashboard.alert(Globalize.translate('SettingsSaved'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(jQuery, window, document);
|