Compare commits

..

11 Commits

11 changed files with 339 additions and 79 deletions

File diff suppressed because one or more lines are too long

View File

@@ -7,7 +7,7 @@ body {
color: black;
}
#cuerpo{
#newViewBody{
top:17%;
left:1%;
width:98%;
@@ -23,46 +23,43 @@ body {
}
#cuerpo .modal-body{
#newViewBody .modal-body{
color: #000;
border:none;
}
#cuerpo .panel-default{
#newViewBody .panel-default{
border: 3px solid #4A89A5;
border-radius: 5px;
}
#cuerpo .panel > .panel-heading {
#newViewBody .panel > .panel-heading {
background-image: none;
background-color: #4A89A5;
color: white;
border-radius: 0;
}
#cuerpo .btn-default{
#newViewBody .btn-default{
border: 2px solid #62655F;
background: #F9DFAF;
}
#cuerpo .btn-default:hover{
#newViewBody .btn-default:hover{
border: 2px solid #62655F;
background: #F9DFAF;
}
#cuerpo .alert-success{
#newViewBody .alert-success{
background: #C6E97C;
}
#modal_header_error{
.modalHeaderError{
background-color: #d9534f;
}
#modal_header_respuesa_servidor_error{
background-color: #d9534f;
}
#modal_header_respuesa_servidor_success{
.modalHeaderSuccess{
background-color: #5bc0de;
}

View File

@@ -0,0 +1,93 @@
<script src="../js/NewEmployee.js"></script>
<script src="../js/getBaseUrl.js"></script>
<form class="form-horizontal" id="newEmployeeForm">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">New employee</h3>
</div>
<div class="panel-body">
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeFirstName">First name</label>
<div class="col-md-5">
<input id="newEmployeeFirstName" name="newEmployeeFirstName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeMiddleName">Middle name</label>
<div class="col-md-5">
<input id="newEmployeeMiddleName" name="newEmployeeMiddleName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeLastName">Last name</label>
<div class="col-md-5">
<input id="newEmployeeLastName" name="newEmployeeLastName" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeBirthDate">Birth date</label>
<div class="col-md-5">
<input id="newEmployeeBirthDate" name="newEmployeeBirthDate" type="text" class="form-control input-md datepicker">
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeEmail">Email</label>
<div class="col-md-5">
<input id="newEmployeeEmail" name="newEmployeeEmail" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeePhone">Phone</label>
<div class="col-md-5">
<input id="newEmployeePhone" name="newEmployeePhone" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="newEmployeeType">Rol</label>
<div class="col-md-5">
<select class="form-control input-md" name="newEmployeeType" id="newEmployeeType">
<option>Employee type</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="col-md-4 control-label" for="NewEmpployyContractType">Contract type</label>
<div class="col-md-5">
<select class="form-control input-md" name="NewEmpployyContractType" id="NewEmpployyContractType">
<option>Contract type</option>
<option value="INTERNO">interno</option>
<option value="EXTERNO">Externo</option>
</select>
</div>
</div>
</div>
</div>
<div class="row col-md-offset-6">
<div class="form-group">
<a href="#" class="btn btn-lg btn-success " onclick="saveNewEmployee();">Create</a>
</div>
</div>
</div>
</div>
</div>
</form>

View File

