list.html 5.35 KB
Newer Older
1 2 3
{% extends "base.html" %}
{% block title %}Catalogue des jeux{% endblock %}
{% block content %}
thejoelinux's avatar
thejoelinux committed
4 5
<div class="panel panel-default">
  <div class="panel-heading">
thejoelinux's avatar
thejoelinux committed
6 7 8
    <span style="font-size: 150%;" class="glyphicon glyphicon-knight"></span>
    <span style="font-size: 150%; font-weight: bold">
        Jeux
thejoelinux's avatar
thejoelinux committed
9 10
    </span>

thejoelinux's avatar
thejoelinux committed
11 12 13 14 15
    <button type="button" class="btn btn-success btn-md" style="float: right"
        id="new_button">
        <i class="glyphicon glyphicon-plus"></i>
        <span>Nouveau jeu...</span>
    </button>
thejoelinux's avatar
thejoelinux committed
16 17 18
  </div>
  <div class="panel-body">

thejoelinux's avatar
thejoelinux committed
19 20 21 22 23 24 25 26 27 28 29 30 31
<table id="list_games"> 
    <thead>
        <tr>
            <th>Nom</th>
            <th>Age min.</th>
            <th>Age max.</th>
            <th>ESAR</th>
            <th>Etat</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
32
</table>
thejoelinux's avatar
thejoelinux committed
33 34 35

  <!-- end of panel -->
  </div>
thejoelinux's avatar
thejoelinux committed
36
</div>
thejoelinux's avatar
thejoelinux committed
37 38 39 40 41
<style>
.dataTables_length {
    padding-top: 0.25em;
}
</style>
42
<script>
43
$(document).ready(function() {
thejoelinux's avatar
thejoelinux committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    $.fn.dataTableExt.afnFiltering.push(
        function( oSettings, aData, iDataIndex ) {
            var row = oSettings.aoData[iDataIndex].nTr;
            var show = $(".toggle_row_display").val();
            var archived = oSettings.aoData[iDataIndex]._aData.archived;
            var borrowed = oSettings.aoData[iDataIndex]._aData.loan_status;

            if(show === "all") {
                return (archived != 1);
            } else if(show === "archived") {
                return (archived == 1);
            } else if(show === "borrowed") {
                return (borrowed !== null);
            } else {
                return true;
            }
        }
    );

    var table = $('#list_games').DataTable({
        "autoWidth": false,
        "dom": '<"filter_comp">frtlp',
        "ajax": "api.php?o=games&a=list&dt_format=1",
67
        "language": {
thejoelinux's avatar
thejoelinux committed
68
            "url": "/cdn/js/jquery/datatables/1.10.9/dataTables.french.json"
thejoelinux's avatar
thejoelinux committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
        },
        "columnDefs": [
            {
                "targets": [1,2],
                className: "text-center"
            },{
                "targets": [1,2,3],
                "defaultContent": ''
            },{
                "targets": 4,
                "defaultContent": 'Disponible',
                "render": function(data, type, row) {
                     if(row.loan_status !== null) {
                         return 'Emprunté';
                     }
                }
            },{
                "targets": 5, // action
                "render": function(data, type, row) {
                    var html = '<button type="button" class="btn btn-primary btn-xs edit_button" '
                        + ' data-toggle="tooltip" title="Editer" '
                        + ' data-id="' + row.id + '"><i class="glyphicon glyphicon-edit"></i></button> ';
                    if(row.loan_status === null) {
                        var color = 'success';
                        var icon = 'open';
                        var help = 'Désarchiver';
                        if(row.archived !== "1") {
                            color = 'danger';
                            icon = 'close';
                            help = 'Archiver le jeu';
                        }
                        return html + '<button data-toggle="tooltip" title="' + help + '" '
                            + ' type="button" class="btn btn-' + color + ' btn-xs toggle_archive_button" '
                            + ' data-id="' + row.id + '"><i class="glyphicon glyphicon-folder-' + icon + '"></i></button>';
                    } else {
                        return html;
                    }
                }
            }
        ],
        "columns": [
            {"data": "name"},
            {"data": "age_min"},
            {"data": "age_max"},
            {"data": "label"},
            {"data": "loan_status"},
            {"data": null}

        ],
        "fnDrawCallback": function() {
            $(this).show();

            $('.toggle_archive_button').on("click", function(e) {
                var button = $(e.currentTarget);
                $.ajax({url: 'api.php?o=games&a=toggle_archive&i=' + button.data('id'),
                    success: function(output) {
                        table.ajax.reload(null, false);
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert('Erreur lors de l\'archivage');
                        return false;
                    }
                });
            });

            $('.edit_button').on("click", function(e) {
                var button = $(e.currentTarget);
                window.location.href='index.php?o=games&a=edit&i=' + button.data('id');
            });

            if($("div.filter_comp").html() === "") {
                $("div.filter_comp").html('<select class="toggle_row_display pull-left" style="margin-top: 5px">'
                                + '<option value="all">Tous sauf archivés</option>'
                                + '<option value="borrowed">Seulement les empruntés</option>'
                                + '<option value="archived">Seulement les archivés</option></select>');

                $(".toggle_row_display").on("change", function() {
                    table.draw();
                });
            }
149
        }
thejoelinux's avatar
thejoelinux committed
150
    });
thejoelinux's avatar
thejoelinux committed
151
    
thejoelinux's avatar
thejoelinux committed
152
    $('#new_button').click(function(){
thejoelinux's avatar
thejoelinux committed
153
        window.location.href='index.php?o=games&a=new';
thejoelinux's avatar
thejoelinux committed
154
    });
155

thejoelinux's avatar
thejoelinux committed
156

157
});
158
</script>
159
{% endblock %}