Commit 45514589 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

fixes #61 + correction sur l'index

parent 5c79fb68
......@@ -54,6 +54,7 @@ class Loan extends Record {
public static function fetch_loans(&$loans, $id) {
// SQL SELECT loans members
$sql = " SELECT l.id, start_date, end_date, is_back, l.created_at, l.updated_at,
CASE WHEN (end_date < curdate() AND is_back = 0) THEN 1 ELSE 0 END AS is_late,
l.member_id, CONCAT(m.firstname, ' ', m.lastname) AS member_name
FROM loans l, members m
WHERE l.game_id = $id
......
......@@ -44,6 +44,7 @@ if($logged_user->id == 0) {
if(!array_key_exists("o", $_REQUEST) || $_REQUEST["o"] == ""
|| !file_exists("controllers/".$_REQUEST["o"].".php")) {
$_REQUEST["o"] = "home";
$_REQUEST["a"] = "index";
}
}
$_REQUEST["a"] = (array_key_exists("a", $_REQUEST)) ? $_REQUEST["a"] : "";
......
......@@ -11,17 +11,22 @@
{% if game.loan_id %}
INDISPONIBLE :
jusqu'au {{ game.loan_end_date | date("d/m/Y") }}
<span class="btn btn-success btn-md" style="float: right" id="reservation_button">
<i class="glyphicon glyphicon-plus"></i>
<span>Réserver...</span>
</span>
<button type="button" class="btn btn-primary btn-md"
style="float: right; margin-right: 20px"
data-toggle="modal" data-target="#editModal" data-id="reservations">
<i class="glyphicon glyphicon-plus"></i>
<span>Réserver...</span>
</button>
{% else %}
DISPONIBLE
{% endif %}
</small>
<a href="index.php?o=games&a=loans&i={{ game.id }}">
Historique des emprunts
</a>
<button type="button" class="btn btn-primary btn-md"
style="float: right; margin-right: 20px"
data-toggle="modal" data-target="#editModal" data-id="loans">
<i class="glyphicon glyphicon-list"></i>
<span>Historique des emprunts</span>
</button>
{% else %}
Nouveau jeu
{% endif %}
......@@ -183,39 +188,62 @@
<!-- end of panel -->
</div>
</div>
<!-- edit modal skel -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
<!-- end edit modal -->
<script>
// buttons events
$('#save_button').click(function(){
if(document.defaultform.name.value == 0) {
alert ("Vous n'avez pas saisi de nom !");
return false;
}
if($('#i').val() == 0) {
$('#a').val('create');
} else {
$('#a').val('update');
}
document.defaultform.submit();
return true;
});
$('#delete_button').click(function(){
var msg = 'Voulez-vous réellement supprimer un jeu ?\n' +
'Cette action n\'est possible que si le jeu n\'a été\n' +
'l\'objet d\'aucun emprunt.';
if(confirm(msg)) {
$('#a').val('confirm_delete');
document.defaultform.submit();
}
});
$('#back_button').click(function(){
// TODO this function should verify that the object has not been modified
// and if yes, ask for confirmation from the user.
window.location.href='index.php?o=games&a=list';
});
$('#reservation_button').click(function(){
$('#o').val('reservations');
$('#a').val('new');
document.defaultform.submit();
$(document).ready(function() {
// buttons events
$('#save_button').click(function(){
if(document.defaultform.name.value == 0) {
alert ("Vous n'avez pas saisi de nom !");
return false;
}
if($('#i').val() == 0) {
$('#a').val('create');
} else {
$('#a').val('update');
}
document.defaultform.submit();
return true;
});
$('#delete_button').click(function(){
var msg = 'Voulez-vous réellement supprimer un jeu ?\n' +
'Cette action n\'est possible que si le jeu n\'a été\n' +
'l\'objet d\'aucun emprunt.';
if(confirm(msg)) {
$('#a').val('confirm_delete');
document.defaultform.submit();
}
});
$('#back_button').click(function(){
// TODO this function should verify that the object has not been modified
// and if yes, ask for confirmation from the user.
window.location.href='index.php?o=games&a=list';
});
$('#reservation_button').click(function(){
$('#o').val('reservations');
$('#a').val('new');
document.defaultform.submit();
});
$("#editModal").on("show.bs.modal", function(e) {
var button = $(e.relatedTarget);
if(button.data('id') == 'loans') {
$(this).find(".modal-content").load("index.php?o=games&a=loans&i=" + {{ game.id }});
} else { // reservation
$(this).find(".modal-content")
.load("index.php?o=games&a=reservations&i=" + {{ game.id }});
}
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
});
});
</script>
{% endblock %}
{% extends "base.html" %}
{% block title %}Historique des emprunts{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4><!-- class="panel-title" -->
<span class="glyphicon glyphicon-knight" style="margin-right: 10px" ></span>
{{ game.name }}
<small>
{% if game.loan_id %}
INDISPONIBLE :
jusqu'au {{ game.loan_end_date | date("d/m/Y") }}
<span class="btn btn-success btn-md" style="float: right" id="reservation_button">
<i class="glyphicon glyphicon-plus"></i>
<span>Réserver...</span>
</span>
{% else %}
DISPONIBLE
{% endif %}
</small>
<a href="index.php?o=games&a=loans&i={{ game.id }}">
Historique des emprunts
</a>
</h4>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">
<span class="glyphicon glyphicon-list-alt" style="margin-right: 10px;" ></span>
{{ game.name }} - Historique des emprunts
</h4>
</div>
<div class="panel-body">
<table id="object_list" class="col-sm-12" width="100%">
<div class="modal-body">
<table id="object_list" width="100%">
<thead>
<tr>
<th>Nom</th>
<th>Date emprunt</th>
<th>Date retour</th>
<th>Rendu</th>
<th>Actions</th>
<th>Adhérent</th>
<th>Date emprunt / retour</th>
</tr>
</thead>
<tbody>
{% for key, val in game.loans %}
<tr>
<td><a href="index.php?o=member&a=edit&i={{ val.member_id }}">{{ val.member_name }}</a>
{% if val.is_late %} <span class="label label-warning">En retard</span> {% endif %}
</td>
<td>{{ val.start_date | date("d/m/Y") }}</td>
<td>{{ val.end_date | date("d/m/Y") }}</td>
<td><input type="checkbox" id="is_back_{{ val.id }}" name="is_back_{{ val.id }}" class="form-control is_back_cbx"
data-switch-with-ajax {{ val.is_back ? ' checked ' }}></td>
<td>
whatever...
<td><a href="index.php?o=members&a=edit&i={{ val.member_id }}">{{ val.member_name }}</a>
{% if val.is_late %}
<span class="label label-warning">En retard</span>
{% else %}
{% if val.is_back == 0 %}
<span class="label label-success">En cours</span>
{% endif %}
{% endif %}
</td>
<td>{{ val.start_date | date("d/m/Y") }} / {{ val.end_date | date("d/m/Y") }}</td>
{% else %}
<tr>
<th colspan="5">
<th colspan="2">
<div class="alert alert-warning" role="alert">Aucun emprunt</div>
</th>
</tr>
......@@ -57,13 +38,8 @@
</tbody>
</table>
<!-- end of panel -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<script>
$('#back_button').click(function(){
window.location.href='index.php?o=games&a=list';
});
</script>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment