Bug 34945: Remove the use of event attributes from OPAC clubs tab
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / modules / clubs / clubs-tab.tt
1 [% USE KohaDates %]
2
3 [% IF enrollments %]
4
5     <h2>Clubs currently enrolled in</h2>
6
7     <table id="clubs-table-enrolled" class="table table-bordered table-striped">
8         <caption class="sr-only">Clubs</caption>
9         <thead>
10             <tr>
11                 <th class="all">Name</th>
12                 <th>Description</th>
13                 <th>Date enrolled</th>
14                 <th class="NoSort all">&nbsp;</th>
15                 <th></th>
16             </tr>
17         </thead>
18
19         <tbody>
20             [% FOREACH e IN enrollments %]
21                 <tr>
22                     <td>[% e.club.name | html %]</td>
23                     <td>[% e.club.description | html %]</td>
24                     <td>[% e.date_enrolled | $KohaDates %]</td>
25                     <td>
26                         [% IF e.club.club_template.is_enrollable_from_opac %]
27                             <button class="btn btn-sm btn-danger cancel_enrollment cancel_enrollment">
28                                 <i class="fa fa-remove" aria-hidden="true"></i> Cancel enrollment
29                             </button>
30                         [% ELSE %]
31                             Contact your library to be disenrolled from this club.
32                         [% END %]
33                     </td>
34                     <td></td>
35                 </tr>
36             [% END %]
37         </tbody>
38     </table>
39 [% END %]
40
41 [% IF clubs %]
42
43     <h2>Clubs you can enroll in</h2>
44
45     <table id="clubs-table-unenrolled" class="table table-bordered table-striped">
46         <thead>
47             <tr>
48                 <th class="all">Name</th>
49                 <th>Description</th>
50                 <th class="NoSort all">&nbsp;</th>
51                 <th></th>
52             </tr>
53         </thead>
54
55         <tbody>
56             [% FOREACH c IN clubs %]
57                 <tr>
58                     <td>[% c.name | html %]</td>
59                     <td>[% c.description | html %]</td>
60                     <td>
61                         [% IF !c.club_template.is_email_required || ( c.club_template.is_email_required && borrower.first_valid_email_address ) %]
62                             <button class="btn btn-sm btn-primary load_enrollment" data-id="[% c.id | html%]">
63                                 <i class="fa fa-plus" aria-hidden="true"></i> Enroll
64                             </button>
65                         [% ELSE %]
66                             <span class="hint">You must have an email address to enroll</span>
67                         [% END %]
68                     </td>
69                     <td></td>
70                 </tr>
71             [% END %]
72         </tbody>
73     </table>
74 [% END %]
75
76 <script>
77 function loadEnrollmentForm( id ) {
78     $("body").css("cursor", "progress");
79     $('#opac-user-clubs').load('/cgi-bin/koha/clubs/enroll.pl?borrowernumber=[% borrower.borrowernumber | html %]&id=' + id, function() {
80         $("body").css("cursor", "default");
81     });
82
83     return false;
84 }
85
86 function cancelEnrollment( id ) {
87     $("body").css("cursor", "progress");
88     $.ajax({
89         type: "POST",
90         url: '/cgi-bin/koha/svc/club/cancel_enrollment',
91         data: { id: id },
92         success: function( data ) {
93             if ( data.success ) {
94                 $('#opac-user-clubs').load('/cgi-bin/koha/clubs/clubs-tab.pl?borrowernumber=[% borrower.borrowernumber | html %]', function() {
95                     $("body").css("cursor", "default");
96                 });
97             } else {
98                 alert(_("Unable to cancel enrollment!"));
99             }
100         },
101         dataType: 'json'
102     });
103     return false;
104 }
105
106     var Tables = $("#clubs-table-enrolled,#clubs-table-unenrolled");
107     Tables.each(function(){
108         $(this).dataTable($.extend(true, {}, dataTablesDefaults, {
109             "searching": false,
110             "paging": false,
111             "info": false,
112             "autoWidth": false,
113             "responsive": {
114                 "details": { "type": "column", "target": -1 }
115             },
116             "columnDefs": [
117                 { "orderable": false, "searchable": false, "targets": [ 'NoSort' ] },
118                 { "className": "dtr-control", "orderable": false, "targets": -1 },
119             ],
120         }));
121     });
122
123     $(".cancel_enrollment").on("click", function(e){
124         e.preventDefault();
125         let clubid = $(this).data("id");
126         cancelEnrollment( clubid );
127     });
128
129     $(".load_enrollment").on("click", function(e){
130         e.preventDefault();
131         let clubid = $(this).data("id");
132         loadEnrollmentForm( clubid );
133     });
134
135
136 </script>