1 /* Copyright 2013 C & P Bibliography Services
3 * This file is part of Koha.
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
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.
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.
19 (function( kohadb, $, undefined ) {
20 kohadb.settings = kohadb.settings || {};
21 kohadb.initialize = function (callback) {
25 "1": function(versionTransaction){
26 var patrons = versionTransaction.createObjectStore("patrons", {
27 "keyPath": "cardnumber"
29 var items = versionTransaction.createObjectStore("items", {
32 var issues = versionTransaction.createObjectStore("issues", {
35 issues.createIndex("cardnumber", { "multiEntry": true });
36 var transactions = versionTransaction.createObjectStore("transactions", {
37 "keyPath": "timestamp"
39 var settings = versionTransaction.createObjectStore("offline_settings", {
45 if (typeof callback === 'function') {
47 kohadb.loadSetting('userid');
48 kohadb.loadSetting('branchcode');
52 kohadb.loadSetting = function (key, callback) {
53 $.indexedDB("koha").transaction(["offline_settings"]).then(function(){
55 }, function(transaction){
56 var settings = transaction.objectStore("offline_settings");
57 settings.get(key).done(function (item, error) {
58 if (typeof item !== 'undefined') {
59 kohadb.settings[key] = item.value;
61 if (typeof callback === 'function') {
62 callback(key, kohadb.settings[key]);
67 kohadb.saveSetting = function (key, value) {
68 $.indexedDB("koha").transaction(["offline_settings"]).then(function(){
70 }, function(transaction){
71 var settings = transaction.objectStore("offline_settings");
72 settings.put({ "key" : key, "value" : value });
73 kohadb.settings[key] = value;
76 kohadb.recordTransaction = function (newtrans, callback) {
77 $.indexedDB("koha").transaction(["transactions"]).then(function(){
80 }, function(dbtransaction) {
81 var transactions = dbtransaction.objectStore("transactions");
82 transactions.put(newtrans);
85 }( window.kohadb = window.bndb || {}, jQuery ));
87 if ( !Date.prototype.toMySQLString ) {
90 function pad(number) {
91 var r = String(number);
92 if ( r.length === 1 ) {
98 Date.prototype.toMySQLString = function() {
99 return this.getFullYear()
100 + '-' + pad( this.getMonth() + 1 )
101 + '-' + pad( this.getDate() )
102 + ' ' + pad( this.getHours() )
103 + ':' + pad( this.getMinutes() )
104 + ':' + pad( this.getSeconds() )
105 + '.' + String( (this.getMilliseconds()/1000).toFixed(3) ).slice( 2, 5 );