Bug 15099: Move admin/categorie.pl to admin/categories.pl
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / offlinecirc.js
1 /* Copyright 2013 C & P Bibliography Services
2  *
3  * This file is part of Koha.
4  *
5  * Koha is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12  * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with Koha; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 (function( kohadb, $, undefined ) {
20     kohadb.settings = kohadb.settings || {};
21     kohadb.initialize = function (callback) {
22         $.indexedDB("koha", {
23             "version": 1,
24             "schema": {
25                 "1": function(versionTransaction){
26                     var patrons = versionTransaction.createObjectStore("patrons", {
27                         "keyPath": "cardnumber"
28                     });
29                     var items = versionTransaction.createObjectStore("items", {
30                         "keyPath": "barcode"
31                     });
32                     var issues = versionTransaction.createObjectStore("issues", {
33                         "keyPath": "barcode"
34                     });
35                     issues.createIndex("cardnumber", { "multiEntry": true });
36                     var transactions = versionTransaction.createObjectStore("transactions", {
37                         "keyPath": "timestamp"
38                     });
39                     var settings = versionTransaction.createObjectStore("offline_settings", {
40                         "keyPath": "key"
41                     });
42                 },
43             }
44         }).done(function(){
45             if (typeof callback === 'function') {
46                 callback();
47                 kohadb.loadSetting('userid');
48                 kohadb.loadSetting('branchcode');
49             }
50         });
51     };
52     kohadb.loadSetting = function (key, callback) {
53         $.indexedDB("koha").transaction(["offline_settings"]).then(function(){
54         }, function(err, e){
55             if (typeof callback === 'function') {
56                 callback(key, undefined);
57             }
58         }, function(transaction){
59             var settings = transaction.objectStore("offline_settings");
60             settings.get(key).done(function (item, error) {
61                 if (typeof item !== 'undefined') {
62                     kohadb.settings[key] = item.value;
63                 }
64                 if (typeof callback === 'function') {
65                     callback(key, kohadb.settings[key]);
66                 }
67             });
68         });
69     };
70     kohadb.saveSetting = function (key, value) {
71         $.indexedDB("koha").transaction(["offline_settings"]).then(function(){
72         }, function(err, e){
73         }, function(transaction){
74             var settings = transaction.objectStore("offline_settings");
75             settings.put({ "key" : key, "value" : value });
76             kohadb.settings[key] = value;
77         });
78     };
79     kohadb.recordTransaction = function (newtrans, callback) {
80         $.indexedDB("koha").transaction(["transactions"]).then(function(){
81             callback(newtrans);
82         }, function(err, e){
83         }, function(dbtransaction) {
84             var transactions = dbtransaction.objectStore("transactions");
85             transactions.put(newtrans);
86             kohadb.saveSetting('dirty', true);
87         });
88     };
89 }( window.kohadb = window.kohadb || {}, jQuery ));
90
91 if ( !Date.prototype.toMySQLString ) {
92   ( function() {
93
94     function pad(number) {
95       var r = String(number);
96       if ( r.length === 1 ) {
97         r = '0' + r;
98       }
99       return r;
100     }
101
102     Date.prototype.toMySQLString = function() {
103       return this.getFullYear()
104         + '-' + pad( this.getMonth() + 1 )
105         + '-' + pad( this.getDate() )
106         + ' ' + pad( this.getHours() )
107         + ':' + pad( this.getMinutes() )
108         + ':' + pad( this.getSeconds() )
109         + '.' + String( (this.getMilliseconds()/1000).toFixed(3) ).slice( 2, 5 );
110     };
111
112   }() );
113 }