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