2013-08-29 23:38:28 -04:00
|
|
|
/*global indexedDB*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var AvatarStorage = require('./avatars');
|
|
|
|
var RosterStorage = require('./roster');
|
|
|
|
var DiscoStorage = require('./disco');
|
|
|
|
var ArchiveStorage = require('./archive');
|
2013-10-15 17:48:39 -04:00
|
|
|
var ProfileStorage = require('./profile');
|
2013-08-29 23:38:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
function Storage() {
|
|
|
|
this.db = null;
|
|
|
|
this.init = [];
|
|
|
|
|
|
|
|
this.avatars = new AvatarStorage(this);
|
|
|
|
this.roster = new RosterStorage(this);
|
|
|
|
this.disco = new DiscoStorage(this);
|
|
|
|
this.archive = new ArchiveStorage(this);
|
2013-10-15 17:48:39 -04:00
|
|
|
this.profiles = new ProfileStorage(this);
|
2013-08-29 23:38:28 -04:00
|
|
|
}
|
|
|
|
Storage.prototype = {
|
|
|
|
constructor: {
|
|
|
|
value: Storage
|
|
|
|
},
|
2013-10-15 17:48:39 -04:00
|
|
|
version: 3,
|
2013-08-29 23:38:28 -04:00
|
|
|
open: function (cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var request = indexedDB.open('datastorage', this.version);
|
|
|
|
request.onsuccess = function (e) {
|
|
|
|
self.db = e.target.result;
|
2015-10-26 14:35:33 -04:00
|
|
|
cb(true);
|
2013-08-29 23:38:28 -04:00
|
|
|
};
|
|
|
|
request.onupgradeneeded = function (e) {
|
|
|
|
var db = e.target.result;
|
|
|
|
self.avatars.setup(db);
|
|
|
|
self.roster.setup(db);
|
|
|
|
self.disco.setup(db);
|
|
|
|
self.archive.setup(db);
|
2013-10-15 17:48:39 -04:00
|
|
|
self.profiles.setup(db);
|
2013-08-29 23:38:28 -04:00
|
|
|
};
|
2015-10-26 14:35:33 -04:00
|
|
|
request.onerror = function(e) {
|
|
|
|
cb(false);
|
|
|
|
};
|
2013-08-29 23:38:28 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Storage;
|