From dc8e18ac04c65ebb2ddcb58233ea428c45b0ef30 Mon Sep 17 00:00:00 2001 From: Frederic van der Essen Date: Tue, 2 Sep 2014 17:35:01 +0200 Subject: [PATCH] [WIP] point_of_sale: refactor error popups in preparation of a multicompany-screwup prevention error popup --- addons/point_of_sale/static/src/js/screens.js | 69 ++++++------------- addons/point_of_sale/static/src/js/widgets.js | 10 --- addons/point_of_sale/static/src/xml/pos.xml | 51 +------------- 3 files changed, 21 insertions(+), 109 deletions(-) diff --git a/addons/point_of_sale/static/src/js/screens.js b/addons/point_of_sale/static/src/js/screens.js index 5626ae822bd..215aa0f1ab6 100644 --- a/addons/point_of_sale/static/src/js/screens.js +++ b/addons/point_of_sale/static/src/js/screens.js @@ -314,58 +314,28 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa }, }); - - module.ChooseReceiptPopupWidget = module.PopUpWidget.extend({ - template:'ChooseReceiptPopupWidget', - show: function(){ - this._super(); - this.renderElement(); - var self = this; - var currentOrder = self.pos.get('selectedOrder'); - - this.$('.button.receipt').off('click').click(function(){ - currentOrder.set_receipt_type('receipt'); - self.pos_widget.screen_selector.set_current_screen('products'); - }); - - this.$('.button.invoice').off('click').click(function(){ - currentOrder.set_receipt_type('invoice'); - self.pos_widget.screen_selector.set_current_screen('products'); - }); - }, - get_client_name: function(){ - var client = this.pos.get('selectedOrder').get_client(); - if( client ){ - return client.name; - }else{ - return ''; - } - }, - }); - module.ErrorPopupWidget = module.PopUpWidget.extend({ template:'ErrorPopupWidget', - show: function(text){ + show: function(options){ + options = options || {}; var self = this; this._super(); $('body').append(''); - if( text ) { - if ( text.message || text.comment ) { - this.$('.message').text(text.message); - this.$('.comment').text(text.comment); - } else { - this.$('.message').text(_t('Error')); - this.$('.comment').html(text); - } - } + this.message = options.message || _t('Error'); + this.comment = options.comment || ''; + + this.renderElement(); this.pos.barcode_reader.save_callbacks(); this.pos.barcode_reader.reset_action_callbacks(); - this.$('.footer .button').off('click').click(function(){ + + this.$('.footer .button').click(function(){ self.pos_widget.screen_selector.close_popup(); - }); + if ( options.confirm ) { + options.confirm.call(self); + } }, close:function(){ this._super(); @@ -377,16 +347,11 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa template:'ErrorTracebackPopupWidget', }); - module.ErrorSessionPopupWidget = module.ErrorPopupWidget.extend({ - template:'ErrorSessionPopupWidget', - }); - module.ErrorBarcodePopupWidget = module.ErrorPopupWidget.extend({ template:'ErrorBarcodePopupWidget', show: function(barcode){ + this.barcode = barcode; this._super(); - this.$('.barcode').text(barcode); - }, }); @@ -1117,9 +1082,15 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa invoiced.fail(function(error){ if(error === 'error-no-client'){ - self.pos_widget.screen_selector.show_popup('error-no-client'); + self.pos_widget.screen_selector.show_popup('error',{ + message: _t('An anonymous order cannot be invoiced'), + comment: _t('Please select a client for this order. This can be done by clicking the order tab'), + }); }else{ - self.pos_widget.screen_selector.show_popup('error-invoice-transfer'); + self.pos_widget.screen_selector.show_popup('error',{ + message: _t('The order could not be sent'), + comment: _t('Check your internet connection and try again.'), + }); } self.pos_widget.action_bar.set_button_disabled('validation',false); self.pos_widget.action_bar.set_button_disabled('invoice',false); diff --git a/addons/point_of_sale/static/src/js/widgets.js b/addons/point_of_sale/static/src/js/widgets.js index fc6076e3ee0..2418468f3d2 100644 --- a/addons/point_of_sale/static/src/js/widgets.js +++ b/addons/point_of_sale/static/src/js/widgets.js @@ -1113,15 +1113,9 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa this.error_barcode_popup = new module.ErrorBarcodePopupWidget(this, {}); this.error_barcode_popup.appendTo(this.$el); - this.error_session_popup = new module.ErrorSessionPopupWidget(this, {}); - this.error_session_popup.appendTo(this.$el); - this.choose_receipt_popup = new module.ChooseReceiptPopupWidget(this, {}); this.choose_receipt_popup.appendTo(this.$el); - this.error_no_client_popup = new module.ErrorNoClientPopupWidget(this, {}); - this.error_no_client_popup.appendTo(this.$el); - this.error_invoice_transfer_popup = new module.ErrorInvoiceTransferPopupWidget(this, {}); this.error_invoice_transfer_popup.appendTo(this.$el); @@ -1198,10 +1192,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa popup_set:{ 'error': this.error_popup, 'error-barcode': this.error_barcode_popup, - 'error-session': this.error_session_popup, - 'choose-receipt': this.choose_receipt_popup, - 'error-no-client': this.error_no_client_popup, - 'error-invoice-transfer': this.error_invoice_transfer_popup, 'error-traceback': this.error_traceback_popup, 'confirm': this.confirm_popup, 'unsent-orders': this.unsent_orders_popup, diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index ece15535b0b..f002a88a225 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -574,55 +574,6 @@ - - - - - - - - - - - - - - - -