[IMP] point_of_sale: numpad & password popups
authorFrederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com>
Tue, 7 Oct 2014 23:54:51 +0000 (01:54 +0200)
committerFrédéric van der Essen <fvdessen@gmail.com>
Wed, 26 Nov 2014 11:11:44 +0000 (12:11 +0100)
Conflicts:
addons/point_of_sale/static/src/js/widgets.js

addons/point_of_sale/static/src/css/pos.css
addons/point_of_sale/static/src/js/screens.js
addons/point_of_sale/static/src/js/widgets.js
addons/point_of_sale/static/src/xml/pos.xml

index 717772e..3221647 100644 (file)
@@ -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  ********* */
 
index 713f520..35feec3 100644 (file)
@@ -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();
index 074aa16..1109168 100644 (file)
@@ -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',
index 3ea598e..7861a90 100644 (file)
     <t t-name="SelectionPopupWidget">
         <div class="modal-dialog">
             <div class="popup popup-selection">
-                <p class="message"><t t-esc=" widget.message || 'Confirm ?' " /></p>
+                <p class="message"><t t-esc=" widget.message || 'Select' " /></p>
                 <div class='selection scrollable-y touch-scrollable'>
                     <t t-foreach="widget.list || []" t-as="item">
                         <div class='selection-item' t-att-data-item-index='item_index'>
         </div>
     </t>
 
+    <t t-name="NumberPopupWidget">
+        <div class="modal-dialog">
+            <div class="popup popup-number">
+                <p class="message"><t t-esc=" widget.message || '' " /></p>
+                <div class='popup-input value active'>
+                    <t t-esc='widget.inputbuffer' />
+                </div>
+                <div class='popup-numpad'>
+                    <button class="input-button number-char" data-action='1'>1</button>
+                    <button class="input-button number-char" data-action='2'>2</button>
+                    <button class="input-button number-char" data-action='3'>3</button>
+                    <button class="mode-button add" data-action='+10'>+10</button>
+                    <br />
+                    <button class="input-button number-char" data-action='4'>4</button>
+                    <button class="input-button number-char" data-action='5'>5</button>
+                    <button class="input-button number-char" data-action='6'>6</button>
+                    <button class="mode-button add" data-action='+20'>+20</button>
+                    <br />
+                    <button class="input-button number-char" data-action='7'>7</button>
+                    <button class="input-button number-char" data-action='8'>8</button>
+                    <button class="input-button number-char" data-action='9'>9</button>
+                    <button class="mode-button add" data-action='+50'>+50</button>
+                    <br />
+                    <button class="input-button numpad-char" data-action='CLEAR' >C</button>
+                    <button class="input-button number-char" data-action='0'>0</button>
+                    <button class="input-button number-char dot" data-action='.'>.</button>
+                    <button class="input-button numpad-backspace" data-action='BACKSPACE' >
+                        <img src="/point_of_sale/static/src/img/backspace.png" width="24" height="21" />
+                    </button>
+                    <br />
+                </div>
+                <div class="footer">
+                    <div class="button confirm">
+                        Ok
+                    </div>
+                    <div class="button cancel">
+                        Cancel 
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+
     <t t-name="Product">
         <span class='product' t-att-data-product-id="product.id">
             <div class="product-img">