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

refactoring des editions de liste

parent a1605066
...@@ -48,7 +48,7 @@ class Record { ...@@ -48,7 +48,7 @@ class Record {
$sql = " UPDATE ".$this->table." SET ".$update_sql." updated_at = now() $sql = " UPDATE ".$this->table." SET ".$update_sql." updated_at = now()
WHERE id = ".$this->id; WHERE id = ".$this->id;
return $GLOBALS["data"]->update($sql); return $GLOBALS["data"]->update($sql);
} }
} }
} }
...@@ -59,7 +59,11 @@ class AppController { ...@@ -59,7 +59,11 @@ class AppController {
try { try {
$classname = $this->model; $classname = $this->model;
$object = new $classname(0); $object = new $classname(0);
$object->create(); if($object->create()) {
$this->set_message("Création effectuée");
} else {
$this->set_message("Aucun nouvel objet n'a été créé");
}
// FIXME : may be this fail !!! // FIXME : may be this fail !!!
if($render == "list") { if($render == "list") {
$classname::fetch_all($objects); $classname::fetch_all($objects);
...@@ -97,8 +101,10 @@ class AppController { ...@@ -97,8 +101,10 @@ class AppController {
try { try {
$classname = $this->model; $classname = $this->model;
$object = $classname::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"])); $object = $classname::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($object->id != 0) { if($object->id != 0) {
$object->update(); if($object->update()) {
$this->set_message("Modification enregistrée");
}
$objects = array(); $objects = array();
$classname::fetch_all($objects); $classname::fetch_all($objects);
$this->set("objects", $objects); $this->set("objects", $objects);
...@@ -115,6 +121,7 @@ class AppController { ...@@ -115,6 +121,7 @@ class AppController {
try { try {
$classname = $this->model; $classname = $this->model;
if($_REQUEST["i"] = $classname::delete($_REQUEST["i"])) { if($_REQUEST["i"] = $classname::delete($_REQUEST["i"])) {
$this->set_message("Suppression effectuée");
$classname::fetch_all($objects); $classname::fetch_all($objects);
$this->set("objects", $objects); $this->set("objects", $objects);
return $_REQUEST["o"]."/list"; return $_REQUEST["o"]."/list";
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel"> <h4 class="modal-title" id="myModalLabel">
<span class="glyphicon glyphicon-list-alt" style="margin-right: 10px;" ></span> <span class="glyphicon glyphicon-list-alt" style="margin-right: 10px;" ></span>
{% if object.id %} Catégorie ESAR : {{ object.name }} {% else %} Nouvelle catégorie ESAR {% endif %} {% if object.id %} Catégorie ESAR : {{ object.name }} {% else %} Nouvelle catégorie ESAR {% endif %}
</h4> </h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="name">Nom</label> <label class="control-label col-sm-2" for="name">Nom</label>
<div class="col-sm-4"> <div class="col-sm-4">
...@@ -44,22 +44,22 @@ $('#save_button').click(function(){ ...@@ -44,22 +44,22 @@ $('#save_button').click(function(){
alert ("Vous n'avez pas saisi de nom !"); alert ("Vous n'avez pas saisi de nom !");
return false; return false;
} }
if($('#esar_category_id').val() == 0) { if($('#esar_category_id').val() == 0) {
$('#a').val('create'); $('#a').val('create');
} else { } else {
$('#i').val($('#esar_category_id').val()); $('#i').val($('#esar_category_id').val());
$('#a').val('update'); $('#a').val('update');
} }
document.defaultform.submit(); document.defaultform.submit();
return true; return true;
}); });
$('#delete_button').click(function(){ $('#delete_button').click(function(){
var msg = 'Voulez-vous réellement supprimer cette catégorie ?\n' + var msg = 'Voulez-vous réellement supprimer cette catégorie ?\n' +
'Cette action n\'est possible que si celle-ci n\'a pas été\n' + 'Cette action n\'est possible que si celle-ci n\'a pas été\n' +
'utilisée pour la classification d\'un jeu.'; 'utilisée pour la classification d\'un jeu.';
if(confirm(msg)) { if(confirm(msg)) {
$('#a').val('delete'); $('#a').val('delete');
document.defaultform.submit(); document.defaultform.submit();
} }
}); });
</script> </script>
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
{% block content %} {% block content %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<span style="font-size: 150%;" class="glyphicon glyphicon-user"></span> <span style="font-size: 150%;" class="glyphicon glyphicon-user"></span>
<span style="font-size: 150%; font-weight: bold"> <span style="font-size: 150%; font-weight: bold">
Catégories ESAR Catégories ESAR
</span> </span>
<button type="button" class="btn btn-success btn-md" style="float: right" <button type="button" class="btn btn-success btn-md" style="float: right"
data-toggle="modal" data-target="#editModal" data-id="0"> data-toggle="modal" data-target="#editModal" data-id="0">
...@@ -18,35 +18,33 @@ ...@@ -18,35 +18,33 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% include 'ihm_messages.html' %}
<div class="col-sm-12" align="center"> <div class="col-sm-12" align="center">
<table id="list_esar" style="display:none"> <table id="object_list" style="display:none">
<thead> <thead>
<tr> <tr>
<th>Label</th> <th>Label</th>
<th>Description</th> <th>Description</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for key, val in objects %} {% for key, val in objects %}
<tr> <tr>
<td> <td>{{ val.label }}</td>
{{ val.label }} <td>{{ val.name }}</td>
</td> <td align="center">
<td>
{{ val.name }}
</td>
<td align="center">
<button type="button" class="btn btn-success btn-xs" <button type="button" class="btn btn-success btn-xs"
data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}"> data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}">
<i class="glyphicon glyphicon-edit"></i> <i class="glyphicon glyphicon-edit"></i>
</button> </button>
<a onClick="if(confirm('Êtes vous sur ?')) { $('#a').val('delete'); $('i').val('{{ val.id }}'); defaultform.submit()}" href="#"> <a href="#" onClick="if(confirm('Êtes vous sur ?')) { $('#a').val('delete'); $('#i').val('{{ val.id }}'); defaultform.submit()}" href="#">
<button type="button" class="btn btn-danger btn-xs"> <button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button> <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</a> </a>
</td> </td>
</tr> </tr>
{% else %} {% else %}
<tr> <tr>
<td colspan="2"> <td colspan="2">
...@@ -54,7 +52,7 @@ ...@@ -54,7 +52,7 @@
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>
...@@ -72,7 +70,7 @@ ...@@ -72,7 +70,7 @@
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$('#list_esar').DataTable({ $('#object_list').DataTable({
"autoWidth": false, "autoWidth": false,
"fnDrawCallback": function() { "fnDrawCallback": function() {
$(this).show(); $(this).show();
...@@ -81,9 +79,9 @@ $(document).ready(function() { ...@@ -81,9 +79,9 @@ $(document).ready(function() {
$("#editModal").on("show.bs.modal", function(e) { $("#editModal").on("show.bs.modal", function(e) {
var button = $(e.relatedTarget); var button = $(e.relatedTarget);
if(button.data('id') == 0) { if(button.data('id') == 0) {
$(this).find(".modal-content").load("index.php?o=esar_categories&a=new"); $(this).find(".modal-content").load("index.php?o=" + $('#o').val() + "&a=new");
} else { } else {
$(this).find(".modal-content").load("index.php?o=esar_categories&a=edit&i=" + button.data('id')); $(this).find(".modal-content").load("index.php?o=" + $('#o').val() + "&a=edit&i=" + button.data('id'));
} }
}).on("hidden.bs.modal", function(e) { }).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty(); $(this).find(".modal-content").empty();
......
<div class="panel panel-default"> <div class="modal-content">
<div class="panel-heading"> <div class="modal-header">
<h4><!-- class="panel-title" --> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<span class="glyphicon glyphicon-user" style="margin-right: 10px" ></span> <h4 class="modal-title" id="myModalLabel">
<span class="glyphicon glyphicon-list-alt" style="margin-right: 10px;" ></span>
{% if object.id %} Méthode de paiement : {{ object.name }} {% else %} Nouvelle méthode de paiement {% endif %} {% if object.id %} Méthode de paiement : {{ object.name }} {% else %} Nouvelle méthode de paiement {% endif %}
</h4> </h4>
</div> </div>
<div class="panel-body"> <div class="modal-body">
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="name">Nom</label> <label class="control-label col-sm-2" for="name">Nom</label>
...@@ -19,16 +20,19 @@ ...@@ -19,16 +20,19 @@
<textarea id="description" name="description" class="form-control" rows="4">{{ object.description }}</textarea> <textarea id="description" name="description" class="form-control" rows="4">{{ object.description }}</textarea>
</div> </div>
</div> </div>
<div class="form-group">
<div class="col-sm-12" align="center"> </div>
<input type="button" class="btn btn-primary" id="back_button" value="&lt;&lt; Retour à la liste"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{% if object.id != 0 %} {% if object.id != 0 %}
<input type="hidden" id="paiement_method_id" value="{{ object.id }}">
<input type="submit" class="btn btn-success" id="save_button" value="Enregistrer les changements"> <input type="submit" class="btn btn-success" id="save_button" value="Enregistrer les changements">
<input type="button" class="btn btn-danger" id="delete_button" value="Supprimer"> <input type="button" class="btn btn-danger" id="delete_button" value="Supprimer">
{% else %} {% else %}
<input type="hidden" id="paiement_method_id" value="0">
<input type="button" class="btn btn-success" id="save_button" value="Créer"> <input type="button" class="btn btn-success" id="save_button" value="Créer">
{% endif %} {% endif %}
</div> </div>
</div> </div>
<!-- end of panel --> <!-- end of panel -->
...@@ -42,26 +46,22 @@ $('#save_button').click(function(){ ...@@ -42,26 +46,22 @@ $('#save_button').click(function(){
alert ("Vous n'avez pas saisi de nom !"); alert ("Vous n'avez pas saisi de nom !");
return false; return false;
} }
if($('#i').val() == 0) { if($('#paiement_method_id').val() == 0) {
$('#a').val('create'); $('#a').val('create');
} else { } else {
$('#a').val('update'); $('#i').val($('#paiement_method_id').val());
} $('#a').val('update');
}
document.defaultform.submit(); document.defaultform.submit();
return true; return true;
}); });
$('#delete_button').click(function(){ $('#delete_button').click(function(){
var msg = 'Voulez-vous réellement supprimer cette méthode de paiement ?\n' + var msg = 'Voulez-vous réellement supprimer cette méthode de paiement ?\n' +
'Cette action n\'est possible que si cette méthode n\'a pas été\n' + 'Cette action n\'est possible que si cette méthode n\'a pas été\n' +
'utilisée pour l\'inscription d\'un adhérent.'; 'utilisée pour l\'inscription d\'un adhérent.';
if(confirm(msg)) { if(confirm(msg)) {
$('#a').val('delete'); $('#a').val('delete');
document.defaultform.submit(); 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=payment_methods&a=list';
}); });
</script> </script>
{% extends "base.html" %}
{% block title %}Méthode de paiement{% endblock %}
{% block content %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<span style="font-size: 150%;" class="glyphicon glyphicon-user"></span> <span style="font-size: 150%;" class="glyphicon glyphicon-user"></span>
<span style="font-size: 150%; font-weight: bold"> <span style="font-size: 150%; font-weight: bold">
Méthodes de paiement Méthodes de paiement
</span> </span>
<span class="btn btn-success btn-md" style="float: right" id="new_button"> <button type="button" class="btn btn-success btn-md" style="float: right"
<i class="glyphicon glyphicon-plus"></i> data-toggle="modal" data-target="#editModal" data-id="0">
<span>Nouvelle méthode...</span> <i class="glyphicon glyphicon-plus"></i>
</span> <span>Nouvelle méthode...</span>
</button>
</div> </div>
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% include 'ihm_messages.html' %}
<div class="col-sm-12" align="center"> <div class="col-sm-12" align="center">
<table id="payment_methods_list" class="col-sm-12" width="100%"> <table id="object_list" style="display:none">
<thead> <thead>
<tr> <tr>
<th width="">Nom</th> <th>Nom</th>
<th>Description</th> <th>Description</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
<tbody>
{% for key, val in objects %} {% for key, val in objects %}
<tr> <tr>
<th>{{ val.name }}</th> <td>{{ val.name }}</td>
<td>{{ val.description }}</td> <td>{{ val.description }}</td>
<td> <td align="center">
<a href="index.php?o=payment_methods&a=edit&i={{ val.id }}"> <button type="button" class="btn btn-success btn-xs"
<button type="button" class="btn btn-default btn-sm"> data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span></button> <i class="glyphicon glyphicon-edit"></i>
</a> </button>
<a onClick="if(confirm('Êtes vous sur ?')) { $('#a').val('delete'); $('#i').val('{{ val.id }}'); defaultform.submit()}" href="#"> <a href="#" onClick="if(confirm('Êtes vous sur ?')) { $('#a').val('delete'); $('#i').val('{{ val.id }}'); defaultform.submit()}" href="#">
<button type="button" class="btn btn-danger btn-sm"> <button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button> <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</a> </a>
</td> </td>
</tr> </tr>
{% else %} {% else %}
<tr> <tr>
<td colspan="2"> <td colspan="2">
...@@ -45,18 +52,44 @@ ...@@ -45,18 +52,44 @@
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody>
</table> </table>
</div> </div>
<!-- end of panel --> <!-- end of panel -->
</div> </div>
</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> <script>
$(document).ready(function() { $(document).ready(function() {
$('#new_button').click(function(){ $('#object_list').DataTable({
$('#a').val('new'); "autoWidth": false,
defaultform.submit(); "fnDrawCallback": function() {
$(this).show();
}
});
$("#editModal").on("show.bs.modal", function(e) {
var button = $(e.relatedTarget);
if(button.data('id') == 0) {
$(this).find(".modal-content").load("index.php?o=" + $('#o').val() + "&a=new");
} else {
$(this).find(".modal-content").load("index.php?o=" + $('#o').val() + "&a=edit&i=" + button.data('id'));
}
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
}); });
}); });
/* FIXME : translation of the table
see https://datatables.net/plug-ins/i18n/French
*/
</script> </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