2015-10-05 00:19:15 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
2015-10-05 00:19:15 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2021-12-10 11:07:10 +03:00
|
|
|
(function () {
|
|
|
|
const MIN_PASSWORD_LENGTH = 7;
|
|
|
|
const $install = $('#install');
|
|
|
|
const $alert = $('.alert');
|
|
|
|
const $loading = $('#loading');
|
|
|
|
const $firstName = $('#first-name');
|
|
|
|
const $lastName = $('#last-name');
|
|
|
|
const $email = $('#email');
|
|
|
|
const $phoneNumber = $('#phone-number');
|
|
|
|
const $username = $('#username');
|
|
|
|
const $password = $('#password');
|
|
|
|
const $retypePassword = $('#retype-password');
|
|
|
|
const $companyName = $('#company-name');
|
|
|
|
const $companyEmail = $('#company-email');
|
|
|
|
const $companyLink = $('#company-link');
|
2015-10-05 00:19:15 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$(document).ajaxStart(function () {
|
2021-12-10 11:07:10 +03:00
|
|
|
$loading.removeClass('d-none');
|
2015-10-05 00:19:15 +03:00
|
|
|
});
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$(document).ajaxStop(function () {
|
2021-12-10 11:07:10 +03:00
|
|
|
$loading.addClass('d-none');
|
2015-10-05 00:19:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Install Easy!Appointments Button "Click"
|
|
|
|
*/
|
2020-09-07 10:53:39 +03:00
|
|
|
$install.on('click', function () {
|
2016-04-24 20:13:39 +03:00
|
|
|
if (!validate()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-05 00:19:15 +03:00
|
|
|
|
2021-12-10 11:07:10 +03:00
|
|
|
const url = GlobalVariables.baseUrl + '/index.php/installation/perform';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2021-12-10 11:07:10 +03:00
|
|
|
const data = {
|
2021-12-14 09:29:51 +03:00
|
|
|
csrf_token: GlobalVariables.csrfToken,
|
2018-03-28 15:36:28 +03:00
|
|
|
admin: getAdminData(),
|
|
|
|
company: getCompanyData()
|
2016-07-16 18:36:33 +03:00
|
|
|
};
|
2015-10-05 00:19:15 +03:00
|
|
|
|
|
|
|
$.ajax({
|
2018-03-28 15:36:28 +03:00
|
|
|
url: url,
|
2015-10-05 00:19:15 +03:00
|
|
|
type: 'POST',
|
2018-03-28 15:36:28 +03:00
|
|
|
data: data,
|
|
|
|
dataType: 'json'
|
2021-12-10 11:07:10 +03:00
|
|
|
}).done(() => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$alert
|
|
|
|
.text('Easy!Appointments has been successfully installed!')
|
|
|
|
.addClass('alert-success')
|
2021-11-23 12:06:13 +03:00
|
|
|
.prop('hidden', false);
|
2021-11-06 19:38:37 +03:00
|
|
|
|
|
|
|
setTimeout(function () {
|
2021-12-10 11:07:10 +03:00
|
|
|
window.location.href = GlobalVariables.baseUrl + '/index.php/calendar';
|
2021-11-06 19:38:37 +03:00
|
|
|
}, 1000);
|
|
|
|
});
|
2015-10-05 00:19:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2016-05-14 13:26:08 +03:00
|
|
|
* Validates the user input.
|
2015-10-05 00:19:15 +03:00
|
|
|
*
|
2021-12-10 11:07:10 +03:00
|
|
|
* Use this before executing the installation procedure.
|
2016-05-14 13:26:08 +03:00
|
|
|
*
|
2020-04-27 21:14:20 +03:00
|
|
|
* @return {Boolean} Returns the validation result.
|
2015-10-05 00:19:15 +03:00
|
|
|
*/
|
|
|
|
function validate() {
|
|
|
|
try {
|
2021-12-10 11:07:10 +03:00
|
|
|
const $fields = $('input');
|
|
|
|
|
2021-11-23 12:06:13 +03:00
|
|
|
$alert.removeClass('alert-danger').prop('hidden', true);
|
2021-12-10 11:07:10 +03:00
|
|
|
|
|
|
|
$fields.removeClass('is-invalid');
|
2015-10-05 00:19:15 +03:00
|
|
|
|
|
|
|
// Check for empty fields.
|
2021-12-10 11:07:10 +03:00
|
|
|
let missingRequired = false;
|
|
|
|
|
|
|
|
$fields.each((index, field) => {
|
2020-05-12 21:52:32 +03:00
|
|
|
if (!$(field).val()) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$(field).addClass('is-invalid');
|
2015-10-05 00:19:15 +03:00
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-24 20:13:39 +03:00
|
|
|
if (missingRequired) {
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error('All the page fields are required.');
|
2016-04-24 20:13:39 +03:00
|
|
|
}
|
2015-10-05 00:19:15 +03:00
|
|
|
|
|
|
|
// Validate Passwords
|
2021-12-10 11:07:10 +03:00
|
|
|
if ($password.val() !== $retypePassword.val()) {
|
|
|
|
$password.addClass('is-invalid');
|
|
|
|
$retypePassword.addClass('is-invalid');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error('Passwords do not match!');
|
2015-10-05 00:19:15 +03:00
|
|
|
}
|
|
|
|
|
2021-12-10 11:07:10 +03:00
|
|
|
if ($password.val().length < MIN_PASSWORD_LENGTH) {
|
|
|
|
$password.addClass('is-invalid');
|
|
|
|
$retypePassword.addClass('is-invalid');
|
|
|
|
throw new Error(`The password must be at least ${MIN_PASSWORD_LENGTH} characters long.`);
|
2015-10-05 00:19:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate Email
|
2021-12-10 11:07:10 +03:00
|
|
|
if (!GeneralFunctions.validateEmail($email.val())) {
|
|
|
|
$email.addClass('is-invalid');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error('The email address is invalid!');
|
2015-10-05 00:19:15 +03:00
|
|
|
}
|
|
|
|
|
2021-12-10 11:07:10 +03:00
|
|
|
if (!GeneralFunctions.validateEmail($companyEmail.val())) {
|
|
|
|
$companyEmail.addClass('is-invalid');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error('The email address is invalid!');
|
2015-10-05 00:19:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-03-28 15:36:28 +03:00
|
|
|
} catch (error) {
|
2021-11-23 12:06:13 +03:00
|
|
|
$alert.addClass('alert-danger').text(error.message).prop('hidden', false);
|
2018-03-28 15:36:28 +03:00
|
|
|
|
2015-10-05 00:19:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the admin data as an object.
|
|
|
|
*
|
2016-05-14 13:26:08 +03:00
|
|
|
* @return {Object}
|
2015-10-05 00:19:15 +03:00
|
|
|
*/
|
|
|
|
function getAdminData() {
|
2020-05-06 20:15:11 +03:00
|
|
|
return {
|
2021-12-10 11:07:10 +03:00
|
|
|
first_name: $firstName.val(),
|
|
|
|
last_name: $lastName.val(),
|
|
|
|
email: $email.val(),
|
|
|
|
phone_number: $phoneNumber.val(),
|
|
|
|
username: $username.val(),
|
|
|
|
password: $password.val()
|
2015-10-05 00:19:15 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the company data as an object.
|
|
|
|
*
|
2016-05-14 13:26:08 +03:00
|
|
|
* @return {Object}
|
2015-10-05 00:19:15 +03:00
|
|
|
*/
|
|
|
|
function getCompanyData() {
|
2020-05-06 20:15:11 +03:00
|
|
|
return {
|
2021-12-10 11:07:10 +03:00
|
|
|
company_name: $companyName.val(),
|
|
|
|
company_email: $companyEmail.val(),
|
|
|
|
company_link: $companyLink.val()
|
2015-10-05 00:19:15 +03:00
|
|
|
};
|
|
|
|
}
|
2018-01-23 11:51:56 +03:00
|
|
|
|
|
|
|
// Validate the base URL setting (must not contain any trailing slash).
|
|
|
|
if (GlobalVariables.baseUrl.slice(-1) === '/') {
|
2021-11-06 19:38:37 +03:00
|
|
|
GeneralFunctions.displayMessageBox(
|
2021-12-10 11:07:10 +03:00
|
|
|
'Invalid Configuration Detected',
|
|
|
|
'Please remove any trailing slashes from your "BASE_URL" setting of the root "config.php" file and try again.'
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
|
|
|
$install.prop('disabled', true).fadeTo('0.4');
|
2018-01-23 11:51:56 +03:00
|
|
|
}
|
2015-10-05 00:19:15 +03:00
|
|
|
});
|