summaryrefslogtreecommitdiff
path: root/addons/pos_restaurant/static/src/js
diff options
context:
space:
mode:
authorFrédéric van der Essen <fvdessen@gmail.com>2014-12-30 16:08:54 +0100
committerFrédéric van der Essen <fvdessen@gmail.com>2014-12-31 15:34:32 +0100
commit5a8838243d62af2ed760a1a69a968d36ccbf1178 (patch)
treeda486af859528d1d097b91dc0a2de3610e7d85e8 /addons/pos_restaurant/static/src/js
parent68ca9465771d6c22136a05849465afcb543ff8bc (diff)
[WIP] point_of_sale, pos_restaurant: continued refactor
- this time it's the restaurant module that has been refactored - the point of sale extensions points have been reviewed to be more constistent and allow conditional extensions. - the chrome subwidgets are instanciated before screens, so that screens can manipulate them if needed.
Diffstat (limited to 'addons/pos_restaurant/static/src/js')
-rw-r--r--addons/pos_restaurant/static/src/js/floors.js51
-rw-r--r--addons/pos_restaurant/static/src/js/multiprint.js54
-rw-r--r--addons/pos_restaurant/static/src/js/notes.js24
-rw-r--r--addons/pos_restaurant/static/src/js/printbill.js40
-rw-r--r--addons/pos_restaurant/static/src/js/splitbill.js45
5 files changed, 96 insertions, 118 deletions
diff --git a/addons/pos_restaurant/static/src/js/floors.js b/addons/pos_restaurant/static/src/js/floors.js
index 686593eb887..d6d694578a9 100644
--- a/addons/pos_restaurant/static/src/js/floors.js
+++ b/addons/pos_restaurant/static/src/js/floors.js
@@ -3,7 +3,7 @@ function openerp_restaurant_floors(instance,module){
var _t = instance.web._t;
// At POS Startup, load the floors, and add them to the pos model
- module.PosModel.prototype.models.push({
+ module.load_models({
model: 'restaurant.floor',
fields: ['name','background_image','table_ids','sequence'],
domain: function(self){ return [['pos_config_id','=',self.config.id]] },
@@ -25,7 +25,7 @@ function openerp_restaurant_floors(instance,module){
// At POS Startup, after the floors are loaded, load the tables, and associate
// them with their floor.
- module.PosModel.prototype.models.push({
+ module.load_models({
model: 'restaurant.table',
fields: ['name','width','height','position_h','position_v','shape','floor_id','color'],
loaded: function(self,tables){
@@ -324,11 +324,11 @@ function openerp_restaurant_floors(instance,module){
if (this.editing) {
this.toggle_editing();
}
- this.pos_widget.order_selector.show();
+ this.chrome.widget.order_selector.show();
},
show: function(){
this._super();
- this.pos_widget.order_selector.hide();
+ this.chrome.widget.order_selector.hide();
for (var i = 0; i < this.table_widgets.length; i++) {
this.table_widgets[i].renderElement();
}
@@ -393,8 +393,8 @@ function openerp_restaurant_floors(instance,module){
tool_rename_table: function(){
var self = this;
if (this.selected_table) {
- this.pos_widget.screen_selector.show_popup('textinput',{
- 'message':_t('Table Name ?'),
+ this.gui.show_popup('textinput',{
+ 'title':_t('Table Name ?'),
'value': this.selected_table.table.name,
'confirm': function(value) {
self.selected_table.set_table_name(value);
@@ -441,8 +441,8 @@ function openerp_restaurant_floors(instance,module){
tool_trash_table: function(){
var self = this;
if (this.selected_table) {
- this.pos_widget.screen_selector.show_popup('confirm',{
- 'message':_t('Are you sure ?'),
+ this.gui.show_popup('confirm',{
+ 'title': _t('Are you sure ?'),
'comment':_t('Removing a table cannot be undone'),
'confirm': function(){
self.selected_table.trash();
@@ -562,36 +562,21 @@ function openerp_restaurant_floors(instance,module){
},
});
+ module.Gui.define_screen({
+ 'name': 'floors',
+ 'widget': module.FloorScreenWidget,
+ 'condition': function(){
+ return this.pos.config.iface_floorplan;
+ },
+ });
+
// Add the FloorScreen to the GUI, and set it as the default screen
- module.PosWidget.include({
+ module.Chrome.include({
build_widgets: function(){
var self = this;
this._super();
if (this.pos.config.iface_floorplan) {
- this.floors_screen = new module.FloorScreenWidget(this,{});
- this.floors_screen.appendTo(this.$('.screens'));
- this.screen_selector.add_screen('floors',this.floors_screen);
- this.screen_selector.change_default_screen('floors');
- }
- },
- });
-
- // when the floor plan is activated, we need to go back to the floor plan
- // when an order is completed. Usually on order completion, a new order is
- // set as the current one. Now, we set the new order to null.
- // load_saved_screen() is called whenever the current order is changed, and
- // will detect this, and set the current screen to the default_screen,
- // which is the floor plan.
- module.ScreenSelector.include({
- load_saved_screen: function(){
- if (this.pos.config.iface_floorplan) {
- if (!this.pos.get_order()) {
- this.set_current_screen(this.default_screen,null,'refresh');
- } else {
- this._super({default_screen:'products'});
- }
- } else {
- this._super.apply(this,arguments);
+ this.gui.set_startup_screen('floors');
}
},
});
diff --git a/addons/pos_restaurant/static/src/js/multiprint.js b/addons/pos_restaurant/static/src/js/multiprint.js
index c2d4461c3ae..0ca4695768b 100644
--- a/addons/pos_restaurant/static/src/js/multiprint.js
+++ b/addons/pos_restaurant/static/src/js/multiprint.js
@@ -33,7 +33,7 @@ function openerp_restaurant_multiprint(instance,module){
},
});
- module.PosModel.prototype.models.push({
+ module.load_models({
model: 'restaurant.printer',
fields: ['name','proxy_ip','product_categories_ids'],
domain: null,
@@ -220,39 +220,39 @@ function openerp_restaurant_multiprint(instance,module){
},
});
- module.PosWidget.include({
- build_widgets: function(){
- var self = this;
- this._super();
-
- if(this.pos.printers.length){
- var submitorder = $(QWeb.render('SubmitOrderButton'));
-
- submitorder.click(function(){
- var order = self.pos.get('selectedOrder');
- if(order.hasChangesToPrint()){
- order.printChanges();
- order.saveChanges();
- self.pos_widget.order_widget.update_summary();
- }
- });
-
- submitorder.appendTo(this.$('.control-buttons'));
- this.$('.control-buttons').removeClass('oe_hidden');
+ module.SubmitOrderButton = module.ActionButtonWidget.extend({
+ 'template': 'SubmitOrderButton',
+ button_click: function(){
+ var order = this.pos.get_order();
+ if(order.hasChangesToPrint()){
+ order.printChanges();
+ order.saveChanges();
+ }
+ },
+ hilight: function(hi){
+ if (hi) {
+ this.$el.addClass('highlight');
+ } else {
+ this.$el.removeClass('highlight');
}
},
-
+ });
+
+ module.define_action_button({
+ 'name': 'submit_order',
+ 'widget': module.SubmitOrderButton,
+ 'condition': function() {
+ return this.pos.printers.length;
+ },
});
module.OrderWidget.include({
update_summary: function(){
this._super();
- var order = this.pos.get('selectedOrder');
-
- if(order.hasChangesToPrint()){
- this.pos_widget.$('.order-submit').addClass('highlight');
- }else{
- this.pos_widget.$('.order-submit').removeClass('highlight');
+ var changes = this.pos.get_order().hasChangesToPrint();
+ if (this.getParent().action_buttons &&
+ this.getParent().action_buttons.submit_order) {
+ this.getParent().action_buttons.submit_order.highlight(changes);
}
},
});
diff --git a/addons/pos_restaurant/static/src/js/notes.js b/addons/pos_restaurant/static/src/js/notes.js
index 1e4c9489f22..ef33552b8ee 100644
--- a/addons/pos_restaurant/static/src/js/notes.js
+++ b/addons/pos_restaurant/static/src/js/notes.js
@@ -41,13 +41,12 @@ function openerp_restaurant_notes(instance,module){
},
});
- module.PosWidget.include({
- orderline_note_click: function(){
- var self = this;
+ module.OrderlineNoteButton = module.ActionButtonWidget.extend({
+ template: 'OrderlineNoteButton',
+ button_click: function(){
var line = this.pos.get_order().get_selected_orderline();
-
if (line) {
- this.screen_selector.show_popup('textarea',{
+ this.gui.show_popup('textarea',{
message: _t('Orderline Note'),
value: line.get_note(),
confirm: function(note) {
@@ -56,16 +55,13 @@ function openerp_restaurant_notes(instance,module){
});
}
},
- build_widgets: function(){
- var self = this;
- this._super();
+ });
- if (this.pos.config.iface_orderline_notes) {
- var button = $(QWeb.render('OrderlineNoteButton'));
- button.click(function(){ self.orderline_note_click(); });
- button.appendTo(this.$('.control-buttons'));
- this.$('.control-buttons').removeClass('oe_hidden');
- }
+ module.define_action_button({
+ 'name': 'orderline_note',
+ 'widget': module.OrderlineNoteButton,
+ 'condition': function(){
+ return this.pos.config.iface_orderline_notes;
},
});
}
diff --git a/addons/pos_restaurant/static/src/js/printbill.js b/addons/pos_restaurant/static/src/js/printbill.js
index c8bfc8ec93e..3ea879e5b92 100644
--- a/addons/pos_restaurant/static/src/js/printbill.js
+++ b/addons/pos_restaurant/static/src/js/printbill.js
@@ -2,28 +2,26 @@ function openerp_restaurant_printbill(instance,module){
var QWeb = instance.web.qweb;
var _t = instance.web._t;
- module.PosWidget.include({
- build_widgets: function(){
- var self = this;
- this._super();
-
- if(this.pos.config.iface_printbill){
- var printbill = $(QWeb.render('PrintBillButton'));
-
- printbill.click(function(){
- var order = self.pos.get('selectedOrder');
- if(order.get_orderlines().length > 0){
- var receipt = order.export_for_printing();
- receipt.bill = true;
- self.pos.proxy.print_receipt(QWeb.render('BillReceipt',{
- receipt: receipt, widget: self, pos: self.pos, order: order,
- }));
- }
- });
-
- printbill.appendTo(this.$('.control-buttons'));
- this.$('.control-buttons').removeClass('oe_hidden');
+ module.PrintBillButton = module.ActionButtonWidget.extend({
+ template: 'PrintBillButton',
+ button_click: function(){
+ var order = this.pos.get('selectedOrder');
+ if(order.get_orderlines().length > 0){
+ var receipt = order.export_for_printing();
+ receipt.bill = true;
+ this.pos.proxy.print_receipt(QWeb.render('BillReceipt',{
+ receipt: receipt, widget: this, pos: this.pos, order: order,
+ }));
}
},
});
+
+ module.define_action_button({
+ 'name': 'print_bill',
+ 'widget': module.PrintBillButton,
+ 'condition': function(){
+ return this.pos.config.iface_printbill;
+ },
+ });
}
+
diff --git a/addons/pos_restaurant/static/src/js/splitbill.js b/addons/pos_restaurant/static/src/js/splitbill.js
index f58f77eedc8..06d03705d5f 100644
--- a/addons/pos_restaurant/static/src/js/splitbill.js
+++ b/addons/pos_restaurant/static/src/js/splitbill.js
@@ -1,11 +1,9 @@
function openerp_restaurant_splitbill(instance, module){
var QWeb = instance.web.qweb;
- var _t = instance.web._t;
module.SplitbillScreenWidget = module.ScreenWidget.extend({
template: 'SplitbillScreenWidget',
- show_leftpane: false,
previous_screen: 'products',
renderElement: function(){
@@ -29,7 +27,7 @@ function openerp_restaurant_splitbill(instance, module){
this.$('.orderlines').append(linewidget);
}
this.$('.back').click(function(){
- self.pos_widget.screen_selector.set_current_screen(self.previous_screen);
+ self.gui.show_screen(self.previous_screen);
});
},
@@ -102,7 +100,7 @@ function openerp_restaurant_splitbill(instance, module){
if(full){
- this.pos_widget.screen_selector.set_current_screen('payment');
+ this.gui.show_screen('payment');
}else{
for(var id in splitlines){
var split = splitlines[id];
@@ -157,27 +155,28 @@ function openerp_restaurant_splitbill(instance, module){
},
});
- module.PosWidget.include({
- build_widgets: function(){
- var self = this;
- this._super();
-
- if(this.pos.config.iface_splitbill){
- this.splitbill_screen = new module.SplitbillScreenWidget(this,{});
- this.splitbill_screen.appendTo(this.$('.screens'));
- this.screen_selector.add_screen('splitbill',this.splitbill_screen);
-
- var splitbill = $(QWeb.render('SplitbillButton'));
+ module.Gui.define_screen({
+ 'name': 'splitbill',
+ 'widget': module.SplitbillScreenWidget,
+ 'condition': function(){
+ return this.pos.config.iface_splitbill;
+ },
+ });
- splitbill.click(function(){
- if(self.pos.get_order().get_orderlines().length > 0){
- self.pos_widget.screen_selector.set_current_screen('splitbill');
- }
- });
-
- splitbill.appendTo(this.$('.control-buttons'));
- this.$('.control-buttons').removeClass('oe_hidden');
+ module.SplitbillButton = module.ActionButtonWidget.extend({
+ template: 'SplitbillButton',
+ button_click: function(){
+ if(this.pos.get_order().get_orderlines().length > 0){
+ self.gui.show_screen('splitbill');
}
},
});
+
+ module.define_action_button({
+ 'name': 'splitbill',
+ 'widget': module.SplitbillButton,
+ 'condition': function(){
+ return this.pos.config.iface_splitbill;
+ },
+ });
}