68 lines
1.1 KiB
JavaScript
68 lines
1.1 KiB
JavaScript
function ProductSell(o){
|
|
|
|
this.defaults = {
|
|
selector_filter_text: '#filter_text',
|
|
lookup_product_url: ''
|
|
};
|
|
|
|
init();
|
|
|
|
function init(){
|
|
this.defaults = $.extend(this.defaults, o );
|
|
addBehaviorEnterPressedListener();
|
|
}
|
|
|
|
|
|
function addBehaviorEnterPressedListener(){
|
|
alert($( this.defaults.selector_filter_text ).length);
|
|
$( this.defaults.selector_filter_text ).keypress(function( event ) {
|
|
if ( event.which == 13 ) {
|
|
event.preventDefault();
|
|
lookupProduct();
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
function lookupProduct(){
|
|
var data, url;
|
|
|
|
url = this.defaults.lookup_product_url;
|
|
data = {
|
|
'query' : $( this.defaults.selector_filter_text ).val()
|
|
};
|
|
|
|
$.ajax({
|
|
dataType: "json",
|
|
url: url,
|
|
data: data,
|
|
success: onLookupProductReady
|
|
});
|
|
}
|
|
|
|
function onLookupProductReady( data ){
|
|
alert('ok');
|
|
productChanged(data.product);
|
|
}
|
|
|
|
|
|
function productChanged(product){
|
|
clearForm();
|
|
if ( product == null){
|
|
applyProduct();
|
|
}
|
|
}
|
|
|
|
function clearForm(){
|
|
$('.product-name').html('-');
|
|
}
|
|
|
|
function applyProduct(product){
|
|
$('.product-name').html(product.name);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|