//
This commit is contained in:
+145
-17
@@ -28,7 +28,7 @@ $(document).ready(function() {
|
||||
|
||||
bind_inputs();
|
||||
initCarrierWizard();
|
||||
|
||||
|
||||
});
|
||||
|
||||
function initCarrierWizard()
|
||||
@@ -58,6 +58,7 @@ function leaveStepCallback(obj, context)
|
||||
|
||||
function validateSteps(step_number)
|
||||
{
|
||||
$('.wizard_error').remove();
|
||||
var is_ok = true;
|
||||
form = $('#carrier_wizard #step-'+step_number+' form');
|
||||
$.ajax({
|
||||
@@ -71,13 +72,12 @@ function validateSteps(step_number)
|
||||
if (datas.has_error)
|
||||
{
|
||||
is_ok = false;
|
||||
$('#wizard_error').remove();
|
||||
|
||||
$('input').focus( function () {
|
||||
$(this).removeClass('field_error');
|
||||
});
|
||||
|
||||
str_error = '<div class="error" id="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"><span style="float:right"><a id="hideError" href="#"><img alt="X" src="../img/admin/close.png" /></a></span><ul>';
|
||||
for (var error in datas.errors)
|
||||
{
|
||||
$('#carrier_wizard').smartWizard('setError',{stepnum:step_number,iserror:true});
|
||||
@@ -99,29 +99,157 @@ function resizeWizard()
|
||||
|
||||
function bind_inputs()
|
||||
{
|
||||
$('a#add_new_range').bind('click', function () {
|
||||
add_new_range();
|
||||
$('tr.delete_range td button').off('click').on('click', function () {
|
||||
index = $(this).parent('td').index();
|
||||
$('tr.range_sup td:eq('+index+'), tr.range_inf td:eq('+index+'), tr.fees_all td:eq('+index+'), tr.delete_range td:eq('+index+')').remove();
|
||||
$('tr.fees').each( function () {
|
||||
$(this).children('td:eq('+index+')').remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('tr.zones_delete td button').each( function () {
|
||||
$(this).bind('click', function () {
|
||||
|
||||
return false;
|
||||
});
|
||||
$('tr.fees_all td button').off('click').on('click', function () {
|
||||
index = $(this).parent('td').index();
|
||||
if (validateRange(index))
|
||||
enableRange(index);
|
||||
else
|
||||
disableRange(index);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('tr.fees td input:checkbox').off('change').on('change', function () {
|
||||
|
||||
if($(this).is(':checked'))
|
||||
{
|
||||
$(this).closest('tr').children('td').each( function (){
|
||||
index = $(this).index();
|
||||
if ($('tr.fees_all td:eq('+index+')').hasClass('validated'))
|
||||
$(this).children('input:text').removeAttr('disabled');
|
||||
});
|
||||
}
|
||||
else
|
||||
$(this).closest('tr').children('td').children('input:text').attr('disabled', 'disabled');
|
||||
return false;
|
||||
});
|
||||
|
||||
$('tr.range_sup td input:text, tr.range_inf td input:text').focus( function () {
|
||||
$(this).removeClass('field_error');
|
||||
});
|
||||
|
||||
$('tr.range_sup td input:text, tr.range_inf td input:text').off('change').on('change', function () {
|
||||
index = $(this).parent('td').index();
|
||||
|
||||
if ($('tr.fees_all td:eq('+index+')').hasClass('validated') || $('tr.fees_all td:eq('+index+')').hasClass('not_validated'))
|
||||
{
|
||||
if (validateRange(index))
|
||||
enableRange(index);
|
||||
else
|
||||
disableRange(index);
|
||||
}
|
||||
});
|
||||
|
||||
$('tr.fees_all td input').off('change').on('change', function () {
|
||||
index = $(this).parent('td').index();
|
||||
val = $(this).val();
|
||||
$('tr.fees td input:text').not('disabled').val(val);
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function validateRange(index)
|
||||
{
|
||||
//reset error css
|
||||
$('tr.range_sup td input:text').removeClass('field_error');
|
||||
$('tr.range_inf td input:text').removeClass('field_error');
|
||||
|
||||
is_ok = true;
|
||||
range_sup = parseInt($('tr.range_sup td:eq('+index+')').children('input:text').val().trim());
|
||||
range_inf = parseInt($('tr.range_inf td:eq('+index+')').children('input:text').val().trim());
|
||||
|
||||
if (isNaN(range_sup) || range_sup.length === 0)
|
||||
{
|
||||
$('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
}
|
||||
|
||||
if (isNaN(range_inf) || range_inf.length === 0)
|
||||
{
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
}
|
||||
|
||||
if (is_ok)
|
||||
{
|
||||
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;
|
||||
}
|
||||
//check if previous range is inf only if it's not the first range
|
||||
if (index > 2)
|
||||
{
|
||||
previous_range_sup = parseInt($('tr.range_sup td:eq('+(index -1)+')').children('input:text').val().trim());
|
||||
console.log(range_inf+' < '+previous_range_sup);
|
||||
if (range_inf < previous_range_sup)
|
||||
{
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
}
|
||||
}
|
||||
//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 = parseInt($('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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
function enableRange(index)
|
||||
{
|
||||
$('tr.fees').each( function () {
|
||||
//only enable fees for enabled zones
|
||||
if ($(this).children('td').children('input:checkbox').attr('checked') == 'checked')
|
||||
$(this).children('td:eq('+index+')').children('input').removeAttr('disabled');
|
||||
});
|
||||
$('span.fees_all').show();
|
||||
$('tr.fees_all td:eq('+index+')').children('input').show().removeAttr('disabled');
|
||||
$('tr.fees_all td:eq('+index+')').addClass('validated').removeClass('not_validated');
|
||||
$('tr.fees_all td:eq('+index+')').children('button').remove();
|
||||
}
|
||||
|
||||
function disableRange(index)
|
||||
{
|
||||
$('tr.fees').each( function () {
|
||||
//only enable fees for enabled zones
|
||||
if ($(this).children('td').children('input:checkbox').attr('checked') == 'checked')
|
||||
$(this).children('td:eq('+index+')').children('input').attr('disabled', 'disabled');
|
||||
});
|
||||
$('tr.fees_all td:eq('+index+')').children('input').attr('disabled', 'disabled');
|
||||
$('tr.fees_all td:eq('+index+')').removeClass('validated').addClass('not_validated');
|
||||
}
|
||||
|
||||
function add_new_range()
|
||||
{
|
||||
$('.zones td input:checkbox').removeAttr('disabled');
|
||||
$('td#range_limit').children('table').show();
|
||||
$('tr#new_range_form_placeholder').children('td:last').after('<td><table cellpadding="0" cellspacing="0">'+$('#new_range_form').html()+'</table></td>');
|
||||
$('tr.zones').each( function () {
|
||||
$(this).children('td:eq(1)').removeClass('border_right');
|
||||
$(this).children('td:last').after('<td class="border_right" style="width:173px;text-align:center"><input type="text" disabled="disabled"/></td>');
|
||||
//add new rand sup input
|
||||
$('tr.range_sup td:last').after('<td class="center"><input name="range_sup[]" type="text" /></td>');
|
||||
//add new rand inf input
|
||||
$('tr.range_inf td:last').after('<td class="border_bottom center"><input name="range_inf[]" type="text" /></td>');
|
||||
|
||||
$('tr.fees_all td:last').after('<td class="center border_top border_bottom"><input style="display:none" type="text" /> <button class="button">'+labelValidate+'</button</td>');
|
||||
|
||||
$('tr.fees').each( function () {
|
||||
$(this).children('td:last').after('<td><input disabled="disabled" name="fees['+$(this).data('zoneid')+'][]" type="text" /></td>');
|
||||
});
|
||||
$('tr.zones_delete:last').children('td:last').after('<td class="border_right" style="width:173px;text-align:center"><button class="button">'+labelDelete+'</button></td>');
|
||||
$('tr.delete_range td:last').after('<td class="center"><button class="button">'+labelDelete+'</button</td>');
|
||||
|
||||
resizeWizard();
|
||||
bind_inputs();
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user