1 openerp.point_of_sale.load_keyboard = function load_keyboard(instance, module){ //module is instance.point_of_sale
4 // ---------- OnScreen Keyboard Widget ----------
5 // A Widget that displays an onscreen keyboard.
6 // There are two options when creating the widget :
8 // * 'keyboard_model' : 'simple' | 'full' (default)
9 // The 'full' emulates a PC keyboard, while 'simple' emulates an 'android' one.
11 // * 'input_selector : (default: '.searchbox input')
12 // defines the dom element that the keyboard will write to.
14 // The widget is initially hidden. It can be shown with this.show(), and is
15 // automatically shown when the input_selector gets focused.
17 module.OnscreenKeyboardWidget = instance.web.Widget.extend({
18 template: 'OnscreenKeyboardSimple',
19 init: function(parent, options){
21 this._super(parent,options);
22 options = options || {};
24 this.keyboard_model = options.keyboard_model || 'full';
25 if(this.keyboard_model === 'full'){
26 this.template = 'OnscreenKeyboardFull';
29 this.input_selector = options.input_selector || '.searchbox input';
33 this.capslock = false;
38 connect : function(target){
40 this.$target = $(target);
41 this.$target.focus(function(){self.show();});
43 generateEvent: function(type,key){
44 var event = document.createEvent("KeyboardEvent");
45 var initMethod = event.initKeyboardEvent ? 'initKeyboardEvent' : 'initKeyEvent';
46 event[initMethod]( type,
54 ((typeof key.code === 'undefined') ? key.char.charCodeAt(0) : key.code),
55 ((typeof key.char === 'undefined') ? String.fromCharCode(key.code) : key.char)
61 // Write a character to the input zone
62 writeCharacter: function(character){
63 var input = this.$target[0];
64 input.dispatchEvent(this.generateEvent('keydown',{char: character}));
65 if(character !== '\n'){
66 input.value += character;
68 input.dispatchEvent(this.generateEvent('keyup',{char: character}));
71 // Removes the last character from the input zone.
72 deleteCharacter: function(){
73 var input = this.$target[0];
74 input.dispatchEvent(this.generateEvent('keydown',{code: 8}));
75 input.value = input.value.substr(0, input.value.length -1);
76 input.dispatchEvent(this.generateEvent('keyup',{code: 8}));
79 // Clears the content of the input zone.
80 deleteAllCharacters: function(){
81 var input = this.$target[0];
83 input.dispatchEvent(this.generateEvent('keydown',{code: 8}));
85 input.dispatchEvent(this.generateEvent('keyup',{code: 8}));
89 // Makes the keyboard show and slide from the bottom of the screen.
91 $('.keyboard_frame').show().css({'height':'235px'});
94 // Makes the keyboard hide by sliding to the bottom of the screen.
102 //What happens when the shift key is pressed : toggle case, remove capslock
103 toggleShift: function(){
104 $('.letter').toggleClass('uppercase');
105 $('.symbol span').toggle();
107 self.shift = (self.shift === true) ? false : true;
108 self.capslock = false;
111 //what happens when capslock is pressed : toggle case, set capslock
112 toggleCapsLock: function(){
113 $('.letter').toggleClass('uppercase');
114 self.capslock = true;
117 //What happens when numlock is pressed : toggle symbols and numlock label
118 toggleNumLock: function(){
119 $('.symbol span').toggle();
120 $('.numlock span').toggle();
121 self.numlock = (self.numlock === true ) ? false : true;
124 //After a key is pressed, shift is disabled.
125 removeShift: function(){
126 if (self.shift === true) {
127 $('.symbol span').toggle();
128 if (this.capslock === false) $('.letter').toggleClass('uppercase');
134 // Resets the keyboard to its original state; capslock: false, shift: false, numlock: false
140 this.toggleCapsLock();
143 this.toggleNumLock();
147 //called after the keyboard is in the DOM, sets up the key bindings.
154 $('.close_button').click(function(){
155 self.deleteAllCharacters();
159 // Keyboard key click handling
160 $('.keyboard li').click(function(){
163 character = $this.html(); // If it's a lowercase letter, nothing happens to this variable
165 if ($this.hasClass('left-shift') || $this.hasClass('right-shift')) {
170 if ($this.hasClass('capslock')) {
171 self.toggleCapsLock();
175 if ($this.hasClass('delete')) {
176 self.deleteCharacter();
180 if ($this.hasClass('numlock')){
181 self.toggleNumLock();
185 // Special characters
186 if ($this.hasClass('symbol')) character = $('span:visible', $this).html();
187 if ($this.hasClass('space')) character = ' ';
188 if ($this.hasClass('tab')) character = "\t";
189 if ($this.hasClass('return')) character = "\n";
192 if ($this.hasClass('uppercase')) character = character.toUpperCase();
194 // Remove shift once a key is clicked.
197 self.writeCharacter(character);