// Product tab objects refactoring

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14499 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2012-04-05 15:07:46 +00:00
parent 89be86ba77
commit 64c0219094
2 changed files with 257 additions and 242 deletions
@@ -40,8 +40,6 @@
<br /> <br />
<h4>{l s='Available quantities for sale'}</h4> <h4>{l s='Available quantities for sale'}</h4>
<div class="separation"></div> <div class="separation"></div>
{if $show_quantities == true} {if $show_quantities == true}
<div class="warn" id="available_quantity_ajax_msg" style="display: none;"></div> <div class="warn" id="available_quantity_ajax_msg" style="display: none;"></div>
<div class="error" id="available_quantity_ajax_error_msg" style="display: none;"></div> <div class="error" id="available_quantity_ajax_error_msg" style="display: none;"></div>
@@ -191,183 +189,57 @@
</ul> </ul>
</div> </div>
{/if} {/if}
<div class="separation"></div> <div class="separation"></div>
<h4>{l s='Availability settings'}</h4> <h4>{l s='Availability settings'}</h4>
<table cellpadding="5"> <table cellpadding="5">
{if !$ps_stock_management} {if !$ps_stock_management}
<tr>
<td colspan="2">{l s='The stock management is disabled'}</td>
</tr>
{/if}
{if !$has_attribute}
<tr> <tr>
<td colspan="2">{l s='The stock management is disabled'}</td> <td class="col-left"><label>{l s='Minimum quantity:'}</label></td>
<td style="padding-bottom:5px;">
<input size="3" maxlength="6" name="minimal_quantity" id="minimal_quantity" type="text" value="{$product->minimal_quantity|default:1}" />
<p class="preference_description">{l s='The minimum quantity to buy this product (set to 1 to disable this feature)'}</p>
</td>
</tr>
{/if}
<tr>
<td class="col-left"><label>{l s='Displayed text when in-stock:'}</label></td>
<td style="padding-bottom:5px;">
{include file="controllers/products/input_text_lang.tpl"
languages=$languages
input_value=$product->available_now
input_name='available_now'}
<span class="hint" name="help_box">{l s='Forbidden characters:'} <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
</td>
</tr>
<tr>
<td class="col-left"><label>{l s='Displayed text when allowed to be back-ordered:'}</label></td>
<td style="padding-bottom:5px;">
{include file="controllers/products/input_text_lang.tpl"
languages=$languages
input_value=$product->available_later
input_name='available_later'}
<span class="hint" name="help_box">{l s='Forbidden characters:'} <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
</td>
</tr>
{if !$countAttributes}
<tr>
<td class="col-left"><label>{l s='Available date:'}</label></td>
<td style="padding-bottom:5px;">
<input id="available_date" name="available_date" value="{$product->available_date}" class="datepicker"
style="text-align: center;" type="text" />
<p>{l s='The available date when this product is out of stock'}</p>
</td>
</tr> </tr>
{/if} {/if}
{if !$has_attribute} </table>
<tr>
<td class="col-left"><label>{l s='Minimum quantity:'}</label></td>
<td style="padding-bottom:5px;">
<input size="3" maxlength="6" name="minimal_quantity" id="minimal_quantity" type="text" value="{$product->minimal_quantity|default:1}" />
<p class="preference_description">{l s='The minimum quantity to buy this product (set to 1 to disable this feature)'}</p>
</td>
</tr>
{/if}
<tr>
<td class="col-left"><label>{l s='Displayed text when in-stock:'}</label></td>
<td style="padding-bottom:5px;">
{include file="controllers/products/input_text_lang.tpl"
languages=$languages
input_value=$product->available_now
input_name='available_now'}
<span class="hint" name="help_box">{l s='Forbidden characters:'} <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
</td>
</tr>
<tr>
<td class="col-left"><label>{l s='Displayed text when allowed to be back-ordered:'}</label></td>
<td style="padding-bottom:5px;">
{include file="controllers/products/input_text_lang.tpl"
languages=$languages
input_value=$product->available_later
input_name='available_later'}
<span class="hint" name="help_box">{l s='Forbidden characters:'} <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
</td>
</tr>
{if !$countAttributes}
<tr>
<td class="col-left"><label>{l s='Available date:'}</label></td>
<td style="padding-bottom:5px;">
<input id="available_date" name="available_date" value="{$product->available_date}" class="datepicker"
style="text-align: center;" type="text" />
<p>{l s='The available date when this product is out of stock'}</p>
</td>
</tr>
{/if}
</table>
<script type="text/javascript"> <script type="text/javascript">
$('.datepicker').datepicker({ var quantities_ajax_success = '{l s='Data saved'}';
prevText: '', var quantities_ajax_waiting = '{l s='Saving data...'}';
nextText: '',
dateFormat: 'yy-mm-dd'
});
var showAjaxError = function(msg)
{
$('#available_quantity_ajax_error_msg').html(msg);
$('#available_quantity_ajax_error_msg').show();
$('#available_quantity_ajax_msg').hide();
$('#available_quantity_ajax_success_msg').hide();
};
var showAjaxSuccess = function(msg)
{
$('#available_quantity_ajax_success_msg').html(msg);
$('#available_quantity_ajax_error_msg').hide();
$('#available_quantity_ajax_msg').hide();
$('#available_quantity_ajax_success_msg').show();
};
var showAjaxMsg = function(msg)
{
$('#available_quantity_ajax_msg').html(msg);
$('#available_quantity_ajax_error_msg').hide();
$('#available_quantity_ajax_msg').show();
$('#available_quantity_ajax_success_msg').hide();
};
var ajaxCall = function(data)
{
data.ajaxProductQuantity = 1;
data.id_product = '{$product->id}';
data.token = "{$token}";
data.ajax = 1;
data.controller = "AdminProducts";
data.action = "productQuantity";
showAjaxMsg('{l s='Saving data...'}');
$.ajax({
type: "POST",
url: "ajax-tab.php",
data: data,
dataType: 'json',
async : true,
success: function(msg)
{
if (msg.error)
{
showAjaxError(msg.error);
return;
}
showAjaxSuccess('{l s='Data saved'}');
},
error: function(msg)
{
showAjaxError(msg.error);
}
});
};
var refreshQtyAvaibilityForm = function()
{
if ($('#depends_on_stock_0').attr('checked'))
{
$('.available_quantity').find('input').show();
$('.available_quantity').find('span').hide();
}
else
{
$('.available_quantity').find('input').hide();
$('.available_quantity').find('span').show();
}
};
$('.depends_on_stock').click(function(e)
{
refreshQtyAvaibilityForm();
ajaxCall( { actionQty: 'depends_on_stock', value: $(this).val() } );
if($(this).val() == 0)
$('.available_quantity input').trigger('change');
});
$('.advanced_stock_management').click(function(e)
{
var val = 0;
if ($(this).attr('checked'))
val = 1;
ajaxCall( { actionQty: 'advanced_stock_management', value: val } );
if (val == 1)
{
$(this).val(1);
$('#depends_on_stock_1').attr('disabled', false);
}
else
{
$(this).val(0);
$('#depends_on_stock_1').attr('disabled', true);
$('#depends_on_stock_0').attr('checked', true);
ajaxCall( { actionQty: 'depends_on_stock', value: 0} );
refreshQtyAvaibilityForm();
}
refreshQtyAvaibilityForm();
});
// bind enter key event on search field
$('.available_quantity').find('input').bind('keypress', function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
e.stopPropagation();//Stop event propagation
return false;
}
});
$('.available_quantity').find('input').change(function(e, init_val)
{
ajaxCall( { actionQty: 'set_qty', id_product_attribute: $(this).parent().attr('id').split('_')[1], value: $(this).val() } );
});
$('.out_of_stock').click(function(e)
{
refreshQtyAvaibilityForm();
ajaxCall( { actionQty: 'out_of_stock', value: $(this).val() } );
});
refreshQtyAvaibilityForm();
</script> </script>
{/if} {/if}
+210 -67
View File
@@ -27,8 +27,9 @@
// The ProductTabsManager instance will make sure the onReady() methods of each tabs are executed once the tab has loaded // The ProductTabsManager instance will make sure the onReady() methods of each tabs are executed once the tab has loaded
var product_tabs = []; var product_tabs = [];
product_tabs['Combinations'] = { product_tabs['Combinations'] = new function(){
'bindEdit' : function(){ var self = this;
this.bindEdit = function(){
$('table[name=list_table]').delegate('a.edit', 'click', function(e){ $('table[name=list_table]').delegate('a.edit', 'click', function(e){
e.preventDefault(); e.preventDefault();
editProductAttribute(this.href, $(this).closest('tr')); editProductAttribute(this.href, $(this).closest('tr'));
@@ -120,8 +121,9 @@ product_tabs['Combinations'] = {
} }
}); });
} }
}, };
'bindDefault' : function(){
this.bindDefault = function(){
$('table[name=list_table]').delegate('a.default', 'click', function(e){ $('table[name=list_table]').delegate('a.default', 'click', function(e){
e.preventDefault(); e.preventDefault();
defaultProductAttribute(this.href, $(this).closest('tr')); defaultProductAttribute(this.href, $(this).closest('tr'));
@@ -161,8 +163,9 @@ product_tabs['Combinations'] = {
} }
}); });
} }
}, };
'bindDelete' : function() {
this.bindDelete = function() {
$('table[name=list_table]').delegate('a.delete', 'click', function(e){ $('table[name=list_table]').delegate('a.delete', 'click', function(e){
e.preventDefault(); e.preventDefault();
deleteProductAttribute(this.href, $(this).closest('tr')); deleteProductAttribute(this.href, $(this).closest('tr'));
@@ -191,8 +194,9 @@ product_tabs['Combinations'] = {
} }
}); });
} }
}, };
'bindToggleAddCombination' : function (){
this.bindToggleAddCombination = function (){
$('#desc-product-newCombination').click(function() { $('#desc-product-newCombination').click(function() {
if ($('.process-icon-newCombination').hasClass('toolbar-new')) if ($('.process-icon-newCombination').hasClass('toolbar-new'))
removeButtonCombination('add'); removeButtonCombination('add');
@@ -217,13 +221,14 @@ product_tabs['Combinations'] = {
$('#desc-product-newCombination div').html(msg_new_combination); $('#desc-product-newCombination div').html(msg_new_combination);
} }
}); });
}, };
'onReady' : function(){
product_tabs['Combinations'].bindEdit(); this.onReady = function(){
product_tabs['Combinations'].bindDefault(); self.bindEdit();
product_tabs['Combinations'].bindDelete(); self.bindDefault();
product_tabs['Combinations'].bindToggleAddCombination(); self.bindDelete();
} self.bindToggleAddCombination();
};
} }
/** /**
@@ -322,19 +327,22 @@ function handleSaveButtonsForPack()
return ""; return "";
} }
product_tabs['Seo'] = { product_tabs['Seo'] = new function(){
var self = this;
// Enable writing of the product name when the friendly url field in tab SEO is loaded // Enable writing of the product name when the friendly url field in tab SEO is loaded
'enableProductName' : function (){ this.enableProductName = function (){
$('.copy2friendlyUrl').removeAttr('disabled'); $('.copy2friendlyUrl').removeAttr('disabled');
}, };
'onReady' : function() {
product_tabs['Seo'].enableProductName(); this.onReady = function() {
} self.enableProductName();
};
} }
product_tabs['Prices'] = { product_tabs['Prices'] = new function(){
var self = this;
// Bind to show/hide new specific price form // Bind to show/hide new specific price form
'toggleSpecificPrice' : function (){ this.toggleSpecificPrice = function (){
$('#show_specific_price').click(function() $('#show_specific_price').click(function()
{ {
$('#add_specific_price').slideToggle(); $('#add_specific_price').slideToggle();
@@ -355,7 +363,8 @@ product_tabs['Prices'] = {
$('#show_specific_price').show(); $('#show_specific_price').show();
return false; return false;
}); });
}, };
/** /**
* Ajax call to delete a specific price * Ajax call to delete a specific price
* *
@@ -363,7 +372,7 @@ product_tabs['Prices'] = {
* @param token * @param token
* @param parent * @param parent
*/ */
'deleteSpecificPrice' : function (url, parent){ this.deleteSpecificPrice = function (url, parent){
$.ajax({ $.ajax({
url: url, url: url,
data: { data: {
@@ -383,23 +392,26 @@ product_tabs['Prices'] = {
showErrorMessage(data.message); showErrorMessage(data.message);
} }
}); });
}, };
// Bind to delete specific price link // Bind to delete specific price link
'bindDelete' : function(){ this.bindDelete = function(){
$('#specific_prices_list').delegate('a[name="delete_link"]', 'click', function(e){ $('#specific_prices_list').delegate('a[name="delete_link"]', 'click', function(e){
e.preventDefault(); e.preventDefault();
product_tabs['Prices'].deleteSpecificPrice(this.href, $(this).parents('tr')); self.deleteSpecificPrice(this.href, $(this).parents('tr'));
}) })
}, };
'onReady' : function(){
product_tabs['Prices'].toggleSpecificPrice(); this.onReady = function(){
product_tabs['Prices'].deleteSpecificPrice(); self.toggleSpecificPrice();
product_tabs['Prices'].bindDelete(); self.deleteSpecificPrice();
} self.bindDelete();
};
} }
product_tabs['Associations'] = { product_tabs['Associations'] = new function(){
'initAccessoriesAutocomplete' : function (){ var self = this;
this.initAccessoriesAutocomplete = function (){
$('#product_autocomplete_input') $('#product_autocomplete_input')
.autocomplete('ajax_products_list.php', { .autocomplete('ajax_products_list.php', {
minChars: 1, minChars: 1,
@@ -428,11 +440,11 @@ product_tabs['Associations'] = {
return ids; return ids;
} }
}, };
/** /**
* Update the manufacturer select element with the list of existing manufacturers * Update the manufacturer select element with the list of existing manufacturers
*/ */
'getManufacturers' : function(){ this.getManufacturers = function(){
$.ajax({ $.ajax({
url: 'ajax-tab.php', url: 'ajax-tab.php',
cache: false, cache: false,
@@ -456,15 +468,17 @@ product_tabs['Associations'] = {
$("select#id_manufacturer").replaceWith("<p id=\"id_manufacturer\">[TECHNICAL ERROR] ajaxProductManufacturers: "+textStatus+"</p>"); $("select#id_manufacturer").replaceWith("<p id=\"id_manufacturer\">[TECHNICAL ERROR] ajaxProductManufacturers: "+textStatus+"</p>");
} }
}); });
}, };
'onReady' : function(){
product_tabs['Associations'].initAccessoriesAutocomplete(); this.onReady = function(){
product_tabs['Associations'].getManufacturers(); self.initAccessoriesAutocomplete();
self.getManufacturers();
} }
} }
product_tabs['Attachments'] = { product_tabs['Attachments'] = new function(){
'bindAttachmentEvents' : function (){ var self = this;
this.bindAttachmentEvents = function (){
$("#addAttachment").live('click', function() { $("#addAttachment").live('click', function() {
$("#selectAttachment2 option:selected").each(function(){ $("#selectAttachment2 option:selected").each(function(){
var val = $('#arrayAttachments').val(); var val = $('#arrayAttachments').val();
@@ -495,14 +509,16 @@ product_tabs['Attachments'] = {
$(this).attr("selected", "selected"); $(this).attr("selected", "selected");
}); });
}); });
}, };
'onReady' : function(){
product_tabs['Attachments'].bindAttachmentEvents(); this.onReady = function(){
} self.bindAttachmentEvents();
};
} }
product_tabs['Informations'] = { product_tabs['Informations'] = new function(){
'bindAvailableForOrder' : function (){ var self = this;
this.bindAvailableForOrder = function (){
$("#available_for_order").click(function(){ $("#available_for_order").click(function(){
if ($(this).is(':checked')) if ($(this).is(':checked'))
{ {
@@ -514,8 +530,9 @@ product_tabs['Informations'] = {
$('#show_price').attr('disabled', ''); $('#show_price').attr('disabled', '');
} }
}); });
}, };
'bindTagImage' : function (){
this.bindTagImage = function (){
function changeTagImage(){ function changeTagImage(){
var smallImage = $('input[name=smallImage]:checked').attr('value'); var smallImage = $('input[name=smallImage]:checked').attr('value');
var leftRight = $('input[name=leftRight]:checked').attr('value'); var leftRight = $('input[name=leftRight]:checked').attr('value');
@@ -542,8 +559,9 @@ product_tabs['Informations'] = {
i = 0; i = 0;
} }
}); });
}, };
'switchProductType' : function(){
this.switchProductType = function(){
if (product_type == product_type_pack) if (product_type == product_type_pack)
{ {
$('#pack_product').attr('checked', 'checked'); $('#pack_product').attr('checked', 'checked');
@@ -629,7 +647,7 @@ product_tabs['Informations'] = {
// this handle the save button displays and warnings // this handle the save button displays and warnings
handleSaveButtons(); handleSaveButtons();
}); });
}, };
/*'setup_tinymce': function(){ /*'setup_tinymce': function(){
// change each by click to load only on click // change each by click to load only on click
$(".autoload_rte").each(function(e){ $(".autoload_rte").each(function(e){
@@ -662,15 +680,16 @@ product_tabs['Informations'] = {
}); });
}); });
},*/ },*/
'onReady' : function(){ this.onReady = function(){
product_tabs['Informations'].bindAvailableForOrder(); self.bindAvailableForOrder();
product_tabs['Informations'].bindTagImage(); self.bindTagImage();
product_tabs['Informations'].switchProductType(); self.switchProductType();
} };
} }
product_tabs['Pack'] = { product_tabs['Pack'] = new function(){
'bindPackEvents' : function (){ var self = this;
this.bindPackEvents = function (){
if ($('#ppack').attr('checked')) if ($('#ppack').attr('checked'))
{ {
$('#ppack').attr('disabled', 'disabled'); $('#ppack').attr('disabled', 'disabled');
@@ -801,18 +820,142 @@ product_tabs['Pack'] = {
ids = ids.replace(/\,$/,''); ids = ids.replace(/\,$/,'');
return ids; return ids;
} }
}, };
'onReady' : function(){
product_tabs['Pack'].bindPackEvents(); this.onReady = function(){
self.bindPackEvents();
} }
} }
product_tabs['Features'] = { product_tabs['Features'] = new function(){
'onReady' : function(){ this.onReady = function(){
displayFlags(languages, id_language, allowEmployeeFormLang); displayFlags(languages, id_language, allowEmployeeFormLang);
} }
} }
product_tabs['Quantities'] = new function(){
var self = this;
this.ajaxCall = function(data){
data.ajaxProductQuantity = 1;
data.id_product = id_product;
data.token = token;
data.ajax = 1;
data.controller = "AdminProducts";
data.action = "productQuantity";
showAjaxMsg(quantities_ajax_waiting);
$.ajax({
type: "POST",
url: "ajax-tab.php",
data: data,
dataType: 'json',
async : true,
success: function(msg)
{
if (msg.error)
{
showAjaxError(msg.error);
return;
}
showAjaxSuccess(quantities_ajax_success);
},
error: function(msg)
{
showAjaxError(msg.error);
}
});
function showAjaxError(msg)
{
$('#available_quantity_ajax_error_msg').html(msg);
$('#available_quantity_ajax_error_msg').show();
$('#available_quantity_ajax_msg').hide();
$('#available_quantity_ajax_success_msg').hide();
}
function showAjaxSuccess(msg)
{
$('#available_quantity_ajax_success_msg').html(msg);
$('#available_quantity_ajax_error_msg').hide();
$('#available_quantity_ajax_msg').hide();
$('#available_quantity_ajax_success_msg').show();
}
function showAjaxMsg(msg)
{
$('#available_quantity_ajax_msg').html(msg);
$('#available_quantity_ajax_error_msg').hide();
$('#available_quantity_ajax_msg').show();
$('#available_quantity_ajax_success_msg').hide();
}
};
this.refreshQtyAvailabilityForm = function()
{
if ($('#depends_on_stock_0').attr('checked'))
{
$('.available_quantity').find('input').show();
$('.available_quantity').find('span').hide();
}
else
{
$('.available_quantity').find('input').hide();
$('.available_quantity').find('span').show();
}
};
this.onReady = function(){
$('#available_date').datepicker({
prevText: '',
nextText: '',
dateFormat: 'yy-mm-dd'
});
$('.depends_on_stock').click(function(e)
{
self.refreshQtyAvailabilityForm();
self.ajaxCall( { actionQty: 'depends_on_stock', value: $(this).val() } );
if($(this).val() == 0)
$('.available_quantity input').trigger('change');
});
$('.advanced_stock_management').click(function(e)
{
var val = 0;
if ($(this).attr('checked'))
val = 1;
self.ajaxCall({actionQty: 'advanced_stock_management', value: val});
if (val == 1)
{
$(this).val(1);
$('#depends_on_stock_1').attr('disabled', false);
}
else
{
$(this).val(0);
$('#depends_on_stock_1').attr('disabled', true);
$('#depends_on_stock_0').attr('checked', true);
self.ajaxCall({actionQty: 'depends_on_stock', value: 0});
self.refreshQtyAvailabilityForm();
}
self.refreshQtyAvailabilityForm();
});
$('.available_quantity').find('input').change(function(e, init_val)
{
self.ajaxCall({actionQty: 'set_qty', id_product_attribute: $(this).parent().attr('id').split('_')[1], value: $(this).val()});
});
$('.out_of_stock').click(function(e)
{
self.refreshQtyAvailabilityForm();
self.ajaxCall({actionQty: 'out_of_stock', value: $(this).val()});
});
self.refreshQtyAvailabilityForm();
};
}
var tabs_manager = new ProductTabsManager(); var tabs_manager = new ProductTabsManager();
tabs_manager.setTabs(product_tabs); tabs_manager.setTabs(product_tabs);