add inventory changes

This commit is contained in:
2016-03-23 08:15:37 +01:00
parent 7db129de92
commit e7b16f20ce
15 changed files with 413 additions and 62 deletions

View File

@@ -0,0 +1,58 @@
var inventoryItemIndex = {
defaults : {
products: [],
selector_type : '#inventoryitemsearch-item_type',
selector_name : '#inventoryitemsearch-item_name',
selector_id : '#inventoryitemsearch-item_id',
},
product: null,
init: function(o){
this.defaults = $.extend( this.defaults, o );
this.initAutocomplete();
},
initAutocomplete : function (){
var self = this;
var $input = $(self.defaults.selector_name);
$input.typeahead({source : self.defaults.products,
autoSelect: true,
items: 20,
minLength: 3,
});
$input.change(function() {
var current = $input.typeahead("getActive");
$("#filter_text").val('');
if (current) {
// Some item from your model is active!
if (current.name == $input.val()) {
self.product = current;
} else {
self.product = null;
}
} else {
self.product = null;
}
self.productChange();
});
},
productChange: function( ){
this.clearProductData();
this.setProductData();
},
clearProductData: function(){
$(this.defaults.selector_type).val('');
$(this.defaults.selector_id).val('');
},
setProductData: function(){
if ( this.product ){
$(this.defaults.selector_type).val( this.product.type);
$(this.defaults.selector_id ).val( this.product.id);
}
}
}