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
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2018-03-28 15:36:28 +03:00
|
|
|
$(function () {
|
2016-04-24 20:13:39 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-07-16 18:36:33 +03:00
|
|
|
var MIN_PASSWORD_LENGTH = 7;
|
2018-03-28 15:36:28 +03:00
|
|
|
|
|
|
|
var $alert = $('.alert');
|
2015-10-05 00:19:15 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$(document).ajaxStart(function () {
|
2016-07-16 18:36:33 +03:00
|
|
|
$('#loading').removeClass('hidden');
|
2015-10-05 00:19:15 +03:00
|
|
|
});
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$(document).ajaxStop(function () {
|
2016-07-16 18:36:33 +03:00
|
|
|
$('#loading').addClass('hidden');
|
2015-10-05 00:19:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Install Easy!Appointments Button "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#install').click(function () {
|
2016-04-24 20:13:39 +03:00
|
|
|
if (!validate()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-05 00:19:15 +03:00
|
|
|
|
2018-03-28 15:36:28 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/installation/ajax_install';
|
|
|
|
var data = {
|
2016-07-16 18:36:33 +03:00
|
|
|
csrfToken: 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'
|
|
|
|
})
|
|
|
|
.done(function (response) {
|
|
|
|
$alert
|
|
|
|
.text('Easy!Appointments has been successfully installed!')
|
|
|
|
.addClass('alert-success')
|
|
|
|
.show();
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
setTimeout(function () {
|
2015-11-05 22:30:54 +03:00
|
|
|
window.location.href = GlobalVariables.baseUrl + '/index.php/backend';
|
|
|
|
}, 1000);
|
2018-03-28 15:36:28 +03:00
|
|
|
})
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
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
|
|
|
*
|
2016-05-14 13:26:08 +03:00
|
|
|
* Use this before executing the installation procedure.
|
|
|
|
*
|
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 {
|
2020-02-17 04:14:53 +03:00
|
|
|
$alert
|
|
|
|
.removeClass('alert-danger')
|
|
|
|
.hide();
|
2017-11-14 15:52:59 +03:00
|
|
|
$('input').closest('.form-group').removeClass('has-error');
|
2015-10-05 00:19:15 +03:00
|
|
|
|
|
|
|
// Check for empty fields.
|
|
|
|
var missingRequired = false;
|
2018-01-23 12:08:37 +03:00
|
|
|
$('input').each(function () {
|
2015-10-05 00:19:15 +03:00
|
|
|
if ($(this).val() == '') {
|
2017-11-14 15:52:59 +03:00
|
|
|
$(this).closest('.form-group').addClass('has-error');
|
2015-10-05 00:19:15 +03:00
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-24 20:13:39 +03:00
|
|
|
if (missingRequired) {
|
2015-10-05 00:19:15 +03:00
|
|
|
throw 'All the page fields are required.';
|
2016-04-24 20:13:39 +03:00
|
|
|
}
|
2015-10-05 00:19:15 +03:00
|
|
|
|
|
|
|
// Validate Passwords
|
|
|
|
if ($('#password').val() != $('#retype-password').val()) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#password').closest('.form-group').addClass('has-error');
|
|
|
|
$('#retype-password').closest('.form-group').addClass('has-error');
|
2015-10-05 00:19:15 +03:00
|
|
|
throw 'Passwords do not match!';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($('#password').val().length < MIN_PASSWORD_LENGTH) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#password').closest('.form-group').addClass('has-error');
|
|
|
|
$('#retype-password').closest('.form-group').addClass('has-error');
|
2015-10-05 00:19:15 +03:00
|
|
|
throw 'The password must be at least ' + MIN_PASSWORD_LENGTH + ' characters long.';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate Email
|
|
|
|
if (!GeneralFunctions.validateEmail($('#email').val())) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#email').closest('.form-group').addClass('has-error');
|
2015-10-05 00:19:15 +03:00
|
|
|
throw 'The email address is invalid!';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GeneralFunctions.validateEmail($('#company-email').val())) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#company-email').closest('.form-group').addClass('has-error');
|
2015-10-05 00:19:15 +03:00
|
|
|
throw 'The email address is invalid!';
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-03-28 15:36:28 +03:00
|
|
|
} catch (error) {
|
|
|
|
$alert
|
2020-02-17 04:14:53 +03:00
|
|
|
.addClass('alert-danger')
|
2018-03-28 15:36:28 +03:00
|
|
|
.text(error)
|
|
|
|
.show();
|
|
|
|
|
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() {
|
|
|
|
var admin = {
|
2016-04-24 20:13:39 +03:00
|
|
|
first_name: $('#first-name').val(),
|
|
|
|
last_name: $('#last-name').val(),
|
|
|
|
email: $('#email').val(),
|
|
|
|
phone_number: $('#phone-number').val(),
|
|
|
|
username: $('#username').val(),
|
|
|
|
password: $('#password').val()
|
2015-10-05 00:19:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return admin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
var company = {
|
2016-04-24 20:13:39 +03:00
|
|
|
company_name: $('#company-name').val(),
|
|
|
|
company_email: $('#company-email').val(),
|
|
|
|
company_link: $('#company-link').val()
|
2015-10-05 00:19:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return company;
|
|
|
|
}
|
2018-01-23 11:51:56 +03:00
|
|
|
|
|
|
|
// Validate the base URL setting (must not contain any trailing slash).
|
|
|
|
if (GlobalVariables.baseUrl.slice(-1) === '/') {
|
|
|
|
GeneralFunctions.displayMessageBox('Misconfiguration Detected', 'Please remove any trailing slashes from your '
|
2018-01-23 12:08:37 +03:00
|
|
|
+ 'BASE_URL setting of the root config.php file and try again.');
|
2018-01-23 11:51:56 +03:00
|
|
|
$('#install')
|
|
|
|
.prop('disabled', true)
|
|
|
|
.fadeTo('0.4');
|
|
|
|
}
|
2015-10-05 00:19:15 +03:00
|
|
|
});
|