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
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * Koha is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Koha; if not, see <http://www.gnu.org/licenses>.
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 if (typeof callback === 'function') {
56 callback(key, undefined);
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;
64 if (typeof callback === 'function') {
65 callback(key, kohadb.settings[key]);
70 kohadb.saveSetting = function (key, value) {
71 $.indexedDB("koha").transaction(["offline_settings"]).then(function(){
73 }, function(transaction){
74 var settings = transaction.objectStore("offline_settings");
75 settings.put({ "key" : key, "value" : value });
76 kohadb.settings[key] = value;
79 kohadb.recordTransaction = function (newtrans, callback) {
80 $.indexedDB("koha").transaction(["transactions"]).then(function(){
83 }, function(dbtransaction) {
84 var transactions = dbtransaction.objectStore("transactions");
85 transactions.put(newtrans);
86 kohadb.saveSetting('dirty', true);
89 }( window.kohadb = window.kohadb || {}, jQuery ));
91 if ( !Date.prototype.toMySQLString ) {
94 function pad(number) {
95 var r = String(number);
96 if ( r.length === 1 ) {
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 );