From 624ced718fc87ee94783617eb29ef592b737f338 Mon Sep 17 00:00:00 2001 From: Frederic van der Essen Date: Wed, 8 Oct 2014 01:54:51 +0200 Subject: [PATCH] [IMP] point_of_sale: numpad & password popups Conflicts: addons/point_of_sale/static/src/js/widgets.js --- addons/point_of_sale/static/src/css/pos.css | 47 +++++++++- addons/point_of_sale/static/src/js/screens.js | 85 ++++++++++++++++++- addons/point_of_sale/static/src/js/widgets.js | 28 +++--- addons/point_of_sale/static/src/xml/pos.xml | 45 +++++++++- 4 files changed, 191 insertions(+), 14 deletions(-) diff --git a/addons/point_of_sale/static/src/css/pos.css b/addons/point_of_sale/static/src/css/pos.css index 717772ebd88..322164772c0 100644 --- a/addons/point_of_sale/static/src/css/pos.css +++ b/addons/point_of_sale/static/src/css/pos.css @@ -1925,7 +1925,13 @@ td { height: 180px; line-height:180px; } -.pos .popup input { +.pos .popup input, +.pos .popup-input { + text-align: left; + display: inline-block; + overflow: hidden; + background: white; + min-height: 44px; font-family: "Lato"; font-size: 20px; color: #444; @@ -1936,7 +1942,8 @@ td { box-sizing: border-box; width: 80%; } -.pos .popup input:focus { +.pos .popup input:focus, +.pos .popup-input.active { outline: none; box-shadow: 0px 0px 0px 3px #6EC89B; } @@ -1962,6 +1969,42 @@ td { .pos .popup.popup-selection .selection-item:nth-child(even) { background: rgb(247,247,247); } +.pos .popup-numpad { + margin: 12px auto; + text-align: left; + width: 244px; +} +.pos .popup-number .message { + margin-top: 0; +} +.pos .popup-numpad .input-button, +.pos .popup-numpad .mode-button { + background: none; + height: 50px; + width: 50px; + padding: 0; + border-radius: 25px; + margin: 4px; + vertical-align: top; + color: #444; +} +.pos .popup-numpad .input-button:active, +.pos .popup-numpad .mode-button:active { + background: #444; + color: white; + border-color: #444; +} + +.pos .popup-password .mode-button.add, +.pos .popup-password .input-button.dot { + display: none; +} +.pos .popup-password .popup-numpad { + width: 182px; +} +.pos .popup-password .popup-input { + -webkit-text-security: disc; + } /* ********* The Webkit Scrollbar ********* */ diff --git a/addons/point_of_sale/static/src/js/screens.js b/addons/point_of_sale/static/src/js/screens.js index 713f5208c1a..35feec37f2e 100644 --- a/addons/point_of_sale/static/src/js/screens.js +++ b/addons/point_of_sale/static/src/js/screens.js @@ -462,6 +462,89 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa template: 'TextAreaPopupWidget', }); + module.NumberPopupWidget = module.PopUpWidget.extend({ + template: 'NumberPopupWidget', + click_numpad_button: function($el,event){ + this.numpad_input($el.data('action')); + }, + numpad_input: function(input) { //FIXME -> Deduplicate code + var oldbuf = this.inputbuffer.slice(0); + + if (input === '.') { + if (this.firstinput) { + this.inputbuffer = "0."; + }else if (!this.inputbuffer.length || this.inputbuffer === '-') { + this.inputbuffer += "0."; + } else if (this.inputbuffer.indexOf('.') < 0){ + this.inputbuffer = this.inputbuffer + '.'; + } + } else if (input === 'CLEAR') { + this.inputbuffer = ""; + } else if (input === 'BACKSPACE') { + this.inputbuffer = this.inputbuffer.substring(0,this.inputbuffer.length - 1); + } else if (input === '+') { + if ( this.inputbuffer[0] === '-' ) { + this.inputbuffer = this.inputbuffer.substring(1,this.inputbuffer.length); + } + } else if (input === '-') { + if ( this.inputbuffer[0] === '-' ) { + this.inputbuffer = this.inputbuffer.substring(1,this.inputbuffer.length); + } else { + this.inputbuffer = '-' + this.inputbuffer; + } + } else if (input[0] === '+' && !isNaN(parseFloat(input))) { + this.inputbuffer = '' + ((parseFloat(this.inputbuffer) || 0) + parseFloat(input)); + } else if (!isNaN(parseInt(input))) { + if (this.firstinput) { + this.inputbuffer = '' + input; + } else { + this.inputbuffer += input; + } + } + + this.firstinput = this.inputbuffer.length === 0; + + if (this.inputbuffer !== oldbuf) { + this.$('.value').text(this.inputbuffer); + } + }, + show: function(options){ + options = options || {}; + var self = this; + this._super(); + + this.message = options.message || ''; + this.comment = options.comment || ''; + this.inputbuffer = options.value || ''; + this.renderElement(); + this.firstinput = true; + + this.$('.input-button,.mode-button').click(function(event){ + self.click_numpad_button($(this),event); + }); + this.$('.button.cancel').click(function(){ + self.pos_widget.screen_selector.close_popup(); + if( options.cancel ){ + options.cancel.call(self); + } + }); + + this.$('.button.confirm').click(function(){ + self.pos_widget.screen_selector.close_popup(); + if( options.confirm ){ + options.confirm.call(self,self.inputbuffer); + } + }); + }, + }); + + module.PasswordPopupWidget = module.NumberPopupWidget.extend({ + renderElement: function(){ + this._super(); + this.$('.popup').addClass('popup-password'); // HELLO HACK ! + }, + }); + module.ErrorNoClientPopupWidget = module.ErrorPopupWidget.extend({ template: 'ErrorNoClientPopupWidget', }); @@ -1160,7 +1243,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa } } - this.firstinput = false; + this.firstinput = this.inputbuffer.length === 0; if (this.inputbuffer !== oldbuf) { var order = this.pos.get_order(); diff --git a/addons/point_of_sale/static/src/js/widgets.js b/addons/point_of_sale/static/src/js/widgets.js index 074aa16dd80..110916814ec 100644 --- a/addons/point_of_sale/static/src/js/widgets.js +++ b/addons/point_of_sale/static/src/js/widgets.js @@ -1063,6 +1063,12 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa this.textarea_popup = new module.TextAreaPopupWidget(this,{}); this.textarea_popup.appendTo(this.$el); + this.number_popup = new module.NumberPopupWidget(this,{}); + this.number_popup.appendTo(this.$el); + + this.password_popup = new module.PasswordPopupWidget(this,{}); + this.password_popup.appendTo(this.$el); + this.unsent_orders_popup = new module.UnsentOrdersPopupWidget(this,{}); this.unsent_orders_popup.appendTo(this.$el); @@ -1133,16 +1139,18 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa 'clientlist': this.clientlist_screen, }, popup_set:{ - 'error': this.error_popup, - 'error-barcode': this.error_barcode_popup, - 'error-traceback': this.error_traceback_popup, - 'textinput': this.textinput_popup, - 'textarea': this.textarea_popup, - 'confirm': this.confirm_popup, - 'fullscreen': this.fullscreen_popup, - 'selection': this.selection_popup, - 'unsent-orders': this.unsent_orders_popup, - 'unpaid-orders': this.unpaid_orders_popup, + 'error': this.error_popup, + 'error-barcode': this.error_barcode_popup, + 'error-traceback': this.error_traceback_popup, + 'textinput': this.textinput_popup, + 'textarea': this.textarea_popup, + 'number': this.number_popup, + 'password': this.password_popup, + 'confirm': this.confirm_popup, + 'fullscreen': this.fullscreen_popup, + 'selection': this.selection_popup, + 'unsent-orders': this.unsent_orders_popup, + 'unpaid-orders': this.unpaid_orders_popup, }, default_screen: 'products', default_mode: 'cashier', diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 3ea598ea983..7861a90fb4c 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -1012,7 +1012,7 @@