add inventory item fast edit
This commit is contained in:
123
backend/web/js/inventory,item.update.js
Normal file
123
backend/web/js/inventory,item.update.js
Normal file
@@ -0,0 +1,123 @@
|
||||
var FitnessAdmin;
|
||||
|
||||
FitnessAdmin = {};
|
||||
|
||||
FitnessAdmin.InventoryItem = {};
|
||||
|
||||
FitnessAdmin.InventoryItem.Update = new function(){
|
||||
|
||||
var defaults = {
|
||||
'selector_product' : '#product_autocomplete',
|
||||
'url_find_inventory_item' : 'inventory-item/update-item',
|
||||
"products" : [],
|
||||
"url_save" : '',
|
||||
"id_product": null
|
||||
};
|
||||
|
||||
var _SELECTORS = {
|
||||
INVENTORY_PRODUCT_NAME: '#inventory_product_name',
|
||||
INVENTORYITEM_TYPE: '#inventoryitem-type',
|
||||
INVENTORYITEM_COUNT: '#inventoryitem-count',
|
||||
INVENTORY_FORM: '#inventory-form'
|
||||
};
|
||||
|
||||
var product = null;
|
||||
|
||||
this.init = function (options) {
|
||||
defaults = $.extend(defaults,options);
|
||||
createGUI();
|
||||
preselectProduct();
|
||||
};
|
||||
|
||||
var preselectProduct = function () {
|
||||
if ( defaults.id_product ){
|
||||
for (var i = 0; i < defaults.products.length ;i++ ){
|
||||
var p = defaults.products[i];
|
||||
if ( p.id_product == defaults.id_product){
|
||||
$(defaults.selector_product).val(p.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
$(defaults.selector_product).focus().select();
|
||||
};
|
||||
|
||||
var createGUI = function () {
|
||||
initAutoComplete();
|
||||
};
|
||||
|
||||
var initAutoComplete = function () {
|
||||
var $input = $(defaults.selector_product);
|
||||
$input.typeahead({source : 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()) {
|
||||
// This means the exact match is found. Use toLowerCase() if you want case insensitive match.
|
||||
//noinspection JSUnresolvedVariable
|
||||
console.info(current);
|
||||
_findProduct(current.id_inventory_item);
|
||||
} else {
|
||||
// This means it is only a partial match, you can either add a new item
|
||||
// or take the active if you don't want new items
|
||||
product = null;
|
||||
renderForm();
|
||||
}
|
||||
} else {
|
||||
// Nothing is active so it is a new value (or maybe empty value)
|
||||
product = null;
|
||||
renderForm();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var selectInventoryItem = function (data) {
|
||||
console.info('data',data);
|
||||
product = data;
|
||||
};
|
||||
|
||||
var _findProduct = function (id){
|
||||
var data, url;
|
||||
|
||||
url = defaults.url_find_inventory_item;
|
||||
data = {
|
||||
'id' : id
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: url,
|
||||
data: data
|
||||
}).then(selectInventoryItem).then(renderForm);
|
||||
};
|
||||
|
||||
function renderForm( ) {
|
||||
console.info( "render",product);
|
||||
var name = "",type = "",count = "";
|
||||
if ( product){
|
||||
name = product.productName;
|
||||
type = product.type;
|
||||
if ( product.count ){
|
||||
count = product.count;
|
||||
}
|
||||
}
|
||||
$(_SELECTORS.INVENTORY_PRODUCT_NAME).html(name);
|
||||
$(_SELECTORS.INVENTORYITEM_TYPE).html(type);
|
||||
$(_SELECTORS.INVENTORYITEM_COUNT).html(count);
|
||||
|
||||
var form = $(_SELECTORS.INVENTORY_FORM).find('form');
|
||||
|
||||
if ( product == null ){
|
||||
form.hide();
|
||||
}else {
|
||||
form.show();
|
||||
form.attr('action', defaults.url_save +"&id="+product.id_inventory_item);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@@ -26,8 +26,6 @@ function WasteCreate(o){
|
||||
|
||||
|
||||
function initAutocomplete(){
|
||||
// var colors = ["red", "blue", "green", "yellow", "brown", "black"];
|
||||
// $('#product_search').typeahead( {source: colors } );
|
||||
|
||||
var $input = $(defaults.selector_product);
|
||||
console.info("len:" + $input.length);
|
||||
@@ -69,10 +67,9 @@ function WasteCreate(o){
|
||||
|
||||
function _findProduct(id){
|
||||
var data, url;
|
||||
|
||||
url = defaults.url_product_find;
|
||||
data = {
|
||||
'id' : id,
|
||||
'id' : id
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
|
||||
Reference in New Issue
Block a user