/* * 2007-2013 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA * @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ $(document).ready(function() { bind_inputs(); initCarrierWizard(); }); function initCarrierWizard() { $("#carrier_wizard").smartWizard({ 'labelNext' : labelNext, 'labelPrevious' : labelPrevious, 'labelFinish' : labelFinish, 'fixHeight' : 1, 'onShowStep' : onShowStepCallback, 'onLeaveStep' : onLeaveStepCallback, 'onFinish' : onFinishCallback, 'transitionEffect' : 'slideleft', 'enableAllSteps' : enableAllSteps }); displayRangeType(); } function displayRangeType() { if ($('input[name="shipping_method"]:checked').val() == 1) string = string_weight; else string = string_price; $('.range_type').html(string); } function onShowStepCallback() { $('.anchor li a').each( function () { $(this).parent('li').addClass($(this).attr('class')); }); $('#carrier_logo_block').prependTo($('div.content').filter(function() { return $(this).css('display') != 'none' }).children('.defaultForm').children('fieldset')); resizeWizard(); } function onFinishCallback(obj, context) { $('.wizard_error').remove(); $.ajax({ type:"POST", url : validate_url, async: false, dataType: 'json', data : $('#carrier_wizard .stepContainer .content form').serialize() + '&action=finish_step&ajax=1', success : function(data) { if (data.has_error) { displayError(data.errors, context.fromStep); resizeWizard(); } else window.location.href = carrierlist_url; } }); } function onLeaveStepCallback(obj, context) { if (context.toStep == nbr_steps) displaySummary(); return validateSteps(context.fromStep); // return false to stay on step and true to continue navigation } function displaySummary() { // used as buffer - you must not replace directly in the translation vars var tmp; // Carrier name $('#summary_name').html($('#name').val()); // Delay and pricing tmp = summary_translation_meta_informations.replace('@s2', '' + $('#delay_1').val() + ''); if ($('#is_free_on').attr('checked')) tmp = tmp.replace('@s1', summary_translation_free); else tmp = tmp.replace('@s1', summary_translation_paid); $('#summary_meta_informations').html(tmp); // Tax and calculation mode for the shipping cost tmp = summary_translation_shipping_cost.replace('@s2', '' + $('#id_tax_rules_group option:selected').text() + ''); if ($('#billing_price').attr('checked')) tmp = tmp.replace('@s1', summary_translation_price); else if ($('#billing_weight').attr('checked')) tmp = tmp.replace('@s1', summary_translation_weight); else tmp = tmp.replace('@s1', '' + summary_translation_undefined + ''); $('#summary_shipping_cost').html(tmp); // Weight or price ranges $('#summary_range').html(summary_translation_range); var range_inf = summary_translation_undefined; var range_sup = summary_translation_undefined; $('input[name$="range_inf[]"]').each(function(){ if (!isNaN(parseFloat($(this).val())) && (range_inf == summary_translation_undefined || range_inf < $(this).val())) range_inf = $(this).val(); }); $('input[name$="range_sup[]"]').each(function(){ if (!isNaN(parseFloat($(this).val())) && (range_sup == summary_translation_undefined || range_sup > $(this).val())) range_sup = $(this).val(); }); $('#summary_range').html( $('#summary_range').html() .replace('@s1', '' + range_inf + '') .replace('@s2', '' + range_sup + '') .replace('@s3', '' + $('#range_behavior option:selected').text().toLowerCase() + '') ); // Delivery zones $('#summary_zones').html(''); $('.input_zone').each(function(){ if ($(this).attr('checked')) $('#summary_zones').html($('#summary_zones').html() + '
  • ' + $(this).parent().prev().text() + '
  • '); }); // Group restrictions $('#summary_groups').html(''); $('input[name$="groupBox[]"]').each(function(){ if ($(this).attr('checked')) $('#summary_groups').html($('#summary_groups').html() + '
  • ' + $(this).parent().next().next().text() + '
  • '); }); // shop restrictions $('#summary_shops').html(''); $('.input_shop').each(function(){ if ($(this).attr('checked')) $('#summary_shops').html($('#summary_shops').html() + '
  • ' + $(this).parent().text() + '
  • '); }); } function validateSteps(step_number) { $('.wizard_error').remove(); var is_ok = true; form = $('#carrier_wizard #step-'+step_number+' form'); $.ajax({ type:"POST", url : validate_url, async: false, dataType: 'json', data : form.serialize()+'&step_number='+step_number+'&action=validate_step&ajax=1', success : function(datas) { if (datas.has_error) { is_ok = false; $('input').focus( function () { $(this).removeClass('field_error'); }); displayError(datas.errors, step_number); resizeWizard(); } } }); return is_ok; } function displayError(errors, step_number) { $('.wizard_error').remove(); str_error = '
    X
    '); } function resizeWizard() { resizeInterval = setInterval(function (){$("#carrier_wizard").smartWizard('fixHeight'); clearInterval(resizeInterval)}, 100); } function bind_inputs() { $('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(); }); rebuildTabindex(); 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').each( function () { $(this).find('td:eq('+index+') input:text').not('disabled').val(val); }); return false; }); $('input[name="is_free"]').on('click', function() { var is_free = $(this); $("#step_carrier_ranges .margin-form").each(function() { var field = $(this).children().attr('name'); if (typeof(field) != 'undefined' && field != 'is_free' && field != 'shipping_handling') { if (parseInt(is_free.val())) { $(this).hide(); $(this).prev().hide(); } else { $(this).show(); $(this).prev().show(); } } }); if (parseInt(is_free.val())) { $('#zones_table').hide(); $('.new_range').hide(); } else { $('#zones_table').show(); $('.new_range').show(); } resizeWizard(); }); $('input[name="is_free"]:checked').click(); $('input[name="shipping_method"]').on('click', function() { $.ajax({ type:"POST", url : validate_url, async: false, dataType: 'html', data : 'id_carrier='+parseInt($('#id_carrier').val())+'&shipping_method='+parseInt($(this).val())+'&action=changeRanges&ajax=1', success : function(data) { $('#zone_ranges').replaceWith(data); displayRangeType(); } }); }); } 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()); 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() { //add new rand sup input $('tr.range_sup td:last').after(''); //add new rand inf input $('tr.range_inf td:last').after(''); $('tr.fees_all td:last').after('