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