//new place for validate and add new range && global range validation part 1 on carrier wizard
This commit is contained in:
@@ -31,8 +31,11 @@
|
||||
{block name="field"}
|
||||
{if $input.name == 'zones'}
|
||||
{include file='controllers/carrier_wizard/helpers/form/form_ranges.tpl'}
|
||||
<div class="validate_range" style="display:none">
|
||||
<a href="#" class="button" id="validate_range_button">{l s="Validate"}</a>
|
||||
</div>
|
||||
<div class="new_range">
|
||||
<a href="#" onclick="add_new_range();return false;" class="button" id="add_new_range">{l s='Add new range'}<img src="../img/admin/add.gif"/></a>
|
||||
<a href="#" onclick="add_new_range();return false;" class="button" id="add_new_range">{l s='Add new range'}</a>
|
||||
</div>
|
||||
{/if}
|
||||
{if $input.name == 'logo'}
|
||||
|
||||
+2
-4
@@ -3,7 +3,7 @@
|
||||
<table cellpadding="5" cellspacing="0" id="zones_table">
|
||||
<tr class="range_inf">
|
||||
<td class="range_type"></td>
|
||||
<td class="border_left border_bottom">>=</td>
|
||||
<td class="border_left border_bottom range_sign">>=</td>
|
||||
{foreach from=$ranges key=r item=range}
|
||||
<td class="border_bottom center"><input name="range_inf[{$range.id_range|intval}]" type="text" value="{$range.delimiter1|string_format:"%.6f"}" /><sup>*</sup><span class="weight_unit"> {$PS_WEIGHT_UNIT}</span><span class="price_unit"> {$currency_sign}</span></td>
|
||||
{foreachelse}
|
||||
@@ -12,7 +12,7 @@
|
||||
</tr>
|
||||
<tr class="range_sup">
|
||||
<td class="center range_type"></td>
|
||||
<td class="border_left "><</td>
|
||||
<td class="border_left range_sign"><</td>
|
||||
{foreach from=$ranges key=r item=range}
|
||||
<td class="center"><input name="range_sup[{$range.id_range|intval}]" type="text" {if isset($form_id) && !$form_id} value="" {else} value="{if isset($change_ranges) && $range.id_range == -1} {else}{$range.delimiter2|string_format:"%.6f"}{/if}" {/if}/><sup>*</sup><span class="weight_unit"> {$PS_WEIGHT_UNIT}</span><span class="price_unit"> {$currency_sign}</span></td>
|
||||
{foreachelse}
|
||||
@@ -25,12 +25,10 @@
|
||||
{foreach from=$ranges key=r item=range}
|
||||
<td class="center border_top border_bottom {if $range.id_range != -1} validated {/if}" >
|
||||
<input type="text" {if isset($form_id) && !$form_id} disabled="disabled"{/if} {if $range.id_range == -1} style="display:none"{/if} /><span class="currency_sign" {if $range.id_range == -1} style="display:none" {/if}> {$currency_sign}</span>
|
||||
{if $range.id_range == -1} <button class="button">{l s="Validate"}</button> {/if}
|
||||
</td>
|
||||
{foreachelse}
|
||||
<td class="center border_top border_bottom">
|
||||
<input style="display:none" type="text" /><span class="currency_sign" style="display:none"> {$currency_sign}</span>
|
||||
<button class="button">{l s="Validate"}</button>
|
||||
</td>
|
||||
{/foreach}
|
||||
</tr>
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
var delete_range_confirm = '{l s='Are you sure to delete this range ?' js=1}';
|
||||
var currency_sign = '{$currency_sign}';
|
||||
var PS_WEIGHT_UNIT = '{$PS_WEIGHT_UNIT}';
|
||||
var invalid_range = '{l s='This range is not valid' js=1}';
|
||||
var range_is_overlapping = '{l s='Ranges are overlapping' js=1}';
|
||||
</script>
|
||||
<div id="carrier_wizard" class="swMain">
|
||||
<ul class="nbr_steps_{$wizard_steps.steps|count}">
|
||||
|
||||
@@ -599,7 +599,7 @@ class AdminCarrierWizardControllerCore extends AdminController
|
||||
$range_type = Tools::getValue('shipping_method');
|
||||
|
||||
$fees = Tools::getValue('fees');
|
||||
|
||||
|
||||
$carrier->deleteDeliveryPrice($carrier->getRangeTable());
|
||||
if ($range_type != Carrier::SHIPPING_METHOD_FREE)
|
||||
{
|
||||
@@ -620,23 +620,23 @@ class AdminCarrierWizardControllerCore extends AdminController
|
||||
|
||||
if (!Validate::isLoadedObject($range))
|
||||
return false;
|
||||
|
||||
$price_list = array();
|
||||
if (is_array($fees) && count($fees))
|
||||
foreach ($fees as $id_zone => $fee)
|
||||
$price_list[] = array(
|
||||
'id_range_price' => ($range_type == Carrier::SHIPPING_METHOD_PRICE ? (int)$range->id : null),
|
||||
'id_range_weight' => ($range_type == Carrier::SHIPPING_METHOD_WEIGHT ? (int)$range->id : null),
|
||||
'id_carrier' => (int)$carrier->id,
|
||||
'id_zone' => (int)$id_zone,
|
||||
'price' => (float)$fee[$key]
|
||||
);
|
||||
|
||||
{
|
||||
foreach ($fees as $id_zone => $fee)
|
||||
$price_list[] = array(
|
||||
'id_range_price' => ($range_type == Carrier::SHIPPING_METHOD_PRICE ? (int)$range->id : null),
|
||||
'id_range_weight' => ($range_type == Carrier::SHIPPING_METHOD_WEIGHT ? (int)$range->id : null),
|
||||
'id_carrier' => (int)$carrier->id,
|
||||
'id_zone' => (int)$id_zone,
|
||||
'price' => (float)$fee[$key]
|
||||
);
|
||||
}
|
||||
|
||||
if (count($price_list) && !$carrier->addDeliveryPrice($price_list, true))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -739,7 +739,7 @@ class AdminCarrierWizardControllerCore extends AdminController
|
||||
}
|
||||
|
||||
if (!$carrier->is_free)
|
||||
if (!Tools::getValue('id_carrier') && !$this->processRanges((int)$carrier->id))
|
||||
if (!$this->processRanges((int)$carrier->id))
|
||||
{
|
||||
$return['has_error'] = true;
|
||||
$return['errors'][] = $this->l('An error occurred while saving carrier ranges.');
|
||||
|
||||
+51
-35
@@ -24,12 +24,14 @@
|
||||
*/
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function() {
|
||||
validateAndAddRangeButtonDisplay();
|
||||
bind_inputs();
|
||||
initCarrierWizard();
|
||||
if (parseInt($('input[name="is_free"]:checked').val()))
|
||||
is_freeClick($('input[name="is_free"]:checked'));
|
||||
displayRangeType();
|
||||
|
||||
});
|
||||
|
||||
function initCarrierWizard()
|
||||
@@ -208,7 +210,7 @@ function validateSteps(step_number)
|
||||
function displayError(errors, step_number)
|
||||
{
|
||||
$('.wizard_error').remove();
|
||||
str_error = '<div class="error wizard_error"><span style="float:right"><a id="hideError" href="#"><img alt="X" src="../img/admin/close.png" /></a></span><ul>';
|
||||
str_error = '<div class="error wizard_error" style="display:none"><span style="float:right"><a id="hideError" href="#"><img alt="X" src="../img/admin/close.png" /></a></span><ul>';
|
||||
for (var error in errors)
|
||||
{
|
||||
$('#carrier_wizard').smartWizard('setError',{stepnum:step_number,iserror:true});
|
||||
@@ -216,6 +218,7 @@ function displayError(errors, step_number)
|
||||
str_error += '<li>'+errors[error]+'</li>';
|
||||
}
|
||||
$('#step-'+step_number).prepend(str_error+'</ul></div>');
|
||||
$('.wizard_error').fadeIn('fast');
|
||||
}
|
||||
|
||||
function resizeWizard()
|
||||
@@ -227,6 +230,7 @@ function bind_inputs()
|
||||
{
|
||||
$('input').focus( function () {
|
||||
$(this).removeClass('field_error');
|
||||
$('.wizard_error').fadeOut('fast', function () { $(this).remove()});
|
||||
});
|
||||
|
||||
$('tr.delete_range td button').off('click').on('click', function () {
|
||||
@@ -242,8 +246,8 @@ function bind_inputs()
|
||||
return false;
|
||||
});
|
||||
|
||||
$('tr.fees_all td button').off('click').on('click', function () {
|
||||
index = $(this).parent('td').index();
|
||||
$('#validate_range_button').off('click').on('click', function () {
|
||||
index = $('tr.fees_all td:last').index();
|
||||
if (validateRange(index))
|
||||
{
|
||||
enableRange(index);
|
||||
@@ -251,6 +255,7 @@ function bind_inputs()
|
||||
}
|
||||
else
|
||||
disableRange(index);
|
||||
validateAndAddRangeButtonDisplay();
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -263,7 +268,6 @@ function bind_inputs()
|
||||
if ($('tr.fees_all td:eq('+index+')').hasClass('validated'))
|
||||
$(this).children('input:text').removeAttr('disabled');
|
||||
});
|
||||
console.log($(this).next());
|
||||
}
|
||||
else
|
||||
$(this).closest('tr').children('td').children('input:text').attr('disabled', 'disabled');
|
||||
@@ -372,44 +376,41 @@ function validateRange(index)
|
||||
{
|
||||
$('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
displayError([invalid_range], $("#carrier_wizard").smartWizard('currentStep'));
|
||||
}
|
||||
|
||||
if (isNaN(range_inf) || range_inf.length === 0)
|
||||
else if (is_ok && (isNaN(range_inf) || range_inf.length === 0))
|
||||
{
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
displayError([invalid_range], $("#carrier_wizard").smartWizard('currentStep'));
|
||||
}
|
||||
|
||||
if (is_ok)
|
||||
else if (is_ok && range_inf >= range_sup)
|
||||
{
|
||||
if (range_inf >= range_sup)
|
||||
$('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
displayError([invalid_range], $("#carrier_wizard").smartWizard('currentStep'));
|
||||
}
|
||||
else if (is_ok && index > 2)//check range only if it's not the first range
|
||||
{
|
||||
is_ok = false;
|
||||
$('tr.range_sup td').not('.range_type, .range_sign, tr.range_sup td:last').each( function ()
|
||||
{
|
||||
index = $(this).index();
|
||||
current_val = $(this).find('input').val();
|
||||
if ((range_inf >= current_val) && (($('tr.range_inf td:eq('+index+1+')').length && range_inf <= $('tr.range_inf td:eq('+index+1+') input').val()) || !$('tr.range_inf td:eq('+index+1+')').length))
|
||||
{
|
||||
if (range_sup >= $('tr.range_inf td:eq('+index+') input').val() && ($('tr.range_inf td:eq('+index+1+')').length && range_sup < $('tr.range_inf td:eq('+index+1+') input').val() || !$('tr.range_inf td:eq('+index+1+')').length ))
|
||||
is_ok = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!is_ok)
|
||||
{
|
||||
$('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
displayError([range_is_overlapping], $("#carrier_wizard").smartWizard('currentStep'));
|
||||
}
|
||||
//check if previous range is inf only if it's not the first range
|
||||
if (index > 2)
|
||||
{
|
||||
previous_range_sup = parseFloat($('tr.range_sup td:eq('+(index -1)+')').children('input:text').val().trim());
|
||||
if (range_inf < previous_range_sup)
|
||||
{
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
}
|
||||
}
|
||||
//check if next range is sup only if it's not the last range
|
||||
if ($('tr.range_inf td:eq('+(index + 1)+')').length)
|
||||
{
|
||||
next_range_inf = parseFloat($('tr.range_inf td:eq('+(index +1)+')').children('input:text').val().trim());
|
||||
|
||||
if ((isNaN(range_sup) || range_sup.length === 0) && range_sup > next_range_inf)
|
||||
{
|
||||
$('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return is_ok;
|
||||
}
|
||||
@@ -454,17 +455,18 @@ function add_new_range()
|
||||
//add new rand inf input
|
||||
$('tr.range_inf td:last').after('<td class="border_bottom center"><input name="range_inf[]" type="text" value="'+last_sup_val+'" /><sup>*</sup><span class="weight_unit" style="display: none;"> '+PS_WEIGHT_UNIT+'</span><span class="price_unit" style="display: none;"> '+currency_sign+'</span></td>');
|
||||
|
||||
$('tr.fees_all td:last').after('<td class="center border_top border_bottom"><input style="display:none" type="text" /><span class="currency_sign" style="display:none" >'+currency_sign+'</span> <button class="button">'+labelValidate+'</button</td>');
|
||||
$('tr.fees_all td:last').after('<td class="center border_top border_bottom"><input style="display:none" type="text" /><span class="currency_sign" style="display:none" > '+currency_sign+'</span></td>');
|
||||
|
||||
$('tr.fees').each( function () {
|
||||
$(this).children('td:last').after('<td class="center"><input disabled="disabled" name="fees['+$(this).data('zoneid')+'][]" type="text" /> '+currency_sign+'</td>');
|
||||
});
|
||||
$('tr.delete_range td:last').after('<td class="center"><button class="button">'+labelDelete+'</button</td>');
|
||||
|
||||
resizeWizard();
|
||||
validateAndAddRangeButtonDisplay();
|
||||
bind_inputs();
|
||||
rebuildTabindex();
|
||||
displayRangeType();
|
||||
resizeWizard();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -502,4 +504,18 @@ function rebuildTabindex()
|
||||
});
|
||||
i++;
|
||||
});
|
||||
}
|
||||
|
||||
function validateAndAddRangeButtonDisplay()
|
||||
{
|
||||
if ($('tr.fees_all td:last').hasClass('validated'))
|
||||
{
|
||||
$('.validate_range').hide();
|
||||
$('.new_range').show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('.validate_range').show();
|
||||
$('.new_range').hide();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user