fast inventory item edit

This commit is contained in:
2016-08-08 18:46:58 +02:00
parent e79187c50e
commit c5bfae9ec1
5 changed files with 74 additions and 53 deletions

View File

@@ -18,10 +18,10 @@ FitnessAdmin.InventoryItem.Update = new function(){
INVENTORY_PRODUCT_NAME: '#inventory_product_name',
INVENTORYITEM_TYPE: '#inventoryitem-type',
INVENTORYITEM_COUNT: '#inventoryitem-count',
INVENTORY_FORM: '#inventory-form'
INVENTORY_FORM: '#inventory-product'
};
var product = null;
var inventoryItem = null;
this.init = function (options) {
defaults = $.extend(defaults,options);
@@ -37,6 +37,8 @@ FitnessAdmin.InventoryItem.Update = new function(){
$(defaults.selector_product).val(p.name);
}
}
}else{
$(_SELECTORS.INVENTORY_FORM).hide();
}
$(defaults.selector_product).focus().select();
};
@@ -65,12 +67,12 @@ FitnessAdmin.InventoryItem.Update = new function(){
} 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;
inventoryItem = null;
renderForm();
}
} else {
// Nothing is active so it is a new value (or maybe empty value)
product = null;
inventoryItem = null;
renderForm();
}
});
@@ -78,7 +80,7 @@ FitnessAdmin.InventoryItem.Update = new function(){
var selectInventoryItem = function (data) {
console.info('data',data);
product = data;
inventoryItem = data;
};
var _findProduct = function (id){
@@ -97,26 +99,28 @@ FitnessAdmin.InventoryItem.Update = new function(){
};
function renderForm( ) {
console.info( "render",product);
console.info( "render",inventoryItem);
var name = "",type = "",count = "";
if ( product){
name = product.productName;
type = product.type;
if ( product.count ){
count = product.count;
if ( inventoryItem){
name = inventoryItem.productName;
type = inventoryItem.type;
if ( inventoryItem.count != null ){
count = inventoryItem.count;
}
}
$(_SELECTORS.INVENTORY_PRODUCT_NAME).html(name);
$(_SELECTORS.INVENTORYITEM_TYPE).html(type);
$(_SELECTORS.INVENTORYITEM_COUNT).html(count);
$(_SELECTORS.INVENTORYITEM_TYPE).val(type);
$(_SELECTORS.INVENTORYITEM_COUNT).val(count);
var formContainer = $(_SELECTORS.INVENTORY_FORM);
var form = $(_SELECTORS.INVENTORY_FORM).find('form');
if ( product == null ){
form.hide();
if ( inventoryItem == null ){
formContainer.hide();
}else {
form.show();
form.attr('action', defaults.url_save +"&id="+product.id_inventory_item);
formContainer.show();
form.attr('action', defaults.url_save +"&id="+inventoryItem.id_inventory_item);
$(_SELECTORS.INVENTORYITEM_COUNT).focus().select();
}
}