Bug 32786: Display admin header on curbside pickup admin
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / curbside_pickup.tt
1 [% USE raw %]
2 [% USE KohaSpan %]
3 [% USE Koha %]
4 [% USE Asset %]
5 [% SET footerjs = 1 %]
6 [% USE TablesSettings %]
7 [% PROCESS 'i18n.inc' %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 <title>
10     Curbside pickup &rsaquo; Administration &rsaquo; Koha
11 </title>
12 [% INCLUDE 'doc-head-close.inc' %]
13 <style>
14     .pickup-slot {
15         border: 2px solid #b9d8d9;
16         padding: 0 .1em;
17         margin: 0 .1em;
18     }
19 </style>
20 </head>
21
22 <body id="admin_curbside_pickup" class="admin">
23 [% WRAPPER 'header.inc' %]
24     [% INCLUDE 'prefs-admin-search.inc' %]
25 [% END %]
26
27 [% USE format_minutes = format('%02d') %]
28 [% MACRO minutes_format BLOCK %][% IF m != "" %][% format_minutes(m) | html %][% END %][% END %]
29 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
30     <ol>
31         <li>
32             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
33         </li>
34         <li>
35             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
36         </li>
37
38         <li>
39             <a href="#" aria-current="page">
40                 Curbside pickup
41             </a>
42         </li>
43     </ol>
44 </nav>
45
46 <div class="main container-fluid">
47     <div class="row">
48         <div class="col-sm-10 col-sm-push-2">
49             <main>
50
51 [% FOR m IN messages %]
52     <div class="dialog [% m.type | html %]">
53         [% SWITCH m.code %]
54         [% CASE %]
55             <span>[% m.code | html %]</span>
56         [% END %]
57     </div>
58 [% END %]
59
60 [% IF op == 'list' %]
61
62     <h1>Curbside pickup configuration</h1>
63
64     [% UNLESS Koha.Preference('CurbsidePickup') %]
65         [% SET pref_CurbsidePickup_link = '<a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=CurbsidePickup">CurbsidePickup</a>' %]
66         <div class="dialog message">The [% pref_CurbsidePickup_link | $raw | $KohaSpan %] preference is not enabled, do not forget to enable it to turn the feature on.</div>
67     [% END %]
68     <form method="post" class="form">
69         <div id="curbside_pickup_tabs" class="toptabs">
70             <ul class="nav nav-tabs" role="tablist">
71                 [% FOREACH l IN libraries %]
72                     [% IF loop.first %]
73                     <li role="presentation" class="active">
74                     [% ELSE %]
75                     <li role="presentation">
76                     [% END %]
77                         <a href="#conf-[% l.branchcode | uri %]" aria-controls="conf-[% l.branchcode | html %]" role="tab" data-toggle="tab">[% l.branchname | html %]</a>
78                     </li>
79                 [% END %]
80             </ul>
81
82             <div class="tab-content">
83                 [% FOREACH l IN libraries %]
84                     [% SET branchcode = l.branchcode %]
85                     [% IF loop.first %]
86                     <div id="conf-[% l.branchcode | html %]" role="tabpanel" class="tab-pane active">
87                     [% ELSE %]
88                     <div id="conf-[% l.branchcode | html %]" role="tabpanel" class="tab-pane">
89                     [% END %]
90                         <fieldset class="rows" style="float: none;">
91                             <ol>
92                                 <li>
93                                     <label for="enable-[% l.branchcode | html %]">Enable: </label>
94                                     [% IF policies.$branchcode.enabled %]
95                                         <input name="enable-[% l.branchcode | html %]" id="enable-[% l.branchcode | html %]" value="1" type="checkbox" checked>
96                                     [% ELSE %]
97                                         <input name="enable-[% l.branchcode | html %]" id="enable-[% l.branchcode | html %]" value="1" type="checkbox">
98                                     [% END %]
99                                     <span class="hint">Enable curbside pickup.<span>
100                                 </li>
101
102                                 <li>
103                                     <label for="interval-[% l.branchcode | html %]">Pickup interval: </label>
104                                     <input name="interval-[% l.branchcode | html %]" id="interval-[% l.branchcode | html %]" value="[% policies.$branchcode.pickup_interval | html %]" type="text">
105                                     <span class="hint">Number of minutes each curbside pickup interaction will take.</span>
106                                 </li>
107
108                                 <li>
109                                     <label for="max-per-interval-[% l.branchcode | html %]">Maximum patrons per interval: </label>
110                                     <input name="max-per-interval-[% l.branchcode | html %]" id="max-per-interval-[% l.branchcode | html %]" value="[% policies.$branchcode.patrons_per_interval | html %]" type="text">
111                                     <span class="hint">Maximum number of simultaneous pickups per interval.</span>
112                                 </li>
113
114                                 <li>
115                                     <label for="patron-scheduled-[% l.branchcode | html %]">Patron-scheduled pickup: </label>
116                                     [% IF policies.$branchcode.patron_scheduled_pickup %]
117                                         <input name="patron-scheduled-[% l.branchcode | html %]" id="patron-scheduled-[% l.branchcode | html %]" value="1" type="checkbox" checked>
118                                     [% ELSE %]
119                                         <input name="patron-scheduled-[% l.branchcode | html %]" id="patron-scheduled-[% l.branchcode | html %]" value="1" type="checkbox">
120                                     [% END %]
121                                     <span class="hint">Enable patrons to schedule their own curbside pickups.</span>
122                                 </li>
123
124                                 <li>
125                                     <label for="enable-waiting-holds-only-[% l.branchcode | html %]">Enable for waiting holds only: </label>
126                                     [% IF policies.$branchcode.enable_waiting_holds_only %]
127                                         <input name="enable-waiting-holds-only-[% l.branchcode | html %]" id="enable-waiting-holds-only-[% l.branchcode | html %]" value="1" type="checkbox" checked>
128                                     [% ELSE %]
129                                         <input name="enable-waiting-holds-only-[% l.branchcode | html %]" id="enable-waiting-holds-only-[% l.branchcode | html %]" value="1" type="checkbox">
130                                     [% END %]
131                                     <span class="hint">Enable only if the patron has waiting holds.</span>
132                                 </li>
133                             </ol>
134                         </fieldset>
135
136                         <fieldset class="rows" style="float: none;">
137                             <legend>Curbside pickup hours</legend>
138
139                             <em>Times should be in 24-hour format (00:00 to 23:59).</em>
140
141                             <ol class="pickup_hours"></ol>
142
143                             <ol>
144                                 <li>
145                                     <label>New slot:</label>
146                                     [% days = { "0" = t("Sunday"), "1" = t("Monday"), "2" = t("Tuesday"), "3" = t("Wednesday"), "4" = t("Thursday"), "5" = t("Friday"), "6" = t("Saturday") } %]
147                                     [% SET CalendarFirstDayOfWeek = Koha.Preference("CalendarFirstDayOfWeek") %]
148                                     <div>
149                                         <select id="day-[% l.branchcode | html %]">
150                                             [% FOR i IN [0, 1, 2, 3, 4, 5, 6] %]
151                                                 [% SET d = ( CalendarFirstDayOfWeek + i ) % 7 %]
152                                                 <option value="[% d | html %]">[% days.$d | html %]</option>
153                                             [% END %]
154                                         </select>
155                                             <span>
156                                                 From <input type="text" size="5" class="noEnterSubmit" id="new-start-[% l.branchcode | html %]" placeholder="00:00" />
157                                                 to <input type="text" size="5" class="noEnterSubmit" id="new-end-[% l.branchcode | html %]" placeholder="23:55" />
158                                             </span>
159                                         <input type="button" class="add-new-slot" data-branchcode="[% l.branchcode | html %]" value="Add" />
160                                         <span id="invalid_slot_warning" style="display:none;">Invalid format for this new slot, must be '00:00 to 23:59'.</span>
161                                     </div>
162                                 </li>
163
164                             </ol>
165                         </fieldset>
166                     </div>
167                 [% END %]
168             </div>
169         </div>
170
171         <input type="hidden" name="op" value="save" />
172
173         <fieldset class="action">
174             <input type="submit" class="btn btn-primary" value="Save configuration" />
175         </fieldset>
176     </form>
177 [% END %]
178
179             </main>
180         </div> <!-- /.col-sm-10.col-sm-push-2 -->
181
182         <div class="col-sm-2 col-sm-pull-10">
183             <aside>
184                 [% INCLUDE 'admin-menu.inc' %]
185             </aside>
186         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
187      </div> <!-- /.row -->
188
189 [% MACRO jsinclude BLOCK %]
190     [% Asset.js("js/admin-menu.js") | $raw %]
191     <script>
192
193         let opening_slots = {};
194         let slots;
195         [% FOR l IN libraries %]
196             [% SET branchcode = l.branchcode %]
197             slots = [];
198             [% FOR p IN policies.$branchcode.opening_slots %]
199                 slots.push('%s-%s-%s'.format("[% p.day | html %]", format_hhmm("[% p.start_hour | html %]:[% p.start_minute | html %]"), format_hhmm("[% p.end_hour | html %]:[% p.end_minute | html %]")));
200             [% END %]
201             opening_slots["[% l.branchcode | html %]"] = slots;
202         [% END %]
203
204         function format_hhmm(hhmm){
205             let hh, mm;
206             [ hh, mm ] = hhmm.split(':');
207             return String(hh).padStart(2, '0') + ':' + String(mm).padStart(2, '0');
208         }
209         function format_slot(slot){
210             let day, start, end;
211             [ day, start, end ] = slot.split("-");
212             return format_hhmm(start) + _(" to ") + format_hhmm(end);
213         }
214         function delete_slot(node, branchcode){
215             let slot = $(node).find('input').val();
216             opening_slots[branchcode] = $.grep(opening_slots[branchcode], function(elt, index) {
217                 return elt !== slot;
218             });
219             refresh_pickup_hours(branchcode);
220         }
221         function refresh_pickup_hours(branchcode) {
222             let slots_per_day = {};
223             opening_slots[branchcode].forEach(function(slot){
224                 let day, start, end;
225                 [ day, start, end ] = slot.split("-");
226                 if(!slots_per_day[day]) slots_per_day[day] = [];
227                 slots_per_day[day].push(slot);
228             });
229
230             $("#conf-"+branchcode).find(".pickup_hours li").remove();
231
232             const CalendarFirstDayOfWeek = [% Koha.Preference("CalendarFirstDayOfWeek") || 0 | html %];
233             [0, 1, 2, 3, 4, 5, 6]
234                .map(i => ( CalendarFirstDayOfWeek + i ) % 7)
235                .filter(d => d in slots_per_day)
236                .map( day => {
237                     let li_node = $('<li><label>'+get_day_lib(day)+'<label></li>');
238                     slots_per_day[day].forEach(function(slot) {
239                         let span_node = $('<span class="pickup-slot"></span>');
240                         span_node.append('<input type="hidden" name="pickup-slot-'+branchcode+'" value="'+slot+'"/>');
241                         span_node.append('<span>'+format_slot(slot)+'</span>');
242
243                         let delete_link = $('<a href="#" on> <i class="fa fa-trash" aria-hidden="true" title="%s"></i>'.format(_("Remove this slot"))).on('click', function(e){ e.preventDefault(); delete_slot($(this).closest('li'), branchcode); });
244                         span_node.append(delete_link);
245
246                         span_node.appendTo(li_node);
247                     });
248                     li_node.appendTo($("#conf-"+branchcode).find(".pickup_hours"));
249                 });
250         }
251         function get_day_lib(day){
252             let lib;
253             switch(day){
254             case 0:
255                 lib = _("Sunday");
256                 break;
257             case 1:
258                 lib = _("Monday");
259                 break;
260             case 2:
261                 lib = _("Tuesday");
262                 break;
263             case 3:
264                 lib = _("Wednesday");
265                 break;
266             case 4:
267                 lib = _("Thursday");
268                 break;
269             case 5:
270                 lib = _("Friday");
271                 break;
272             case 6:
273                 lib = _("Saturday");
274                 break;
275             }
276             return lib;
277         }
278
279         $(document).ready(function(){
280             [% FOR l IN libraries %]
281                 refresh_pickup_hours("[% l.branchcode | html %]");
282             [% END %]
283
284             $(".add-new-slot").on("click", function(){
285                 let branchcode = $(this).data('branchcode');
286                 let day = $("#day-" + branchcode).val();
287                 let start = $("#new-start-" + branchcode).val();
288                 let end = $("#new-end-" + branchcode).val();
289
290                 let start_hour, start_minute, end_hour, end_minute;
291                 [ start_hour, start_minute ] = start.split(":");
292                 [ end_hour, end_minute ] = end.split(":");
293                 if ( start_hour === undefined
294                   || start_minute === undefined
295                   || end_hour === undefined
296                   || end_minute === undefined
297                   || isNaN(parseInt(start_hour))
298                   || isNaN(parseInt(end_hour))
299                   || isNaN(parseInt(start_minute))
300                   || isNaN(parseInt(end_minute))
301                   || start_hour > 23 || start_minute > 59
302                   || end_hour > 23 || end_minute > 59
303                   ) {
304                     $("#invalid_slot_warning").show();
305                     return;
306                 } else {
307                     $("#invalid_slot_warning").hide();
308                 }
309
310                 let new_slot = day + '-' + start + '-' + end;
311                 if ( opening_slots[branchcode].indexOf(new_slot) < 0 )
312                     opening_slots[branchcode].push(new_slot);
313
314                 refresh_pickup_hours(branchcode);
315             })
316         });
317     </script>
318 [% END %]
319 [% INCLUDE 'intranet-bottom.inc' %]