[IMP] point_of_sale: when the product search returns only one product, order it on 'enter' keypress

bzr revid: fva@openerp.com-20130918134208-t9g50q8whdft4xzq
This commit is contained in:
Frédéric van der Essen 2013-09-18 15:42:08 +02:00
parent 645c3ccf65
commit d30f5e8be6
2 changed files with 33 additions and 18 deletions

View File

@ -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

View File

@ -530,7 +530,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
@ -539,12 +538,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'
@ -556,7 +556,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
@ -568,12 +575,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);
@ -581,14 +596,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();
});
},
});