/**
* 2007-2018 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 SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
var tabsMEP = {
'category': function () {
window.tree_categories = new TreeCustom(
'.tree_custom_categories .tree_categories',
'.tree_custom_categories .tree_categories_header'
);
window.tree_categories.init();
window.tree_categories.afterChange = function () {
var categories = this.getListSelectedCategories();
var category_default = $('[name=category_default]');
category_default.html('');
category_default.append('');
$.each(categories, function (index, value) {
category_default.append('');
});
};
window.tree_categories.checkAssociatedCategory(2);
$('[name=action_with_category]').live('change', function () {
$('._action').hide();
if (!parseInt($(this).val()))
$('._action_add').show();
});
$('[name=action_with_category]:checked').trigger('change');
$('#setCategoryAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
var categories = tree_categories.getListSelectedCategories();
data['category'] = [];
data['id_category_default'] = parseInt(tab.find('[name=category_default]').val());
data['action_with_category'] = parseInt(tab.find('[name=action_with_category]:checked').val());
data['remove_old_categories'] = (tab.find('[name=remove_old_categories]').length
&& tab.find('[name=remove_old_categories]').is(':checked') ? 1 : 0);
$.each(categories, function (index, category) {
data['category'].push(category.id);
});
setAllProducts(data, 'category');
});
},
'price': function () {
$('#setPriceAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
data['type_price'] = tab.find('[name="type_price"]:checked').val();
data['action_price'] = tab.find('[name="action_price"]:checked').val();
data['change_for'] = tab.find('[name="change_for"]:checked').val();
data['combinations'] = $.getAllValues();
data['price_value'] = tab.find('[name="price_value"]').val();
data['id_tax_rules_group'] = tab.find('[name="id_tax_rules_group"]').val();
data['not_change_final_price'] = (tab.find('[name="not_change_final_price"]').prop('checked') ? 1 : 0);
data['unity'] = tab.find('[name="unity"]').val();
data['unity_price'] = tab.find('[name="unity_price"]').val();
data['type_price_r'] = tab.find('[name="type_price_r"]:checked').val();
data['action_direction'] = tab.find('[name="action_direction"]:checked').val();
data['action_rounding_value'] = tab.find('[name="action_rounding_value"]:checked').val();
// data['unity_price'] = tab.find('[name="unity_price"]').val();
setAllProducts(data, 'price');
});
$('[value=price]').live('change', function () {
var checkbox = $('[value=tax_rule_group]');
var checkbox_price_round = $('[value=price_round]');
if ($(this).prop('checked')) {
checkbox.attr('disabled', false);
checkbox_price_round.attr('disabled', false);
} else {
checkbox.attr('disabled', true);
checkbox_price_round.attr('disabled', true);
}
});
$('[value=tax_rule_group]').live('change', function () {
var checkbox = $('[value=price]');
var checkbox_price_round = $('[value=price_round]');
if ($(this).prop('checked')) {
checkbox.attr('disabled', false);
checkbox_price_round.attr('disabled', false);
} else {
checkbox.attr('disabled', true);
checkbox_price_round.attr('disabled', true);
}
});
$('[value=unity]').live('change', function () {
var checkbox_price_round = $('[value=price_round]');
if ($(this).prop('checked')) {
checkbox_price_round.attr('disabled', false);
} else {
checkbox_price_round.attr('disabled', true);
}
});
$('[value=specific_price]').live('change', function () {
var checkbox = $('[value=delete_specific_price_all]');
if ($(this).prop('checked')) {
checkbox.attr('disabled', false);
} else {
checkbox.attr('disabled', true);
}
});
$('[value=delete_specific_price_all]').live('change', function () {
var checkbox = $('[value=specific_price]');
if ($(this).prop('checked')) {
checkbox.attr('disabled', false);
} else {
checkbox.attr('disabled', true);
}
});
$('#action_thousand').live('change', function () {
$('.rounding-table tr').removeClass('active');
$('.rounding-table tr.tr_thousand').addClass('active');
});
$('#action_hundred').live('change', function () {
$('.rounding-table tr').removeClass('active');
$('.rounding-table tr.tr_hundred').addClass('active');
});
$('#action_ten').live('change', function () {
$('.rounding-table tr').removeClass('active');
$('.rounding-table tr.tr_ten').addClass('active');
});
$('#action_one').live('change', function () {
$('.rounding-table tr').removeClass('active');
$('.rounding-table tr.tr_one').addClass('active');
});
$('#action_one_tenth').live('change', function () {
$('.rounding-table tr').removeClass('active');
$('.rounding-table tr.tr_one_tenth').addClass('active');
});
$('#action_one_cell').live('change', function () {
$('.rounding-table tr').removeClass('active');
$('.rounding-table tr.tr_one_cell').addClass('active');
});
},
'virtual': function () {
$('#setVirtualAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var file = $('#virtual_product_file').get(0).files[0];
var data = new FormData();
data.append('file', file);
data.append('method', 'virtual');
data.append('action','virtual');
data.append('ajax', true);
data.append('action_for_virtual', tab.find('[name="action_for_virtual"]:checked').val());
data.append('action_virtual', tab.find('[name="action_virtual"]').prop('checked'));
data.append('virtual_product_file', tab.find('[name="virtual_product_file"]').val());
data.append('name_file', tab.find('[name="name_file"]').val());
data.append('number_downloads', tab.find('[name="number_downloads"]').val());
data.append('amount_of_days', tab.find('[name="amount_of_days"]').val());
data.append('expiration_date', tab.find('[name="expiration_date"]').val());
data.append('tab_name', 'virtual');
var exclude_ids = [];
$('.table_selected_products [name="id_product"]').each(function () {
exclude_ids.push($(this).val());
});
data.append('ids', exclude_ids );
$.ajax({
url: document.location.href.replace(document.location.hash, ''),
data: data,
dataType: 'json',
processData: false,
contentType: false,
type: 'POST',
success: function (r) {
if (!r.hasError) {
$('.tn-box.mv_succes').not('.tn-box_combinations').addClass('tn-box-active');
setTimeout(function () {
$('.stage_mv.mv_succes').fadeOut(300);
$('.tn-box').removeClass('tn-box-active');
}, 5000);
} else {
var error_mesage = [];
$.each(r.log, function (index, log) {
if (log.type == 'error')
error_mesage.push(log.message);
});
$('.tn-box.mv_error .message_mv_content').html(error_mesage.join('
')).slideDown(500);
$('.tn-box.mv_error').addClass('tn-box-active');
setTimeout(function () {
$('.stage_mv').fadeOut(300);
$('.tn-box.mv_error').removeClass('tn-box-active');
}, 5000);
}
}
});
});
},
'active': function () {
$('[name=available_for_order]').live('change', function () {
if ($(this).is(':checked'))
$('[name=show_price]').attr('checked', 'checked').attr('disabled', 'disabled');
else
$('[name=show_price]').removeAttr('disabled');
});
$('#setActiveAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
data['active'] = parseInt(tab.find('[name="is_active"]:checked').val());
data['on_sale'] = (tab.find('[name="on_sale"]').is(':checked') ? 1 : 0);
data['visibility'] = tab.find('[name="visibility"]').val();
data['condition'] = tab.find('[name="condition"]').val();
data['available_for_order'] = (tab.find('[name="available_for_order"]:checked').length ? 1 : 0);
data['show_price'] = (tab.find('[name="show_price"]:checked').length ? 1 : 0);
data['online_only'] = (tab.find('[name="online_only"]:checked').length ? 1 : 0);
data['delete_product'] = (tab.find('[name="delete_product"]:checked').length ? 1 : 0);
data['show_condition'] = (tab.find('[name="show_condition"]').is(':checked') ? 1 : 0);
data['delete_type'] = (tab.find('[name="delete_type"]:checked').val() == 1 ? 1 : 0);
data['combinations'] = $.getAllValues();
setAllProducts(data, 'active');
});
},
'manufacturer': function () {
$('#setManufacturerAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
data['id_manufacturer'] = parseInt(tab.find('[name="id_manufacturer"]').val());
setAllProducts(data, 'manufacturer');
});
},
'accessories': function () {
$('#setAccessoriesAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
data['accessories'] = [];
tab.find('[name="accessories[]"] option').each(function () {
data['accessories'].push({
id: parseInt($(this).attr('value'))
});
});
data['remove_old'] = parseInt(tab.find('[name=remove_old]:checked').val());
setAllProducts(data, 'accessories');
});
},
'supplier': function () {
$('#setSupplierAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
data['supplier'] = [];
tab.find('[name="supplier[]"] option:selected').each(function () {
data['supplier'].push(parseInt($(this).attr('value')));
});
data['id_supplier_default'] = tab.find('[name="id_supplier_default"]').val();
data['suppliers_sr[]'] = tab.find('[name="suppliers_sr[]"]').val();
data['supplier_reference'] = tab.find('[name="supplier_reference"]').val();
data['product_price'] = tab.find('[name="product_price"]').val();
data['product_price_currency'] = tab.find('[name="product_price_currency"]').val();
data['combinations'] = $.getAllValues();
setAllProducts(data, 'supplier');
});
},
'carrier': function () {
$('#setCarrierAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
data['carrier'] = [];
tab.find('[name="carrier[]"] option:selected').each(function () {
data['carrier'].push(parseInt($(this).attr('value')));
});
data['id_carrier_default'] = tab.find('[name="id_carrier_default"]').val();
data['carriers_sr[]'] = tab.find('[name="carriers_sr[]"]').val();
data['carrier_reference'] = tab.find('[name="carrier_reference"]').val();
data['product_price'] = tab.find('[name="product_price"]').val();
data['product_price_currency'] = tab.find('[name="product_price_currency"]').val();
data['combinations'] = $.getAllValues();
setAllProducts(data, 'carrier');
});
},
'discount': function () {
$('#setDiscountAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
$priceD = tab.find('[name="price"]').val();
if($priceD == ''){
$priceD = -1;
}
data['action_for_sp'] = tab.find('[name="action_for_sp"]:checked').val();
data['sp_from_quantity'] = tab.find('[name="sp_from_quantity"]').val();
data['sp_id_currency'] = tab.find('[name="sp_id_currency"]').val();
data['sp_id_country'] = tab.find('[name="sp_id_country"]').val();
data['sp_id_group'] = tab.find('[name="sp_id_group"]').val();
data['sp_from'] = tab.find('[name="sp_from"]').val();
data['sp_to'] = tab.find('[name="sp_to"]').val();
data['sp_reduction'] = tab.find('[name="sp_reduction"]').val();
data['sp_reduction_type'] = tab.find('[name="sp_reduction_type"]').val();
data['sp_reduction_tax'] = tab.find('[name="sp_reduction_tax"]').val();
data['change_for'] = tab.find('[name="change_for_sp"]:checked').val();
data['price'] = $priceD;
data['delete_old_discount'] = (tab.find('[name="delete_old_discount"]').is(':checked') ? 1 : 0);
data['delete_old_discount_all'] = (tab.find('[name="delete_old_discount_all"]').is(':checked') ? 1 : 0);
data['leave_base_price'] = (tab.find('[name="leave_base_price"]').is(':checked') ? 1 : 0);
data['action_discount'] = tab.find('[name="action_discount"]:checked').val();
data['search_id_currency'] = tab.find('[name=search_id_currency]').val();
data['search_id_country'] = tab.find('[name=search_id_country]').val();
data['search_id_group'] = tab.find('[name=search_id_group]').val();
data['search_from'] = tab.find('[name=search_from]').val();
data['search_to'] = tab.find('[name=search_to]').val();
data['search_from_quantity'] = tab.find('[name=search_from_quantity]').val();
data['discount_price_reduction_type'] = tab.find('[name=discount_price_reduction_type]').val();
data['discount_price'] = tab.find('[name=discount_price]:checked').val();
data['discount_discount'] = tab.find('[name=discount_discount]:checked').val();
data['combinations'] = $.getAllValues();
setAllProducts(data, 'discount');
});
$('#discount #off_menu').click(function () {
$('#discount .edit_menu').show();
$('#discount .search-block').hide();
$('#discount .edit-block').show();
return true;
});
$('#discount #off_menus').click(function () {
$('#discount .edit_menu').hide();
$('#discount .search-block').show();
$('#discount .edit-block').hide();
return true;
});
$('#discount #trigger').click(function () {
$('#discount .edit_menu').show();
$('#discount .search-block').show();
$('#discount .edit-block').show();
return true;
});
$('.leave_base_price').live('change', function () {
if ($(this).is(':checked')) {
$('.specific_price_price').attr('disabled', true).val('');
$('#discount_price_disable').trigger('click');
} else {
$('.specific_price_price').removeAttr('disabled').val(0);
$('#discount_price_rewrite').trigger('click');
}
});
$('[name="discount_price"]').live('change', function () {
$('.leave_base_price').prop('checked', false);
$('.specific_price_price').removeAttr('disabled').val(0);
if ($('[name="discount_price"]:checked').val() == -1) {
$('.leave_base_price').prop('checked', true);
$('.specific_price_price').attr('disabled', true).val('');
}
if ($('[name="discount_price"]:checked').val() == 0 || $('[name="discount_price"]:checked').val() == 1) {
$('[name="discount_price_reduction_type"]').fadeIn();
} else {
$('[name="discount_price_reduction_type"]').fadeOut();
}
});
},
'features': function () {
$('.view_more_features').live('click', function (e) {
e.preventDefault();
var self = $(this);
if (self.is('.off'))
return false;
var page = feature_pages.shift();
self.addClass('off');
$.ajax({
url: document.location.href.replace(document.location.hash, ''),
type: 'POST',
dataType: 'json',
data: {
ajax: true,
action: 'load_features',
p: page
},
success: function (r) {
self.removeClass('off');
if (!r.hasError)
{
$('.list_features').append(r.features_list);
initLanguages();
$('.disable_option').trigger('change');
var counter = self.find('.counter');
counter.text(parseInt(counter.text()) - count_feature_view);
}
else
{
feature_pages.unshift(page);
}
if (!feature_pages.length)
self.remove();
},
error: function ()
{
self.removeClass('off');
feature_pages.unshift(page);
}
});
});
$('#setFeaturesAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
if ($('[name="old_feature_delete"]:checked').length > 0) {
data.delete_old = 1;
} else {
data.delete_old = 0;
}
if (typeof window.parent.frames['seosaextendedfeatures'] != 'undefined') {
var contentWindow = window.parent.frames['seosaextendedfeatures'].contentWindow;
var table_features = $('.table-features', contentWindow.document);
table_features.trigger('change');
table_features.find(':input:not(button)').each(function () {
var original_name = $(this).attr('name');
if (original_name.match(/\[custom\]/)) {
var values = contentWindow.angular.element($('[name="'+original_name+'"]', contentWindow.document)).scope().values;
var match = original_name.match(/\[[a-zA-Z]+\]$/);
var name = original_name.replace(match[0], '');
$.each(languages, function (index, l) {
data[name+'['+l.iso_code+']'] = (typeof values[l.id_lang] != 'undefined' ? values[l.id_lang] : '');
});
} else {
data[$(this).attr('name')] = $(this).val();
}
});
} else {
$('.table-features').trigger('change');
tab.find(':input:not(button)').each(function () {
data[$(this).attr('name')] = $(this).val();
});
tab.find('[name*="delete_form_features"]').each(function () {
if ($(this).prop('checked')) {
data[$(this).attr('name')] = 1;
} else {
data[$(this).attr('name')] = 0;
}
});
// fix enabled feature TODO
data.enabled_feature_fix = [];
$('[id^="enable_feature_"]').each(function () {
if ($(this).prop('checked') == false) {
data.enabled_feature_fix.push($(this).val());
}
});
}
setAllProducts(data, 'features');
});
},
'delivery': function () {
$('#setDeliveryAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
tab.find('input[type=text], input[type=checkbox]:checked').not('button').each(function () {
data[$(this).attr('name')] = $(this).val();
});
data['combinations'] = $.getAllValues();
data['change_for'] = tab.find('[name="weight_change_for_combination"]:checked').val();
data['del_carrier'] = tab.find('[name="on_delete"]:checked').val();
data['additional_delivery_times'] = tab.find('[name="additional_delivery_times"]:checked').val();
setAllProducts(data, 'delivery');
});
},
'image': function () {
$('#setImageAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
tab.addClass('loading');
var images = new FormData();
images.append('action', 'upload_images');
images.append('ajax', true);
tab.find('input[name="image[]"]').each(function (index, value) {
images.append('image['+index+']', $(this).get(0).files[0]);
});
$.ajax({
url: document.location.href,
type: 'POST',
processData: false,
contentType: false,
dataType: 'json',
data: images,
success: function (r)
{
var data = {};
data['responseImages'] = r.responseImages;
data['combinations'] = $.getAllValues();
data['change_for'] = parseInt(tab.find('[name="change_for_img"]:checked').val());
data['delete_images'] = (tab.find('[name=delete_images]').is(':checked') ? 1 : 0);
tab.find('[name^=legend_]').each(function() {
data['legend_' + $(this).data('lang')] = $(this).val();
});
data['position'] = tab.find('[name="id_caption"]').val();
data['delete_captions'] = (tab.find('[name=delete_captions]').is(':checked') ? 1 : 0);
setAllProducts(data, 'image', function () {
tab.removeClass('loading');
});
},
error: function ()
{
tab.removeClass('loading');
}
});
});
},
'description': function () {
$('#setDescriptionAllProduct').live('click', function () {
var tab = $(this).closest('.tab_content');
var data = {};
data['description'] = tab.find('[name=description]').val();
data['replace_description_short'] = tab.find('[name=replace_description_short]').val();
data['replace_description'] = tab.find('[name=replace_description]').val();
data['description_short'] = tab.find('[name=description_short]').val();
data['language'] = tab.find('[name=language]:checked').val();
data['product_name'] = tab.find('[name=name]').val();
data['location_description_short'] = tab.find('[name=location_description_short]:checked').val();
data['location_description'] = tab.find('[name=location_description]:checked').val();
data['location_name'] = tab.find('[name=location_name]:checked').val();
setAllProducts(data, 'description');
});
$('.editor_html').redactor({
buttonSource: true,
imageUpload: upload_image_dir,
fileUpload: upload_file_dir,
plugins: ['table', 'video']
});
},
'rule_combination': function () {
$('[name="attribute_group"]').live('change', function () {
var row = $(this).closest('.row_attributes');
row.find('[id^="attribute_group_"]').hide();
row.find('[id="attribute_group_'+$(this).val()+'"]').show();
}).trigger('change');
$('.removeRowAttributes').live('click', function () {
var selected_attributes = $('[name=selected_attributes]').val();
selected_attributes = (selected_attributes ? selected_attributes.split('|') : []);
var attr = $(this).closest('').data('key');
var key = $.inArray(attr, selected_attributes)
if (key == -1)
{
selected_attributes.splice(key, 1);
$('[name=selected_attributes]').val(selected_attributes.join('|'));
$(this).closest('.selected_attribute').remove();
}
else
{
$.alert('Not exists key!');
setTimeout(function() {
$('body').find('.jconfirm').addClass('bootstrap');
}, 1);
}
});
$('.addAttribute').live('click', function (e) {
e.preventDefault();
var selected_attributes = $('[name=selected_attributes]').val();
selected_attributes = (selected_attributes ? selected_attributes.split('|') : []);
var row_attributes = $(this).closest('.row_attributes');
var id_attribute_group = row_attributes.find('[name=attribute_group]').val();
var id_attribute = row_attributes.find('#attribute_group_'+id_attribute_group+' [name=attributes]').val();
var group_name = row_attributes.find('[name=attribute_group] option:selected').text();
var attr_name = row_attributes.find('#attribute_group_'+id_attribute_group+' [name=attributes] option:selected').text();
var attr = id_attribute_group+'_'+id_attribute;
if ($.inArray(attr, selected_attributes) != -1 || $('[data-key^="'+id_attribute_group+'_"]').length)
{
$.alert(text_already_exists_attribute);
setTimeout(function() {
$('body').find('.jconfirm').addClass('bootstrap');
}, 1);
return false;
}
selected_attributes.push(attr);
$('[name=selected_attributes]').val(selected_attributes.join('|'));
$('.selected_attributes').append('