[-] BO : #PSTEST-248 - ergonomy in Product (pack) edition

This commit is contained in:
mMarinetti
2012-01-04 15:08:57 +00:00
parent b90c4b6a45
commit da65db4318
3 changed files with 45 additions and 12 deletions
@@ -107,11 +107,14 @@
$('#is_virtual').val(0); $('#is_virtual').val(0);
$("#virtual_good_attributes").hide(); $("#virtual_good_attributes").hide();
var val = $(this).val(); var product_type = $(this).val();
if (val == 1) // until a product is added in the pack
// if product is PTYPE_PACK, save buttons will be disabled
if (product_type == {Product::PTYPE_PACK})
{ {
$('li.tab-row a[id*="Pack"]').show(); //when you change the type of the product, directly go to the pack tab
$('li.tab-row a[id*="Pack"]').show().click();
$('#ppack').val(1).attr('checked', true).attr('disabled', 'disabled'); $('#ppack').val(1).attr('checked', true).attr('disabled', 'disabled');
$('#ppackdiv').show(); $('#ppackdiv').show();
// If the pack tab has not finished loaded the changes will be made when the loading event is triggered // If the pack tab has not finished loaded the changes will be made when the loading event is triggered
@@ -127,9 +130,13 @@
$('#condition').removeAttr('disabled'); $('#condition').removeAttr('disabled');
$('#condition option[value=new]').removeAttr('selected'); $('#condition option[value=new]').removeAttr('selected');
$('.stockForVirtualProduct').show(); $('.stockForVirtualProduct').show();
// if pack is enabled, if you choose pack, automatically switch to pack page
if ($("#link-Pack:visible").length)
handleSaveForPack();
} }
else if (val == 2) else if (product_type == {Product::PTYPE_VIRTUAL})
{ {
enableSave();
$('li.tab-row a[id*="VirtualProduct"]').show(); $('li.tab-row a[id*="VirtualProduct"]').show();
$('#is_virtual_good').attr('checked', true); $('#is_virtual_good').attr('checked', true);
$('#virtual_good').show(); $('#virtual_good').show();
@@ -152,6 +159,8 @@
} }
else else
{ {
// 3rd case : product_type is PTYPE_SIMPLE (0)
enableSave();
$('li.tab-row a[id*="Shipping"]').show(); $('li.tab-row a[id*="Shipping"]').show();
$('#condition').removeAttr('disabled'); $('#condition').removeAttr('disabled');
$('#condition option[value=new]').removeAttr('selected'); $('#condition option[value=new]').removeAttr('selected');
@@ -195,21 +204,22 @@
if (btn_name == "Combinations") if (btn_name == "Combinations")
{ {
$('#desc-product-new').hide(); $('#desc-product-new').hide();
$('#desc-product-save-and-stay').hide(); disableSave();
$('#desc-product-save').hide();
$('#desc-product-newCombination').show(); $('#desc-product-newCombination').show();
populate_attrs(); populate_attrs();
} }
else if (btn_name == "Attachments") else if (btn_name == "Attachments")
{ {
$('#desc-product-save-and-stay').hide(); disableSave();
$('#desc-product-save').hide();
} }
else else
{ {
$('#desc-product-newCombination').hide(); $('#desc-product-newCombination').hide();
$('#desc-product-save-and-stay').show(); // if pack is enabled, save button are visible only if pack is valid
$('#desc-product-save').show(); if ($("#link-Pack:visible").length)
handleSaveForPack();
else
enableSave();
} }
}); });
@@ -92,9 +92,10 @@
divContent += '<span onclick="delPackItem(' + curPackItemId + ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />'; divContent += '<span onclick="delPackItem(' + curPackItemId + ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />';
// QTYxID-QTYxID // QTYxID-QTYxID
// @todo : it should be better to create input for each items and each qty
// instead of only one separated by x, - and ¤
var line = curPackItemQty+ 'x' +curPackItemId; var line = curPackItemQty+ 'x' +curPackItemId;
$('#inputPackItems').val($('#inputPackItems').val() + line + '-'); $('#inputPackItems').val($('#inputPackItems').val() + line + '-');
$('#divPackItems').html(divContent); $('#divPackItems').html(divContent);
$('#namePackItems').val($('#namePackItems').val() + lineDisplay + '¤'); $('#namePackItems').val($('#namePackItems').val() + lineDisplay + '¤');
@@ -108,6 +109,8 @@
excludeIds : getSelectedIds() excludeIds : getSelectedIds()
} }
}); });
// show / hide save buttons
handleSaveForPack();
} }
function delPackItem(id) function delPackItem(id)
@@ -145,6 +148,9 @@
excludeIds : getSelectedIds() excludeIds : getSelectedIds()
} }
}); });
// if no item left in the pack, disable save buttons
handleSaveForPack();
} }
function getSelectedIds() function getSelectedIds()
@@ -155,6 +161,19 @@
return ids; return ids;
} }
function handleSaveForPack()
{
// if no item left in the pack, disable save buttons
$("#disablePackMessage").remove();
if ($("#inputPackItems").val() == "")
{
disableSave();
$(".leadin").append('<div id="disablePackMessage" class="warn">{l s='Pack is empty. Please at at least one product in the pack tab.'}</div>');
}
else
enableSave();
}
</script> </script>
<h4>{l s='Pack'}</h4> <h4>{l s='Pack'}</h4>
+5 -1
View File
@@ -302,13 +302,17 @@ function disableSave()
} }
/** /**
* hide save and save-and-stay buttons * show save and save-and-stay buttons
* *
* @access public * @access public
* @return void * @return void
*/ */
function enableSave() function enableSave()
{ {
// if no item left in the pack, disable save buttons
if ($("#disablePackMessage").length)
$("#disablePackMessage").remove();
$('#desc-product-save').show(); $('#desc-product-save').show();
$('#desc-product-save-and-stay').show(); $('#desc-product-save-and-stay').show();
} }