[FIX] point_of_sale: onscreen keyboard working again

bzr revid: fva@openerp.com-20131216182059-4wukpqfvyagzm5vu
This commit is contained in:
Frédéric van der Essen 2013-12-16 19:20:59 +01:00
parent a50930e0d6
commit d9f1ee976e
3 changed files with 36 additions and 28 deletions

View 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() {

View 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}));
}
},

View 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')));
}
},