mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-25 17:33:19 +03:00
Refactored the installation page js.
This commit is contained in:
parent
79fa0ba7f5
commit
648fb96b85
1 changed files with 209 additions and 335 deletions
|
@ -1,173 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<?php // PAGE META ?>
|
||||
<title>Easy!Appointments - Installation</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
|
||||
<?php // INCLUDE CSS ?>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="<?php echo $base_url; ?>/assets/ext/bootstrap/css/bootstrap.min.css">
|
||||
|
||||
<?php // SET FAVICON FOR PAGE ?>
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/x-icon"
|
||||
<link rel="icon" type="image/x-icon"
|
||||
href="<?php echo $base_url; ?>/assets/img/favicon.ico">
|
||||
|
||||
<?php // INCLUDE SCRIPTS ?>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $base_url; ?>/assets/ext/jquery/jquery.min.js"></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $base_url; ?>/assets/ext/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $base_url; ?>/assets/ext/datejs/date.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var GlobalVariables = {
|
||||
'csrfToken': <?php echo json_encode($this->security->get_csrf_hash()); ?>,
|
||||
'baseUrl': <?php echo '"' . $base_url . '"'; ?>
|
||||
};
|
||||
|
||||
var EALang = <?php echo json_encode($this->lang->language); ?>;
|
||||
|
||||
$(document).ready(function() {
|
||||
var MIN_PASSWORD_LENGTH = 7;
|
||||
var AJAX_SUCCESS = 'SUCCESS';
|
||||
var AJAX_FAILURE = 'FAILURE';
|
||||
|
||||
$(document).ajaxStart(function() {
|
||||
$('#loading').show();
|
||||
});
|
||||
|
||||
$(document).ajaxStop(function() {
|
||||
$('#loading').hide();
|
||||
});
|
||||
|
||||
/**
|
||||
* Event: Install Easy!Appointments Button "Click"
|
||||
*/
|
||||
$('#install').click(function() {
|
||||
if (!validate()) return;
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_install';
|
||||
var postData = {
|
||||
'csrfToken': GlobalVariables.csrfToken,
|
||||
'admin': JSON.stringify(getAdminData()),
|
||||
'company': JSON.stringify(getCompanyData())
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function(response) {
|
||||
//////////////////////////////////////////////////////
|
||||
console.log('Ajax Install E!A Response:', response);
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
||||
|
||||
if (response == AJAX_SUCCESS) {
|
||||
$('.alert').text('Easy!Appointments has been successfully installed!');
|
||||
$('.alert').addClass('alert-success');
|
||||
$('.alert').show();
|
||||
setTimeout(function() {
|
||||
window.location.href = GlobalVariables.baseUrl + '/index.php/backend';
|
||||
}, 1000);
|
||||
}
|
||||
}, 'json');
|
||||
});
|
||||
|
||||
/**
|
||||
* Validates the user input. Use this before executing the installation procedure.
|
||||
*
|
||||
* @returns {bool} Returns the validation result.
|
||||
*/
|
||||
function validate() {
|
||||
try {
|
||||
$('.alert').hide();
|
||||
$('input').css('border', '');
|
||||
|
||||
// Check for empty fields.
|
||||
var missingRequired = false;
|
||||
$('input').each(function() {
|
||||
if ($(this).val() == '') {
|
||||
$(this).css('border', '2px solid red');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequired)
|
||||
throw 'All the page fields are required.';
|
||||
|
||||
// Validate Passwords
|
||||
if ($('#password').val() != $('#retype-password').val()) {
|
||||
$('#password').css('border', '2px solid red');
|
||||
$('#retype-password').css('border', '2px solid red');
|
||||
throw 'Passwords do not match!';
|
||||
}
|
||||
|
||||
if ($('#password').val().length < MIN_PASSWORD_LENGTH) {
|
||||
$('#password').css('border', '2px solid red');
|
||||
$('#retype-password').css('border', '2px solid red');
|
||||
throw 'The password must be at least ' + MIN_PASSWORD_LENGTH + ' characters long.';
|
||||
}
|
||||
|
||||
// Validate Email
|
||||
if (!GeneralFunctions.validateEmail($('#email').val())) {
|
||||
$('#email').css('border', '2px solid red');
|
||||
throw 'The email address is invalid!';
|
||||
}
|
||||
|
||||
if (!GeneralFunctions.validateEmail($('#company-email').val())) {
|
||||
$('#company-email').css('border', '2px solid red');
|
||||
throw 'The email address is invalid!';
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch(exc) {
|
||||
$('.alert').text(exc);
|
||||
$('.alert').show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the admin data as an object.
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
function getAdminData() {
|
||||
var admin = {
|
||||
'first_name': $('#first-name').val(),
|
||||
'last_name': $('#last-name').val(),
|
||||
'email': $('#email').val(),
|
||||
'phone_number': $('#phone-number').val(),
|
||||
'username': $('#username').val(),
|
||||
'password': $('#password').val()
|
||||
};
|
||||
|
||||
return admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the company data as an object.
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
function getCompanyData() {
|
||||
var company = {
|
||||
'company_name': $('#company-name').val(),
|
||||
'company_email': $('#company-email').val(),
|
||||
'company_link': $('#company-link').val()
|
||||
};
|
||||
|
||||
return company;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="<?php echo $this->config->item('base_url'); ?>/assets/ext/jquery-ui/jquery-ui.min.css">
|
||||
|
||||
<style>
|
||||
header {
|
||||
|
@ -214,7 +58,8 @@
|
|||
|
||||
<header>
|
||||
<a href="http://easyappointments.org" target="_blank">
|
||||
<img src="<?php echo $base_url; ?>/assets/img/installation-banner.png" alt="Easy!Appointents Installation Banner">
|
||||
<img src="<?php echo $base_url; ?>/assets/img/installation-banner.png"
|
||||
alt="Easy!Appointents Installation Banner">
|
||||
</a>
|
||||
</header>
|
||||
|
||||
|
@ -328,8 +173,37 @@
|
|||
Powered by <a href="http://easyappointments.org">Easy!Appointments</a>
|
||||
</footer>
|
||||
|
||||
<script type="text/javascript">
|
||||
var GlobalVariables = {
|
||||
'csrfToken': <?php echo json_encode($this->security->get_csrf_hash()); ?>,
|
||||
'baseUrl': <?php echo '"' . $base_url . '"'; ?>
|
||||
};
|
||||
|
||||
var EALang = <?php echo json_encode($this->lang->language); ?>;
|
||||
</script>
|
||||
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $base_url; ?>/assets/ext/jquery/jquery.min.js"></script>
|
||||
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $this->config->item('base_url'); ?>/assets/ext/jquery-ui/jquery-ui.min.js"></script>
|
||||
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $base_url; ?>/assets/ext/bootstrap/js/bootstrap.min.js"></script>
|
||||
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $base_url; ?>/assets/js/general_functions.js"></script>
|
||||
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $base_url; ?>/assets/ext/datejs/date.js"></script>
|
||||
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="<?php echo $base_url; ?>/assets/js/installation.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue