Full Calendar Add funcional

Solo falta que el formulario se reinicie una vez se ha completado la operacion
This commit is contained in:
Markines16 2021-06-05 14:28:52 +02:00 committed by GitHub
parent 31cb6b3212
commit d8e08b7c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 167 additions and 84 deletions

View File

@ -72,7 +72,6 @@ switch($_SERVER['REQUEST_METHOD']) {
$data = []; $data = [];
//Testing hacks //Testing hacks
$correct_response = 'Operación completada'; $correct_response = 'Operación completada';
$film = "1";
$entityBody = file_get_contents('php://input'); $entityBody = file_get_contents('php://input');
$dictionary = json_decode($entityBody); $dictionary = json_decode($entityBody);
@ -86,6 +85,7 @@ switch($_SERVER['REQUEST_METHOD']) {
$startDate = $dictionary->{"startDate"} ?? ""; $startDate = $dictionary->{"startDate"} ?? "";
$endDate = $dictionary->{"endDate"} ?? ""; $endDate = $dictionary->{"endDate"} ?? "";
$startHour = $dictionary->{"startHour"} ?? ""; $startHour = $dictionary->{"startHour"} ?? "";
$idfilm = $dictionary->{"idFilm"} ?? "";
if (empty($price) || $price <= 0 ) if (empty($price) || $price <= 0 )
$errors['price'] = 'El precio no puede ser 0.'; $errors['price'] = 'El precio no puede ser 0.';
@ -108,9 +108,14 @@ switch($_SERVER['REQUEST_METHOD']) {
} }
if (empty($startHour)) if (empty($startHour))
$errors['startHour'] = 'Es necesario escoger el horario de la sesion.'; $errors['startHour'] = 'Es necesario escoger el horario de la sesion.';
error_log("El valor de idfilm: ".$idfilm);
if (!is_numeric($idfilm) && $idfilm <= 0 )
$errors['idfilm'] = 'No se ha seleccionado una pelicula.';
while($startDate < $endDate && empty($errors)){ while($startDate < $endDate && empty($errors)){
$msg = Session::create_session($_SESSION["cinema"], $hall, $startHour, $startDate, $film, $price, $format); $msg = Session::create_session($_SESSION["cinema"], $hall, $startHour, $startDate, $idfilm, $price, $format);
if(strcmp($msg,$correct_response)!== 0) if(strcmp($msg,$correct_response)!== 0)
$errors['price'] = $msg; $errors['price'] = $msg;
@ -121,11 +126,9 @@ switch($_SERVER['REQUEST_METHOD']) {
} }
if (!empty($errors)) { if (!empty($errors)) {
error_log("no success");
$data['success'] = false; $data['success'] = false;
$data['errors'] = $errors; $data['errors'] = $errors;
} else { } else {
error_log("succes");
$data['success'] = true; $data['success'] = true;
} }

View File

@ -19,17 +19,14 @@ class NewSessionForm {
<div id="format_group" class="form_group"> <div id="format_group" class="form_group">
<input type="text" id="format" name="format" value="" placeholder="Formato de pelicula" /> <br> <input type="text" id="format" name="format" value="" placeholder="Formato de pelicula" /> <br>
</div> </div>
<div id="hall_group" class="form_group">'; <div id="hall_group" class="form_group">
<select id="hall" name="hall" class="button large">>';
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){ foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
if($hll->getNumber() == $hall){ $form.= '
$panel.= ' <option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
<option data-feed="./eventos.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
}else{
$panel.= '
<option data-feed="./eventos.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
}
} }
$form.='</select> $form.=' </select>
</div>
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend>Horario</legend> <legend>Horario</legend>
@ -50,27 +47,45 @@ class NewSessionForm {
</fieldset> </fieldset>
<input type="reset" id="reset" value="Limpiar Campos" > <input type="reset" id="reset" value="Limpiar Campos" >
<input type="submit" id="submit" name="sumbit" class="primary" value="Crear" /> <input type="submit" id="submit" name="sumbit" class="primary" value="Crear" />
</form> <div id="film_msg_group" class="form_group"> </div>
<div id="film_group" class="form_group"> <div id="film_group" class="form_group">
<div class="code showtimes">
<input type="hidden" id="film_id" name="film_id" value=""/>
<h2 id="film_title"> titulo </h2>
<hr />
<div class="img_desc">
<div class="image"> <img src="../img/films/iron_man.jpg" alt="iron man" id="film_img" /> </div>
<div class="blockquote">
<p id="film_desc">"Un empresario millonario construye un traje blindado y lo usa para combatir el crimen y el terrorismo."</p>
</div>
</div>
<li id="film_dur"> Duración: duracion minutos</li>
<li id="film_lan"> Lenguaje: idioma </li>
</div>
<button type="button" class="button large" id="return"> Cambiar pelicula </button>
</div> </div>
<div class="film_list"> <div class="film_list" id="film_list">
<ul class="tablelist col3">'; <ul class="tablelist col3">';
$parity = "odd"; $parity = "odd";
$i = 0;
foreach($filmslist as $film){ foreach($filmslist as $film){
$form .='<div class="'.$parity.'"> $form .='<div class="'.$parity.'">
<li> '. str_replace('_', ' ',$film->getTittle()).'</li> <input type="hidden" value="'.$film->getId().'" id="id'.$i.'"/>
<li> '.$film->getDuration().' min</li> <input type="hidden" value="'.$film->getImg().'" id="img'.$i.'"/>
<li> <button type="button" id="select_button"> Seleccionar </button> </li> <input type="hidden" value="'.$film->getLanguage().'" id="lan'.$i.'"/>
<input type="hidden" value="'.$film->getDescription().'" id="desc'.$i.'"/>
<li value="'.$film->getTittle().'"id="title'.$i.'"> '. str_replace('_', ' ',$film->getTittle()).'</li>
<li id="dur'.$i.'"> '.$film->getDuration().' min</li>
<li> <button type="button" class="film_button" id="'.$i.'"> Seleccionar </button> </li>
</div> </div>
'; ';
$parity = ($parity == "odd") ? "even" : "odd"; $parity = ($parity == "odd") ? "even" : "odd";
$i++;
} }
$form.=' $form.='
</ul> </ul>
</div>'; </div>
</form>';
return $form; return $form;
} }

