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