[IMP] point_of_sale: refactoring screens to make it more extensible
bzr revid: fva@openerp.com-20120611140441-13tksy80lrr9ndgh
This commit is contained in:
@@ -720,6 +720,7 @@
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
z-index:10000;
|
||||
|
||||
}
|
||||
.point-of-sale .keyboard_frame .close_button{
|
||||
|
||||
@@ -207,15 +207,15 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||
// and deactivate the barcode reader. Use set_action_callbacks to tell it
|
||||
// what to do when it reads a barcode.
|
||||
module.BarcodeReader = instance.web.Class.extend({
|
||||
|
||||
actions:[
|
||||
'product',
|
||||
'cashier',
|
||||
'client',
|
||||
'discount',
|
||||
],
|
||||
init: function(attributes){
|
||||
this.pos = attributes.pos;
|
||||
this.action_callback = {
|
||||
'product': undefined,
|
||||
'cashier': undefined,
|
||||
'client': undefined,
|
||||
'discount': undefined,
|
||||
};
|
||||
this.action_callback = {};
|
||||
|
||||
this.action_callback_stack = [];
|
||||
|
||||
@@ -250,9 +250,13 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||
// possible actions include :
|
||||
// 'product' | 'cashier' | 'client' | 'discount'
|
||||
|
||||
set_action_callbacks: function(callbacks){
|
||||
for(action in callbacks){
|
||||
this.action_callback[action] = callbacks[action];
|
||||
set_action_callback: function(action, callback){
|
||||
if(arguments.length == 2){
|
||||
this.action_callback[action] = callback;
|
||||
}else{
|
||||
for(action in arguments[0]){
|
||||
this.set_action_callback(action,arguments[0][action]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -395,12 +399,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||
console.log('BARCODE:',parse_result);
|
||||
|
||||
if (parse_result.type === 'error') { //most likely a checksum error, raise warning
|
||||
$(QWeb.render('pos-scan-warning')).dialog({
|
||||
resizable: false,
|
||||
height:220,
|
||||
modal: true,
|
||||
title: "Warning",
|
||||
});
|
||||
console.log('ERROR: barcode checksum error:',parse_result);
|
||||
}else if(parse_result.type in {'unit':'', 'weight':'', 'price':''}){ //ean is associated to a product
|
||||
if(self.action_callback['product']){
|
||||
self.action_callback['product'](parse_result);
|
||||
|
||||
@@ -20,6 +20,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
|
||||
module.ScreenSelector = instance.web.Class.extend({
|
||||
init: function(options){
|
||||
console.log("ScreenSelector Initialized");
|
||||
this.pos = options.pos;
|
||||
|
||||
this.screen_set = options.screen_set || {};
|
||||
@@ -29,36 +30,20 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
this.default_client_screen = options.default_client_screen;
|
||||
this.default_cashier_screen = options.default_cashier_screen;
|
||||
|
||||
this.current_client_screen = this.screen_set[this.default_client_screen];
|
||||
|
||||
this.current_cashier_screen = this.screen_set[this.default_cashier_screen];
|
||||
|
||||
this.current_popup = null;
|
||||
|
||||
this.current_mode = options.default_mode || 'client';
|
||||
|
||||
this.current_screen = this.current_mode === 'client' ?
|
||||
this.current_client_screen:
|
||||
this.current_cashier_screen;
|
||||
this.current_screen = null;
|
||||
|
||||
var current = null;
|
||||
for(screen_name in this.screen_set){
|
||||
var screen = this.screen_set[screen_name];
|
||||
if(screen === this.current_screen){
|
||||
current = screen;
|
||||
}else{
|
||||
screen.hide();
|
||||
}
|
||||
this.screen_set[screen_name].hide();
|
||||
}
|
||||
|
||||
for(popup_name in this.popup_set){
|
||||
this.popup_set[popup_name].hide();
|
||||
}
|
||||
|
||||
if(current){
|
||||
current.show();
|
||||
}
|
||||
|
||||
this.selected_order = this.pos.get('selectedOrder');
|
||||
this.selected_order.set({
|
||||
user_mode : this.current_mode,
|
||||
@@ -73,12 +58,11 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
this.screen_set[screen_name] = screen;
|
||||
return this;
|
||||
},
|
||||
show_popup: function(name,message){
|
||||
show_popup: function(name){
|
||||
if(this.current_popup){
|
||||
this.close_popup();
|
||||
}
|
||||
this.current_popup = this.popup_set[name];
|
||||
this.current_popup.set_message(message);
|
||||
this.current_popup.show();
|
||||
},
|
||||
close_popup: function(){
|
||||
@@ -122,15 +106,20 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
|
||||
if(screen && screen !== this.current_screen){
|
||||
if(this.current_screen){
|
||||
this.current_screen.close();
|
||||
this.current_screen.hide();
|
||||
}
|
||||
this.current_screen = screen;
|
||||
this.current_screen.show();
|
||||
}
|
||||
},
|
||||
set_default_screen: function(){
|
||||
this.set_current_screen(this.current_mode === 'client' ? this.default_client_screen : this.default_cashier_screen);
|
||||
},
|
||||
});
|
||||
|
||||
module.ScreenWidget = module.PosBaseWidget.extend({
|
||||
|
||||
init: function(parent,options){
|
||||
this._super(parent,options);
|
||||
this.hidden = false;
|
||||
@@ -153,6 +142,8 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
this.pos_widget.action_bar.destroy_buttons();
|
||||
}
|
||||
},
|
||||
close: function(){
|
||||
},
|
||||
// we need this because some screens re-render themselves when they are hidden
|
||||
// (due to some events, or magic, or both...) we must make sure they remain hidden.
|
||||
// the good solution would probably be to make them not re-render themselves when they
|
||||
@@ -166,19 +157,22 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
module.PopUpWidget = module.ScreenWidget.extend({
|
||||
module.PopUpWidget = module.PosBaseWidget.extend({
|
||||
show: function(){
|
||||
if(this.$element){
|
||||
this.$element.show();
|
||||
}
|
||||
},
|
||||
hide: function(){
|
||||
if(this.$element){
|
||||
this.$element.hide();
|
||||
}
|
||||
},
|
||||
set_message: function(message){
|
||||
this.message = message || '';
|
||||
this.renderElement();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
module.HelpPopupWidget = module.PopUpWidget.extend({
|
||||
template:'HelpPopupWidget',
|
||||
show: function(){
|
||||
@@ -219,7 +213,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
|
||||
this.pos.barcode_reader.save_callbacks();
|
||||
this.pos.barcode_reader.reset_action_callbacks();
|
||||
this.pos.barcode_reader.set_action_callbacks({
|
||||
this.pos.barcode_reader.set_action_callback({
|
||||
'cashier': function(ean){
|
||||
clearInterval(this.intervalID);
|
||||
self.pos.proxy.cashier_mode_activated();
|
||||
@@ -227,7 +221,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
},
|
||||
});
|
||||
},
|
||||
hide:function(){
|
||||
close:function(){
|
||||
this._super();
|
||||
this.pos.proxy.help_canceled();
|
||||
this.pos.barcode_reader.restore_callbacks();
|
||||
@@ -277,7 +271,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
}
|
||||
);
|
||||
|
||||
this.pos.barcode_reader.set_action_callbacks({
|
||||
this.pos.barcode_reader.set_action_callback({
|
||||
'cashier': function(ean){
|
||||
self.pos.proxy.cashier_mode_activated();
|
||||
self.pos_widget.screen_selector.set_user_mode('cashier');
|
||||
@@ -292,7 +286,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
},
|
||||
});
|
||||
},
|
||||
hide: function(){
|
||||
close: function(){
|
||||
this._super();
|
||||
clearInterval(this.intervalID);
|
||||
},
|
||||
@@ -337,7 +331,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
}
|
||||
}
|
||||
);
|
||||
this.pos.barcode_reader.set_action_callbacks({
|
||||
this.pos.barcode_reader.set_action_callback({
|
||||
'cashier': function(ean){
|
||||
self.pos.proxy.cashier_mode_activated();
|
||||
self.pos_widget.screen_selector.set_user_mode('cashier');
|
||||
@@ -386,7 +380,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
}
|
||||
},500);
|
||||
},
|
||||
hide: function(){
|
||||
close: function(){
|
||||
this._super();
|
||||
this.pos_widget.order_widget.set_numpad_state(null);
|
||||
this.pos_widget.payment_screen.set_numpad_state(null);
|
||||
@@ -453,7 +447,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
}
|
||||
);
|
||||
|
||||
this.pos.barcode_reader.set_action_callbacks({
|
||||
this.pos.barcode_reader.set_action_callback({
|
||||
'cashier': function(ean){
|
||||
clearInterval(this.intervalID);
|
||||
self.pos.proxy.cashier_mode_activated();
|
||||
@@ -461,7 +455,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
},
|
||||
});
|
||||
},
|
||||
hide: function(){
|
||||
close: function(){
|
||||
this._super();
|
||||
clearInterval(this.intervalID);
|
||||
},
|
||||
@@ -492,7 +486,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
});
|
||||
}
|
||||
|
||||
this.pos.barcode_reader.set_action_callbacks({
|
||||
this.pos.barcode_reader.set_action_callback({
|
||||
'product': function(ean){
|
||||
self.pos.proxy.transaction_start();
|
||||
if(self.pos_widget.scan_product(ean)){
|
||||
@@ -520,11 +514,6 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
},
|
||||
});
|
||||
},
|
||||
hide: function(){
|
||||
this._super();
|
||||
this.pos.barcode_reader.reset_action_callbacks();
|
||||
this.pos_widget.action_bar.destroy_buttons();
|
||||
},
|
||||
});
|
||||
|
||||
module.ScanProductScreenWidget = module.ScreenWidget.extend({
|
||||
@@ -559,7 +548,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
}
|
||||
});
|
||||
|
||||
this.pos.barcode_reader.set_action_callbacks({
|
||||
this.pos.barcode_reader.set_action_callback({
|
||||
'product': function(ean){
|
||||
if(self.pos_widget.scan_product(ean)){
|
||||
self.pos.proxy.scan_item_success();
|
||||
@@ -621,7 +610,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
});
|
||||
}
|
||||
|
||||
this.pos.barcode_reader.set_action_callbacks({
|
||||
this.pos.barcode_reader.set_action_callback({
|
||||
'product': function(ean){
|
||||
if(self.pos_widget.scan_product(ean)){
|
||||
self.pos.proxy.scan_item_success();
|
||||
@@ -642,7 +631,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
},
|
||||
});
|
||||
},
|
||||
hide: function(){
|
||||
close: function(){
|
||||
this._super();
|
||||
this.pos_widget.order_widget.set_numpad_state(null);
|
||||
this.pos_widget.payment_screen.set_numpad_state(null);
|
||||
@@ -755,7 +744,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
||||
},
|
||||
});
|
||||
},
|
||||
hide: function(){
|
||||
close: function(){
|
||||
this._super();
|
||||
this.pos_widget.order_widget.set_numpad_state(null);
|
||||
this.pos_widget.payment_screen.set_numpad_state(null);
|
||||
|
||||
@@ -330,11 +330,37 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
|
||||
init: function(parent, options){
|
||||
this._super(parent,options);
|
||||
this.button_list = [];
|
||||
this.fake_buttons = {};
|
||||
this.visibility = {};
|
||||
this.total_visibility = true;
|
||||
this.help_visibility = true;
|
||||
this.logout_visibility = true;
|
||||
this.close_visibility = true;
|
||||
},
|
||||
set_element_visible: function(button, visible, action){
|
||||
if(visible != this.visibility[button]){
|
||||
this.visibility[button] = visible;
|
||||
if(visible){
|
||||
this.$('.'+button).show();
|
||||
}else{
|
||||
this.$('.'+button).hide();
|
||||
}
|
||||
}
|
||||
if(visible && action){
|
||||
this.$('.'+button).off('click').click(action);
|
||||
}
|
||||
},
|
||||
set_all_elements_invisible: function(){
|
||||
for(el in this.visibility){
|
||||
if(this.visibility[el]){
|
||||
this.visibility[el] = false;
|
||||
this.$('.'+el).hide();
|
||||
}
|
||||
}
|
||||
},
|
||||
set_total_value: function(value){
|
||||
this.$('.value').html(value);
|
||||
},
|
||||
destroy_buttons:function(){
|
||||
for(var i = 0; i < this.button_list.length; i++){
|
||||
this.button_list[i].destroy();
|
||||
@@ -404,9 +430,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
|
||||
this.$element.find('.close-button').off('click').click(action);
|
||||
}
|
||||
},
|
||||
set_total_value: function(value){
|
||||
this.$element.find('.value').html(value);
|
||||
},
|
||||
});
|
||||
|
||||
module.ProductCategoriesWidget = module.PosBaseWidget.extend({
|
||||
@@ -791,6 +814,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
|
||||
|
||||
this.pos = new module.PosModel(this.session);
|
||||
window.pos = this.pos;
|
||||
window.pos_widget = this;
|
||||
this.pos_widget = this; //So that pos_widget's childs have pos_widget set automatically
|
||||
|
||||
this.numpad_visible = true;
|
||||
@@ -919,10 +943,10 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
|
||||
this.order_widget = new module.OrderWidget(this, {});
|
||||
this.order_widget.replace($('#placeholder-OrderWidget'));
|
||||
|
||||
/*this.onscreen_keyboard = new module.OnscreenKeyboardWidget(this, {
|
||||
this.onscreen_keyboard = new module.OnscreenKeyboardWidget(this, {
|
||||
'keyboard_model': 'simple'
|
||||
});
|
||||
this.onscreen_keyboard.appendTo($(".point-of-sale #content")); */
|
||||
this.onscreen_keyboard.appendTo($(".point-of-sale #content"));
|
||||
|
||||
// -------- Screen Selector ---------
|
||||
|
||||
@@ -949,6 +973,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
|
||||
default_cashier_screen: 'products',
|
||||
default_mode: this.pos.use_selfcheckout ? 'client' : 'cashier',
|
||||
});
|
||||
this.screen_selector.set_default_screen();
|
||||
|
||||
window.screen_selector = this.screen_selector; //DEBUG
|
||||
|
||||
|
||||
Reference in New Issue
Block a user