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