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