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()
{
$("#provincia").change(function()
{
$(document).ready(function() {
$("#provincia").change(function() {
var id_provincia = $(this).val();
var post_id = 'id='+ id_provincia;
var post_id = 'id=' + id_provincia;
$.ajax({
type: "POST",
url: "ajax.php",
data: post_id,
cache: false,
success: function(response)
{
success: function(response) {
$("#localidad").html(response);
}
});

View File

@ -1,65 +1,71 @@
$(document).ready(function() {
var queryString = window.location.search;
var calendar = $('#calendar').fullCalendar({
selectable: true,
editable: false,
var queryString = window.location.search;
var calendar = $('#calendar').fullCalendar({
selectable: true,
editable: false,
header: {
left: 'prev,next,today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
header: {
left: 'prev,next,today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventSources: [
"appointment_feed.php" + queryString,
"holiday_feed.php" + queryString
],
eventSources: [
"appointment_feed.php" + queryString,
"holiday_feed.php" + queryString
],
select: function(start, end) {
$("#dialog-form").dialog({ modal: true, width:450});
var date = $.fullCalendar.formatDate(start, 'YYYY-MM-DD');
$("#fecha").val(date);
},
select: function(start, end) {
$("#dialog-form").dialog({
modal: true,
width: 450
});
var date = $.fullCalendar.formatDate(start, 'YYYY-MM-DD');
$("#fecha").val(date);
},
selectAllow: function(selectInfo){
var daysOff = null;
var holidays = null;
$.ajax({
url: 'holiday_feed.php' + queryString,
async: false,
dataType: 'json',
success: function (json) {
holidays = json;
}
});
$.ajax({
url: 'calendar_settings_feed.php' + queryString,
async: false,
dataType: 'json',
success: function (json) {
daysOff = json;
}
});
var date = selectInfo.start._d;
var formatted_date = date.toISOString().substr(0, 10);
var foundHoliday = holidays.find(el => el.start === formatted_date);
var foundDayOff = daysOff.find(el => el === date.getDay());
if(foundDayOff == null && foundHoliday == null){
return true;
}
return false;
},
selectAllow: function(selectInfo) {
var daysOff = null;
var holidays = null;
$.ajax({
url: 'holiday_feed.php' + queryString,
async: false,
dataType: 'json',
success: function(json) {
holidays = json;
}
});
$.ajax({
url: 'calendar_settings_feed.php' + queryString,
async: false,
dataType: 'json',
success: function(json) {
daysOff = json;
}
});
var date = selectInfo.start._d;
var formatted_date = date.toISOString().substr(0, 10);
var foundHoliday = holidays.find(el => el.start === formatted_date);
var foundDayOff = daysOff.find(el => el === date.getDay());
if (foundDayOff == null && foundHoliday == null) {
return true;
}
return false;
},
eventClick: function(event) {
var start = $.fullCalendar.formatDate(event.start, 'HH:mm');
var end = $.fullCalendar.formatDate(event.end, 'HH:mm');
$("#event_id").val(event.id);
$("#event-patient").html("<b>DNI/NIE: </b>" + event.patient);
$("#event-description").html("<b>Observaciones: </b>" + event.description);
$("#event-start").html("<b>Comienzo: </b>" + start);
$("#event-end").html("<b>Fin: </b>" + end);
$("#event-info").dialog({title: event.title, width:450});
}
eventClick: function(event) {
var start = $.fullCalendar.formatDate(event.start, 'HH:mm');
var end = $.fullCalendar.formatDate(event.end, 'HH:mm');
$("#event_id").val(event.id);
$("#event-patient").html("<b>DNI/NIE: </b>" + event.patient);
$("#event-description").html("<b>Observaciones: </b>" + event.description);
$("#event-start").html("<b>Comienzo: </b>" + start);
$("#event-end").html("<b>Fin: </b>" + end);
$("#event-info").dialog({
title: event.title,
width: 450
});
}
});
});
});
});

View File

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

View File

@ -4,7 +4,7 @@ function printExternalHTML(url) {
printWindow.addEventListener('load', function() {
if (Boolean(printWindow.chrome)) {
printWindow.print();
setTimeout(function(){
setTimeout(function() {
printWindow.close();
}, 500);
} else {
@ -14,12 +14,12 @@ function printExternalHTML(url) {
}, true);
}
function getHTML(url){
function getHTML(url) {
html = null;
$.ajax({
url: url,
async: false,
success: function (data) {
success: function(data) {
console.log(data);
html = data;
}
@ -38,11 +38,11 @@ function printExternalPDF(url) {
width: 522
};
pdf.fromHTML(
html,
margins.left,
margins.top, {
'width': margins.width
}
),
pdf.save();
html,
margins.left,
margins.top, {
'width': margins.width
}
),
pdf.save();
}

View File

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

View File

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

View File

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