Bug 14060: Force the input to contain a valid date
[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 %]/[% theme %]/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) {
557             if (validate_date(dateText, inst) ) {
558                 setTimeout(function() { $('#checkout-barcode').trigger('focus'), 1 });
559             }
560         },
561         hour: 23,
562         minute: 59
563     }).on("change", function(e, value) {
564         if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");}
565     });
566     $('#mainform').submit(function (event) {
567         event.preventDefault();
568         var barcode = $('#checkout-barcode').val();
569         $.indexedDB("koha").transaction(["items"]).then(function() {
570         }, function(err, e){
571         }, function(transaction){
572             var items = transaction.objectStore("items");
573             items.get(barcode).done(function (item, error) {
574                 checkout(barcode, item, error);
575             });
576         });
577     });
578 });
579 //]]>
580 </script>
581 </head>
582 <body id="circ_offline" class="circ">
583 [% INCLUDE 'header.inc' %]
584 [% INCLUDE 'circ-search.inc' %]
585 <div class="loading-overlay" style="display: none;">
586     <div>Downloading records, please wait...</div>
587 </div>
588
589 <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>
590
591 <div id="doc3" class="yui-t2">
592
593     <div id="bd">
594         <div id="yui-main">
595             <audio id="alert_sound" src="[% interface %]/prog/sound/critical.ogg" preload="auto"></audio>
596             <audio id="success_sound" src="[% interface %]/prog/sound/beep.ogg" preload="auto"></audio>
597
598             <div id="alerts" class="yui-b">
599             </div>
600             [% UNLESS (AllowOfflineCirculation) %]
601                 <div id="noofflinecircwarning" class="dialog alert">
602                     <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>
603                 </div>
604             [% END %]
605
606             <div id="offline-home" class="yui-b offline-home">
607                 <div class="yui-g">
608                     <h1>Offline circulation</h1>
609                     <div class="yui-u first">
610                         <ul>
611                             <li><a id="go-to-circ" href="#offline-circulation">Check out</a></li>
612                             <li><a id="go-to-returns" href="#offline-returns">Check in</a></li>
613                         </ul>
614                     </div>
615
616                     <div class="yui-u">
617                         <p><strong>Note:</strong> You must be online to use these options.</p>
618                         <ul>
619                             <li><a id="go-to-sync" href="#offline-sync">Synchronize</a></li>
620                             <li><a id="go-to-pending" href="/cgi-bin/koha/offline_circ/list.pl">Pending offline circulation actions</a>
621                         </ul>
622                     </div>
623                 </div>
624             </div>
625
626             <div id="offline-sync" style="display: none;" class="yui-b offline-sync">
627                 <div id="toolbar" class="btn-toolbar">
628                     [% IF (AllowOfflineCirculation) %]
629                         <a href="#" id="download-records" class="btn btn-small"><i class="fa fa-arrow-down"></i>Download records</a>
630                     [% END %]
631                     <a href="#" id="upload-transactions" class="btn btn-small"><i class="fa fa-arrow-up"></i>Upload transactions</a>
632                 </div>
633                 <div class="yui-g">
634                     <h1>Offline circulation</h1>
635                     <div class="yui-u first">
636                         <div id="download-message">
637                             In order for offline circulation to work on this computer,
638                             your library's records must be up-to-date on this computer:
639                             <ul>
640                                 <li>Patron records were last synced on: <span id="patron-timestamp">(checking)</span></li>
641                                 <li>Item records were last synced on: <span id="item-timestamp">(checking)</span></li>
642                                 <li>Circulation records were last synced on: <span id="issue-timestamp">(checking)</span></li>
643                             </ul>
644                         </div>
645                     </div>
646
647                     <div class="yui-u">
648                         <div id="upload-message">
649                         </div>
650                         <div>View <a href="/cgi-bin/koha/offline_circ/list.pl">pending offline circulation actions</a></div>
651                     </div>
652                 </div>
653             </div>
654
655             <div id="offline-returns" style="display: none;" class="yui-b offline-returns">
656                 <div class="yui-g">
657                     <form id="checkin-form" method="post" action="/cgi-bin/koha/circ/returns.pl" autocomplete="off" >
658                         <div class="yui-u first">
659                             <fieldset>
660                                 <legend>Check In</legend>
661                                 <label for="checkin-barcode">Enter item barcode: </label>
662                                 <input name="barcode" id="checkin-barcode" size="14" class="focus"/>
663                                 <input type="submit" class="submit" value="Submit" />
664                             </fieldset>
665                         </div>
666                     </form>
667                 </div>
668
669                 <div id="session-returned" style="display: none;">
670                     <h2>Checked-in items</h2>
671                     <table id="already-checked-in">
672                         <thead>
673                             <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>
674                         </thead>
675                         <tbody>
676                         </tbody>
677                     </table>
678                 </div>
679             </div>
680
681             <div style="display: none;" class="yui-b offline-circulation-instructions">
682                 <div class="yui-g">
683                     Scan a patron barcode to start.
684                 </div>
685             </div>
686
687             <div id="offline-circulation" style="display: none;" class="yui-b offline-circulation">
688                 <div class="yui-g">
689                     <form method="post" action="/cgi-bin/koha/circ/offline.pl" id="mainform" name="mainform" autocomplete="off">
690                         <fieldset id="circ_circulation_issue">
691                             <span id="clearscreen"><a href="/cgi-bin/koha/circ/offline.pl" title="Clear screen">x</a></span>
692                             <label for="checkout-barcode">Checking out to <span class="patron-title"></span></label>
693                             <div class="hint">Enter item barcode:</div>
694                             <input type="text" name="barcode" id="checkout-barcode" class="barcode focus" size="14" />
695                             <input type="submit" value="Check Out" />
696
697                             <div class="date-select">
698                                 <div class="hint">Specify due date [% INCLUDE 'date-format.inc' %]: </div>
699                                 <input type="text" size="13" id="duedatespec" name="duedatespec" value="[% duedatespec %]" />
700                                 <label for="stickyduedate"> Remember for session:</label>
701                                 <input type="checkbox" id="stickyduedate" onclick="this.form.barcode.focus();" name="stickyduedate" checked="checked" />
702                                 <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;" />
703                             </div>
704                         </fieldset>
705                     </form>
706                 </div>
707
708                 <div class="yui-g"><div id="patronlists" class="toptabs">
709                     <ul>
710                         <li><a href="#checkouts"><span class="checkout-count">0</span> Checkouts</a></li>
711                         <li><a href="#fines"><span class="fine-amount">0</span> in fines</a></li>
712                     </ul>
713
714                     <!-- SUMMARY : TODAY & PREVIOUS ISSUES -->
715                     <div id="checkouts">
716                         <div id="session-issues">
717                             <table id="issuest">
718                                 <thead><tr>
719                                     <th scope="col">Due date</th>
720                                     <th scope="col">Title</th>
721                                     <th scope="col">Barcode</th>
722                                     <th scope="col">Item type</th>
723                                     <th scope="col">Checked out on</th>
724                                     <th scope="col">Checked out from</th>
725                                     <th scope="col">Call no</th>
726                                     <th scope="col">Charge</th>
727                                 </tr></thead>
728                                 <tbody>
729                                 </tbody>
730                             </table>
731                         </div>
732
733                         <div id="oldissues">
734                             <h5>Previous checkouts</h5>
735                             <table id="oldissuest">
736                                 <thead><tr>
737                                     <th scope="col">Due date</th>
738                                     <th scope="col">Title</th>
739                                     <th scope="col">Barcode</th>
740                                     <th scope="col">Item type</th>
741                                     <th scope="col">Checked out on</th>
742                                     <th scope="col">Checked out from</th>
743                                     <th scope="col">Call no</th>
744                                     <th scope="col">Charge</th>
745                                 </tr></thead>
746                                 <tbody>
747                                 </tbody>
748                             </table>
749                         </div>
750                     </div>
751
752                     <div id="fines">
753                         <span class="patron-title"></span> has <span class="fine-amount">0</span> in fines. If you would like you can record payments.
754                         <fieldset><legend>Pay fines</legend>
755                             <label for="pay-fine-amount">Fine amount: </label><input type="text" name="pay-fine-amount" id="pay-fine-amount"/>
756                             <button id="pay-fine" class="submit">Pay fine</button>
757
758                             <table id="session-payments" style="display: none;">
759                                 <thead><tr><th>Amount</th><th>Timestamp</th></tr></thead>
760                                 <tbody></tbody>
761                             </table>
762                         </fieldset>
763                     </div>
764                 </div>
765             </div>
766         </div>
767     </div>
768
769     <div class="yui-b offline-circulation" style="display: none;">
770         <div class="patroninfo"><h5 class="patron-title">&nbsp;</h5>
771             <ul>
772                 <li id="patron-address-1"></li>
773                 <li id="patron-address-2"></li>
774                 <li id="patron-address-parts"><!-- city, state, zipcode, country --></li>
775                 <li id="patron-phone"></li>
776                 <li id="patron-email"></li>
777                 <li id="patron-category"></li>
778                 <li id="patron-library"></li>
779             </ul>
780         </div>
781     </div>
782 </div>
783
784 [% INCLUDE 'intranet-bottom.inc' %]