Files
2025-01-06 20:47:25 +01:00

1256 lines
53 KiB
JavaScript

/**
* Copyright ETS Software Technology Co., Ltd
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 website only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future.
*
* @author ETS Software Technology Co., Ltd
* @copyright ETS Software Technology Co., Ltd
* @license Valid for 1 website (or project) for each purchase of license
*/
var name_pr_search_product='';
$(document).ready(function(){
var menu_space_height = $('.ets_pr_tabs_height').offset().top - 15;
console.log(menu_space_height);
$('.ets_pr_tabs').css('top',menu_space_height+'px');
$(document).on('click','.ets_pr_row_ETS_PR_AUTO_CLEAR_RULE_EXPIRED .help-block a,.ets_pr_row_ETS_PR_AUTO_CLEAR_DISCOUNT_USED .help-block a',function(){
$('.rule_tab_cronjob').click();
return false;
});
if($('.help-block code').length)
{
$('.help-block code').attr('title',text_Click_to_copy);
$(document).on('click','.help-block code',function(){
$('.pr-text-copy').remove();
if($('input#pr_select_code').length==0)
$('body').append('<input id="pr_select_code" value="'+$(this).html()+'" type="text">');
else
$('#pr_select_code').val($(this).html());
$('#pr_select_code').select();
document.execCommand("copy");
var copy_text = $('<span class="pr-text-copy">'+text_Copied+'</span>');
$(this).append(copy_text);
setTimeout(function() { copy_text.remove(); }, 2000);
});
}
$(document).on('change','.specific_occasion_month_of_year',function(){
ets_pr_rule.changeDayOfMonth($(this).parents('.row.month_of_year'));
});
if($('.specific_occasion_month_of_year').length)
{
$('.specific_occasion_month_of_year').each(function(){
ets_pr_rule.changeDayOfMonth($(this).parents('.row.month_of_year'));
});
}
$(document).on('click','input[name="pr_search_product"]',function(){
name_pr_search_product = $(this).data('name');
});
$(document).on('click','.btn_delete_row_specific_occasion',function(e){
$(this).parents('.form-group.parent_codition.specific_occasion').remove();
});
$(document).on('click','.btn_add_new_row_specific_occasion',function(e){
e.preventDefault();
$('.new_row_specific_occasion .datetimepicker').removeClass('hasDatepicker');
$('.new_row_specific_occasion .datepicker').removeClass('hasDatepicker');
$(this).parent().parent().before($(this).parent().parent().next('.new_row_specific_occasion').html().replace(new RegExp('data-name', 'g'),'name'));
if ($(".datepicker").length > 0)
$(".datepicker").datepicker({
prevText: '',
nextText: '',
dateFormat: 'yy-mm-dd'
});
if ($(".datetimepicker").length > 0)
{
$('.datetimepicker').datetimepicker({
prevText: '',
nextText: '',
dateFormat: 'yy-mm-dd',
// Define a custom regional settings in order to use PrestaShop translation tools
currentText: 'Now',
closeText: 'Done',
ampm: false,
amNames: ['AM', 'A'],
pmNames: ['PM', 'P'],
timeFormat: 'hh:mm:ss tt',
timeSuffix: '',
timeOnlyTitle: 'Choose Time',
timeText: 'Time',
hourText: 'Hour',
minuteText: 'Minute',
});
}
});
if($('.module_confirmation.alert-success').length)
{
setTimeout(function(){$('.module_confirmation.alert-success').remove();},5000);
}
if($('input.color').length)
{
$('input.color').each(function(){
if($(this).val()=='')
{
$(this).css('background-color','#ffffff');
$(this).css('color','black');
}
});
}
$(document).on('change','#way_to_promote,input.display_hook',function(){
ets_pr_rule.displayPromoteRule();
});
$(document).on('change','input[type="range"]',function(){
ets_pr_rule.changeRange($(this));
});
$(document).on('click','.btn-new-promote',function(e){
e.preventDefault();
$('.ets_condition_popup .form_promote').html('');
$('.ets_condition_popup .form_promote').html($('#new_from_promote_rule').data('form'));
$('.ets_condition_popup').addClass('show');
ets_pr_rule.displayPromoteRule();
ets_pr_rule.searchProduct();
if($('input[type="range"]').length)
{
$('input[type="range"]').each(function(){
ets_pr_rule.changeRange($(this));
});
}
if($('input[type="color"]').length)
{
if ($.fn.mColorPicker.init.replace) {
$('input[data-mcolorpicker!="true"]').filter(function() {
return ($.fn.mColorPicker.init.replace == '[type=color]')? this.getAttribute("type") == 'color': $(this).is($.fn.mColorPicker.init.replace);
}).mColorPicker();
$.fn.mColorPicker.liveEvents();
}
setTimeout(function(){
$('input.color').each(function(){
if($(this).val()=='')
{
$(this).css('background-color','#ffffff');
$(this).css('color','black');
}
else
{
$(this).css('background-color',$(this).val());
}
});
},300);
}
$('.help-block code').attr('title',text_Click_to_copy);
if($('.autoload_rte').length)
{
var date_time = new Date();
$('.autoload_rte').each(function(){
$(this).attr('id',$(this).attr('id')+date_time.getTime());
});
tinySetup({
editor_selector :"autoload_rte"
});
}
});
$(document).on('click','button[name="save_condition_rule"],button[name="save_promote_discount_rule"],button[name="btnSubmitSettingsRule"]',function(e){
e.preventDefault();
if(!$(this).hasClass('loading'))
{
if(typeof tinymce !== 'undefined' && tinymce.editors.length > 0)
{
tinyMCE.triggerSave();
}
$('.module_error.alert').parent().remove();
$(this).addClass('loading');
var $this= $(this);
var formData = new FormData($(this).parents('form').get(0));
$.ajax({
url: $(this).parents('form').eq(0).attr('action'),
data: formData,
type: 'post',
dataType: 'json',
processData: false,
contentType: false,
success: function(json){
$this.removeClass('loading');
if(json.errors)
{
$this.before(json.errors);
}
if(json.success)
{
if($this.attr('name')=='save_condition_rule' || $this.attr('name')=='save_promote_discount_rule')
{
$('.ets_condition_popup').removeClass('show');
if($this.attr('name')=='save_condition_rule')
{
if($('.row-condtion-'+json.id_ets_pr_condition_rule).length >0)
$('.row-condtion-'+json.id_ets_pr_condition_rule).replaceWith(json.row_condtion);
else
{
$('.list-rule tbody').append(json.row_condtion);
$('tr.no-data').hide();
}
}
else
{
if($('.row-promote-'+json.id_ets_pr_promote_rule).length >0)
$('.row-promote-'+json.id_ets_pr_promote_rule).replaceWith(json.row_promote);
else
{
$('.list-rule tbody').append(json.row_promote);
$('tr.no-data').hide();
}
}
}
showSuccessMessage(json.success);
}
},
error: function(xhr, status, error)
{
$this.removeClass('loading');
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
}
});
if ($(".ets_pr_datepicker input").length > 0) {
$(".ets_pr_datepicker input").datepicker({
dateFormat: 'yy-mm-dd',
});
}
ets_pr_rule.init();
$(document).on('click','input[name="apply_customer"],input[name="apply_cart"]',function(){
ets_pr_rule.displayFieldRule()
});
$(document).on('click','.ets_pr_row_code .input-group-addon',function(){
ets_pr_rule.gencode(8);
});
$(document).on('change','#parent_codition,#type_action',function(){
ets_pr_rule.displayFieldRule();
});
$(document).on('click','.link_delete_condition',function(e){
e.preventDefault();
if(!$('body').hasClass('loading') && confirm($(this).data('confirm')))
{
$('body').addClass('loading');
var link_delelte = $(this).attr('href');
$.ajax({
url: link_delelte,
dataType: 'json',
type: 'post',
data: {
ajax: 1,
},
success: function(json){
if(json.success)
{
if(json.id_ets_pr_condition_rule)
$('.row-condtion-'+json.id_ets_pr_condition_rule).remove();
if(json.id_ets_pr_promote_rule)
$('.row-promote-'+json.id_ets_pr_promote_rule).remove();
showSuccessMessage(json.success);
}
$('body').removeClass('loading');
if($('.list-rule tbody tr').length==1)
$('tr.no-data').show();
},
error: function(xhr, status, error)
{
$('body').removeClass('loading');
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
}
});
$(document).on('click','.btn-new-condition',function(){
$('.ets_condition_popup').addClass('show');
$(".datetimepicker").removeClass('hasDatepicker');
$(".datepicker").removeClass('hasDatepicker');
$('#block-form-popup-condition').html($('#new_from_condition_rule').html());
ets_pr_rule.searchProduct();
ets_pr_rule.searchCustomer();
ets_pr_rule.displayFieldRule();
});
$(document).on('click','.link_edit_condition',function(e){
e.preventDefault();
if(!$('body').hasClass('loading'))
{
$('body').addClass('loading');
var link_edit = $(this).attr('href');
$.ajax({
url: link_edit,
dataType: 'json',
type: 'post',
data: {
ajax: 1,
},
success: function(json){
if(json.form_html)
{
$('.ets_condition_popup').addClass('show');
$('#block-form-popup-condition').html(json.form_html);
ets_pr_rule.searchProduct();
ets_pr_rule.searchCustomer();
ets_pr_rule.displayFieldRule();
ets_pr_rule.displayPromoteRule();
if ( $('input[type="range"]').length > 0 ){
$('input[type="range"]').each(function(){
ets_pr_rule.changeRange($(this));
});
}
if($('input[type="color"]').length)
{
if ($.fn.mColorPicker.init.replace) {
$('input[data-mcolorpicker!="true"]').filter(function() {
return ($.fn.mColorPicker.init.replace == '[type=color]')? this.getAttribute("type") == 'color': $(this).is($.fn.mColorPicker.init.replace);
}).mColorPicker();
$.fn.mColorPicker.liveEvents();
}
setTimeout(function(){
$('input.color').each(function(){
if($(this).val()=='')
{
$(this).css('background-color','#ffffff');
$(this).css('color','black');
}
else
{
$(this).css('background-color',$(this).val());
}
});
},300);
}
$('.help-block code').attr('title',text_Click_to_copy);
if($('.autoload_rte').length)
{
var date_time = new Date();
$('.autoload_rte').each(function(){
$(this).attr('id',$(this).attr('id')+date_time.getTime());
});
tinySetup({
editor_selector :"autoload_rte"
});
}
}
$('body').removeClass('loading');
},
error: function(xhr, status, error)
{
$('body').removeClass('loading');
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
}
});
$(document).on('change','#block-form-popup-condition #id_country',function(){
var id_country = $(this).val();
$.ajax({
url: '',
dataType: 'json',
type: 'post',
data: {
id_country: id_country,
getStates:1
},
success: function(json){
if(json.list_state)
{
$('#id_state').html(json.list_state);
$('.ets_pr_row_id_state').show();
}
else
$('.ets_pr_row_id_state').hide();
},
error: function(xhr, status, error)
{
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
});
$(document).on('change','#block-form-popup-condition #delivery_id_country',function(){
var id_country = $(this).val();
$.ajax({
url: '',
dataType: 'json',
type: 'post',
data: {
id_country: id_country,
getStates:1
},
success: function(json){
if(json.list_state)
{
$('#delivery_id_state').html(json.list_state);
$('.ets_pr_row_delivery_id_state').show();
}
else
$('.ets_pr_row_delivery_id_state').hide();
},
error: function(xhr, status, error)
{
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
});
$(document).on('click','.close_popup,button[name="btncancel"]',function(){
$('.ets_condition_popup').removeClass('show');
return false;
});
$(document).keyup(function(e) {
if(e.keyCode == 27 && $('.ets_condition_popup.show').length) {
$('.ets_condition_popup').removeClass('show');
}
});
$(document).on('change','input[name="specific_occasion"],input[name="first_order_of_customer"],input[name="order_criteria"],input[name="order_time_in"],input[name="applicable_product_categories"],input[name="apply_all_attribute"],input[name="apply_all_features"],input[name="apply_all_supplier"],input[name="apply_all_manufacturer"]',function(){
if($('#ets_pr_action_rule_form').length)
ets_pr_rule.displayRowActionRule();
else
ets_pr_rule.displayRowConditionRule();
});
$(document).on('click','.checkbox_all input',function(){
if($(this).is(':checked'))
{
$(this).closest('.form-group').find('input').prop('checked',true);
}
else
{
$(this).closest('.form-group').find('input').prop('checked',false);
}
if($('input.display_hook').length)
ets_pr_rule.displayPromoteRule();
});
$(document).on('click','.checkbox input',function(){
if($(this).is(':checked'))
{
if($(this).closest('.form-group').find('input:checked').length==$(this).closest('.form-group').find('input').length-1)
$(this).closest('.form-group').find('.checkbox_all input').prop('checked',true);
}
else
{
$(this).closest('.form-group').find('.checkbox_all input').prop('checked',false);
}
});
$(document).on('click','.pr_product_item .pr_block_item_close',function(){
var $ul = $(this).parents('ul.pr_products');
var ids = '';
$(this).parent().remove();
if($ul.find('.pr_product_item').length)
{
$ul.find('.pr_product_item').each(function(){
ids += $(this).attr('data-id')+',';
});
}
$ul.prev('.pr_ids_product').val(ids.trim(','));
});
$(document).on('click','.form_codition .pr_customer_item .pr_block_item_close',function(){
var $ul = $(this).parents('ul.pr_customers');
var ids = '';
$(this).parent().remove();
if($ul.find('.pr_customer_item').length)
{
$ul.find('.pr_customer_item').each(function(){
ids += $(this).attr('data-id')+',';
});
}
$ul.prev('.pr_ids_customer').val(ids.trim(','));
});
$(document).on('click','.btn-advanced-settings',function(e){
e.preventDefault();
$('.wapper-advanced-settings').addClass('active');
$('.btn-advanced-settings').hide();
$('input[name="display_advanced_setting"]').val('1');
});
$(document).on('click','.btn-hide-advanced-settings',function(e){
e.preventDefault();
$('.wapper-advanced-settings').removeClass('active');
$('.btn-advanced-settings').show();
$('input[name="display_advanced_setting"]').val('0');
});
$(document).on('change','.ets_pr_row_id_groups input[type="checkbox"]',function(){
if($('#ets_pr_action_rule_form').length)
ets_pr_rule.displayRowActionRule();
else
ets_pr_rule.displayRowConditionRule();
});
$(document).on('change','input[name="apply_discount_code"],input[name="repeat_the_action_on_next_same_product"],input[name="discount_on_next_same_product"],input[name="discount_purchase_more_product_quantity"],input[name="discount_purchase_more_product_amount"],input[name="new_product_with_discount_price"],input[name="gift_or_with_discount_product"],input[name="discount_on_total_cart"],input[name="discount_type"],input[name="discount_on_all_quantities"],input[name="apply_free_shipping"],input[name="discount_on_shipping_cost"]',function(){
ets_pr_rule.displayRowActionRule();
});
if ( $('input[type="range"]').length > 0 ){
$('input[type="range"]').each(function(){
ets_pr_rule.changeRange($(this));
});
}
$(document).on('click','.ets_rule_tabs_configs .rule_tab',function(){
if(!$(this).hasClass('active'))
{
$('.ets_rule_tabs_configs .rule_tab').removeClass('active');
$(this).addClass('active');
ets_pr_rule.displayFromSettings();
}
});
$(document).on('click','button[name="etsprSubmitUpdateToken"]',function(e){
e.preventDefault();
if(!$(this).hasClass('loading'))
{
$(this).addClass('loading');
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: '',
async: true,
cache: false,
dataType : "json",
data:'etsprSubmitUpdateToken=1&ETS_PR_CRONJOB_TOKEN='+$('#ETS_PR_CRONJOB_TOKEN').val(),
success: function(json)
{
$('button[name="etsprSubmitUpdateToken"]').removeClass('loading');
if(json.success)
{
showSuccessMessage(json.success)
$('.js-emp-test-cronjob').attr('data-secure',$('#ETS_PR_CRONJOB_TOKEN').val());
$('.emp-cronjob-secure-value').html($('#ETS_PR_CRONJOB_TOKEN').val());
}
if(json.errors)
{
showErrorMessage(json.errors);
}
}
});
}
});
$(document).on('click','.js-emp-test-cronjob',function(e){
e.preventDefault();
if(!$(this).hasClass('loading'))
{$(this).addClass('loading');
var secure = $(this).attr('data-secure');
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: '',
async: true,
cache: false,
dataType : "json",
data:'submitCronjob&ajax=1&secure='+secure,
success: function(json)
{
if(json.success)
{
showSuccessMessage(json.success);
$('.cronjob_log').val(json.cronjob_log);
}
if(json.errors)
{
showErrorMessage(json.errors);
}
$('.js-emp-test-cronjob').removeClass('loading');
}
});
}
});
$(document).on('click','button[name="etsprSubmitClearLog"]',function(e){
e.preventDefault();
$(this).addClass('loading');
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: '',
async: true,
cache: false,
dataType : "json",
data:'ajax=1&etsprSubmitClearLog=1',
success: function(json)
{
if(json.success)
{
showSuccessMessage(json.success);
$('.cronjob_log').val('');
}
if(json.errors)
{
showErrorMessage(json.errors)
}
$('button[name="etsprSubmitClearLog"]').removeClass('loading');
}
});
});
$(document).on('click','input[name="ETS_PR_SAVE_CRONJOB_LOG"]',function(){
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: '',
async: true,
cache: false,
dataType : "json",
data:'ETS_PR_SAVE_CRONJOB_LOG='+$('input[name="ETS_PR_SAVE_CRONJOB_LOG"]:checked').val(),
success: function(json)
{
if(json.success)
{
showSuccessMessage(json.success);
}
if(json.errors)
{
showErrorMessage(json.errors);
}
}
});
});
});
var ets_pr_rule = {
init : function(){
ets_pr_rule.searchProduct();
ets_pr_rule.searchCustomer();
ets_pr_rule.displayFieldRule();
ets_pr_rule.displayFromSettings();
},
displayFromSettings:function()
{
if($('.ets_rule_tabs_configs .rule_tab').length)
{
var curentTab = $('.ets_rule_tabs_configs .rule_tab.active').data('tab-id');
$('.ets_rule_tab_content').hide();
$('.ets_rule_tab_content.rule_tab_content_'+curentTab).show();
if(curentTab=='cronjob')
$('.panel-footer').hide();
else
$('.panel-footer').show();
}
},
displayPromoteRule:function()
{
if($('#way_to_promote').length)
{
var way_to_promote = $('#way_to_promote').val();
$('.form-group.way_to_promote').hide();
$('.form-group.way_to_promote.'+way_to_promote).show();
if(way_to_promote=='display_notification' || way_to_promote=='display_banner')
{
if($('input.display_hook:checked').length)
$('.form-group.display_hook').show();
else
$('.form-group.display_hook').hide();
}
else
$('.form-group.display_hook').hide();
}
if($('input[name="applicable_product_categories"]:checked').val()=='all_product')
{
$('.ets_pr_row_applicable_categories').hide();
$('.ets_pr_row_include_sub_categories').hide();
$('.ets_pr_row_include_specific_products').hide();
}
else
{
$('.ets_pr_row_applicable_categories').show();
$('.ets_pr_row_include_sub_categories').show();
$('.ets_pr_row_include_specific_products').show();
}
},
displayRowActionRule:function(){
if($('input[name="apply_discount_code"]:checked').val()=='code')
{
$('.rule_tab_content_apply_discount_code.code').show();
}
else
{
$('.rule_tab_content_apply_discount_code.code').hide();
}
if($('input[name="repeat_the_action_on_next_same_product"]:checked').val()=='many_time_on_1_product')
{
$('.ets_pr_row_maximum_time_on_next_same_product').show();
}
else
{
$('.ets_pr_row_maximum_time_on_next_same_product').hide();
}
if($('input[name="discount_on_next_same_product"]:checked').val()=='free')
{
$('.ets_pr_row_percent_discount_on_next_same_product').hide();
$('.ets_pr_row_amount_discount_on_next_same_product').hide();
}
else if($('input[name="discount_on_next_same_product"]:checked').val()=='percent')
{
$('.ets_pr_row_percent_discount_on_next_same_product').show();
$('.ets_pr_row_amount_discount_on_next_same_product').hide();
}
else
{
$('.ets_pr_row_percent_discount_on_next_same_product').hide();
$('.ets_pr_row_amount_discount_on_next_same_product').show();
}
if($('input[name="discount_purchase_more_product_amount"]:checked').val()=='percent')
{
$('.ets_pr_row_percent_discount_purchase_more_product_amount').show();
$('.ets_pr_row_amount_discount_purchase_more_product_amount').hide();
}
else
{
$('.ets_pr_row_percent_discount_purchase_more_product_amount').hide();
$('.ets_pr_row_amount_discount_purchase_more_product_amount').show();
}
if($('input[name="discount_purchase_more_product_quantity"]:checked').val()=='percent')
{
$('.ets_pr_row_percent_discount_purchase_more_product_quantity').show();
$('.ets_pr_row_amount_discount_purchase_more_product_quantity').hide();
}
else
{
$('.ets_pr_row_percent_discount_purchase_more_product_quantity').hide();
$('.ets_pr_row_amount_discount_purchase_more_product_quantity').show();
}
if($('input[name="gift_or_with_discount_product"]:checked').val()=='gift_product')
{
$('.rule_tab_content_gift_product').show();
$('.rule_tab_content_new_product').hide();
}
else
{
$('.rule_tab_content_gift_product').hide();
$('.rule_tab_content_gift_product.new_product').show();
$('.rule_tab_content_new_product').show();
if($('input[name="new_product_with_discount_price"]:checked').val()=='percent')
{
$('.ets_pr_row_percent_new_product_with_discount_price').show();
$('.ets_pr_row_maximum_new_product_with_discount_price').show();
$('.ets_pr_row_amount_new_product_with_discount_price').hide();
}
else
{
$('.ets_pr_row_percent_new_product_with_discount_price').hide();
$('.ets_pr_row_maximum_new_product_with_discount_price').hide();
$('.ets_pr_row_amount_new_product_with_discount_price').show();
}
}
if($('input[name="apply_free_shipping"]:checked').val()==1)
{
$('.ets_pr_row_discount_on_shipping_cost').hide();
$('.ets_pr_row_percent_discount_on_shipping_cost').hide();
$('.ets_pr_row_maximum_discount_on_shipping_cost').hide();
$('.ets_pr_row_amount_discount_on_shipping_cost').hide();
}
else
{
$('.ets_pr_row_discount_on_shipping_cost').show();
if($('input[name="discount_on_shipping_cost"]:checked').val()=='percent')
{
$('.ets_pr_row_percent_discount_on_shipping_cost').show();
$('.ets_pr_row_maximum_discount_on_shipping_cost').show();
$('.ets_pr_row_amount_discount_on_shipping_cost').hide();
}
else
{
$('.ets_pr_row_percent_discount_on_shipping_cost').hide();
$('.ets_pr_row_maximum_discount_on_shipping_cost').hide();
$('.ets_pr_row_amount_discount_on_shipping_cost').show();
}
}
if($('input[name="discount_on_all_quantities"]:checked').val()=='percent')
{
$('.ets_pr_row_percent_discount_on_all_quantities').show();
$('.ets_pr_row_amount_discount_on_all_quantities').hide();
}
else
{
$('.ets_pr_row_percent_discount_on_all_quantities').hide();
$('.ets_pr_row_amount_discount_on_all_quantities').show();
}
if($('input[name="discount_on_total_cart"]:checked').val()=='percent')
{
$('.ets_pr_row_percent_total_cart').show();
$('.ets_pr_row_maximum_discount_value').show();
$('.ets_pr_row_amount_total_cart').hide();
}
else
{
$('.ets_pr_row_percent_total_cart').hide();
$('.ets_pr_row_maximum_discount_value').hide();
$('.ets_pr_row_amount_total_cart').show();
}
if($('input[name="discount_type"]:checked').val()=='percent')
{
$('.ets_pr_row_percent_discount_proudct').show();
$('.ets_pr_row_amount_discount_product').hide();
}
else
{
$('.ets_pr_row_percent_discount_proudct').hide();
$('.ets_pr_row_amount_discount_product').show();
}
if($('input[name="applicable_product_categories"]:checked').val()=='all_product')
{
$('.ets_pr_row_applicable_categories').hide();
$('.ets_pr_row_include_sub_categories').hide();
$('.ets_pr_row_include_specific_products').hide();
}
else
{
$('.ets_pr_row_applicable_categories').show();
$('.ets_pr_row_include_sub_categories').show();
$('.ets_pr_row_include_specific_products').show();
}
if($('input[name="apply_all_attribute"]:checked').val()==0)
{
$('.ets_pr_row_select_attributes').show();
}
else
{
$('.ets_pr_row_select_attributes').hide();
}
if($('input[name="apply_all_features"]:checked').val()==0)
{
$('.ets_pr_row_select_features').show();
}
else
{
$('.ets_pr_row_select_features').hide();
}
if($('input[name="apply_all_supplier"]:checked').val()==0)
{
$('.ets_pr_row_select_suppliers').show();ets_pr_row_select_suppliers
}
else
{
$('.ets_pr_row_select_suppliers').hide();
}
if($('input[name="apply_all_manufacturer"]:checked').val()==0)
{
$('.ets_pr_row_select_manufacturers').show();
}
else
{
$('.ets_pr_row_select_manufacturers').hide();
}
if($('input[name="first_order_of_customer"]:checked').val()==1)
$('.wapper-first_order_of_customer').hide();
else
$('.wapper-first_order_of_customer').show();
if($('.ets_pr_row_select_manufacturers input[type="checkbox"]').length==0)
{
$('.ets_pr_row_select_manufacturers').hide();
$('.ets_pr_row_apply_all_manufacturer').hide();
}
if($('.ets_pr_row_select_suppliers input[type="checkbox"]').length==0)
{
$('.ets_pr_row_select_suppliers').hide();
$('.ets_pr_row_apply_all_supplier').hide();
}
if($('.ets_pr_row_select_features input[type="checkbox"]').length==0)
{
$('.ets_pr_row_select_features').hide();
$('.ets_pr_row_apply_all_features').hide();
}
if($('.ets_pr_row_select_attributes input[type="checkbox"]').length==0)
{
$('.ets_pr_row_select_attributes').hide();
$('.ets_pr_row_apply_all_attribute').hide();
}
},
displayRowConditionRule: function(){
var specific_occasion = $('#block-form-popup-condition input[name="specific_occasion"]:checked').val();
$('.ets_pr_row_specific_occasion_day_of_week').hide();
$('.ets_pr_row_specific_occasion_month_of_year').hide();
$('.ets_pr_row_specific_occasion_date_from').hide();
$('.ets_pr_row_specific_occasion_hour_of_day_from').hide();
if(specific_occasion=='hour_of_day')
{
$('.ets_pr_row_specific_occasion_hour_of_day_from').show();
}
else if(specific_occasion=='day_of_week')
{
$('.ets_pr_row_specific_occasion_day_of_week').show();
}
else if(specific_occasion=='month_of_year')
{
$('.ets_pr_row_specific_occasion_month_of_year').show();
}
else if(specific_occasion=='from_to')
{
$('.ets_pr_row_specific_occasion_date_from').show();
}
var order_criteria = $('#block-form-popup-condition input[name="order_criteria"]:checked').val();
if(order_criteria=='number_of_orders')
{
$('#block-form-popup-condition .ets_pr_row_number_of_order').show();
$('#block-form-popup-condition .ets_pr_row_number_of_product').hide();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent').hide();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_tax_incl').hide();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_shipping_incl').hide();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_discount_incl').hide();
}
else if(order_criteria=='number_of_products')
{
$('#block-form-popup-condition .ets_pr_row_number_of_order').hide();
$('#block-form-popup-condition .ets_pr_row_number_of_product').show();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent').hide();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_tax_incl').hide();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_shipping_incl').hide();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_discount_incl').hide();
}
else
{
$('#block-form-popup-condition .ets_pr_row_number_of_order').hide();
$('#block-form-popup-condition .ets_pr_row_number_of_product').hide();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent').show();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_tax_incl').show();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_shipping_incl').show();
$('#block-form-popup-condition .ets_pr_row_amount_of_money_spent_discount_incl').show();
}
if($('#block-form-popup-condition input[name="order_time_in"]:checked').val()=='from_to')
$('#block-form-popup-condition .ets_pr_row_order_time_in_from').show();
else
$('#block-form-popup-condition .ets_pr_row_order_time_in_from').hide();
if($('#block-form-popup-condition input[name="order_time_in"]:checked').val()=='in_last_day')
$('#block-form-popup-condition .ets_pr_row_order_time_in_last_day').show();
else
$('#block-form-popup-condition .ets_pr_row_order_time_in_last_day').hide();
if($('#block-form-popup-condition input[name="applicable_product_categories"]:checked').val()=='all_product')
{
$('#block-form-popup-condition .ets_pr_row_applicable_categories').hide();
$('#block-form-popup-condition .ets_pr_row_include_sub_categories').hide();
$('.ets_pr_row_include_specific_products').hide();
}
else
{
$('#block-form-popup-condition .ets_pr_row_applicable_categories').show();
$('#block-form-popup-condition .ets_pr_row_include_sub_categories').show();
$('.ets_pr_row_include_specific_products').show();
}
if($('#block-form-popup-condition input[name="apply_all_attribute"]:checked').val()==0)
{
$('#block-form-popup-condition .ets_pr_row_select_attributes').show();
}
else
{
$('#block-form-popup-condition .ets_pr_row_select_attributes').hide();
}
if($('#block-form-popup-condition input[name="apply_all_features"]:checked').val()==0)
{
$('#block-form-popup-condition .ets_pr_row_select_features').show();
}
else
{
$('#block-form-popup-condition .ets_pr_row_select_features').hide();
}
if($('#block-form-popup-condition input[name="apply_all_supplier"]:checked').val()==0)
{
$('#block-form-popup-condition .ets_pr_row_select_suppliers').show();
}
else
{
$('#block-form-popup-condition .ets_pr_row_select_suppliers').hide();
}
if($('#block-form-popup-condition input[name="apply_all_manufacturer"]:checked').val()==0)
{
$('#block-form-popup-condition .ets_pr_row_select_manufacturers').show();
}
else
{
$('#block-form-popup-condition .ets_pr_row_select_manufacturers').hide();
}
if($('#block-form-popup-condition input[name="first_order_of_customer"]:checked').val()==1)
$('#block-form-popup-condition .wapper-first_order_of_customer').hide();
else
$('#block-form-popup-condition .wapper-first_order_of_customer').show();
if($('#block-form-popup-condition .ets_pr_row_select_manufacturers input[type="checkbox"]').length==0)
{
$('#block-form-popup-condition .ets_pr_row_select_manufacturers').hide();
$('#block-form-popup-condition .ets_pr_row_apply_all_manufacturer').hide();
}
if($('#block-form-popup-condition .ets_pr_row_select_suppliers input[type="checkbox"]').length==0)
{
$('#block-form-popup-condition .ets_pr_row_select_suppliers').hide();
$('#block-form-popup-condition .ets_pr_row_apply_all_supplier').hide();
}
if($('#block-form-popup-condition .ets_pr_row_select_features input[type="checkbox"]').length==0)
{
$('#block-form-popup-condition .ets_pr_row_select_features').hide();
$('#block-form-popup-condition .ets_pr_row_apply_all_features').hide();
}
if($('#block-form-popup-condition .ets_pr_row_select_attributes input[type="checkbox"]').length==0)
{
$('#block-form-popup-condition .ets_pr_row_select_attributes').hide();
$('#block-form-popup-condition .ets_pr_row_apply_all_attribute').hide();
}
if($('#block-form-popup-condition #id_groups_all').is(':checked'))
$('#block-form-popup-condition .ets_pr_row_only_apply_on_default_group').hide();
else
$('#block-form-popup-condition .ets_pr_row_only_apply_on_default_group').show();
},
displayFieldRule : function(){
if($('#block-form-popup-condition #parent_codition').length)
{
var parent_codition = $('#block-form-popup-condition #parent_codition').val();
$('#block-form-popup-condition .form-group.parent_codition').hide();
if(parent_codition)
$('#block-form-popup-condition .form-group.parent_codition.'+parent_codition).show();
if($('#block-form-popup-condition #id_state option').length<=1)
$('#block-form-popup-condition .ets_pr_row_id_state').hide();
if($('#block-form-popup-condition #delivery_id_state option').length<=1)
$('#block-form-popup-condition .ets_pr_row_delivery_id_state').hide();
ets_pr_rule.displayRowConditionRule();
}
if($('#type_action').length)
{
var type_action = $('#type_action').val();
$('.form-group.type_action').hide();
if(type_action)
{
$('.form-group.type_action.'+type_action).show();
$('.form-group.has_action').show();
}
else
$('.form-group.has_action').hide();
ets_pr_rule.displayRowActionRule();
}
},
gencode :function(size)
{
code = '';
/* There are no O/0 in the codes in order to avoid confusion */
var chars = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
for (var i = 1; i <= size; ++i)
code += chars.charAt(Math.floor(Math.random() * chars.length));
$('input[name="code"]').val(code).change();
},
searchCustomer : function() {
if ($('.pr_ids_customer').length > 0 && $('.pr_search_customer').length > 0 && typeof pr_link_search_customer !== "undefined")
{
var pr_autocomplete = $('.pr_search_customer');
pr_autocomplete.autocomplete(pr_link_search_customer, {
resultsClass: "pr_results",
minChars: 1,
delay: 300,
appendTo: '.pr_search_customer_form',
autoFill: false,
max: 20,
matchContains: false,
mustMatch: false,
scroll: true,
cacheLength: 100,
scrollHeight: 180,
extraParams: {
excludeIds: $('input[name="id_customers"]').val(),
},
formatItem: function (item) {
return '<span data-item-id="'+item[0]+'" class="pr_item_title">' +item[1]+' ('+item[2]+')</span>';
},
}).result(function (event, data, formatted) {
if (data)
{
ets_pr_rule.addCustomer(data);
}
});
}
},
searchProduct : function() {
if ($('.form_codition .pr_ids_product').length > 0 && $('.form_codition .pr_search_product').length > 0 && typeof pr_link_search_product !== "undefined")
{
var pr_autocomplete = $('.form_codition .pr_search_product');
pr_autocomplete.autocomplete(pr_link_search_product, {
resultsClass: "pr_results",
minChars: 1,
delay: 300,
appendTo: '.pr_search_product_form',
autoFill: false,
max: 20,
matchContains: false,
mustMatch: false,
scroll: true,
cacheLength: 100,
scrollHeight: 180,
formatItem: function (item) {
return '<span data-item-id="'+item[0]+'-'+item[1]+'" class="pr_item_title">' + (item[5] ? '<img src="'+item[5]+'" alt=""/> ' : '') + item[2] + (item[3]? item[3] : '') + (item[4] ? ' (Ref:' + item[4] + ')' : '') + '</span>';
},
}).result(function (event, data, formatted) {
if (data)
{
ets_pr_rule.addProduct(data);
}
});
}
},
addCustomer : function(data)
{
var input_name = 'id_customers';
if ($('.form_codition #block_search_'+input_name).length > 0 && $('.form_codition #block_search_'+input_name+' .pr_customer_item[data-id="'+data[0]+'"]').length==0)
{
if ($('.form_codition #block_search_'+input_name+' .pr_customer_loading.active').length <=0)
{
$('.form_codition #block_search_'+input_name+' .pr_customer_loading').addClass('active');
var row_html ='<li class="pr_customer_item " data-id="'+data[0]+'">';
row_html +='<div class="pr_cusotmer_info"><span class="customer_name">'+data[1]+' ('+data[2]+')</span></div>';
row_html +='<div class="pr_block_item_close" title="'+Delete_text+'">';
row_html += '<i class="ets_svg_fill_lightgray"><svg width="14" height="14" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1490 1322q0 40-28 68l-136 136q-28 28-68 28t-68-28l-294-294-294 294q-28 28-68 28t-68-28l-136-136q-28-28-28-68t28-68l294-294-294-294q-28-28-28-68t28-68l136-136q28-28 68-28t68 28l294 294 294-294q28-28 68-28t68 28l136 136q28 28 28 68t-28 68l-294 294 294 294q28 28 28 68z"> </svg></i>';
row_html +='</div>';
row_html +='</li>';
$('.form_codition #block_search_'+input_name+' .pr_customer_loading.active').before(row_html);
$('.form_codition #block_search_'+input_name+' .pr_customer_loading').removeClass('active');
$('.form_codition .pr_search_customer').val('');
if (!$('.form_codition input[name="'+input_name+'"]').val())
{
$('.form_codition input[name="'+input_name+'"]').val(data[0]);
}
else
{
if ($('.form_codition input[name="'+input_name+'"]').val().split(',').indexOf(data[0]) == -1)
{
$('.form_codition input[name="'+input_name+'"]').val($('input[name="'+input_name+'"]').val() + ',' + data[0]);
}
else
{
showErrorMessage(data[2].toString() + ' has been tagged.');
}
}
}
}
$('.form_codition .pr_search_customer').val('');
},
addProduct: function (data) {
if($('#type_action').length && $('#type_action').val()=='gift_or_with_discount_product')
{
var input_name = 'gift_product';
}
else
var input_name = name_pr_search_product ;
if ($('.form_codition #block_search_'+input_name).length > 0 && $('.form_codition #block_search_'+input_name+' .pr_product_item[data-id="'+data[0] + '-' + data[1]+'"]').length==0)
{
if ($('.form_codition #block_search_'+input_name+' .pr_product_loading.active').length <=0)
{
$('.form_codition #block_search_'+input_name+' .pr_product_loading').addClass('active');
var row_html ='<li class="pr_product_item " data-id="'+data[0]+'-'+data[1]+'">';
row_html +='<a class="product_img_link" href="'+data[6]+'" target="_blank">';
row_html +='<img class="pr_product_image" src="'+data[5]+'" alt="'+data[2]+ (data[3] ? ' - '+data[3]:'')+'">';
row_html +='<div class="pr_product_info"><span class="product_name">'+data[2]+ (data[3] ? ' - '+data[3]:'')+'</span></div>';
row_html +='</a>';
row_html +='<div class="pr_block_item_close" title="'+Delete_text+'">';
row_html += '<i class="ets_svg_fill_lightgray"><svg width="14" height="14" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1490 1322q0 40-28 68l-136 136q-28 28-68 28t-68-28l-294-294-294 294q-28 28-68 28t-68-28l-136-136q-28-28-28-68t28-68l294-294-294-294q-28-28-28-68t28-68l136-136q28-28 68-28t68 28l294 294 294-294q28-28 68-28t68 28l136 136q28 28 28 68t-28 68l-294 294 294 294q28 28 28 68z"> </svg></i>';
row_html +='</div>';
row_html +='</li>';
$('.form_codition #block_search_'+input_name+' .pr_product_loading.active').before(row_html);
$('.form_codition #block_search_'+input_name+' .pr_product_loading').removeClass('active');
if (!$('.form_codition input[name="'+input_name+'"]').val())
{
$('.form_codition input[name="'+input_name+'"]').val(data[0] + '-' + data[1]);
}
else
{
if ($('.form_codition input[name="'+input_name+'"]').val().split(',').indexOf(data[0] + '-' + data[1]) == -1)
{
$('.form_codition input[name="'+input_name+'"]').val($('input[name="'+input_name+'"]').val() + ',' + data[0] + '-' + data[1]);
}
else
{
showErrorMessage(data[2].toString() + ' has been tagged.');
}
}
}
}
$('.form_codition .pr_search_product').val('');
},
removeIds: function (parent, element) {
var ax = -1;
if ((ax = parent.indexOf(element)) !== -1)
{
parent.splice(ax, 1);
}
return parent;
},
changeRange : function($range){
if($range.val()<=1){
$range.next('.range_new').next('.input-group-unit').html($range.val());
}
else
{
$range.next('.range_new').next('.input-group-unit').html($range.val());
}
var newPoint = ($range.val() - $range.attr("min")) / ($range.attr("max") - $range.attr("min"));
var offset = -1;
var percent = ( $range.val() / $range.attr("max") )*100;
$range.next('.range_new').find('.range_new_run').css({width: percent+'%'});
$range.next('.range_new').next('.input-group-unit').css({left: percent+'%'});
/**/
var range = $range,value = range.next().next('.input-group-unit');
var max = range.attr('max');
var min = range.attr('min');
var beginvalue = range.value;
range.on('input', function(){
value.html(this.value);
var current_value = this.value;
var max = range.attr('max'),
min = range.attr('min'),
percent = (current_value / max) * 100;
range.next('.range_new').find('.range_new_run').css('width', percent + '%');
range.next('.range_new').next('.input-group-unit').css({left: percent+'%'});
});
},
changeDayOfMonth: function($row)
{
if($row.find('.specific_occasion_month_of_year').length)
{
var row_month = $row.find('.specific_occasion_month_of_year').val()
if(row_month==2)
{
$row.find('.day_month_of_year_from option[value="30"]').hide();
$row.find('.day_month_of_year_to option[value="30"]').hide();
if($row.find('.day_month_of_year_from').val()==30)
$row.find('.day_month_of_year_from').val('').change();
if($row.find('.day_month_of_year_to').val()==30)
$row.find('.day_month_of_year_to').val('').change();
}
else
{
$row.find('.day_month_of_year_from option[value="30"]').show();
$row.find('.day_month_of_year_to option[value="30"]').show();
}
if(row_month==2 || row_month==4 || row_month==6 || row_month==9 || row_month==11)
{
$row.find('.day_month_of_year_from option[value="31"]').hide();
$row.find('.day_month_of_year_to option[value="31"]').hide();
if($row.find('.day_month_of_year_from').val()==31)
$row.find('.day_month_of_year_from').val('').change();
if($row.find('.day_month_of_year_to').val()==31)
$row.find('.day_month_of_year_to').val('').change();
}
else
{
$row.find('.day_month_of_year_from option[value="31"]').show();
$row.find('.day_month_of_year_to option[value="31"]').show();
}
}
}
}