Beautify javascript code

This commit is contained in:
coolneng 2020-07-16 03:32:09 +02:00
parent b0238cc9b0
commit 0b91047625
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
7 changed files with 122 additions and 117 deletions

View File

@ -1,17 +1,14 @@
$(document).ready(function() $(document).ready(function() {
{ $("#provincia").change(function() {
$("#provincia").change(function()
{
var id_provincia = $(this).val(); var id_provincia = $(this).val();
var post_id = 'id='+ id_provincia; var post_id = 'id=' + id_provincia;
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "ajax.php", url: "ajax.php",
data: post_id, data: post_id,
cache: false, cache: false,
success: function(response) success: function(response) {
{
$("#localidad").html(response); $("#localidad").html(response);
} }
}); });

View File

@ -16,19 +16,22 @@
], ],
select: function(start, end) { select: function(start, end) {
$("#dialog-form").dialog({ modal: true, width:450}); $("#dialog-form").dialog({
modal: true,
width: 450
});
var date = $.fullCalendar.formatDate(start, 'YYYY-MM-DD'); var date = $.fullCalendar.formatDate(start, 'YYYY-MM-DD');
$("#fecha").val(date); $("#fecha").val(date);
}, },
selectAllow: function(selectInfo){ selectAllow: function(selectInfo) {
var daysOff = null; var daysOff = null;
var holidays = null; var holidays = null;
$.ajax({ $.ajax({
url: 'holiday_feed.php' + queryString, url: 'holiday_feed.php' + queryString,
async: false, async: false,
dataType: 'json', dataType: 'json',
success: function (json) { success: function(json) {
holidays = json; holidays = json;
} }
}); });
@ -36,7 +39,7 @@
url: 'calendar_settings_feed.php' + queryString, url: 'calendar_settings_feed.php' + queryString,
async: false, async: false,
dataType: 'json', dataType: 'json',
success: function (json) { success: function(json) {
daysOff = json; daysOff = json;
} }
}); });
@ -44,7 +47,7 @@
var formatted_date = date.toISOString().substr(0, 10); var formatted_date = date.toISOString().substr(0, 10);
var foundHoliday = holidays.find(el => el.start === formatted_date); var foundHoliday = holidays.find(el => el.start === formatted_date);
var foundDayOff = daysOff.find(el => el === date.getDay()); var foundDayOff = daysOff.find(el => el === date.getDay());
if(foundDayOff == null && foundHoliday == null){ if (foundDayOff == null && foundHoliday == null) {
return true; return true;
} }
return false; return false;
@ -58,8 +61,11 @@
$("#event-description").html("<b>Observaciones: </b>" + event.description); $("#event-description").html("<b>Observaciones: </b>" + event.description);
$("#event-start").html("<b>Comienzo: </b>" + start); $("#event-start").html("<b>Comienzo: </b>" + start);
$("#event-end").html("<b>Fin: </b>" + end); $("#event-end").html("<b>Fin: </b>" + end);
$("#event-info").dialog({title: event.title, width:450}); $("#event-info").dialog({
title: event.title,
width: 450
});
} }
}); });
}); });

View File

