Bug 32200: Add page-section to checkout notes page
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / circ / offline.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% SET footerjs = 1 %]
5 <!DOCTYPE html>
6 [% IF (AllowOfflineCirculation) %]
7 [% SET manifestattr = 'manifest="/cgi-bin/koha/circ/offline-mf.pl"' %]
8 [% END %]
9 [% IF ( bidi && AllowOfflineCirculation ) %]<html lang="[% lang | html %]" dir="[% bidi | html %]" manifest="/cgi-bin/koha/circ/offline-mf.pl">
10 [% ELSIF ( bidi ) %]<html lang="[% lang | html %]" dir="[% bidi | html %]">
11 [% ELSIF ( AllowOfflineCirculation ) %]<html lang="[% lang | html %]" manifest="/cgi-bin/koha/circ/offline-mf.pl">
12 [% ELSE %]<html lang="[% lang | html %]">[% END %]
13 <head>
14 <title>Circulation &rsaquo; Koha</title>
15 [% INCLUDE 'doc-head-close.inc' %]
16 </head>
17
18 <body id="circ_offline" class="circ">
19 [% WRAPPER 'header.inc' %]
20     [% INCLUDE 'circ-search.inc' %]
21 [% END %]
22 <div class="loading-overlay" style="display: none;">
23     <div>Downloading records, please wait...</div>
24 </div>
25
26
27 [% WRAPPER 'sub-header.inc' %]
28 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
29     <ol>
30         <li>
31             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
32         </li>
33         <li>
34             <a id="go-to-home" href="#offline-home" aria-current="page">Offline circulation</a>
35         </li>
36     </ol>
37 </nav>
38 [% END %]
39
40 <div class="main container-fluid">
41     <div class="row">
42         <div class="col-sm-10 col-sm-push-2">
43             <main>
44                 <h1>Offline circulation</h1>
45
46             <audio id="alert_sound" src="[% interface | html %]/prog/sound/critical.ogg" preload="auto"></audio>
47             <audio id="success_sound" src="[% interface | html %]/prog/sound/beep.ogg" preload="auto"></audio>
48
49             <div id="alerts"></div>
50
51             [% UNLESS (AllowOfflineCirculation) %]
52                 <div id="noofflinecircwarning" class="dialog alert">
53                     <p><strong>Warning:</strong> Offline circulation has been disabled. You may continue and record transactions, but patron and item information will not be available.</p>
54                 </div>
55             [% END %]
56
57             <div id="offline-home" class="offline-home">
58                 <div class="row">
59                     <div class="col-sm-6">
60                         <ul>
61                             <li><a id="go-to-circ" href="#offline-circulation">Check out</a></li>
62                             <li><a id="go-to-returns" href="#offline-returns">Check in</a></li>
63                         </ul>
64                     </div>
65
66                     <div class="col-sm-6">
67                         <p><strong>Note:</strong> You must be online to use these options.</p>
68                         <ul>
69                             <li><a id="go-to-sync" href="#offline-sync">Synchronize</a></li>
70                             <li><a id="go-to-pending" href="/cgi-bin/koha/offline_circ/list.pl">Pending offline circulation actions</a>
71                         </ul>
72                     </div>
73                 </div>
74             </div>
75
76             <div id="offline-sync" style="display: none;" class="offline-sync">
77                 <div id="toolbar" class="btn-toolbar">
78                     [% IF (AllowOfflineCirculation) %]
79                         <a href="#" id="download-records" class="btn btn-default"><i class="fa fa-arrow-down"></i> Download records</a>
80                     [% END %]
81                     <a href="#" id="upload-transactions" class="btn btn-default"><i class="fa fa-arrow-up"></i> Upload transactions</a>
82                 </div>
83                 <h1>Offline circulation</h1>
84                 <div class="row">
85                     <div class="col-sm-6">
86                         <div id="download-message">
87                             In order for offline circulation to work on this computer,
88                             your library's records must be up-to-date on this computer:
89                             <ul>
90                                 <li>Patron records were last synced on: <span id="patron-timestamp">(checking)</span></li>
91                                 <li>Item records were last synced on: <span id="item-timestamp">(checking)</span></li>
92                                 <li>Circulation records were last synced on: <span id="issue-timestamp">(checking)</span></li>
93                             </ul>
94                         </div>
95                     </div>
96
97                     <div class="col-sm-6">
98                         <div id="upload-message">
99                         </div>
100                         <div>View <a href="/cgi-bin/koha/offline_circ/list.pl">pending offline circulation actions</a></div>
101                     </div>
102                 </div>
103             </div>
104
105             <div id="offline-returns" style="display: none;" class="offline-returns">
106                 <div class="row">
107                     <form id="checkin-form" method="post" action="/cgi-bin/koha/circ/returns.pl" autocomplete="off" >
108                         <div class="col-sm-6">
109                             <fieldset>
110                                 <legend>Check in</legend>
111                                 <label for="checkin-barcode">Enter item barcode: </label>
112                                 <input name="barcode" id="checkin-barcode" size="14" class="focus" type="text" />
113                                 <input type="submit" class="btn btn-primary" value="Submit" />
114                             </fieldset>
115                         </div>
116                     </form>
117                 </div>
118
119                 <div id="session-returned" style="display: none;">
120                     <h2>Checked-in items</h2>
121                     <table id="already-checked-in">
122                         <thead>
123                             <tr><th>Title</th><th>Author</th><th>Barcode</th><th>Home library</th><th>Holding library</th><th>Shelving location</th><th>Call number</th><th>Type</th></tr>
124                         </thead>
125                         <tbody>
126                         </tbody>
127                     </table>
128                 </div>
129             </div>
130
131             <div style="display: none;" class="offline-circulation-instructions">
132                 Scan a patron barcode to start.
133             </div>
134
135             <div id="offline-circulation" style="display: none;" class="offline-circulation">
136                 <form method="post" action="/cgi-bin/koha/circ/offline.pl" id="mainform" name="mainform" autocomplete="off">
137                     <fieldset id="circ_circulation_issue">
138                         <span id="clearscreen"><a href="/cgi-bin/koha/circ/offline.pl" title="Clear screen">x</a></span>
139                         <label for="checkout-barcode">Checking out to <span class="patron-title"></span></label>
140                         <div class="hint">Enter item barcode:</div>
141                         <input type="text" name="barcode" id="checkout-barcode" class="barcode focus" size="14" />
142                         <input type="submit" class="btn btn-primary" value="Check out" />
143
144                         <div class="date-select">
145                             <div class="hint">Specify due date [% INCLUDE 'date-format.inc' %]: </div>
146                                 <input type="text" size="13" id="duedatespec" name="duedatespec" value="[% duedatespec | html %]" class="flatpickr" data-flatpickr-enable-time="true" data-flatpickr-on-close-focus="#checkout-barcode" />
147                             <label for="stickyduedate"> Remember for session:</label>
148                             <input type="checkbox" id="stickyduedate" onclick="this.form.barcode.focus();" name="stickyduedate" checked="checked" />
149                             <input type="button" class="action" id="cleardate" value="Clear" name="cleardate" onclick="this.checked = false; this.form.duedatespec.value = ''; this.form.stickyduedate.checked = false; this.form.barcode.focus(); return false;" />
150                         </div>
151                     </fieldset>
152                 </form>
153
154                 <div id="patronlists" class="toptabs">
155                     <ul class="nav nav-tabs" role="tablist">
156                         <li role="presentation" class="active"><a href="#checkouts" aria-controls="checkouts" role="tab" data-toggle="tab"><span class="checkout-count">0</span> Checkouts</a></li>
157                         <li role="presentation"><a href="#fines" aria-controls="fines" role="tab" data-toggle="tab"><span class="fine-amount">0</span> in fines</a></li>
158                     </ul>
159                     <div class="tab-content">
160                         <!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
161                         <div role="tabpanel" class="tab-pane active" id="checkouts">
162                             <div id="session-issues">
163                                 <table id="issuest">
164                                     <thead><tr>
165                                         <th scope="col">Due date</th>
166                                         <th scope="col">Title</th>
167                                         <th scope="col">Barcode</th>
168                                         <th scope="col">Item type</th>
169                                         <th scope="col">Checked out on</th>
170                                         <th scope="col">Checked out from</th>
171                                         <th scope="col">Call number</th>
172                                         <th scope="col">Charge</th>
173                                     </tr></thead>
174                                     <tbody>
175                                     </tbody>
176                                 </table>
177                             </div>
178
179                             <div id="oldissues">
180                                 <h5>Previous checkouts</h5>
181                                 <table id="oldissuest">
182                                     <thead><tr>
183                                         <th scope="col">Due date</th>
184                                         <th scope="col">Title</th>
185                                         <th scope="col">Barcode</th>
186                                         <th scope="col">Item type</th>
187                                         <th scope="col">Checked out on</th>
188                                         <th scope="col">Checked out from</th>
189                                         <th scope="col">Call number</th>
190                                         <th scope="col">Charge</th>
191                                     </tr></thead>
192                                     <tbody>
193                                     </tbody>
194                                 </table>
195                             </div>
196                         </div>
197
198                         <div role="tabpanel" class="tab-pane" id="fines">
199                             <span class="patron-title"></span> has <span class="fine-amount">0</span> in fines. If you would like you can record payments.
200                             <fieldset><legend>Pay fines</legend>
201                                 <label for="pay-fine-amount">Fine amount: </label><input type="text" name="pay-fine-amount" id="pay-fine-amount"/>
202                                 <button id="pay-fine" class="submit">Pay fine</button>
203
204                                 <table id="session-payments" style="display: none;">
205                                     <thead><tr><th>Amount</th><th>Date</th></tr></thead>
206                                     <tbody></tbody>
207                                 </table>
208                             </fieldset>
209                         </div> <!-- /# -->fines
210                     </div> <!-- /.tab-content -->
211                 </div> <!-- /#patronlists -->
212             </div>
213         </div>
214     </main>
215
216             </main>
217         </div> <!-- /.col-sm-10.col-sm-push-2 -->
218
219         <div class="offline-circulation" style="display: none;">
220             <div class="col-sm-2 col-sm-pull-10">
221                 <aside>
222                     <div class="patroninfo"><h5 class="patron-title">&nbsp;</h5>
223                         <ul>
224                             <li id="patron-address-1"></li>
225                             <li id="patron-address-2"></li>
226                             <li id="patron-address-parts"><!-- city, state, zipcode, country --></li>
227                             <li id="patron-phone"></li>
228                             <li id="patron-email"></li>
229                             <li id="patron-category"></li>
230                             <li id="patron-library"></li>
231                         </ul>
232                     </div>
233                 </aside>
234             </div> <!-- /.col-sm-2.col-sm-pull-10 -->
235         </div> <!-- /.row -->
236     </div>
237
238 [% MACRO jsinclude BLOCK %]
239     [% INCLUDE 'calendar.inc' %]
240     [% Asset.js("lib/jquery/plugins/jquery.indexeddb.js") | $raw %]
241     [% Asset.js("js/offlinecirc.js") | $raw %]
242     <script>
243         var ALERT_SUCCESSFUL_CHECKIN = _("Checked in item.");
244         var ALERT_MATERIALS = _("Note about the accompanying materials: %s");
245         var ALERT_RESTRICTED = _("Patron is RESTRICTED");
246         var ALERT_NO_MATCHING_ITEM = _("No item with barcode in offline database (transaction recorded anyway): %s");
247         var ALERT_NOT_CHECKED_OUT = _("Item not listed as checked out in offline database (transaction recorded anyway)");
248         var ALERT_ITEM_WITHDRAWN = _("Item has been withdrawn (transaction recorded anyway)");
249         var ALERT_ITEM_RESTRICTED = _("Item is restricted (transaction recorded anyway)");
250         var ALERT_ITEM_LOST = _("Item has been lost (transaction recorded anyway)");
251         var ALERT_NO_MATCHING_PATRON = _("No patron card number in offline database (proceeding anyway): %s");
252         var ALERT_PATRON_GONE_NO_ADDRESS = _("Patron's address is in doubt (proceeding anyway)");
253         var ALERT_PATRON_CARD_LOST = _("Patron's card is lost");
254         var ALERT_PATRON_EXPIRED = _("Patron's card is expired (%s)");
255         var ALERT_PATRON_BLOCKED_TEMPORARY = _("Patron has had overdue items and is restricted until: %s");
256         var ALERT_PATRON_RESTRICTED = _("Patron is restricted");
257         var ALERT_PATRON_FINE = _("Patron has outstanding fines: %s");
258         var ALERT_PATRON_FINE_OVER_LIMIT = _("Patron fines are over limit: %s");
259         var UPLOAD_PENDING_MESSAGE = _("You have transactions in the offline circulation database on this computer that have not been uploaded.");
260         var NO_UPLOAD_PENDING_MESSAGE = _("You do not have any pending transactions in the offline circulation database on this computer.");
261
262         var start;
263
264         var dateformat = '[% IF ( dateformat_us ) %]mm/dd/yy[% ELSIF ( dateformat_metric ) %]dd/mm/yy[% ELSE %]yy-mm-dd[% END %]';
265         var flatpickr_dateformat_string = [% IF ( dateformat == "us" ) %]"m/d/Y"[% ELSIF ( dateformat == "metric" ) %]"d/m/Y"[% ELSIF ( dateformat == "dmydot" ) %]"d.m.Y"[% ELSE %]"Y-m-d"[% END %];
266         var flatpickr_timeformat_string = [% IF Koha.Preference('TimeFormat') == '12hr' %]"G:i K"[% ELSE %]"H:i"[% END %];
267         var flatpickr_timestamp_string = "Y-m-d H:i";
268         var flatpickr_datetime_string = flatpickr_dateformat_string + " " + flatpickr_timeformat_string;
269
270         function checkin(barcode, item, error) {
271             var alerts = checkAlerts(barcode, item);
272             if (typeof item === 'undefined') {
273                 item = { };
274             }
275             item.title = item.title || _("(Unknown)");
276             item.author = item.author || _("(Unknown)");
277             item.homebranch = item.homebranch || "";
278             item.holdingbranch = item.holdingbranch || "";
279             item.callnumber = item.callnumber || "";
280             item.itemtype = item.itemtype || "";
281             item.barcode = item.barcode || barcode;
282             var trans = { "timestamp" : new Date().toMySQLString(),
283                           "barcode" : barcode,
284                           "action" : "return"
285                         };
286             $('#alerts').empty();
287             $('.offline-home').hide();
288             $('.offline-sync').hide();
289             $('.offline-circulation').hide();
290             $('.offline-circulation-instructions').hide();
291             $('.offline-returns').show();
292             kohadb.recordTransaction(trans, function () {
293                 $('#session-returned').show();
294                 $('#already-checked-in tbody').prepend('<tr><td>' + item.title + '</td><td>' + item.author + '</td><td>' + barcode + '</td><td>' + item.homebranch + '</td><td>' + item.holdingbranch + '</td><td></td><td>' + item.callnumber + '</td><td>' + item.itemtype + '</td></tr>');
295                 if (alerts.length > 0) {
296                     $('#alerts').append('<div class="dialog alert"><h3>' + _("Check in message") + '</h3></div>');
297                     for (var msg in alerts) {
298                         $('#alerts .dialog').append('<p>' + alerts[msg] + '</p');
299                     }
300                 } else {
301                     $('#alerts').append('<div class="dialog"><h3>' + ALERT_SUCCESSFUL_CHECKIN + '</h3></div>');
302                 }
303             });
304             setTimeout(function() { $('#checkin-barcode').trigger('focus'), 1 });
305         }
306
307         function checkAlerts(barcode, item) {
308             var alerts = [];
309             if (typeof item === 'undefined') {
310                 alerts.push(ALERT_NO_MATCHING_ITEM.format(barcode));
311             } else {
312                 if (typeof item.materials !== 'undefined' && item.materials != null) {
313                     alerts.push(ALERT_MATERIALS.format(item.materials));
314                 }
315             }
316             return alerts;
317         }
318
319         function showSyncInfo() {
320             kohadb.loadSetting("item-timestamp", showTimestamp);
321             kohadb.loadSetting("patron-timestamp", showTimestamp);
322             kohadb.loadSetting("issue-timestamp", showTimestamp);
323             kohadb.loadSetting("dirty", function (key, val) {
324                 if (val) {
325                     $('#upload-message').text(UPLOAD_PENDING_MESSAGE);
326                 } else {
327                     $('#upload-message').text(NO_UPLOAD_PENDING_MESSAGE);
328                 }
329             });
330         }
331
332         function synchronize() {
333             kohadb.saveSetting("userid", "[% logged_in_user.userid | html %]");
334             kohadb.saveSetting("branchcode", "[% Branches.GetLoggedInBranchcode | html %]");
335             showSyncInfo();
336             [% UNLESS (AllowOfflineCirculation) %]
337                 reloadRecords();
338             [% END %]
339             showSyncInfo();
340             $('#download-records').click(reloadRecords);
341             $('#upload-transactions').click(function () {
342                 $('.loading-overlay div').text(_("Uploading transactions, please wait..."));
343                 $('.loading-overlay').show();
344                 $.ajax({
345                     type: "GET",
346                     url: "/cgi-bin/koha/offline_circ/service.pl",
347                 }).done(function (data) {
348                     if (data) {
349                         $('.loading-overlay').hide();
350                         alert(_("Please log in to Koha and try again. (Error: '%s')").format(data));
351                     } else {
352                         var uploadIter = $.indexedDB("koha").objectStore("transactions").each(uploadTransaction);
353                         uploadIter.done(function() {
354                             $.indexedDB("koha").transaction(["transactions"]).then(function(){
355                             }, function(err, e){
356                             }, function(transaction){
357                                 transaction.objectStore("transactions").clear();
358                             });
359                             $('.loading-overlay').hide();
360                             kohadb.saveSetting("dirty", false);
361                             $('#upload-message').text(NO_UPLOAD_PENDING_MESSAGE);
362                         });
363                     }
364                 });
365             });
366
367         }
368
369         function fPformatTimeStamp( timestamp ){
370             var datetimeObj = flatpickr.parseDate( timestamp, flatpickr_timestamp_string );
371             return flatpickr.formatDate( datetimeObj, flatpickr_datetime_string );
372         }
373
374         function showTimestamp(key, value) {
375             if (typeof value !== 'undefined') {
376                 var ts = new Date(value);
377                 $('#' + key).text( fPformatTimeStamp( ts ) + ' ' + ts.toTimeString());
378             } else {
379                 $('#' + key).text(_("(never)"));
380             }
381         }
382
383         function reloadRecords(ev) {
384             $(".loading-overlay div").text(_("Loading records, please wait..."));
385             $(".loading-overlay").show();
386             start = new Date();
387             $.indexedDB("koha").transaction(["patrons", "items", "issues"]).then(function(){
388                 loadRecords(0);
389             }, function(err, e){
390             }, function(transaction){
391                 transaction.objectStore("patrons").clear();
392                 transaction.objectStore("items").clear();
393                 transaction.objectStore("issues").clear();
394             });
395             if (typeof ev !== 'undefined') {
396                 ev.stopPropagation();
397             }
398         }
399
400         function uploadTransaction(transaction) {
401             $.ajax({
402                 type: "POST",
403                 url: "/cgi-bin/koha/offline_circ/service.pl",
404                 data: { "userid" : kohadb.settings.userid,
405                         "branchcode" : kohadb.settings.branchcode,
406                         "timestamp" : transaction.value.timestamp,
407                         "action" : transaction.value.action,
408                         "barcode" : transaction.value.barcode,
409                         "cardnumber" : transaction.value.cardnumber,
410                         "amount" : transaction.value.amount,
411                         "pending" : true,
412                       },
413             });
414             return undefined, true;
415         }
416
417         function finishedLoading() {
418             kohadb.saveSetting('item-timestamp', start.toISOString())
419             kohadb.saveSetting('patron-timestamp', start.toISOString())
420             kohadb.saveSetting('issue-timestamp', start.toISOString())
421             showTimestamp('item-timestamp', start.toISOString());
422             showTimestamp('patron-timestamp', start.toISOString());
423             showTimestamp('issue-timestamp', start.toISOString());
424             $(".loading-overlay").hide();
425         }
426
427         function loadRecords(page) {
428         [% IF (AllowOfflineCirculation) %]
429             $(".loading-overlay div").text(_("Loading page %s, please wait...").format(page));
430             $(".loading-overlay").show();
431             $.ajax({
432                 type: "GET",
433                 url: "/cgi-bin/koha/offline_circ/download.pl",
434                 data: { "data": "all",
435                         "page": page
436                       },
437                 dataType: "json",
438             }).done(function (data) {
439                 $.indexedDB("koha").transaction(["patrons", "items", "issues"]).then(function(){
440                     if (data.finished) {
441                         finishedLoading();
442                     } else {
443                         setTimeout(function () { loadRecords(page + 1); }, 200);
444                     }
445                 }, function(err, e){
446                 }, function(transaction){
447                     if (data.patrons) {
448                         var patrons = transaction.objectStore("patrons");
449                         $.each(data.patrons, function () {
450                             patrons.put(this);
451                         });
452                     }
453                     if (data.items) {
454                         var items = transaction.objectStore("items");
455                         $.each(data.items, function () {
456                             items.put(this);
457                         });
458                     }
459                     if (data.issues) {
460                         var issues = transaction.objectStore("issues");
461                         $.each(data.issues, function () {
462                             issues.put(this);
463                         });
464                     }
465                 });
466             });
467         [% END %]
468         }
469
470         function loadPatron(barcode) {
471             $('#oldissues').hide();
472             $('#session-issues').hide();
473             $('#issuest tbody').empty();
474             $('#session-payments').hide();
475             $('.checkout-count').text(0);
476             $.indexedDB("koha").transaction(["patrons", "issues"]).then(function() {
477             }, function(err, e){
478             }, function(transaction){
479                 var patrons = transaction.objectStore("patrons");
480                 patrons.get(barcode).done(function (patron, error) {
481                     showPatron(barcode, patron, error);
482                 });
483                 var issuesidx = transaction.objectStore("issues").index("cardnumber");
484                 $('#oldissuest tbody').empty();
485                 issuesidx.each(function (item) {
486                     $('#oldissues').show();
487                     $('#oldissuest tbody').append("<tr><td>" + fPformatTimeStamp( item.value.date_due ) + "</td><td>" + item.value.title + "</td><td>" + item.value.barcode + "</td><td>" + item.value.itype + "</td><td>" + fPformatTimeStamp( item.value.issuedate ) + "</td><td>" + item.value.issuebranch + "</td><td>" + item.value.callnumber + "</td><td>" + "" + "</td></tr>");
488                     $('.checkout-count').text(parseInt($('.checkout-count').text()) + 1);
489                 }, barcode);
490             });
491         }
492
493         function checkout(barcode, item, error) {
494             var alerts = checkAlerts(barcode, item);
495             if (typeof item === 'undefined') {
496                 item = { };
497             }
498             item.title = item.title || "";
499             item.author = item.author || "";
500             item.homebranch = item.homebranch || "";
501             item.holdingbranch = item.holdingbranch || "";
502             item.callnumber = item.callnumber || "";
503             item.itemtype = item.itemtype || "";
504             if ($('#duedatespec').val().length === 0) {
505                 alert(_("You must set a due date in order to use offline circulation!"));
506                 setTimeout(function() { $('#duedatespec').trigger('focus'), 1 });
507                 return;
508             }
509             var date_due = flatpickr.parseDate( $('#duedatespec').val(), flatpickr_datetime_string );
510             var trans = { "timestamp" : new Date().toMySQLString(),
511                           "barcode" : barcode,
512                           "cardnumber" : curpatron.cardnumber,
513                           "date_due" : date_due.toMySQLString(),
514                           "action" : "issue"
515                         };
516             $('#alerts').empty();
517             kohadb.recordTransaction(trans, function () {
518                 $('#session-issues').show();
519                 $('#issuest tbody').prepend('<tr><td>' + flatpickr.formatDate( date_due, flatpickr_datetime_string ) + '</td><td>' + item.title + '</td><td>' + barcode + '</td><td>' + item.itemtype + '</td><td>' + flatpickr.formatDate( new Date(), flatpickr_datetime_string ) + '</td><td>' + kohadb.settings.branchcode + '</td><td>' + item.callnumber + '</td><td></td></tr>');
520                 $('.checkout-count').text(parseInt($('.checkout-count').text()) + 1);
521                 if (alerts.length > 0) {
522                     $('#alerts').append('<div class="dialog alert"><h3>' + _("Check out message") + '</h3></div>');
523                     for (var msg in alerts) {
524                         $('#alerts .dialog').append('<p>' + alerts[msg] + '</p');
525                     }
526                 }
527                 $('#checkout-barcode').val('');
528             });
529         }
530
531         function recordFine(amount) {
532             var timestamp = new Date()
533             var trans = { "timestamp" : timestamp.toMySQLString(),
534                           "cardnumber" : curpatron.cardnumber,
535                           "amount" : amount,
536                           "action" : "payment",
537                         };
538             kohadb.recordTransaction(trans, function () {
539                 $('#session-payments').show();
540                 $('#session-payments tbody').prepend('<tr><td>' + amount + '</td><td>' + fPformatTimeStamp( timestamp ) + '</td></tr>');
541                 $('.fine-amount').text(parseInt($('.fine-amount').text()) - amount);
542             });
543         }
544
545         function checkPatronAlerts(cardnumber, patron) {
546             var alerts = [];
547             if (typeof patron === 'undefined') {
548                 alerts.push(ALERT_NO_MATCHING_PATRON.format(cardnumber));
549             } else {
550                 if (patron.gonenoaddress !== '0') {
551                     alerts.push(ALERT_PATRON_GONE_NO_ADDRESS);
552                 }
553                 if (patron.lost !== '0') {
554                     alerts.push(ALERT_PATRON_CARD_LOST);
555                 }
556                 if (patron.debarred !== null) {
557                     if (patron.debarred != '9999-12-31') {
558                         alerts.push( ALERT_PATRON_BLOCKED_TEMPORARY.format( flatpickr.formatDate( new Date(patron.debarred), flatpickr_datetime_string ) ) );
559                     } else {
560                         alerts.push(ALERT_PATRON_RESTRICTED);
561                     }
562                 }
563                 if (new Date(patron.dateexpiry) < new Date()) {
564                     alerts.push( ALERT_PATRON_EXPIRED.format( flatpickr.formatDate( new Date(patron.dateexpiry), flatpickr_datetime_string ) ) );
565                 }
566                 if (parseInt(patron.fine) > [% maxoutstanding | html %]) {
567                     alerts.push(ALERT_PATRON_FINE_OVER_LIMIT.format(patron.fine));
568                 } else if (parseInt(patron.fine) > 0) {
569                     alerts.push(ALERT_PATRON_FINE.format(patron.fine));
570                 }
571             }
572             return alerts;
573         }
574
575         var curpatron;
576
577         function showPatron(barcode, patron, error) {
578             var alerts = checkPatronAlerts(barcode, patron);
579             if (typeof patron === 'undefined') {
580                 patron = { };
581             }
582             patron.surname = patron.surname || "";
583             patron.firstname = patron.firstname || "";
584             patron.othernames = patron.othernames || "";
585             patron.address = patron.address || "";
586             patron.address2 = patron.address2 || "";
587             patron.city = patron.city || "";
588             patron.state = patron.state || "";
589             patron.country = patron.country || "";
590             patron.zipcode = patron.zipcode || "";
591             patron.phone = patron.phone || "";
592             patron.mobile = patron.mobile || "";
593             patron.phonepro = patron.phonepro || "";
594             patron.email = patron.email || "";
595             patron.emailpro = patron.emailpro || "";
596             patron.categorycode = patron.categorycode || "";
597             patron.branchcode = patron.branchcode || "";
598             patron.cardnumber = barcode;
599             patron.fine = patron.fine || "0";
600
601             patron.name = patron.firstname + (patron.othernames.length > 0 ? " (" + patron.othernames + ") " : " ") + patron.surname + " (" + barcode + ")";
602             if (patron.name.length > 0) {
603                 $('.patron-title').text(patron.name);
604             } else {
605                 $('.patron-title').text(_("Unrecognized patron (%s)").format(barcode));
606             }
607             if (patron.address.length > 0 || patron.address2.length > 0) {
608                 $('#patron-address-1').text(patron.address);
609                 $('#patron-address-2').text(patron.address2);
610             } else {
611                 $('#patron-address-1').html('<span class="empty" id="noaddressstored">' + _("No address stored.") + '</span></li>');
612                 $('#patron-address-2').text('');
613             }
614             if (patron.city.length > 0) {
615                 $('#patron-address-parts').text(patron.city + (patron.state.length > 0 ? ", " + patron.state : "") + " " + patron.zipcode + (patron.country.length > 0 ? ", " + patron.country : ""));
616             } else {
617                 $('#patron-address-parts').html('<span class="empty" id="nocitystored">' + _("No city stored.") + '</span></li>');
618             }
619             if (patron.phone.length > 0 || patron.mobile.length > 0 || patron.phonepro.length > 0) {
620                 $('#patron-phone').text((patron.phone.length > 0 ? patron.phone : (patron.mobile.length > 0 ? patron.mobile : (patron.phonepro.length > 0 ? patron.phonepro : ''))));
621             } else {
622                 $('#patron-phone').html('<span class="empty" id="nophonestored">' + _("No phone stored.") + '</span></li>');
623             }
624             if (patron.email.length > 0 || patron.emailpro.length > 0) {
625                 $('#patron-email').text((patron.email.length > 0 ? patron.email : (patron.emailpro.length > 0 ? patron.emailpro : "")));
626             } else {
627                 $('#patron-email').html('<span class="empty" id="noemailstored">' + _("No email stored.") + '</span></li>');
628             }
629             if (patron.categorycode.length > 0) {
630                 $('#patron-category').text(_("Category: %s").format(patron.categorycode));
631             } else {
632                 $('#patron-category').html('<span class="empty" id="unknowncategory">' + _("Category code unknown.") + '</span></li>');
633             }
634             if (patron.branchcode.length > 0) {
635                 $('#patron-library').text(_("Home library: %s").format(patron.branchcode));
636             } else {
637                 $('#patron-library').html('<span class="empty" id="unknowncategory">' + _("Home library unknown.") + '</span></li>');
638             }
639             $('.fine-amount').text(patron.fine);
640             $('#alerts').empty();
641             if (alerts.length > 0) {
642                 $('#alerts').append('<div class="dialog alert"><h3>' + _("Check out message") + '</h3></div>');
643                 for (var msg in alerts) {
644                     $('#alerts .dialog').append('<p>' + alerts[msg] + '</p>');
645                 }
646             }
647             curpatron = patron;
648             $('main').show();
649             setTimeout(function() { $('#checkout-barcode').trigger('focus'), 1 });
650         }
651
652         // This next bit of code is to deal with the updated session issue
653         if( typeof window.applicationCache !== "undefined" ){
654             window.addEventListener('load', function(e) {
655                 window.applicationCache.addEventListener('updateready', function(e) {
656                     if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
657                         // Browser downloaded a new app cache.
658                         // Swap it in and reload the page to get the new hotness.
659                         window.applicationCache.swapCache();
660                         if (confirm(_("A new version of this site is available. Load it?"))) {
661                             window.location.reload();
662                         }
663                     } else {
664                     // Manifest didn't changed. Nothing new to server.
665                     }
666                 }, false);
667             }, false);
668         }
669
670
671         $(document).ready(function () {
672             if( typeof window.applicationCache === "undefined" ){
673                 $("#offline-home div").html('<div class="dialog alert"><h3>' + _("Offline circulation disabled") + '</h3><p>' + _("Your browser is not compatible with the built-in offline circulation tool.") + '</div>');
674             } else {
675                 kohadb.initialize();
676             }
677             $('#header_search #circ_search .tip').text(_("Enter patron card number:"));
678
679             $('ul[aria-labelledby="logged-in-menu"]').html('<li><a class="toplinks">' + _("You cannot change your branch or logout while using offline circulation") + '</a></li>');
680
681             // Returns code
682             $('#checkin-form, #checkin_search form').submit(function (event) {
683                 event.preventDefault();
684                 var barcode = $('input[name="barcode"]', this).val();
685                 $('input[name="barcode"]', this).val('');
686                 $.indexedDB("koha").transaction(["items"]).then(function() {
687                 }, function(err, e){
688                 }, function(transaction){
689                     var items = transaction.objectStore("items");
690                     items.get(barcode).done(function (item, error) {
691                         checkin(barcode, item, error);
692                     });
693                 });
694             });
695
696             $('#go-to-home').click(function () {
697                 $('#alerts').empty();
698                 $('.offline-sync').hide();
699                 $('.offline-circulation').hide();
700                 $('.offline-returns').hide();
701                 $('.offline-circulation-instructions').hide();
702                 $('.offline-home').show();
703             });
704
705             $('#go-to-returns').click(function () {
706                 $('#alerts').empty();
707                 $('.offline-home').hide();
708                 $('.offline-sync').hide();
709                 $('.offline-circulation').hide();
710                 $('.offline-circulation-instructions').hide();
711                 $('.offline-returns').show();
712                 setTimeout(function() { $('#checkin-form input[name="barcode"]').trigger('focus'), 1 });
713             });
714
715             $('#go-to-circ').click(function () {
716                 $('#alerts').empty();
717                 $('.offline-home').hide();
718                 $('.offline-sync').hide();
719                 $('.offline-returns').hide();
720                 $('.offline-circulation').hide();
721                 $('.offline-circulation-instructions').show();
722                 $('#header_search').tabs("option", "active", 0);
723                 setTimeout(function() { $('#circ_search input[name="findborrower"]').trigger('focus'), 1 });
724             });
725
726             $('#go-to-sync').click(function () {
727                 $('#alerts').empty();
728                 showSyncInfo();
729                 $.ajax({
730                     type: "GET",
731                     url: "/cgi-bin/koha/offline_circ/list.pl",
732                     success: function () {
733                         $('.offline-home').hide();
734                         $('.offline-returns').hide();
735                         $('.offline-circulation').hide();
736                         $('.offline-circulation-instructions').hide();
737                         $('.offline-sync').show();
738                         synchronize();
739                     },
740                     error: function () {
741                         alert(_("You are offline and therefore cannot sync your database"));
742                     }
743                 });
744             });
745
746             $('#go-to-pending').click(function (ev) {
747                 $('#alerts').empty();
748                 ev.preventDefault();
749                 $.ajax({
750                     type: "GET",
751                     url: "/cgi-bin/koha/offline_circ/list.pl",
752                     success: function () {
753                         window.location = '/cgi-bin/koha/offline_circ/list.pl';
754                     },
755                     error: function () {
756                         alert(_("You are offline and therefore cannot process pending operations"));
757                     }
758                 });
759             });
760
761             $('#patronsearch').submit(function (event) {
762                 event.preventDefault();
763                 loadPatron($('#findborrower').val());
764                 $('.offline-home').hide();
765                 $('.offline-returns').hide();
766                 $('.offline-sync').hide();
767                 $('.offline-circulation-instructions').hide();
768                 $('.offline-circulation').show();
769                 $('#findborrower').val('');
770                 setTimeout(function() { $('#checkout-barcode').trigger('focus'), 1 });
771             });
772
773             $('#pay-fine').click(function (event) {
774                 event.preventDefault();
775                 recordFine($('#pay-fine-amount').val());
776             });
777
778             $('#mainform').submit(function (event) {
779                 event.preventDefault();
780                 var barcode = $('#checkout-barcode').val();
781                 $.indexedDB("koha").transaction(["items"]).then(function() {
782                 }, function(err, e){
783                 }, function(transaction){
784                     var items = transaction.objectStore("items");
785                     items.get(barcode).done(function (item, error) {
786                         checkout(barcode, item, error);
787                     });
788                 });
789             });
790         });
791     </script>
792 [% END %]
793
794 [% INCLUDE 'intranet-bottom.inc' %]