Full Calendar Add funcional
Solo falta que el formulario se reinicie una vez se ha completado la operacion
This commit is contained in:
parent
31cb6b3212
commit
d8e08b7c3c
@ -72,7 +72,6 @@ switch($_SERVER['REQUEST_METHOD']) {
|
||||
$data = [];
|
||||
//Testing hacks
|
||||
$correct_response = 'Operación completada';
|
||||
$film = "1";
|
||||
|
||||
$entityBody = file_get_contents('php://input');
|
||||
$dictionary = json_decode($entityBody);
|
||||
@ -86,6 +85,7 @@ switch($_SERVER['REQUEST_METHOD']) {
|
||||
$startDate = $dictionary->{"startDate"} ?? "";
|
||||
$endDate = $dictionary->{"endDate"} ?? "";
|
||||
$startHour = $dictionary->{"startHour"} ?? "";
|
||||
$idfilm = $dictionary->{"idFilm"} ?? "";
|
||||
|
||||
if (empty($price) || $price <= 0 )
|
||||
$errors['price'] = 'El precio no puede ser 0.';
|
||||
@ -109,8 +109,13 @@ switch($_SERVER['REQUEST_METHOD']) {
|
||||
if (empty($startHour))
|
||||
$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)){
|
||||
$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)
|
||||
$errors['price'] = $msg;
|
||||
@ -121,11 +126,9 @@ switch($_SERVER['REQUEST_METHOD']) {
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
error_log("no success");
|
||||
$data['success'] = false;
|
||||
$data['errors'] = $errors;
|
||||
} else {
|
||||
error_log("succes");
|
||||
$data['success'] = true;
|
||||
}
|
||||
|
||||
|
@ -19,17 +19,14 @@ class NewSessionForm {
|
||||
<div id="format_group" class="form_group">
|
||||
<input type="text" id="format" name="format" value="" placeholder="Formato de pelicula" /> <br>
|
||||
</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){
|
||||
if($hll->getNumber() == $hall){
|
||||
$panel.= '
|
||||
<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.= '
|
||||
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
}
|
||||
$form.='</select>
|
||||
$form.=' </select>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Horario</legend>
|
||||
@ -50,27 +47,45 @@ class NewSessionForm {
|
||||
</fieldset>
|
||||
<input type="reset" id="reset" value="Limpiar Campos" >
|
||||
<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 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 class="film_list">
|
||||
</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 class="film_list" id="film_list">
|
||||
<ul class="tablelist col3">';
|
||||
$parity = "odd";
|
||||
$i = 0;
|
||||
foreach($filmslist as $film){
|
||||
$form .='<div class="'.$parity.'">
|
||||
<li> '. str_replace('_', ' ',$film->getTittle()).'</li>
|
||||
<li> '.$film->getDuration().' min</li>
|
||||
<li> <button type="button" id="select_button"> Seleccionar </button> </li>
|
||||
<input type="hidden" value="'.$film->getId().'" id="id'.$i.'"/>
|
||||
<input type="hidden" value="'.$film->getImg().'" id="img'.$i.'"/>
|
||||
<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>
|
||||
';
|
||||
$parity = ($parity == "odd") ? "even" : "odd";
|
||||
$i++;
|
||||
}
|
||||
$form.='
|
||||
</ul>
|
||||
</div>';
|
||||
</div>
|
||||
</form>';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -27,10 +27,17 @@ $(document).ready(function(){
|
||||
{
|
||||
$(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("startDate").value = $.fullCalendar.formatDate( start, "Y-MM-DD" );
|
||||
document.getElementById("endDate").value = $.fullCalendar.formatDate( end, "Y-MM-DD" );
|
||||
|
||||
|
||||
/*
|
||||
var e = {
|
||||
"date" : $.fullCalendar.formatDate(allDay,"Y-MM-DD"),
|
||||
@ -133,14 +140,25 @@ $(document).ready(function(){
|
||||
|
||||
// When the user clicks on <span> (x), close the modal
|
||||
span.onclick = function() {
|
||||
$(modal).fadeOut();
|
||||
formout();
|
||||
}
|
||||
|
||||
// When the user clicks anywhere outside of the modal, close it
|
||||
window.onclick = function(event) {
|
||||
if (event.target == modal) {
|
||||
$(modal).fadeOut();
|
||||
formout();
|
||||
}
|
||||
}
|
||||
|
||||
function formout(){
|
||||
|
||||
var success = document.getElementById("success");
|
||||
if(success){
|
||||
calendar.fullCalendar('refetchEvents');
|
||||
}
|
||||
|
||||
$(modal).fadeOut();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -12,6 +12,7 @@ $(document).ready(function () {
|
||||
startDate: $("#startDate").val(),
|
||||
endDate: $("#endDate").val(),
|
||||
startHour: $("#startHour").val(),
|
||||
idFilm: $("#film_id").val(),
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
@ -23,7 +24,15 @@ $(document).ready(function () {
|
||||
encode: true,
|
||||
}).done(function (data) {
|
||||
console.log(data);
|
||||
checkErrors(data,"form#new_session_form");
|
||||
})
|
||||
.fail(function (jqXHR, textStatus) {
|
||||
$("form#new_session_form").html(
|
||||
'<div class="alert alert-danger">Could not reach server, please try again later. '+textStatus+'</div>'
|
||||
);
|
||||
});
|
||||
|
||||
function checkErrors(data,formname) {
|
||||
if (!data.success) {
|
||||
if (data.errors.price) {
|
||||
$("#price_group").addClass("has_error");
|
||||
@ -67,27 +76,65 @@ $(document).ready(function () {
|
||||
'<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 {
|
||||
$("form#new_session_form").html(
|
||||
'<div class="alert alert-success">' + data.message + "</div>"
|
||||
$(formname).html(
|
||||
'<div class="alert alert-success" id="success">' + data.message + "</div>"
|
||||
);
|
||||
}
|
||||
|
||||
})
|
||||
.fail(function (jqXHR, textStatus) {
|
||||
$("form#new_session_form").html(
|
||||
'<div class="alert alert-danger">Could not reach server, please try again later. '+textStatus+'</div>'
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
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";
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user