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