[WIP] point_of_sale: indexedDB backend

bzr revid: fva@openerp.com-20120806154054-1yubgy8o8wwlc5b8
This commit is contained in:
Frédéric van der Essen 2012-08-06 17:40:54 +02:00
parent 7cf6da22cc
commit 996183acf7
5 changed files with 6 additions and 66 deletions

View File

@ -86,6 +86,7 @@ Main features:
'js': [
'static/lib/backbone/backbone-0.9.2.js',
'static/lib/mousewheel/jquery.mousewheel-3.0.6.js',
'static/src/js/pos_db.js',
'static/src/js/pos_models.js',
'static/src/js/pos_basewidget.js',
'static/src/js/pos_keyboard_widget.js',

View File

@ -1,66 +0,0 @@
function openerp_pos_db(instance, module){
function importIndexedDB(){
if('indexedDB' in window){
return true;
}else if('webkitIndexedDB' in window){
window.indexedDB = window.webkitIndexedDB;
window.IDBCursor = window.webkitIDBCursor;
window.IDBDatabase = window.webkitIDBDatabase;
window.IDBDatabaseError = window.webkitIDBDatabaseError;
window.IDBDatabaseException = window.webkitIDBDatabaseException;
window.IDBFactory = window.webkitIDBFactory;
window.IDBIndex = window.webkitIDBIndex;
window.IDBKeyRange = window.webkitIDBKeyRange;
window.IDBObjectSrore = window.webkitIDBOjbectStore;
window.IDBRequest = window.webkitIDBRequest;
window.IDBTransaction = window.webkitIDBTransaction;
}else if('mozIndexedDB' in window){
window.indexedDB = window.mozIndexedDB;
}else{
throw new Error("DATABASE ERROR: IndexedDB not implemented. Please upgrade your web browser");
}
}
importIndexedDB();
modula.PosDB = modula.Class.extend({
state: 'connecting', // 'connecting' || 'connected' || 'failed'
version: 1,
name: 'openerp_pos_db',
init: function(options){
var open_request = indexedDB.open(this.name, this.version);
},
upgrade_db: function(oldversion, transaction){
this.db = transaction.db;
var productStore = this.db.createObjectStore("products", {keyPath: "id"});
productStore.createIndex("ean13", "ean13", {unique:true});
productStore.createIndex("name", "name", {unique:false});
productStore.createIndex("category","category", {unique:false});
var imageStore = this.db.createObjectStore("images", {keyPath: "id"});
imageStore.createIndex("product_id", "product_id", {unique:true});
},
_add_data: function(store, data, result_callback){
var transaction = this.db.transaction([store], IDBTransaction.READ_WRITE);
transaction.oncomplete = function(event){ if(result_callback){ result_callback(event); }};
},
add_product: function(product){
},
get_product_by_ean: function(ean, result_callback){
},
get_product_by_category: function(category, result_callback){
},
get_product_image: function(product, result_callback){
},
search_product: function(query,result_callback){
},
});
}

View File

@ -5,6 +5,8 @@ openerp.point_of_sale = function(instance) {
var module = instance.point_of_sale;
openerp_pos_db(instance,module); // import db.js
openerp_pos_models(instance,module); // import pos_models.js
openerp_pos_basewidget(instance,module); // import pos_basewidget.js

View File

@ -74,6 +74,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
this.weightable_categories = []; // a flat list of all categories that directly contain weightable products
this.barcode_reader = new module.BarcodeReader({'pos': this}); // used to read barcodes
this.proxy = new module.ProxyDevice(); // used to communicate to the hardware devices via a local proxy
this.db = new module.PosDB(); // a database used to store the products and product images
// pos settings
this.use_scale = false;

View File

@ -968,12 +968,14 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
});
},
close: function() {
var self = this;
this.pos.barcode_reader.disconnect();
return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_close_statement']], ['res_id']).pipe(
_.bind(function(res) {
return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) {
var action = result.result;
action.context = _.extend(action.context || {}, {'cancel_action': {type: 'ir.actions.client', tag: 'reload'}});
//self.destroy();
this.do_action(action);
}, this));
}, this));