Bug 28034: Make club enrollment tables in to DataTables
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / clubs / patron-clubs-tab.tt
1 [% USE KohaDates %]
2
3 [% IF enrollments %]
4     <h4>Clubs currently enrolled in</h4>
5
6     <table id="table_clubenrollments">
7         <thead>
8             <tr>
9                 <th>Name</th>
10                 <th>Description</th>
11                 <th>Date enrolled</th>
12                 [% IF CAN_user_clubs_enroll %]<th class="NoSort">Actions</th>[% END %]
13             </tr>
14         </thead>
15
16         <tbody>
17             [% FOREACH e IN enrollments %]
18                 <tr>
19                     <td>[% e.club.name | html %]</td>
20                     <td>[% e.club.description | html %]</td>
21                     <td>[% e.date_enrolled | $KohaDates %]</td>
22                     [% IF CAN_user_clubs_enroll %]
23                         <td>
24                             <button class="btn btn-xs btn-default" onclick="cancelEnrollment( [% e.id | html %] )">
25                                 <i class="fa fa-remove"></i> Cancel enrollment
26                             </button>
27                         </td>
28                     [% END %]
29                 </tr>
30             [% END %]
31         </tbody>
32     </table>
33 [% END %]
34
35 [% IF clubs %]
36
37     <h4>Clubs not enrolled in</h4>
38
39     <table id="table_clubnoenrollmemnts">
40         <thead>
41             <tr>
42                 <th>Name</th>
43                 <th>Description</th>
44                 [% IF CAN_user_clubs_enroll %]<th class="NoSort">Actions</th>[% END %]
45             </tr>
46         </thead>
47
48         <tbody>
49             [% FOREACH c IN clubs %]
50                 <tr>
51                     <td>[% c.name | html %]</td>
52                     <td>[% c.description | html %]</td>
53                     [% IF CAN_user_clubs_enroll %]
54                         <td class="action">
55                             <button class="btn btn-xs btn-default" onclick="loadEnrollmentForm([% c.id | html %])">
56                                 <i class="fa fa-plus"></i> Enroll
57                             </button>
58                         </td>
59                     [% END %]
60                 </tr>
61             [% END %]
62         </tbody>
63     </table>
64 [% END %]
65
66 <script>
67 $("#table_clubnoenrollmemnts, #table_clubenrollments").dataTable($.extend(true, {}, dataTablesDefaults, {
68     "columnDefs": [
69         { 'sortable': false, 'targets': [ 'NoSort' ] }
70     ],
71     paginate: true
72 }));
73
74 [% IF CAN_user_clubs_enroll %]
75 function loadEnrollmentForm( id ) {
76     $("body").css("cursor", "progress");
77     $('#clubs-tab').load('/cgi-bin/koha/clubs/patron-enroll.pl?borrowernumber=[% borrowernumber | html %]&id=' + id, function() {
78         $("body").css("cursor", "default");
79     });
80
81     return false;
82 }
83
84 function cancelEnrollment( id ) {
85     $("body").css("cursor", "progress");
86     $.ajax({
87         type: "POST",
88         url: '/cgi-bin/koha/svc/club/cancel_enrollment',
89         data: { id: id },
90         success: function( data ) {
91             if ( data.success ) {
92                 $('#clubs-tab').load('/cgi-bin/koha/clubs/patron-clubs-tab.pl?borrowernumber=[% borrowernumber | html %]', function() {
93                     $("body").css("cursor", "default");
94                 });
95             } else {
96                 alert(_("Unable to cancel enrollment!"));
97             }
98         },
99         dataType: 'json'
100     });
101     return false;
102 }
103 </script>
104 [% END %]