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

corrections... etc.

parent 848e0fd6
......@@ -15,8 +15,10 @@ class Role extends Record {
/* fetch ALL the roles, with the selected field = user_id if the
user has the role, NULL otherwise.
Be sure to use user->has_role to check if a user has a role.
FIXME : i can't see the point of doing that
I can't see the point of doing that
Back to a better solution but we'll see that next
OK ! Now i see. I need a list of to modify a user and give him more roles
What i do now is another function for that.
*/
public static function fetch_user_roles($user_id) {
$roles = array();
......@@ -33,6 +35,16 @@ class Role extends Record {
return $roles;
}
public static function fetch_roles_for_user($user_id) {
$roles = array();
// SELECT user_roles roles
$sql = " SELECT r.id, r.name, r.description, ur.user_id AS selected
FROM roles r
LEFT JOIN user_roles ur ON r.id = ur.role_id AND ur.user_id = ".$user_id;
$GLOBALS["data"]->select($sql, $roles, "Role");
return $roles;
}
public static function fetch_all(&$roles) {
$roles = array();
// SQL SELECT roles
......
......@@ -115,5 +115,3 @@ class User extends Record {
return $GLOBALS["data"]->update($sql);
}
}
?>
......@@ -93,6 +93,7 @@ class MembersController extends AppController {
if($member->id != 0) {
$member->fetch_subscriptions();
if($member->has_valid_subscription()) {
$_REQUEST["member_id"] = $_REQUEST["i"];
$member->create_loan();
$member->fetch_loans();
} // no error message - normally you can't do this
......
......@@ -15,7 +15,7 @@ class RolesController extends AppController {
function _user_list() { // for API or HTML
$format = (preg_match("/api.php/", $_SERVER["REQUEST_URI"])) ? "json" : "html";
try {
$roles = Role::fetch_user_roles($_REQUEST["i"]);
$roles = Role::fetch_roles_for_user($_REQUEST["i"]);
if($format == "json") {
echo json_encode($roles);
exit(); // no further rendering needed
......
......@@ -25,25 +25,6 @@ $(document).ready(function () {
}
});
$('#search-games-for-loans .typeahead').typeahead({
highlight: true
},
{
name: 'games',
display: 'name',
source: new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: { url : 'api.php?o=games&a=name_list&filter=available',
cache: false }
})
}).bind('typeahead:selected', function(obj, datum, name) {
if(typeof datum.id !== 'undefined') {
console.log(datum);
$('#game_id').val(datum.id);
}
});
$('#search-all .typeahead').typeahead({
highlight: true
},
......
......@@ -64,10 +64,10 @@
$('#esar_category_id').html('<option value="">Loading...</option>');
$.ajax({url: 'api.php?o=esar_categories&a=list',
success: function(output) {
var html = '';
var html = '<option value="0">Non définie</option>';
$.each(output, function(key, val){
html = html + '<option value="' + val.id + '"'
+ (val.id == {{ game.esar_category_id }} ? ' selected ' : '' ) + '>'
+ (val.id == {{ game.esar_category_id ?: 0 }} ? ' selected ' : '' ) + '>'
+ val.label + ' - ' + val.name + '</option>';
});
$('#esar_category_id').html(html);
......
......@@ -55,10 +55,7 @@
</div>
{% if object.id %}
<div class="form-group">
<div class="control-label col-sm-6">
{{ object.game_name }}
</div>
<div class="control-label col-sm-6">
<div class="control-label col-sm-12">
Créé le : {{ object.created_at }}
{% if object.created_at != object.updated_at %}
/ Mis-à-jour le {{ object.updated_at }}
......@@ -68,14 +65,16 @@
{% else %}
<div class="form-group">
<label class="control-label col-sm-2" for="game_id">Jeu</label>
<div class="col-sm-4">
<div class="col-sm-10">
<input type="hidden" name="game_id" id="game_id" value="">
<div id="search-games-for-loans" >
<input class="typeahead form-control" type="text" placeholder="Jeu...">
</div>
</div>
<div class="control-label col-sm-6">
Si la date de retour est vide, elle sera positionnée à 21 jours plus tard.
</div>
<div class="form-group">
<div class="control-label col-sm-12">
Si la date de retour est identique, elle sera positionnée à 21 jours plus tard.
</div>
</div>
{% endif %}
......@@ -83,11 +82,11 @@
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{% if object.id %}
<input type="hidden" name="load_id" id="loan_id" value="{{ object.id }}">
<input type="hidden" name="loan_id" id="loan_id" value="{{ object.id }}">
<input type="button" class="btn btn-success" id="save_button" value="Enregistrer les changements">
<input type="button" class="btn btn-danger" id="delete_button" value="Supprimer">
{% else %}
<input type="hidden" name="load_id" id="loan_id" value="0">
<input type="hidden" name="loan_id" id="loan_id" value="0">
<input type="button" class="btn btn-success" id="save_button" value="Créer">
{% endif %}
</div>
......@@ -96,6 +95,24 @@
<script>
// buttons events
$(document).ready(function () {
$('#search-games-for-loans .typeahead').typeahead({
highlight: true
},
{
name: 'games',
display: 'name',
source: new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: { url : 'api.php?o=games&a=name_list&filter=available',
cache: false }
})
}).bind('typeahead:selected', function(obj, datum, name) {
if(typeof datum.id !== 'undefined') {
console.log(datum);
$('#game_id').val(datum.id);
}
});
$('#save_button').click(function(){
if(document.defaultform.start_date.value == 0) {
alert ("Vous n'avez pas saisi de date de début !");
......@@ -133,7 +150,7 @@ $(document).ready(function () {
return myXhr;
},
success: function(){
if(state) {
if(state == 1) {
alert('Ce jeu est noté comme restitué aujourd\'hui.');
} else {
alert('Ce jeu est noté comme non restitué aujourd\'hui.');
......
......@@ -105,7 +105,11 @@ $(document).ready(function () {
return myXhr;
},
success: function(){
alert('Le jeu est noté comme restitué aujourd\'hui.');
if(state == 1) {
alert('Le jeu est noté comme restitué aujourd\'hui.');
} else {
alert('Le jeu est noté comme non restitué aujourd\'hui.');
}
},
error: function(){
alert('Une erreur a eu lieu lors de la restitution de ce jeu.');
......
<div class="panel panel-default">
<div class="panel-heading">
<h4><!-- class="panel-title" -->
<span class="glyphicon glyphicon-th-list" style="margin-right: 10px" ></span>
{% if object.id %} {{ object.name }} {% else %} Nouvel utilisateur {% endif %}
</h4>
</div>
<div class="panel-body">
{% extends 'modal.html' %}
{% block modal_title %}
{% if object.id %} {{ object.name }} {% else %} Nouvel utilisateur {% endif %}
{% endblock %}
{% block modal_body %}
<div class="form-group">
<label class="control-label col-sm-2" for="name">Nom</label>
<div class="col-sm-4">
......@@ -50,21 +47,6 @@
<input type="checkbox" id="active_cbx" class="form-control" {{ object.active ? "checked" }}/>
</div>
</div>
<div class="form-group">
<div class="col-sm-12" align="center">
<input type="button" class="btn btn-primary" id="back_button" value="&lt;&lt; Retour à la liste">
{% if object.id %}
<input type="button" class="btn btn-success" id="save_button" value="Enregistrer les changements">
<input type="button" class="btn btn-danger" id="delete_button" value="Supprimer">
{% else %}
<input type="button" class="btn btn-success" id="save_button" value="Créer">
{% endif %}
</div>
</div>
<!-- end of panel -->
</div>
</div>
<script>
$(document).ready(function () {
......@@ -72,35 +54,10 @@ $(document).ready(function () {
$('#active_cbx').on('switchChange.bootstrapSwitch', function(event, state) {
$('#active').val(state == true ? 1 : 0);
});
// buttons events
$('#save_button').click(function(){
if(document.defaultform.name.value == 0) {
alert ("Vous n'avez pas saisi de nom !");
return false;
}
// go to the members controllers, as this action should display
// the list of the subscriptions for the current user
$('#o').val('users');
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 utilisateur ?\n' +
'Cette action n\'est possible qu\'en cas d\'erreur de saisie.\n';
if(confirm(msg)) {
$('#a').val('delete_user');
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=users&a=list';
});
});
</script>
{% endblock %}
{% block javascript_msg %}
var msg = 'Voulez-vous réellement supprimer un utilisateur ?\n' +
'Cette action n\'est possible qu\'en cas d\'erreur de saisie.\n';
{% endblock %}
......@@ -35,8 +35,14 @@
<tr>
<th>{{ val.name }}</th>
<td>{{ val.email }}</td>
<td><input type="checkbox" id="active_{{ val.id }}" name="active_{{ val.id }}" class="form-control active_cbx"
data-switch-with-ajax {{ val.active ? " checked " }}?></td>
<td>
{% if val.id != global['logged_user'].id %}
<input type="checkbox" id="active_{{ val.id }}" name="active_{{ val.id }}" class="form-control active_cbx"
data-switch-with-ajax {{ val.active ? " checked " }}?>
{% else %}
Utiliseur courant
{% endif %}
</td>
<td align="center">
<button type="button" class="btn btn-success btn-xs"
data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}">
......
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