/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* 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 https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
var fees_is_hide = false;
$(document).ready(function() {
carriersRangeInputs.watchCarriersRangeInputChange();
bind_inputs();
initCarrierWizard();
if (parseInt($('input[name="is_free"]:checked').val()))
is_freeClick($('input[name="is_free"]:checked'));
displayRangeType();
$('#attachement_fileselectbutton').click(function(e) {
$('#carrier_logo_input').trigger('click');
});
$('#attachement_filename').click(function(e) {
$('#carrier_logo_input').trigger('click');
});
$('#carrier_logo_input').change(function(e) {
var name = '';
if ($(this)[0].files !== undefined)
{
var files = $(this)[0].files;
$.each(files, function(index, value) {
name += value.name+', ';
});
$('#attachement_filename').val(name.slice(0, -2));
}
else // Internet Explorer 9 Compatibility
{
name = $(this).val().split(/[\\/]/);
$('#attachement_filename').val(name[name.length-1]);
}
});
$('#carrier_logo_remove').click(function(e) {
$('#attachement_filename').val('');
});
if ($('#is_free_on').prop('checked') === true)
{
$('#shipping_handling_off').prop('checked', true).prop('disabled', true);
$('#shipping_handling_on').prop('disabled', true).prop('checked', false);
}
$('#is_free_on').click(function(e) {
$('#shipping_handling_off').prop('checked', true).prop('disabled', true);
$('#shipping_handling_on').prop('disabled', true).prop('checked', false);
});
$('#is_free_off').click(function(e) {
if ($('#shipping_handling_off').prop('disabled') === true)
{
$('#shipping_handling_off').prop('disabled', false).prop('checked', false);
$('#shipping_handling_on').prop('disabled', false).prop('checked', true);
}
});
});
function initCarrierWizard()
{
$("#carrier_wizard").smartWizard({
'labelNext' : labelNext,
'labelPrevious' : labelPrevious,
'labelFinish' : labelFinish,
'fixHeight' : 1,
'onShowStep' : onShowStepCallback,
'onLeaveStep' : onLeaveStepCallback,
'onFinish' : onFinishCallback,
'transitionEffect' : 'slideleft',
'enableAllSteps' : enableAllSteps,
'keyNavigation' : false
});
displayRangeType();
}
function displayRangeType()
{
if ($('input[name="shipping_method"]:checked').val() == 1)
{
string = string_weight;
$('.weight_unit').show();
$('.price_unit').hide();
}
else
{
string = string_price;
$('.price_unit').show();
$('.weight_unit').hide();
}
is_freeClick($('input[name="is_free"]:checked'));
$('.range_type').html(string);
}
function onShowStepCallback()
{
$('.anchor li a').each(function () {
$(this).closest('li').addClass($(this).attr('class'));
});
$('#carrier_logo_block').prependTo($('div.content').filter(function() { return $(this).css('display') != 'none' }).find('.defaultForm').find('fieldset'));
}
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&step_number='+context.fromStep,
success : function(data) {
if (data.has_error)
{
displayError(data.errors, context.fromStep);
}
else
window.location.href = carrierlist_url;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
jAlert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
}
function onLeaveStepCallback(obj, context)
{
if (context.toStep == nbr_steps)
displaySummary();
return validateSteps(context.fromStep, context.toStep); // return false to stay on step and true to continue navigation
}
function displaySummary()
{
var id_default_lang = typeof default_language !== 'undefined' ? default_language : 1,
id_lang = id_default_lang;
// Try to find current employee language
if (typeof languages !== 'undefined' && typeof iso_user !== 'undefined')
for (var i=0; i' + delay_text + '');
if ($('#is_free_on').prop('checked'))
tmp = tmp.replace('%1$s', summary_translation_free);
else
tmp = tmp.replace('%1$s', summary_translation_paid);
$('#summary_meta_informations').html(tmp);
// Tax and calculation mode for the shipping cost
tmp = summary_translation_shipping_cost.replace('%2$s', $('#id_tax_rules_group option:selected').text());
if ($('#billing_price').prop('checked'))
tmp = tmp.replace('%1$s', summary_translation_price);
else if ($('#billing_weight').prop('checked'))
tmp = tmp.replace('%1$s', summary_translation_weight);
else
tmp = tmp.replace('%1$s', '' + summary_translation_undefined + '');
$('#summary_shipping_cost').text(tmp);
// Weight or price ranges
$('#summary_range').text(summary_translation_range+' '+summary_translation_range_limit);
if ($('input[name="shipping_method"]:checked').val() == 1)
unit = PS_WEIGHT_UNIT;
else
unit = currency_sign;
var range_inf = summary_translation_undefined;
var range_sup = summary_translation_undefined;
$('tr.range_inf td input').each(function()
{
if (!isNaN(parseFloat($(this).val())) && (range_inf == summary_translation_undefined || parseFloat(range_inf) > parseFloat($(this).val())))
range_inf = $(this).val();
});
$('tr.range_sup td input').each(function(){
if (!isNaN(parseFloat($(this).val())) && (range_sup == summary_translation_undefined || parseFloat(range_sup) < parseFloat($(this).val())))
range_sup = $(this).val();
});
$('#summary_range').html(
$('#summary_range').html()
.replace('%1$s', '' + range_inf +' '+ unit + '')
.replace('%2$s', '' + range_sup +' '+ unit + '')
.replace('%3$s', '' + $('#range_behavior option:selected').text().toLowerCase() + '')
);
if ($('#is_free_on').prop('checked'))
$('span.is_free').hide();
// Delivery zones
$('#summary_zones').html('');
$('.input_zone').each(function(){
if ($(this).prop('checked'))
$('#summary_zones').html($('#summary_zones').html() + '