@ -1,9 +1,9 @@
function changeInputType(){ function changeInputType() {
country = document.getElementById("pais").value; country = document.getElementById("pais").value;
region = document.getElementById("provincia"); region = document.getElementById("provincia");
city = document.getElementById("localidad"); city = document.getElementById("localidad");
if(country == 73){ if (country == 73) {
region.hidden = false; region.hidden = false;
city.hidden = false; city.hidden = false;
} else { } else {

View File

@ -4,7 +4,7 @@ function printExternalHTML(url) {
printWindow.addEventListener('load', function() { printWindow.addEventListener('load', function() {
if (Boolean(printWindow.chrome)) { if (Boolean(printWindow.chrome)) {
printWindow.print(); printWindow.print();
setTimeout(function(){ setTimeout(function() {
printWindow.close(); printWindow.close();
}, 500); }, 500);
} else { } else {
@ -14,12 +14,12 @@ function printExternalHTML(url) {
}, true); }, true);
} }
function getHTML(url){ function getHTML(url) {
html = null; html = null;
$.ajax({ $.ajax({
url: url, url: url,
async: false, async: false,
success: function (data) { success: function(data) {
console.log(data); console.log(data);
html = data; html = data;
} }

View File

@ -1,63 +1,65 @@
function checkDNI(dni) { function checkDNI(dni) {
var number, let, letter; var number,
let, letter;
var regex = /^[XYZ]?\d{5,8}[A-Z]$/; var regex = /^[XYZ]?\d{5,8}[A-Z]$/;
dni = dni.toUpperCase(); dni = dni.toUpperCase();
if(regex.test(dni) === true){ if (regex.test(dni) === true) {
number = dni.substr(0,dni.length-1); number = dni.substr(0, dni.length - 1);
number = number.replace('X', 0); number = number.replace('X', 0);
number = number.replace('Y', 1); number = number.replace('Y', 1);
number = number.replace('Z', 2); number = number.replace('Z', 2);
let = dni.substr(dni.length-1, 1); let = dni.substr(dni.length - 1, 1);
number = number % 23; number = number % 23;
letter = 'TRWAGMYFPDXBNJZSQVHLCKET'; letter = 'TRWAGMYFPDXBNJZSQVHLCKET';
letter = letter.substring(number, number+1); letter = letter.substring(number, number + 1);
if (letter != let) { if (letter !=
let) {
return false; return false;
}else{ } else {
return true; return true;
} }
return false; return false;
} }
} }
function validateString(input){ function validateString(input) {
if(input == ""){ if (input == "") {
return false; return false;
} }
return true; return true;
} }
function validatePatient(){ function validatePatient() {
var name = document.forms["create_form"]["nombre"]; var name = document.forms["create_form"]["nombre"];
var last_name = document.forms["create_form"]["apellido"]; var last_name = document.forms["create_form"]["apellido"];
var dni = document.forms["create_form"]["documento_identificativo"]; var dni = document.forms["create_form"]["documento_identificativo"];
var address = document.forms["create_form"]["direccion"]; var address = document.forms["create_form"]["direccion"];
var country = document.forms["create_form"]["pais"]; var country = document.forms["create_form"]["pais"];
if(!checkDNI(dni.value)){ if (!checkDNI(dni.value)) {
alert("El DNI/NIE no es correcto"); alert("El DNI/NIE no es correcto");
return false; return false;
} }
if(!validateString(name.value)){ if (!validateString(name.value)) {
alert("Introduce el nombre"); alert("Introduce el nombre");
return false; return false;
} }
if(!validateString(last_name.value)){ if (!validateString(last_name.value)) {
alert("Introduce el apellido"); alert("Introduce el apellido");
return false; return false;
} }
if(!validateString(address.value)){ if (!validateString(address.value)) {
alert("Introduce la dirección"); alert("Introduce la dirección");
return false; return false;
} }
if(!validateString(country.value)){ if (!validateString(country.value)) {
alert("Introduce el país"); alert("Introduce el país");
return false; return false;
} }

View File

@ -1,20 +1,20 @@
function validateString(input){ function validateString(input) {
if(input == ""){ if (input == "") {
return false; return false;
} }
return true; return true;
} }
function validateReport(){ function validateReport() {
var title = document.forms["create_form"]["titulo"]; var title = document.forms["create_form"]["titulo"];
var content = document.forms["create_form"]["contenido"]; var content = document.forms["create_form"]["contenido"];
if(!validateString(title.value)){ if (!validateString(title.value)) {
alert("Introduce el título"); alert("Introduce el título");
return false; return false;
} }
if(!validateString(content.value)){ if (!validateString(content.value)) {
alert("Introduce el contenido"); alert("Introduce el contenido");
return false; return false;
} }

View File

@ -1,44 +1,44 @@
function validateString(input){ function validateString(input) {
if(input == ""){ if (input == "") {
return false; return false;
} }
return true; return true;
} }
function validateEmail(input){ function validateEmail(input) {
var emailID = input; var emailID = input;
atpos = emailID.indexOf("@"); atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf("."); dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || ( dotpos - atpos < 2 )) { if (atpos < 1 || (dotpos - atpos < 2)) {
return false; return false;
} }
return true; return true;
} }
function validateUser(){ function validateUser() {
var name = document.forms["create_form"]["nombre"]; var name = document.forms["create_form"]["nombre"];
var user = document.forms["create_form"]["usuario"]; var user = document.forms["create_form"]["usuario"];
var password = document.forms["create_form"]["contraseña"]; var password = document.forms["create_form"]["contraseña"];
var email = document.forms["create_form"]["correo"]; var email = document.forms["create_form"]["correo"];
if(!validateString(name.value)){ if (!validateString(name.value)) {
alert("Introduce el nombre"); alert("Introduce el nombre");
return false; return false;
} }
if(!validateString(user.value)){ if (!validateString(user.value)) {
alert("Introduce el usuario"); alert("Introduce el usuario");
return false; return false;
} }
if(!validateString(password.value)){ if (!validateString(password.value)) {
alert("Introduce la contraseña"); alert("Introduce la contraseña");
return false; return false;
} }
if(!validateEmail(email.value)){ if (!validateEmail(email.value)) {
alert("El correo proporcionado es incorrecto"); alert("El correo proporcionado es incorrecto");
return false; return false;
} }
@ -46,16 +46,16 @@ function validateUser(){
return true; return true;
} }
function validateLogin(){ function validateLogin() {
var user = document.forms["login_form"]["usuario"]; var user = document.forms["login_form"]["usuario"];
var password = document.forms["login_form"]["contraseña"]; var password = document.forms["login_form"]["contraseña"];
if(!validateString(user.value)){ if (!validateString(user.value)) {
alert("Introduce el usuario"); alert("Introduce el usuario");
return false; return false;
} }
if(!validateString(password.value)){ if (!validateString(password.value)) {
alert("Introduce la contraseña"); alert("Introduce la contraseña");
return false; return false;
} }