MaketRandevu/assets/js/pages/account.js

102 lines
3.3 KiB
JavaScript
Raw Normal View History

/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.0.0
* ---------------------------------------------------------------------------- */
/**
* Account
*
* Contains the functionality of the account page.
*/
App.Pages.Account = (function () {
const $userId = $('#user-id');
const $firstName = $('#first-name');
const $lastName = $('#last-name');
const $email = $('#email');
const $mobileNumber = $('#mobile-number');
const $phoneNumber = $('#phone-number');
const $address = $('#address');
const $city = $('#city');
const $state = $('#state');
const $zipCode = $('#zip-code');
const $notes = $('#notes');
const $timezones = $('#timezone');
const $username = $('#username');
const $password = $('#password');
const $retypePassword = $('#retype-password');
const $calendarView = $('#calendar-view');
const notifications = $('#notifications');
const $saveSettings = $('#save-settings');
function deserialize(account) {
$userId.val(account.id);
$firstName.val(account.first_name);
$lastName.val(account.last_name);
$email.val(account.email);
$mobileNumber.val(account.mobile_number);
$phoneNumber.val(account.phone_number);
$address.val(account.address);
$city.val(account.city);
$state.val(account.state);
$zipCode.val(account.zip_code);
$notes.val(account.notes);
$timezones.val(account.timezone);
$username.val(account.settings.username);
$password.val('');
$retypePassword.val('');
$calendarView.val(account.settings.calendar_view);
notifications.prop('checked', Boolean(Number(account.settings.notifications)));
}
function serialize() {
return {
id: $userId.val(),
first_name: $firstName.val(),
last_name: $lastName.val(),
email: $email.val(),
mobile_number: $mobileNumber.val(),
phone_number: $phoneNumber.val(),
address: $address.val(),
city: $city.val(),
state: $state.val(),
zip_code: $zipCode.val(),
notes: $notes.val(),
timezone: $timezones.val(),
settings: {
username: $username.val(),
password: $password.val(),
calendar_view: $calendarView.val(),
notifications: Number(notifications.prop('checked'))
}
};
}
function onSaveSettingsClick() {
const account = serialize();
App.Http.Account.save(account).done(function () {
Backend.displayNotification(App.Lang.account_saved);
});
}
function init() {
const account = App.Vars.account;
deserialize(account);
$saveSettings.on('click', onSaveSettingsClick);
Backend.placeFooterToBottom();
}
document.addEventListener('DOMContentLoaded', init);
return {};
})();