From 60b17e760c594f4d4b9ffad86e5d002267bdc4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 20 Sep 2013 11:47:34 +0200 Subject: [PATCH] [IMP] point_of_sale: when the product search returns only one product, order it on 'enter' keypress bzr revid: fva@openerp.com-20130920094734-mvte0wkdw151691n --- .../static/src/js/widget_keyboard.js | 13 +++++-- addons/point_of_sale/static/src/js/widgets.js | 38 ++++++++++++------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/addons/point_of_sale/static/src/js/widget_keyboard.js b/addons/point_of_sale/static/src/js/widget_keyboard.js index 05ccdd78ca6..22245b31227 100644 --- a/addons/point_of_sale/static/src/js/widget_keyboard.js +++ b/addons/point_of_sale/static/src/js/widget_keyboard.js @@ -43,10 +43,15 @@ function openerp_pos_keyboard(instance, module){ //module is instance.point_of_s // Write a character to the input zone writeCharacter: function(character){ - var $input = this.$target - $input[0].value += character; - $input.keydown(); - $input.keyup(); + 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(); + } }, // Sends a 'return' character to the input zone. TODO diff --git a/addons/point_of_sale/static/src/js/widgets.js b/addons/point_of_sale/static/src/js/widgets.js index 0768791651b..e36161e289f 100644 --- a/addons/point_of_sale/static/src/js/widgets.js +++ b/addons/point_of_sale/static/src/js/widgets.js @@ -516,7 +516,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa var cat = self.pos.db.get_category_by_id(id); self.set_category(cat); self.renderElement(); - self.search_and_categories(cat); }); }); // breadcrumb click actions @@ -525,12 +524,13 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa var category = self.pos.db.get_category_by_id(id); self.set_category(category); self.renderElement(); - self.search_and_categories(category); }); + + this.search_and_categories(); + if(this.pos.iface_vkeyboard && this.pos_widget.onscreen_keyboard){ this.pos_widget.onscreen_keyboard.connect(this.$('.searchbox input')); } - this.search_and_categories(); }, set_product_type: function(type){ // 'all' | 'weightable' @@ -542,7 +542,14 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa reset_category: function(){ this.set_category(); this.renderElement(); - this.search_and_categories(); + }, + + // empties the content of the search box + clear_search: function(){ + var products = this.pos.db.get_product_by_category(this.category.id); + this.pos.get('products').reset(products); + this.$('.searchbox input').val('').focus(); + this.$('.search-clear').fadeOut(); }, // filters the products, and sets up the search callbacks @@ -554,12 +561,20 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa self.pos.get('products').reset(products); // filter the products according to the search string - this.$('.searchbox input').keyup(function(){ + this.$('.searchbox input').keyup(function(event){ + console.log('event',event); query = $(this).val().toLowerCase(); if(query){ - var products = self.pos.db.search_product_in_category(self.category.id, query); - self.pos.get('products').reset(products); - self.$('.search-clear').fadeIn(); + if(event.which === 13){ + if( self.pos.get('products').size() === 1 ){ + self.pos.get('selectedOrder').addProduct(self.pos.get('products').at(0)); + self.clear_search(); + } + }else{ + var products = self.pos.db.search_product_in_category(self.category.id, query); + self.pos.get('products').reset(products); + self.$('.search-clear').fadeIn(); + } }else{ var products = self.pos.db.get_product_by_category(self.category.id); self.pos.get('products').reset(products); @@ -567,14 +582,9 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa } }); - this.$('.searchbox input').click(function(){}); //Why ??? - //reset the search when clicking on reset this.$('.search-clear').click(function(){ - var products = self.pos.db.get_product_by_category(self.category.id); - self.pos.get('products').reset(products); - self.$('.searchbox input').val('').focus(); - self.$('.search-clear').fadeOut(); + self.clear_search(); }); }, });