+// indexed db service
+
+var idbmod = angular.module('idbmod',[]);
+
+idbmod.factory("idbsrv",function($q) {
+ var srvobject={};
+ srvobject.init=function(name,successcb,version,stores,upgradecb) {
+ var defer=$q.defer();
+ idb.init(name,function(event) {
+ if(successcb!==undefined)
+ successcb(event);
+ defer.resolve(idb.handle);
+ },version,stores);
+ return defer.promise;
+ };
+ srvobject.del_store=function(store,callback) {
+ var defer=$q.defer();
+ idb.del_store(store,function() {
+ if(callback!==undefined)
+ callback();
+ defer.resolve();
+ });
+ return defer.promise;
+ };
+ srvobject.add_store_item=function(store,item,callback) {
+ var defer=$q.defer();
+ idb.add_store_item(store,item,function(event) {
+ if(callback!==undefined)
+ callback(event);
+ defer.resolve();
+ });
+ return defer.promise;
+ };
+ srvobject.del_store_item=function(store,num,callback) {
+ var defer=$q.defer();
+ idb.del_store_item(store,num,function(event) {
+ if(callback!==undefined)
+ callback(event);
+ defer.resolve();
+ });
+ return defer.promise;
+ };
+ srvobject.update_store_item=function(store,num,nitem,callback) {
+ var defer=$q.defer();
+ idb.update_store_item(store,num,nitem,function(event) {
+ if(callback!==undefined)
+ callback(event)
+ defer.resolve();
+ });
+ return defer.promise;
+ };
+ srvobject.get_store_items=function(store,callback,low,up) {
+ var defer=$q.defer();
+ idb.get_store_items(store,function(item) {
+ if(callback!==undefined)
+ callback(item);
+ defer.resolve(item);
+ });
+ return defer.promise;
+ };
+ srvobject.get_item_by_key=function(store,key,callback) {
+ var defer=$q.defer();
+ idb.get_item_by_key(store,key,function(item) {
+ if(callback!==undefined)
+ callback(item);
+ defer.resolve();
+ });
+ return defer.promise;
+ };
+ srvobject.get_item_by_index=function(store,index,val,callback) {
+ var defer=$q.defer();
+ idb.get_item_by_index(store,index,val,function(item) {
+ if(callback!==undefined)
+ callback(item);
+ defer.resolve();
+ });
+ return defer.promise;
+ };
+ srvobject.del_item_by_key=function(store,key,callback) {
+ var defer=$q.defer();
+ idb.del_item_by_key(store,key,function(event) {
+ if(callback!==undefined)
+ callback(event);
+ defer.resolve();
+ });
+ return defer.promise;
+ };
+ srvobject.del=function(callback) {
+ var defer=$q.defer();
+ idb.del(function() {
+ if(callback!==undefined)
+ callback();
+ defer.resolve();
+ });
+ return defer.promise;
+ };
+ return srvobject;
+});
+