add changes sell product
This commit is contained in:
67
frontend/web/js/product.sell.js
Normal file
67
frontend/web/js/product.sell.js
Normal file
@@ -0,0 +1,67 @@
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user