[FIX] point_of_sale: onscreen keyboard working again
authorFrédéric van der Essen <fva@openerp.com>
Mon, 16 Dec 2013 18:20:59 +0000 (19:20 +0100)
committerFrédéric van der Essen <fva@openerp.com>
Mon, 16 Dec 2013 18:20:59 +0000 (19:20 +0100)
bzr revid: fva@openerp.com-20131216182059-4wukpqfvyagzm5vu

addons/point_of_sale/controllers/main.py
addons/point_of_sale/static/src/js/widget_keyboard.js
addons/point_of_sale/static/src/js/widgets.js

index 24cd29f..3d08b4c 100644 (file)
@@ -34,7 +34,7 @@ html_template = """<!DOCTYPE html>
         <link rel="shortcut icon" href="/web/static/src/img/favicon.ico" type="image/x-icon"/>
         <!-- <link rel="stylesheet" href="/point_of_sale/static/src/fonts/lato/stylesheet.css" /> -->
         <link rel="stylesheet" href="/point_of_sale/static/src/css/pos.css" />
-        <!-- <link rel="stylesheet" href="/point_of_sale/static/src/css/keyboard.css" />-->
+        <link rel="stylesheet" href="/point_of_sale/static/src/css/keyboard.css" />
         %(js)s
         <script type="text/javascript">
             $(function() {
index 2544b1b..a174c71 100644 (file)
@@ -35,45 +35,54 @@ function openerp_pos_keyboard(instance, module){ //module is instance.point_of_s
             this.numlock  = false;
         },
         
-        connect : function($target){
+        connect : function(target){
             var self = this;
-            this.$target = $target;
-            $target.focus(function(){self.show();});
+            this.$target = $(target);
+            this.$target.focus(function(){self.show();});
+        },
+        generateEvent: function(type,key){
+            var event = document.createEvent("KeyboardEvent");
+            var initMethod =  event.initKeyboardEvent ? 'initKeyboardEvent' : 'initKeyEvent';
+            event[initMethod](  type,
+                                true, //bubbles
+                                true, //cancelable
+                                window, //viewArg
+                                false, //ctrl
+                                false, //alt
+                                false, //shift
+                                false, //meta
+                                ((typeof key.code === 'undefined') ? key.char.charCodeAt(0) : key.code),
+                                ((typeof key.char === 'undefined') ? String.fromCharCode(key.code) : key.char)
+                            );
+            return event;
+
         },
 
         // Write a character to the input zone
         writeCharacter: function(character){
-            var $input = this.$target;
-            if(character === '\n'){
-                $input.trigger($.Event('keydown',{which:13}));
-                $input.trigger($.Event('keyup',{which:13}));
-            }else{
-                $input[0].value += character;
-                $input.keydown();
-                $input.keyup();
+            var input = this.$target[0];
+            input.dispatchEvent(this.generateEvent('keydown',{char: character}));
+            if(character !== '\n'){
+                input.value += character;
             }
-        },
-        
-        // Sends a 'return' character to the input zone. TODO
-        sendReturn: function(){
+            input.dispatchEvent(this.generateEvent('keyup',{char: character}));
         },
         
         // Removes the last character from the input zone.
         deleteCharacter: function(){
-            var $input = this.$target;
-            var input_value = $input[0].value;
-            $input[0].value = input_value.substr(0, input_value.length - 1);
-            $input.keydown();
-            $input.keyup();
+            var input = this.$target[0];
+            input.dispatchEvent(this.generateEvent('keydown',{code: 8}));
+            input.value = input.value.substr(0, input.value.length -1);
+            input.dispatchEvent(this.generateEvent('keyup',{code: 8}));
         },
         
         // Clears the content of the input zone.
         deleteAllCharacters: function(){
-            var $input = this.$target;
-            if($input[0].value){
-                $input[0].value = "";
-                $input.keydown();
-                $input.keyup();
+            var input = this.$target[0];
+            if(input.value){
+                input.dispatchEvent(this.generateEvent('keydown',{code: 8}));
+                input.value = "";
+                input.dispatchEvent(this.generateEvent('keyup',{code: 8}));
             }
         },
 
index 0b795b9..4c254af 100644 (file)
@@ -409,7 +409,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
             };
             
             this.clear_search_handler = function(event){
-                console.log("CLEAR SEARCH");
                 self.clear_search();
             };
 
@@ -524,7 +523,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
             this.el.querySelector('.search-clear').addEventListener('click',this.clear_search_handler);
 
             if(this.pos.config.iface_vkeyboard && this.pos_widget.onscreen_keyboard){
-                this.pos_widget.onscreen_keyboard.connect(this.$('.searchbox input'));
+                this.pos_widget.onscreen_keyboard.connect($(this.el.querySelector('.searchbox input')));
             }
         },