View File

@ -26,11 +26,18 @@ $(document).ready(function(){
select: function(start, end, allDay) select: function(start, end, allDay)
{ {
$(modal).fadeIn(); $(modal).fadeIn();
var x = document.getElementById("film_group");
x.style.display = "none";
x = document.getElementById("film_list");
x.style.display = "block";
document.getElementById("hall").value = document.getElementById("hall_selector").value; document.getElementById("hall").value = document.getElementById("hall_selector").value;
document.getElementById("startDate").value = $.fullCalendar.formatDate( start, "Y-MM-DD" ); document.getElementById("startDate").value = $.fullCalendar.formatDate( start, "Y-MM-DD" );
document.getElementById("endDate").value = $.fullCalendar.formatDate( end, "Y-MM-DD" ); document.getElementById("endDate").value = $.fullCalendar.formatDate( end, "Y-MM-DD" );
/* /*
var e = { var e = {
"date" : $.fullCalendar.formatDate(allDay,"Y-MM-DD"), "date" : $.fullCalendar.formatDate(allDay,"Y-MM-DD"),
@ -133,14 +140,25 @@ $(document).ready(function(){
// When the user clicks on <span> (x), close the modal // When the user clicks on <span> (x), close the modal
span.onclick = function() { span.onclick = function() {
$(modal).fadeOut(); formout();
} }
// When the user clicks anywhere outside of the modal, close it // When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) { window.onclick = function(event) {
if (event.target == modal) { if (event.target == modal) {
$(modal).fadeOut(); formout();
} }
} }
function formout(){
var success = document.getElementById("success");
if(success){
calendar.fullCalendar('refetchEvents');
}
$(modal).fadeOut();
}
}); });

View File

@ -12,6 +12,7 @@ $(document).ready(function () {
startDate: $("#startDate").val(), startDate: $("#startDate").val(),
endDate: $("#endDate").val(), endDate: $("#endDate").val(),
startHour: $("#startHour").val(), startHour: $("#startHour").val(),
idFilm: $("#film_id").val(),
}; };
$.ajax({ $.ajax({
@ -23,64 +24,7 @@ $(document).ready(function () {
encode: true, encode: true,
}).done(function (data) { }).done(function (data) {
console.log(data); console.log(data);
checkErrors(data,"form#new_session_form");
if (!data.success) {
if (data.errors.price) {
$("#price_group").addClass("has_error");
$("#price_group").append(
'<div class="help_block">' + data.errors.price + "</div>"
);
}
if (data.errors.format) {
$("#format_group").addClass("has_error");
$("#format_group").append(
'<div class="help_block">' + data.errors.format + "</div>"
);
}
if (data.errors.hall) {
$("#hall_group").addClass("has_error");
$("#hall_group").append(
'<div class="help_block">' + data.errors.hall + "</div>"
);
}
if (data.errors.startDate) {
$("#date_group").addClass("has_error");
$("#date_group").append(
'<div class="help_block">' + data.errors.startDate + "</div>"
);
}
if (data.errors.startDate) {
$("#date_group").addClass("has_error");
$("#date_group").append(
'<div class="help_block">' + data.errors.endDate + "</div>"
);
}
if (data.errors.date) {
$("#date_group").addClass("has_error");
$("#date_group").append(
'<div class="help_block">' + data.errors.date + "</div>"
);
}
if (data.errors.startHour) {
$("#hour_group").addClass("has_error");
$("#hour_group").append(
'<div class="help_block">' + data.errors.startHour + "</div>"
);
}
if (data.errors.global) {
$("#global_group").addClass("has_error");
$("#global_group").append(
'<div class="help_block">' + data.errors.global + "</div>"
);
}
} else {
$("form#new_session_form").html(
'<div class="alert alert-success">' + data.message + "</div>"
);
}
}) })
.fail(function (jqXHR, textStatus) { .fail(function (jqXHR, textStatus) {
$("form#new_session_form").html( $("form#new_session_form").html(
@ -88,6 +32,109 @@ $(document).ready(function () {
); );
}); });
function checkErrors(data,formname) {
if (!data.success) {
if (data.errors.price) {
$("#price_group").addClass("has_error");
$("#price_group").append(
'<div class="help_block">' + data.errors.price + "</div>"
);
}
if (data.errors.format) {
$("#format_group").addClass("has_error");
$("#format_group").append(
'<div class="help_block">' + data.errors.format + "</div>"
);
}
if (data.errors.hall) {
$("#hall_group").addClass("has_error");
$("#hall_group").append(
'<div class="help_block">' + data.errors.hall + "</div>"
);
}
if (data.errors.startDate) {
$("#date_group").addClass("has_error");
$("#date_group").append(
'<div class="help_block">' + data.errors.startDate + "</div>"
);
}
if (data.errors.startDate) {
$("#date_group").addClass("has_error");
$("#date_group").append(
'<div class="help_block">' + data.errors.endDate + "</div>"
);
}
if (data.errors.date) {
$("#date_group").addClass("has_error");
$("#date_group").append(
'<div class="help_block">' + data.errors.date + "</div>"
);
}
if (data.errors.startHour) {
$("#hour_group").addClass("has_error");
$("#hour_group").append(
'<div class="help_block">' + data.errors.startHour + "</div>"
);
}
if (data.errors.idfilm) {
$("#film_msg_group").addClass("has_error");
$("#film_msg_group").append(
'<div class="help_block">' + data.errors.idfilm + "</div>"
);
}
if (data.errors.global) {
$("#global_group").addClass("has_error");
$("#global_group").append(
'<div class="help_block">' + data.errors.global + "</div>"
);
}
} else {
$(formname).html(
'<div class="alert alert-success" id="success">' + data.message + "</div>"
);
}
}
e.preventDefault(); e.preventDefault();
}); });
$('.film_button').bind('click', function(e) {
var id = $(this).attr('id');
var x = document.getElementById("film_group");
x.style.display = "block";
var tittle = document.getElementById("title"+id);
document.getElementById("film_title").innerHTML = tittle.innerHTML;
var lan = document.getElementById("lan"+id);
document.getElementById("film_lan").innerHTML = lan.value;
var dur = document.getElementById("dur"+id);
document.getElementById("film_dur").innerHTML = dur.innerHTML;
var img = document.getElementById("img"+id);
document.getElementById("film_img").src = "../img/films/"+img.value;
var desc = document.getElementById("desc"+id);
document.getElementById("film_desc").innerHTML = desc.value;
var idf = document.getElementById("id"+id);
document.getElementById("film_id").value = idf.value;
x = document.getElementById("film_list")
x.style.display = "none";
});
$('#return').click( function() {
var x = document.getElementById("film_group");
x.style.display = "none";
x = document.getElementById("film_list");
x.style.display = "block";
});
}); });