@@ -26,28 +26,28 @@ if(!isset($_SESSION['userName'])){
</button>
</div>
<div class="collapse navbar-collapse navbar-menubuilder">
<ul class="nav navbar-nav navbar-left">
<ul class="nav navbar-nav navbar-left" id="nevatation-options">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-user"></span> Employees<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#" data-nav_accion="views/cliente.php" onclick="vista_crear_nuevo_salon_evento();"> New employee</a></li>
<li><a href="#" data-nav_accion="views/clientess.php" onclick="vista_crear_nuevo_coach();"> Modify employee</a></li>
<li><a href="#" data-nav_accion="NewEmployee.php"> New employee</a></li>
<li><a href="#" data-nav_accion="EditEmployee.php"> Modify employee</a></li>
</ul>
</li>
<li>
<a href="#" onclick="vista_calendario();"><span class="glyphicon glyphicon-tasks"></span> Management</a>
<a href="#" onclick="loadView();"><span class="glyphicon glyphicon-tasks"></span> Management</a>
</li>
<li>
<a href="#" onclick="vista_calendario();"><span class="glyphicon glyphicon-wrench"></span> Change password</a>
<a href="#" onclick="loadView();"><span class="glyphicon glyphicon-wrench"></span> Change password</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#" onclick="logout();"><span class="fa fa-fw fa-power-off"></span> Cerrar Sesión</a>
<a href="#" onclick="logout();"><span class="fa fa-fw fa-power-off"></span> logout</a>
</li>
</ul>
@@ -55,26 +55,25 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
</div>
<div class="col-md-12" id="cuerpo"></div>
<div class="col-md-12" id="newViewBody"></div>
<!--
=================================================================================
Errores en query de AJAX
Modals for errors encountered by ajax
=================================================================================
-->
<!-- Fallo en la conexion de internet -->
<div id="modal_error_internet" class="modal fade" role="dialog">
<div id="modalErrorInternetConnection" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><center>Ha ocurrido un error</center></h4>
<h4 class="modal-title">An error has occurred</h4>
</div>
<div class="modal-body">
<p>Por favor revise su conexión a internet.</p>
<p>Please verify your internet connection and try again.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -84,18 +83,16 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<!-- El recurso solicitado no existe -->
<div id="modal_error_404" class="modal fade" role="dialog">
<div id="modalError404" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><center>Ha ocurrido un error</center></h4>
<h4 class="modal-title">An error has occurred</h4>
</div>
<div class="modal-body">
<p>El URL del formulario no pudo ser encontrado en el servidor.</p>
<p>Unable to find the requested url in the sever.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -105,18 +102,16 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<!-- Error interno del servidor donde no es posible detectar la causa especifica -->
<div id="modal_error_500" class="modal fade" role="dialog">
<div id="modalError500" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><center>Ha ocurrido un error</center></h4>
<h4 class="modal-title">An error has occurred</h4>
</div>
<div class="modal-body">
<p>Error interno del servidor.</p>
<p>The server has encountered an internal error, please try again later.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -126,18 +121,16 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<!-- El servidor respone con un string que no esta en formato JSON o contiene caracteres adicionales al JSON -->
<div id="modal_error_parsererror" class="modal fade" role="dialog">
<div id="modalErrorParsererror" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><center>Ha ocurrido un error</center></h4>
<h4 class="modal-title">An error has occurred</h4>
</div>
<div class="modal-body">
<p>Fallo al procesar el JSON enviado por el servidor.</p>
<p>The response from the sever wasn't a proper JSON format</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -147,18 +140,16 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<!-- El servidortardo demasiado en responder -->
<div id="modal_error_timeout" class="modal fade" role="dialog">
<div id="modalErrorTimeout" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><center>Ha ocurrido un error</center></h4>
<h4 class="modal-title">An error has occurred</h4>
</div>
<div class="modal-body">
<p>La petición excedió el limite de tiempo.</p>
<p>The request timeout, please try again or verify your connection.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -168,18 +159,16 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<!-- Si el request AJAX falla por alguna razon no listada -->
<div id="modal_error_otro" class="modal fade" role="dialog">
<div id="modalErrorOther" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" id="modal_header_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><center>Ha ocurrido un error</center></h4>
<h4 class="modal-title">An error has occurred</h4>
</div>
<div class="modal-body">
<p>Ha ocurrido un error desconocido.</p>
<p>An unknown error occurred.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -191,22 +180,20 @@ if(!isset($_SESSION['userName'])){
<!--
=================================================================================
Respuesta del servidor
Generic response modals
=================================================================================
-->
<!-- Si el request AJAX falla por alguna razon no listada -->
<div id="modal_respuesa_servidor_error" class="modal fade" role="dialog">
<div id="modalServerResponseError" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" id="modal_header_respuesa_servidor_error">
<div class="modal-header modalHeaderError">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><center>Ha ocurrido un error</center></h4>
<h4 class="modal-title">An error has occurred</h4>
</div>
<div class="modal-body">
<p id="respuesa_servidor_error"></p>
<p id="modalResponseError"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -216,18 +203,16 @@ if(!isset($_SESSION['userName'])){
</div>
</div>
<!-- Si el request AJAX recibe un success en la variable pasasa por el servidor -->
<div id="modal_respuesa_servidor_success" class="modal fade" role="dialog">
<div id="modalServerResponseSuccess" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" id="modal_header_respuesa_servidor_success">
<div class="modal-header modalHeaderSuccess" id="modalHeaderServerResponseSuccess">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><center>El almacenado ha sido exitoso</center></h4>
<h4 class="modal-title">Success</h4>
</div>
<div class="modal-body">
<p id="respuesa_servidor_success"></p>
<p id="serverResponseSuccess"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
@@ -240,4 +225,7 @@ if(!isset($_SESSION['userName'])){
<script src="../js/getBaseUrl.js"></script>
<script src="../js/landing.js"></script>
<link href="../css/landing.css" rel="stylesheet">
<script src="../js/bootstrap-datepicker.min.js"></script>
<link href="../css/bootstrap-datepicker.min.css" rel="stylesheet">
<link href="../css/landing.css" rel="stylesheet">

View File

@@ -0,0 +1,94 @@
/**
* Bootstrapping the starting actions for the module
*/
$(document).ready(function(){
loadEmployeeTypes();
$('.datepicker').datepicker({
format: "yyyy/mm/dd",
autoclose: true
});
});
/**
* Loads the the enmployee types into their select option
*/
function loadEmployeeTypes(){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/employee/types',
type: 'GET',
dataType: 'json',
success:function(data){
$(data).each(function(i,v){
$('#newEmployeeType').append(
'<option value="' + v.id + '">'+ v.name + '</option>'
);
});
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}
function saveNewEmployee(){
let baseUrl = getbaseUrl();
let parameters = {
"firstName":$('#newEmployeeFirstName').val(),
"middleName":$('#newEmployeeMiddleName').val(),
"lastName":$('#newEmployeeLastName').val(),
"birthDate":$('#newEmployeeBirthDate').val(),
"email":$('#newEmployeeEmail').val(),
"phone":$('#newEmployeePhone').val(),
"idEmployeeType":$('#newEmployeeType').val(),
"contractType":$('#NewEmpployyContractType').val()
};
$.ajax({
url: baseUrl + '/api/employee',
type: 'POST',
dataType: 'json',
data: parameters,
success:function(data){
$('#modalServerResponseSuccess').modal('show');
document.getElementById('serverResponseSuccess').innerHTML = 'The employee ' + data['fullName'] + ' has been created with the code ' + data['employeeCode'];
},
error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modalErrorOther').modal('show');
}
},
});
}

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,9 @@
/**
* Destorys the session for the current user and redirects
* back to the login form
*/
function logout() {
var baseUrl = getbaseUrl();
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/api/session/logout',
@@ -8,10 +12,65 @@ function logout() {
success:function(data){
window.location.replace(baseUrl + '/html/login.php');
},
error:function(x) {
if (x.status==500){
$('#modalLoginError').modal('show');
document.getElementById('modalLoginErrorBody').innerHTML = "The user or password didnt match, please try again";
error:function(x,e) {
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalError500').modal('show');
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modal_error_otro').modal('show');
}
},
});
}
/**
* Entry point for loading elements from the navatation var, this functuion
* will filter the junk clicks that have landed in a dropdown menu and pass
* only the ones containing an action to the actual view loader
*/
$('#nevatation-options li a').click(function(){
let view = $(this).data('nav_accion');
if (view != "#" && view != undefined) {
loadView(view);
}
});
/**
* Will fetch the html of the desired view and load it into the landing page
*
* @param requestedView string
*/
function loadView(requestedView){
let baseUrl = getbaseUrl();
$.ajax({
url: baseUrl + '/html/' + requestedView,
type: 'get',
success:function(data){
$("#newViewBody").hide().html(data).show('slow');
},
error:function(x,e) {
if (x.status==0) {
$('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) {
$('#modalError404').modal('show');
} else if(x.status==500) {
$('#modalError500').modal('show');
} else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){
$('#modalErrorTimeout').modal('show');
} else {
$('#modal_error_otro').modal('show');
}
},
});

View File

@@ -16,9 +16,9 @@ $(document).keypress(function(e) {
* display errors to the user
*/
function processLogin() {
var baseUrl = getbaseUrl();
let baseUrl = getbaseUrl();
var parameters = {
let parameters = {
"userName":$('#userName').val(),
"password":$('#password').val()
};
@@ -29,7 +29,6 @@ function processLogin() {
dataType: 'json',
data: parameters,
success:function(data){
console.log(JSON.stringify(data));
if(data["status"] == "success"){
window.location.replace(baseUrl + '/html/landing.php');

View File

@@ -138,6 +138,7 @@ class EmployeeApplication{
$email = $requestData['email'];
$this->asserts->isNotEmpty($email, "The email can't be empty.");
$this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters.");
$this->asserts->isEmail($email, "The email isn't in a correct format");
$phone = $requestData['phone'];
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
@@ -409,6 +410,7 @@ class EmployeeApplication{
$email = $requestData['email'];
$this->asserts->isNotEmpty($email, "The email can't be empty.");
$this->asserts->betweenLength($email, 1, 100, "The middle name must have a length between 1 and 100 characters.");
$this->asserts->isEmail($email, "The email isn't in a correct format");
$phone = $requestData['phone'];
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");

View File

@@ -56,5 +56,18 @@ class Asserts{
throw new Exception($errorMessage);
}
}
/**
* Compares a string against a regex to determine if it's an email
*
* @param $string string
* @param $errorMessage string
* @throws Exception
*/
function isEmail($string, $errorMessage){
if(!filter_var($string, FILTER_VALIDATE_EMAIL)){
throw new Exception($errorMessage);
}
}
}
?>

View File

@@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS `persons` (
`lastName` varbinary(500) comment 'The last name of the person',
`birthDate` DATE NOT NULL DEFAULT '1900-01-01' comment 'Date of birth of the person',
`email` varbinary(500) NOT NULL comment 'The email adress of the person',
`phone` INT(10) UNSIGNED NOT NULL comment 'The phone number of the person should be the mobile one but leaves room for home ones',
`phone` BIGINT(10) UNSIGNED NOT NULL comment 'The phone number of the person should be the mobile one but leaves room for home ones',
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',