(function ($) {
$('#translations').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=i18n", function (result) {
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('.azd-content');
var $general = $dialog.find('.azd-general');
$general.closest('.azd-panel').remove();
var $size_chart = $('
').appendTo($content);
var $quantity_discount = $('').appendTo($content);
var $product_bundles = $('').appendTo($content);
var $in_cart = $('').appendTo($content);
var $cart_checkout = $('').appendTo($content);
var $loyalty_widget = $('').appendTo($content);
var $emails = $('').appendTo($content);
var $back_in_stock = $('').appendTo($content);
azd.create_parameter('size_chart', {
type: 'text',
default: 'Size chart',
placeholder: 'Size chart',
}, obj).appendTo($size_chart.find('.azd-panel-content'));
azd.create_parameter('buy_more_save_more', {
type: 'text',
default: 'Buy more save more!',
placeholder: 'Buy more save more!',
}, obj).appendTo($quantity_discount.find('.azd-panel-content'));
azd.create_parameter('items_get_off', {
type: 'text',
default: '{{number}} item(s) get {{discount}} OFF',
placeholder: '{{number}} item(s) get {{discount}} OFF',
}, obj).appendTo($quantity_discount.find('.azd-panel-content'));
azd.create_parameter('add', {
type: 'text',
default: 'Add',
placeholder: 'Add',
}, obj).appendTo($quantity_discount.find('.azd-panel-content'));
azd.create_parameter('added', {
type: 'text',
default: 'Added',
placeholder: 'Added',
}, obj).appendTo($quantity_discount.find('.azd-panel-content'));
azd.create_parameter('on_each_product', {
type: 'text',
default: 'on each product',
placeholder: 'on each product',
}, obj).appendTo($quantity_discount.find('.azd-panel-content'));
azd.create_parameter('frequently_bought_together', {
type: 'text',
default: 'Frequently bought together',
placeholder: 'Frequently bought together',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('you_will_get_off_on_each_product', {
type: 'text',
default: 'You will get {{discount}} OFF on each product',
placeholder: 'You will get {{discount}} OFF on each product',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('this_item', {
type: 'text',
default: 'This item',
placeholder: 'This item',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('select', {
type: 'text',
default: 'Select',
placeholder: 'Select',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('selected', {
type: 'text',
default: 'Selected',
placeholder: 'Selected',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('total_price', {
type: 'text',
default: 'Total price',
placeholder: 'Total price',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('saved', {
type: 'text',
default: 'Saved',
placeholder: 'Saved',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('add_selected_items', {
type: 'text',
default: 'Add selected item(s)',
placeholder: 'Add selected item(s)',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('subtotal', {
type: 'text',
default: 'Subtotal',
placeholder: 'Subtotal',
}, obj).appendTo($product_bundles.find('.azd-panel-content'));
azd.create_parameter('you_just_added', {
type: 'text',
default: 'You just added',
placeholder: 'You just added',
}, obj).appendTo($in_cart.find('.azd-panel-content'));
azd.create_parameter('checkout', {
type: 'text',
default: 'Checkout',
placeholder: 'Checkout',
}, obj).appendTo($in_cart.find('.azd-panel-content'));
azd.create_parameter('add_to_cart', {
type: 'text',
default: 'Add to cart',
placeholder: 'Add to cart',
}, obj).appendTo($in_cart.find('.azd-panel-content'));
azd.create_parameter('frequently_bought_with', {
type: 'text',
default: 'Frequently bought with "{{title}}"',
placeholder: 'Frequently bought with "{{title}}"',
}, obj).appendTo($in_cart.find('.azd-panel-content'));
azd.create_parameter('customers_also_bought', {
type: 'text',
default: 'Customers also bought',
placeholder: 'Customers also bought',
}, obj).appendTo($in_cart.find('.azd-panel-content'));
azd.create_parameter('customers_also_bought_with', {
type: 'text',
default: 'Customers also bought with "{{title}}"',
placeholder: 'Customers also bought with "{{title}}"',
}, obj).appendTo($in_cart.find('.azd-panel-content'));
azd.create_parameter('discount_label', {
type: 'text',
default: 'Speciall offer',
placeholder: 'Speciall offer',
}, obj).appendTo($cart_checkout.find('.azd-panel-content'));
azd.create_parameter('you_got', {
type: 'text',
default: 'You got',
placeholder: 'You got',
}, obj).appendTo($cart_checkout.find('.azd-panel-content'));
azd.create_parameter('discount_off_your_order', {
type: 'text',
default: '{{discount}} OFF your order',
placeholder: '{{discount}} OFF your order',
}, obj).appendTo($cart_checkout.find('.azd-panel-content'));
azd.create_parameter('free_shipping', {
type: 'text',
default: 'Free shipping',
placeholder: 'Free shipping',
}, obj).appendTo($cart_checkout.find('.azd-panel-content'));
azd.create_parameter('apply_discount_and_go_to_checkout', {
type: 'text',
default: 'Apply discount and go to checkout',
placeholder: 'Apply discount and go to checkout',
}, obj).appendTo($cart_checkout.find('.azd-panel-content'));
var loyalty_widget = {
'place_an_order': 'Place an order',
'sign_up': 'Sign up',
'birthday': 'Birthday',
'celebrate_a_birthday': 'Celebrate a birthday',
'referral': 'Referral',
'discount_coupon': 'Discount coupon',
'off_coupon': '{{discount}} off coupon',
'free_shipping_coupon': 'Free shipping coupon',
'spent_points': 'Spent {{cost}} {{points}}',
'points_for_every_1_you_spend': '{{earned}} {{points}} for every 1{{currency}} you spend',
'your_rewards': 'Your rewards',
'your_referrals': 'Your referrals',
'ways_to_earn': 'Ways to earn',
'ways_to_redeem': 'Ways to redeem',
'redeem': 'Redeem',
'spent': 'Spent',
'history': 'History',
'your_points': 'Your {{points}}',
'rewards_program': 'Rewards Program',
'join_now_and_unlock_awesome_rewards': 'Join now and unlock awesome rewards',
'set_date': 'Set date',
'rewards': 'Rewards',
'refer_friends_and_earn': 'Refer friends and earn',
'share_this_link': 'Share this link with a friend for them to claim the reward',
'referral_program': 'Referral Program',
'refer_a_friend': 'Refer a friend who makes a purchase and both of you will claim rewards.',
'they_will_get': 'They will get',
'you_will_get': 'You will get',
'your_referral_link': 'Your referral link to share',
'use_this_discount_code': 'Use this discount code on your next order!',
'apply_code': 'Apply code',
'share_on_facebook': 'Share on facebook',
'share_on_twitter': 'Share on twitter',
'lets_celebrate_your_birthday': "Let's celebrate your birthday! Please give us 30 days notice - otherwise, you'll have to wait another year.",
'month': 'Month',
'day': 'Day',
'save_date': 'Save date',
'heres_your': "Here's your",
'get_your': "Get your",
'claim_your_gift': "Claim your gift",
'no_rewards_yet': "No rewards yet",
'your_rewards_will_show_here': "Your rewards will show here.",
'go_back': "Go back",
'join_and_earn_rewards': "Join and Earn Rewards",
'start_earning': "Start Earning",
'sign_in': "Sign in",
'already_a_member': "Already a member?",
'earn_points': "Earn Points",
'earn_points_and_turn_these_into_rewards': "Earn points and turn these into rewards!",
};
for (var key in loyalty_widget) {
azd.create_parameter(key, {
type: 'text',
default: loyalty_widget[key],
placeholder: loyalty_widget[key],
}, obj).appendTo($loyalty_widget.find('.azd-panel-content'));
}
var emails = {
'unsubscribe_question': 'No longer interested?',
'unsubscribe_text': 'Unsubscribe',
'all_rights_reserved': 'All rights reserved.',
'shop_now': 'Shop now',
'read_more': 'Read more',
'view_all': 'View all',
'by_author': 'by {{author}}',
'date_format': 'Y-m-d',
'add_to_cart': 'Add to cart',
'on_sale': 'on sale',
'view_product': 'View product',
};
for (var key in emails) {
azd.create_parameter(key, {
type: 'text',
default: emails[key],
placeholder: emails[key],
}, obj).appendTo($emails.find('.azd-panel-content'));
}
var back_in_stock = {
'back_in_stock_alert': 'Back in stock alert',
'we_will_send_you_a_notification_as_soon_as_this_product_is_available_again': 'We will send you a notification as soon as this product is available again.',
'notify_me': 'Notify me',
'email_me_when_available': 'Email me when available',
'email_me_with_news_and_offers': 'Email me with news and offers.',
'your_email': 'Your Email',
'your_name': 'Your name',
'your_phone_number': 'Your phone number',
'your_note': 'Your note',
};
for (var key in back_in_stock) {
azd.create_parameter(key, {
type: 'text',
default: back_in_stock[key],
placeholder: back_in_stock[key],
}, obj).appendTo($back_in_stock.find('.azd-panel-content'));
}
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=i18n", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#product-bundles').on('azd-show', function (event, data) {
var $dialog = $(this);
var columns = [
{sName: "id", bVisible: false},
{sName: "heading", bVisible: false},
{sName: "redirect_to_cart", bVisible: false},
{sName: "target_product", bVisible: false},
{sName: "target_product_enable", bVisible: false},
{sName: "activate_discount", bVisible: false},
{sName: "discount_type", bVisible: false},
{sName: "bundle_products", bVisible: false},
{sName: "title", sTitle: azd.i18n.title, orderable: false},
{sName: "status", sTitle: azd.i18n.status, sClass: 'azd-status', orderable: false},
{sName: "discount_value", sTitle: azd.i18n.discount, sClass: 'azd-discount', orderable: false},
{sName: "showed", sTitle: azd.i18n.impressions, orderable: false},
{sName: "cart-add", sTitle: azd.i18n.adds_to_cart, orderable: false},
{sName: "checkout", sTitle: azd.i18n.checkouts, orderable: false},
{sName: "order", sTitle: azd.i18n.orders, orderable: false},
{sName: "paid", sTitle: azd.i18n.revenue, orderable: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-datatable:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-datatable:not(.dataTable)'), columns, azd.ajaxurl + "?action=objects_datatable&type=products-bundle", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-status').each(function () {
var row = convert_table_item(this);
if (row.status == 'true') {
$(this).text(azd.i18n.active);
}
if (row.status == 'false') {
$(this).text(azd.i18n.inactive);
}
});
$table.find('tbody tr .azd-discount').each(function () {
var row = convert_table_item(this);
if (row.discount_type == 'percentage') {
$(this).text($(this).text() + '%');
}
if (row.activate_discount == 'false') {
$(this).text(azd.i18n.none);
}
});
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#create-bundle"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
bundle: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=products-bundle&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
});
});
} else {
$dialog.find('table.azd-datatable').DataTable().ajax.reload();
}
});
$('#create-bundle').on('azd-show', function (event, data) {
var $dialog = $(this);
var bundle = {};
if (data && data.data && data.data.bundle) {
bundle = $.extend({}, data.data.bundle);
$dialog.find('.azd-dialog-header .azd-page-title span').text(bundle.title);
} else {
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.i18n.create_bundle);
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
if (!bundle.bundle_products || !bundle.bundle_products.length) {
bundle.target_product = false;
}
$.post(azd.ajaxurl + "?action=save_object&type=products-bundle", {
object: bundle
}, function (result) {
$('.azd-loader').fadeOut();
//bundle = JSON.parse(result);
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
});
if(data.data) {
data.data.bundle = bundle;
}
});
var $content = $dialog.find('> .azd-content');
var $title = $content.find('.azd-bundle-title').empty();
azd.create_parameter('title', {
type: 'text',
label: azd.i18n.title
}, bundle).appendTo($title);
azd.create_parameter('heading', {
type: 'text',
label: azd.i18n.bundle_heading,
default: 'Frequently bought together'
}, bundle).appendTo($title);
azd.create_parameter('redirect_to_cart', {
type: 'checkbox',
label: azd.i18n.redirect_to_cart_label,
}, bundle).appendTo($title);
var $bundle_products = $content.find('.azd-bundle-products').empty();
var $bundle_products_parameter = azd.create_parameter('bundle_products', {
type: 'ajax_multiselect',
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, bundle).appendTo($bundle_products).on('change', function () {
var $select = $(this).find('select');
var $selected_products = $content.find('.azd-selected-products').empty();
var $tbody = $selected_products.append('').find('tbody');
var data = $select.select2('data');
data.forEach(function (value) {
var $tr = $(' ').appendTo($tbody);
$('' + value.text + ' ').appendTo($tr);
if (bundle.target_product == value.id) {
$('' + azd.i18n.target_product + ' ').appendTo($tr);
} else {
$('' + azd.i18n.set_as_target + ' ').appendTo($(' ').appendTo($tr)).on('click', function () {
bundle.target_product = value.id;
$bundle_products_parameter.trigger('change');
});
}
});
}).trigger('change');
var $target_product = $content.find('.azd-target-product').empty();
azd.create_parameter('target_product_enable', {
type: 'checkbox',
label: azd.i18n.target_product_label,
description: azd.i18n.target_product_description
}, bundle).appendTo($target_product).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$(this).closest('.azd-panel-section').find('.azd-selected-products').show();
} else {
$(this).closest('.azd-panel-section').find('.azd-selected-products').hide();
}
}).trigger('change');
var $status = $content.find('.azd-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active
}, bundle).appendTo($status);
var $offer_discount = $content.find('.azd-offer-discount').empty();
var $activate_discount = azd.create_parameter('activate_discount', {
type: 'checkbox',
label: azd.i18n.activate_discount
}, bundle).appendTo($offer_discount).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$offer_discount.find('[data-parameter="discount_type"], [data-parameter="discount_value"]').show();
} else {
$offer_discount.find('[data-parameter="discount_type"], [data-parameter="discount_value"]').hide();
}
});
azd.create_parameter('discount_type', {
type: 'radio',
label: azd.i18n.discount_type,
options: {
percentage: azd.i18n.percentage,
fixed_amount: azd.i18n.fixed_amount,
},
default: 'percentage'
}, bundle).appendTo($offer_discount).find('.azd-radio').addClass('azd-vertical');
azd.create_parameter('discount_value', {
type: 'number',
label: azd.i18n.discount_value,
step: 1,
min: 0,
max: 100,
default: 10
}, bundle).appendTo($offer_discount);
$activate_discount.trigger('change')
});
$('#quantity-discounts').on('azd-show', function (event, data) {
var $dialog = $(this);
var columns = [
{sName: "id", bVisible: false},
{sName: "heading", bVisible: false},
{sName: "redirect_to_cart", bVisible: false},
{sName: "applies_to_products", bVisible: false},
{sName: "applies_to_collection", bVisible: false},
{sName: "offer_discount", bVisible: false},
{sName: "title", sTitle: azd.i18n.title, orderable: false},
{sName: "status", sTitle: azd.i18n.status, sClass: 'azd-status', orderable: false},
{sName: "applies_to", sTitle: azd.i18n.applies_to, sClass: 'azd-applies-to', orderable: false},
{sName: "showed", sTitle: azd.i18n.impressions, orderable: false},
{sName: "cart-add", sTitle: azd.i18n.adds_to_cart, orderable: false},
{sName: "checkout", sTitle: azd.i18n.checkouts, orderable: false},
{sName: "order", sTitle: azd.i18n.orders, orderable: false},
{sName: "paid", sTitle: azd.i18n.revenue, orderable: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-datatable:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-datatable:not(.dataTable)'), columns, azd.ajaxurl + "?action=objects_datatable&type=quantity-discount", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-status').each(function () {
var row = convert_table_item(this);
if (row.status == 'true') {
$(this).text(azd.i18n.active);
}
if (row.status == 'false') {
$(this).text(azd.i18n.inactive);
}
});
$table.find('tbody tr .azd-applies-to').each(function () {
var row = convert_table_item(this);
switch (row.applies_to) {
case 'all_products':
$(this).text(azd.i18n.all_products);
break;
case 'specific_products':
$(this).text(azd.i18n.specific_products);
break;
case 'specific_collection':
$(this).text(azd.i18n.specific_collection);
break;
}
});
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#create-quantity-discount"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
offer: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=quantity-discount&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
});
});
} else {
$dialog.find('table.azd-datatable').DataTable().ajax.reload();
}
});
$('#create-quantity-discount').on('azd-show', function (event, data) {
var $dialog = $(this);
var offer = {};
if (data && data.data && data.data.offer) {
offer = $.extend({}, data.data.offer);
$dialog.find('.azd-dialog-header .azd-page-title span').text(offer.title);
} else {
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.i18n.create_offer);
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_object&type=quantity-discount", {
object: offer
}, function (result) {
$('.azd-loader').fadeOut();
//offer = JSON.parse(result);
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
});
if(data.data) {
data.data.offer = offer;
}
});
var $content = $dialog.find('> .azd-content');
var $title = $content.find('.azd-offer-title').empty();
azd.create_parameter('title', {
type: 'text',
label: azd.i18n.title
}, offer).appendTo($title);
azd.create_parameter('heading', {
type: 'text',
label: azd.i18n.offer_heading,
default: 'Buy more save more!'
}, offer).appendTo($title);
azd.create_parameter('redirect_to_cart', {
type: 'checkbox',
label: azd.i18n.redirect_to_cart_label,
}, offer).appendTo($title);
var $applies_to = $content.find('.azd-applies-to').empty();
var $applies_to_parameter = azd.create_parameter('applies_to', {
type: 'radio',
label: azd.i18n.applies_to,
options: {
all_products: azd.i18n.all_products,
specific_products: azd.i18n.specific_products,
specific_collection: azd.i18n.specific_collection,
},
default: 'all_products'
}, offer).appendTo($applies_to).on('change', function () {
$specific_products.hide();
$specific_collection.hide();
switch ($applies_to_parameter.find('[name="applies_to"]:checked').attr('value')) {
case 'specific_products':
$specific_products.show();
break;
case 'specific_collection':
$specific_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $specific_products = azd.create_parameter('applies_to_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, offer).appendTo($applies_to);
var $specific_collection = azd.create_parameter('applies_to_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, offer).appendTo($applies_to);
$applies_to_parameter.trigger('change');
var $offer_discount = $content.find('.azd-offer-discount').empty();
azd.create_parameter('offer_discount', {
type: 'group',
label: '',
add_label: azd.i18n.add_discount,
remove_label: '',
add_remove_rows: true,
fields: {
min_quantity: {
type: 'integer',
default: '5',
label: azd.i18n.min_quantity,
},
discount: {
type: 'integer',
default: '10',
label: azd.i18n.discount,
},
discount_type: {
type: 'dropdown',
label: azd.i18n.discount_type,
default: 'percentage',
options: {
percentage: '% off on each product',
fixed_amount: 'Fixed off on each product',
}
}
}
}, offer).appendTo($offer_discount);
var $status = $content.find('.azd-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active
}, offer).appendTo($status);
});
$('#pre-purchase').on('azd-show', function (event, data) {
var $dialog = $(this);
var columns = [
{sName: "id", bVisible: false},
{sName: "target_products", bVisible: false},
{sName: "target_collection", bVisible: false},
{sName: "target_to", bVisible: false},
{sName: "recommended_products", bVisible: false},
{sName: "recommended_collection", bVisible: false},
{sName: "recommended", bVisible: false},
{sName: "activate_discount", bVisible: false},
{sName: "discount_type", bVisible: false},
{sName: "title", sTitle: azd.i18n.title, orderable: false},
{sName: "status", sTitle: azd.i18n.status, sClass: 'azd-status', orderable: false},
{sName: "discount_value", sTitle: azd.i18n.discount, sClass: 'azd-discount', orderable: false},
{sName: "showed", sTitle: azd.i18n.impressions, orderable: false},
{sName: "cart-add", sTitle: azd.i18n.adds_to_cart, orderable: false},
{sName: "checkout", sTitle: azd.i18n.checkouts, orderable: false},
{sName: "order", sTitle: azd.i18n.orders, orderable: false},
{sName: "paid", sTitle: azd.i18n.revenue, orderable: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-datatable:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-datatable:not(.dataTable)'), columns, azd.ajaxurl + "?action=objects_datatable&type=pre-purchase", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-status').each(function () {
var row = convert_table_item(this);
if (row.status == 'true') {
$(this).text(azd.i18n.active);
}
if (row.status == 'false') {
$(this).text(azd.i18n.inactive);
}
});
$table.find('tbody tr .azd-discount').each(function () {
var row = convert_table_item(this);
if (row.discount_type == 'percentage') {
$(this).text($(this).text() + '%');
}
if (row.activate_discount == 'false') {
$(this).text(azd.i18n.none);
}
});
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#create-pre-purchase-offer"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
offer: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=pre-purchase&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
});
});
} else {
$dialog.find('table.azd-datatable').DataTable().ajax.reload();
}
});
$('#create-pre-purchase-offer').on('azd-show', function (event, data) {
var $dialog = $(this);
var offer = {};
if (data && data.data && data.data.offer) {
offer = $.extend({}, data.data.offer);
$dialog.find('.azd-dialog-header .azd-page-title span').text(offer.title);
} else {
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.i18n.create_offer);
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_object&type=pre-purchase", {
object: offer
}, function (result) {
$('.azd-loader').fadeOut();
//offer = JSON.parse(result);
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
});
if(data.data) {
data.data.offer = offer;
}
});
var $content = $dialog.find('> .azd-content');
var $title = $content.find('.azd-offer-title').empty();
azd.create_parameter('title', {
type: 'text',
label: azd.i18n.title
}, offer).appendTo($title);
var $target_to = $content.find('.azd-target-to').empty();
var $target_to_parameter = azd.create_parameter('target_to', {
type: 'radio',
label: azd.i18n.target_to,
options: {
all_products: azd.i18n.all_products,
specific_products: azd.i18n.specific_products,
specific_collection: azd.i18n.specific_collection,
},
default: 'all_products'
}, offer).appendTo($target_to).on('change', function () {
$target_products.hide();
$target_collection.hide();
switch ($target_to_parameter.find('[name="target_to"]:checked').attr('value')) {
case 'specific_products':
$target_products.show();
break;
case 'specific_collection':
$target_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $target_products = azd.create_parameter('target_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, offer).appendTo($target_to);
var $target_collection = azd.create_parameter('target_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, offer).appendTo($target_to);
$target_to_parameter.trigger('change');
var $recommended = $content.find('.azd-recommended').empty();
var $recommended_parameter = azd.create_parameter('recommended', {
type: 'radio',
options: {
specific_products: azd.i18n.specific_products,
specific_collection: azd.i18n.specific_collection,
},
default: 'specific_products'
}, offer).appendTo($recommended).on('change', function () {
$recommended_products.hide();
$recommended_collection.hide();
switch ($recommended_parameter.find('[name="recommended"]:checked').attr('value')) {
case 'specific_products':
$recommended_products.show();
break;
case 'specific_collection':
$recommended_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $recommended_products = azd.create_parameter('recommended_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, offer).appendTo($recommended);
var $recommended_collection = azd.create_parameter('recommended_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, offer).appendTo($recommended);
$recommended_parameter.trigger('change');
var $offer_discount = $content.find('.azd-offer-discount').empty();
var $activate_discount = azd.create_parameter('activate_discount', {
type: 'checkbox',
label: azd.i18n.activate_discount
}, offer).appendTo($offer_discount).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$offer_discount.find('[data-parameter="discount_type"], [data-parameter="discount_value"]').show();
} else {
$offer_discount.find('[data-parameter="discount_type"], [data-parameter="discount_value"]').hide();
}
});
azd.create_parameter('discount_type', {
type: 'radio',
label: azd.i18n.discount_type,
options: {
percentage: azd.i18n.percentage,
fixed_amount: azd.i18n.fixed_amount,
},
default: 'percentage'
}, offer).appendTo($offer_discount).find('.azd-radio').addClass('azd-vertical');
azd.create_parameter('discount_value', {
type: 'number',
label: azd.i18n.discount_value,
step: 1,
min: 0,
max: 100,
default: 10
}, offer).appendTo($offer_discount);
$activate_discount.trigger('change')
var $status = $content.find('.azd-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active
}, offer).appendTo($status);
});
$('#in-cart').on('azd-show', function (event, data) {
var $dialog = $(this);
var columns = [
{sName: "id", bVisible: false},
{sName: "target_products", bVisible: false},
{sName: "target_collection", bVisible: false},
{sName: "recommended_products", bVisible: false},
{sName: "recommended_collection", bVisible: false},
{sName: "recommended", bVisible: false},
{sName: "activate_discount", bVisible: false},
{sName: "discount_type", bVisible: false},
{sName: "title", sTitle: azd.i18n.title, orderable: false},
{sName: "status", sTitle: azd.i18n.status, sClass: 'azd-status', orderable: false},
{sName: "discount_value", sTitle: azd.i18n.discount, sClass: 'azd-discount', orderable: false},
{sName: "target_to", sTitle: azd.i18n.applies_to, sClass: 'azd-target-to', orderable: false},
{sName: "showed", sTitle: azd.i18n.impressions, orderable: false},
{sName: "cart-add", sTitle: azd.i18n.adds_to_cart, orderable: false},
{sName: "checkout", sTitle: azd.i18n.checkouts, orderable: false},
{sName: "order", sTitle: azd.i18n.orders, orderable: false},
{sName: "paid", sTitle: azd.i18n.revenue, orderable: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-datatable:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-datatable:not(.dataTable)'), columns, azd.ajaxurl + "?action=objects_datatable&type=in-cart", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-status').each(function () {
var row = convert_table_item(this);
if (row.status == 'true') {
$(this).text(azd.i18n.active);
}
if (row.status == 'false') {
$(this).text(azd.i18n.inactive);
}
});
$table.find('tbody tr .azd-discount').each(function () {
var row = convert_table_item(this);
if (row.discount_type == 'percentage') {
$(this).text($(this).text() + '%');
}
if (row.activate_discount == 'false') {
$(this).text(azd.i18n.none);
}
});
$table.find('tbody tr .azd-target-to').each(function () {
var row = convert_table_item(this);
switch (row.target_to) {
case 'all_products':
$(this).text(azd.i18n.all_products);
break;
case 'specific_products':
$(this).text(azd.i18n.specific_products);
break;
case 'specific_collection':
$(this).text(azd.i18n.specific_collection);
break;
}
});
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#create-in-cart-offer"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
offer: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=in-cart&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
});
});
} else {
$dialog.find('table.azd-datatable').DataTable().ajax.reload();
}
});
$('#create-in-cart-offer').on('azd-show', function (event, data) {
var $dialog = $(this);
var offer = {};
if (data && data.data && data.data.offer) {
offer = $.extend({}, data.data.offer);
$dialog.find('.azd-dialog-header .azd-page-title span').text(offer.title);
} else {
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.i18n.create_offer);
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_object&type=in-cart", {
object: offer
}, function (result) {
$('.azd-loader').fadeOut();
//offer = JSON.parse(result);
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
});
if(data.data) {
data.data.offer = offer;
}
});
var $content = $dialog.find('> .azd-content');
var $title = $content.find('.azd-offer-title').empty();
azd.create_parameter('title', {
type: 'text',
label: azd.i18n.title
}, offer).appendTo($title);
var $target_to = $content.find('.azd-target-to').empty();
var $target_to_parameter = azd.create_parameter('target_to', {
type: 'radio',
label: azd.i18n.target_to,
options: {
all_products: azd.i18n.all_products,
specific_products: azd.i18n.specific_products,
specific_collection: azd.i18n.specific_collection,
},
default: 'all_products'
}, offer).appendTo($target_to).on('change', function () {
$target_products.hide();
$target_collection.hide();
switch ($target_to_parameter.find('[name="target_to"]:checked').attr('value')) {
case 'specific_products':
$target_products.show();
break;
case 'specific_collection':
$target_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $target_products = azd.create_parameter('target_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, offer).appendTo($target_to);
var $target_collection = azd.create_parameter('target_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, offer).appendTo($target_to);
$target_to_parameter.trigger('change');
var $recommended = $content.find('.azd-recommended').empty();
var $recommended_parameter = azd.create_parameter('recommended', {
type: 'radio',
options: {
specific_products: azd.i18n.specific_products,
specific_collection: azd.i18n.specific_collection,
},
default: 'specific_products'
}, offer).appendTo($recommended).on('change', function () {
$recommended_products.hide();
$recommended_collection.hide();
switch ($recommended_parameter.find('[name="recommended"]:checked').attr('value')) {
case 'specific_products':
$recommended_products.show();
break;
case 'specific_collection':
$recommended_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $recommended_products = azd.create_parameter('recommended_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, offer).appendTo($recommended);
var $recommended_collection = azd.create_parameter('recommended_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, offer).appendTo($recommended);
$recommended_parameter.trigger('change');
var $offer_discount = $content.find('.azd-offer-discount').empty();
var $activate_discount = azd.create_parameter('activate_discount', {
type: 'checkbox',
label: azd.i18n.activate_discount
}, offer).appendTo($offer_discount).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$offer_discount.find('[data-parameter="discount_type"], [data-parameter="discount_value"]').show();
} else {
$offer_discount.find('[data-parameter="discount_type"], [data-parameter="discount_value"]').hide();
}
});
azd.create_parameter('discount_type', {
type: 'radio',
label: azd.i18n.discount_type,
options: {
percentage: azd.i18n.percentage,
fixed_amount: azd.i18n.fixed_amount,
},
default: 'percentage'
}, offer).appendTo($offer_discount).find('.azd-radio').addClass('azd-vertical');
azd.create_parameter('discount_value', {
type: 'number',
label: azd.i18n.discount_value,
step: 1,
min: 0,
max: 100,
default: 10
}, offer).appendTo($offer_discount);
$activate_discount.trigger('change')
var $status = $content.find('.azd-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active
}, offer).appendTo($status);
});
$('#free-shipping-goal').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=free-shipping-goal", function (result) {
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('> .azd-content');
var $settings = $content.find('.azd-settings').empty();
var $messages = $content.find('.azd-messages').empty();
var preview = $content.find('.azd-preview').get(0);
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.activate_goal
}, obj).appendTo($settings);
azd.create_parameter('goal_amount', {
type: 'number',
default: '60',
label: azd.i18n.goal_amount,
}, obj).appendTo($settings);
azd.create_parameter('by_shipping_rates', {
type: 'checkbox',
label: azd.i18n.by_shipping_rates_label
}, obj).appendTo($settings).on('change', function () {
$(this).closest('.azd-panel').find('.azd-by-shipping-rates-on').hide();
$(this).closest('.azd-panel').find('.azd-by-shipping-rates-off').hide();
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$(this).closest('.azd-panel').find('.azd-by-shipping-rates-on').show();
} else {
$(this).closest('.azd-panel').find('.azd-by-shipping-rates-off').show();
}
}).trigger('change');
azd.create_parameter('reached_message', {
type: 'text',
default: 'Congrats! You are eligible for FREE Shipping ',
label: azd.i18n.reached_message,
}, obj).appendTo($messages);
azd.create_parameter('motivational_message', {
type: 'text',
default: 'Buy {{amount}} more to enjoy FREE Shipping ',
label: azd.i18n.motivational_message,
description: azd.i18n.motivational_message_description,
}, obj).appendTo($messages).on('change', function () {
window.azexo_init(preview, {'free-shipping-goal': obj});
});
window.azexo_init(preview, {'free-shipping-goal': obj});
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=free-shipping-goal", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#countdown-timer').on('azd-show', function (event, data) {
var $dialog = $(this);
var columns = [
{sName: "id", bVisible: false},
{sName: "type", bVisible: false},
{sName: "timezone_offset", bVisible: false},
{sName: "expires_at", bVisible: false},
{sName: "time_to_start", bVisible: false},
{sName: "schedule_time_to_start", bVisible: false},
{sName: "applies_to_products", bVisible: false},
{sName: "applies_to_collection", bVisible: false},
{sName: "title", sTitle: azd.i18n.title, orderable: false},
{sName: "status", sTitle: azd.i18n.status, sClass: 'azd-status', orderable: false},
{sName: "duration", sTitle: azd.i18n.duration, sClass: 'azd-duration', orderable: false},
{sName: "applies_to", sTitle: azd.i18n.applies_to, sClass: 'azd-applies-to', orderable: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-datatable:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-datatable:not(.dataTable)'), columns, azd.ajaxurl + "?action=objects_datatable&type=countdown-timer", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-status').each(function () {
var row = convert_table_item(this);
if (row.status == 'true') {
$(this).text(azd.i18n.active);
}
if (row.status == 'false') {
$(this).text(azd.i18n.inactive);
}
});
$table.find('tbody tr .azd-duration').each(function () {
var row = convert_table_item(this);
$(this).text(row.duration + ' hrs');
});
$table.find('tbody tr .azd-applies-to').each(function () {
var row = convert_table_item(this);
switch (row.applies_to) {
case 'all_products':
$(this).text(azd.i18n.all_products);
break;
case 'specific_products':
$(this).text(azd.i18n.specific_products);
break;
case 'specific_collection':
$(this).text(azd.i18n.specific_collection);
break;
}
});
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#create-countdown"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
countdown: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=countdown-timer&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
});
});
} else {
$dialog.find('table.azd-datatable').DataTable().ajax.reload();
}
});
$('#create-countdown').on('azd-show', function (event, data) {
var $dialog = $(this);
var countdown = {};
var preview = $dialog.find('.azd-preview').get(0);
if (data && data.data && data.data.countdown) {
countdown = $.extend({}, data.data.countdown);
$dialog.find('.azd-dialog-header .azd-page-title span').text(countdown.title);
} else {
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.i18n.create_countdown);
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_object&type=countdown-timer", {
object: countdown
}, function (result) {
$('.azd-loader').fadeOut();
//countdown = JSON.parse(result);
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
});
if(data.data) {
data.data.countdown = countdown;
}
});
var $content = $dialog.find('> .azd-content');
var $title = $content.find('.azd-countdown-title').empty();
azd.create_parameter('title', {
type: 'text',
}, countdown).appendTo($title);
var $countdown_settings = $content.find('.azd-countdown-settings').empty();
var $type = azd.create_parameter('type', {
type: 'radio',
label: azd.i18n.countdown_type,
description: azd.i18n.countdown_type_description,
options: {
fixed_time: azd.i18n.fixed_time,
evergreen: azd.i18n.evergreen,
},
default: 'evergreen'
}, countdown).appendTo($countdown_settings).on('change', function () {
$expires_at.hide();
$duration.hide();
switch ($type.find('[name="type"]:checked').attr('value')) {
case 'fixed_time':
$expires_at.show();
break;
case 'evergreen':
$duration.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $expires_at = azd.create_parameter('expires_at', {
type: 'datetime',
label: azd.i18n.expires_at
}, countdown).appendTo($countdown_settings);
var $duration = azd.create_parameter('duration', {
type: 'number',
units: 'hours',
step: 1,
default: '20',
label: azd.i18n.duration
}, countdown).appendTo($countdown_settings);
$expires_at.on('change', function () {
window.azexo_init(preview, {'countdown-timer': countdown});
});
$countdown_settings.find('select, input').on('change', function () {
window.azexo_init(preview, {'countdown-timer': countdown});
});
$type.trigger('change');
var $applies_to = $content.find('.azd-applies-to').empty();
var $applies_to_parameter = azd.create_parameter('applies_to', {
type: 'radio',
label: azd.i18n.applies_to,
options: {
all_products: azd.i18n.all_products,
specific_products: azd.i18n.specific_products,
specific_collection: azd.i18n.specific_collection,
},
default: 'all_products'
}, countdown).appendTo($applies_to).on('change', function () {
$applies_products.hide();
$applies_collection.hide();
switch ($applies_to_parameter.find('[name="applies_to"]:checked').attr('value')) {
case 'specific_products':
$applies_products.show();
break;
case 'specific_collection':
$applies_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $applies_products = azd.create_parameter('applies_to_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, countdown).appendTo($applies_to);
var $applies_collection = azd.create_parameter('applies_to_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, countdown).appendTo($applies_to);
$applies_to_parameter.trigger('change');
var $status = $content.find('.azd-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active
}, countdown).appendTo($status);
var $schedule_time_to_start = azd.create_parameter('schedule_time_to_start', {
type: 'checkbox',
label: azd.i18n.schedule_time_to_start_countdown
}, countdown).appendTo($status).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$(this).closest('.azd-panel').find('[data-parameter="time_to_start"]').show();
} else {
$(this).closest('.azd-panel').find('[data-parameter="time_to_start"]').hide();
}
});
azd.create_parameter('time_to_start', {
type: 'datetime',
label: azd.i18n.schedule_time_to_start_countdown_timer
}, countdown).appendTo($status);
$schedule_time_to_start.trigger('change');
window.azexo_init(preview, {'countdown-timer': countdown});
});
$('#stock-countdown').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=stock-countdown", function (result) {
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('> .azd-content');
var $settings = $content.find('.azd-settings').empty();
var $applies_to = $content.find('.azd-applies-to').empty();
var preview = $content.find('.azd-preview').get(0);
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active
}, obj).appendTo($settings);
azd.create_parameter('motivational_message', {
type: 'text',
default: 'Only {{number}} item(s) left in stock!',
label: azd.i18n.motivational_message,
description: azd.i18n.stock_motivational_message_description,
}, obj).appendTo($settings).on('change', function () {
window.azexo_init(preview, {'stock-countdown': obj});
}).trigger('change');
var $applies_to_parameter = azd.create_parameter('applies_to', {
type: 'radio',
label: azd.i18n.applies_to,
options: {
all_products: azd.i18n.all_products,
specific_products: azd.i18n.specific_products,
specific_collection: azd.i18n.specific_collection,
},
default: 'all_products'
}, obj).appendTo($applies_to).on('change', function () {
$applies_products.hide();
$applies_collection.hide();
switch ($applies_to_parameter.find('[name="applies_to"]:checked').attr('value')) {
case 'specific_products':
$applies_products.show();
break;
case 'specific_collection':
$applies_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $applies_products = azd.create_parameter('applies_to_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, obj).appendTo($applies_to);
var $applies_collection = azd.create_parameter('applies_to_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, obj).appendTo($applies_to);
$applies_to_parameter.trigger('change');
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=stock-countdown", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#cart-countdown').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=cart-countdown", function (result) {
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('> .azd-content');
var $settings = $content.find('.azd-settings').empty();
var $messages = $content.find('.azd-messages').empty();
var preview = $content.find('.azd-preview').get(0);
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active_countdown
}, obj).appendTo($settings);
var $repeat = azd.create_parameter('repeat', {
type: 'checkbox',
label: azd.i18n.repeat_after_ends
}, obj).appendTo($settings).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$time_out_message.hide();
} else {
$time_out_message.show();
}
window.azexo_init(preview, {'cart-countdown': obj});
});
azd.create_parameter('duration', {
type: 'integer',
min: 1,
max: 10,
step: 1,
default: '5',
label: azd.i18n.countdown_duration,
description: azd.i18n.countdown_duration_description,
}, obj).appendTo($settings).on('change', function () {
window.azexo_init(preview, {'cart-countdown': obj});
});
var $time_out_message = azd.create_parameter('time_out_message', {
type: 'text',
default: 'You\'re out of time! Checkout now to avoid losing your order!',
label: azd.i18n.time_out_message,
description: azd.i18n.time_out_message_description,
}, obj).appendTo($messages);
$repeat.trigger('change');
azd.create_parameter('motivational_message', {
type: 'text',
default: 'These products are limited, checkout within {{timer}}',
label: azd.i18n.motivational_message,
description: azd.i18n.countdown_motivational_message_description,
}, obj).appendTo($messages).on('change', function () {
window.azexo_init(preview, {'cart-countdown': obj});
});
window.azexo_init(preview, {'cart-countdown': obj});
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=cart-countdown", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#sales-notifications').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=sales-notifications", function (result) {
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('> .azd-content');
var $visibility = $content.find('.azd-visibility').empty();
var $messages = $content.find('.azd-messages').empty();
var $randomize_data = $content.find('.azd-randomize-data').empty();
var $products_to_show = $content.find('.azd-products-to-show').empty();
var $display_settings = $content.find('.azd-display-settings').empty();
var preview = $content.find('.azd-preview').get(0);
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active
}, obj).appendTo($visibility);
azd.create_parameter('show_on_mobile', {
type: 'checkbox',
label: azd.i18n.show_on_mobile
}, obj).appendTo($visibility);
azd.create_parameter('title_message', {
type: 'text',
default: '{{name}} has purchased!',
label: azd.i18n.title_message,
description: azd.i18n.title_message_description,
}, obj).appendTo($messages);
azd.create_parameter('time_message', {
type: 'text',
default: '{{time}} mins ago - {{location}}',
label: azd.i18n.time_message,
description: azd.i18n.time_message_description,
}, obj).appendTo($messages);
azd.create_parameter('random_names', {
type: 'textarea',
default: 'Enrique West, Damien Braun, Ellie Osborne, Cierra Vega, Alden Cantrell, Kierra Gentry, Pierre Cox, Thomas Crane',
label: azd.i18n.random_names,
description: azd.i18n.separate_by_a_comma,
}, obj).appendTo($randomize_data);
azd.create_parameter('random_locations', {
type: 'textarea',
default: "Morgantown United States, Kuttu Federated States of Micronesia, Wuhu China, East Quincy United States, Raumbach Germany, Wuyang China, Tondela Portugal, N'Djamena Chad, Yanbei China, Quangang China, Le Pallet France, Servon-sur-Vilaine France, Tumut Australia, Goodman United States, Keluke China, Rauchenwarth Austria, Harran Turkey",
label: azd.i18n.random_locations,
description: azd.i18n.separate_by_a_comma,
}, obj).appendTo($randomize_data);
var $products_to_show_parameter = azd.create_parameter('products_to_show', {
type: 'radio',
label: azd.i18n.products_to_show,
options: {
specific_collection: azd.i18n.specific_collection,
specific_products: azd.i18n.specific_products,
},
default: 'specific_collection'
}, obj).appendTo($products_to_show).on('change', function () {
$products_to_show_products.hide();
$products_to_show_collection.hide();
switch ($products_to_show_parameter.find('[name="products_to_show"]:checked').attr('value')) {
case 'specific_products':
$products_to_show_products.show();
break;
case 'specific_collection':
$products_to_show_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $products_to_show_products = azd.create_parameter('products_to_show_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, obj).appendTo($products_to_show);
var $products_to_show_collection = azd.create_parameter('products_to_show_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, obj).appendTo($products_to_show);
$products_to_show_parameter.trigger('change');
var $placement = azd.create_parameter('placement', {
type: 'radio',
label: azd.i18n.placement,
options: {
bottom_left: azd.i18n.bottom_left,
bottom_right: azd.i18n.bottom_right,
},
default: 'bottom_left'
}, obj).appendTo($display_settings).find('.azd-radio').addClass('azd-vertical').on('change', function () {
window.azexo_init(preview, {'sales-notifications': obj});
});
azd.create_parameter('display_time', {
type: 'number',
step: 1,
units: 'seconds',
default: '5',
label: azd.i18n.display_time,
description: azd.i18n.display_time_description,
}, obj).appendTo($display_settings);
azd.create_parameter('delay_time_between_notifications', {
type: 'text',
default: '10-15',
placeholder: '10-15',
label: azd.i18n.delay_time_between_notifications,
}, obj).appendTo($display_settings);
azd.create_parameter('delay_time_to_show_first_notification', {
type: 'number',
units: 'seconds',
step: 1,
default: '5',
label: azd.i18n.delay_time_to_show_first_notification,
}, obj).appendTo($display_settings);
azd.create_parameter('maximum_notifications_per_page', {
type: 'number',
step: 1,
default: '20',
label: azd.i18n.maximum_notifications_per_page,
}, obj).appendTo($display_settings);
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=sales-notifications", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#lucky-wheel').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=lucky-wheel", function (result) {
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('> .azd-content');
var $visibility = $content.find('.azd-visibility').empty();
var $form_settings = $content.find('.azd-form-settings').empty();
var $win_screen = $content.find('.azd-win-screen').empty();
var $coupon_card = $content.find('.azd-coupon-card').empty();
var $limitation = $content.find('.azd-limitation').empty();
var $prizes_list = $content.find('.azd-prizes-list').empty();
var $wheel_design = $content.find('.azd-wheel-design').empty();
var $display_settings = $content.find('.azd-display-settings').empty();
var $teaser_settings = $content.find('.azd-teaser-settings').empty();
var popup = $dialog.find('.sh-lucky-wheel-form').get(0);
var preview = $content.find('.azd-preview').get(0);
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active,
}, obj).appendTo($visibility);
azd.create_parameter('show_on_mobile', {
type: 'checkbox',
label: azd.i18n.show_on_mobile,
}, obj).appendTo($visibility);
azd.create_parameter('form_title', {
type: 'text',
label: azd.i18n.title,
default: 'Spin to get a prize!',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('form_subtitle', {
type: 'textarea',
label: azd.i18n.subtitle,
default: 'Enter your email to spin the wheel for a chance to win a coupon.',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('form_button', {
type: 'text',
label: azd.i18n.button,
default: 'Try your luck',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('form_show_field_name', {
type: 'checkbox',
label: azd.i18n.show_field_name,
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('form_show_field_birthday', {
type: 'checkbox',
label: azd.i18n.show_field_birthday,
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('form_show_agreement_checkbox', {
type: 'checkbox',
label: azd.i18n.show_agreement_checkbox,
default: true,
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('form_agreement_text', {
type: 'text',
label: azd.i18n.agreement_text,
default: 'I agree to subscribe to the mailing list.',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('win_title', {
type: 'text',
label: azd.i18n.title,
default: 'Hurray! You win a',
}, obj).appendTo($win_screen).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('auto_apply_coupon', {
type: 'checkbox',
label: azd.i18n.auto_apply_coupon_on_checkout_page,
default: true,
}, obj).appendTo($win_screen).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('discount_code_label', {
type: 'text',
label: azd.i18n.discount_code_label,
default: 'Your discount code is',
}, obj).appendTo($coupon_card).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('lose_title', {
type: 'text',
label: azd.i18n.lose_title,
default: 'Oops, there is no discount code for this!',
}, obj).appendTo($coupon_card).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('continue_button', {
type: 'text',
label: azd.i18n.continue_button,
default: 'Continue & Use discount',
}, obj).appendTo($coupon_card).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('note', {
type: 'text',
label: azd.i18n.note,
default: 'Remember to use your discount code when you checkout.',
}, obj).appendTo($coupon_card).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('allow_play_multiple', {
type: 'checkbox',
label: azd.i18n.allow_play_multiple_times_with_the_same_email,
default: true,
}, obj).appendTo($limitation);
azd.create_parameter('pointer_color', {
type: 'color',
label: azd.i18n.pointer_color,
default: '#000',
}, obj).appendTo($wheel_design).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('text_color', {
type: 'color',
label: azd.i18n.text_color,
default: '#000',
}, obj).appendTo($wheel_design).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('popup_background', {
type: 'color',
label: azd.i18n.popup_background,
default: '#F1F1F1',
}, obj).appendTo($wheel_design).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('field_background', {
type: 'color',
label: azd.i18n.field_background,
default: '#fff',
}, obj).appendTo($wheel_design).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('button_color', {
type: 'color',
label: azd.i18n.button_color,
default: '#000',
}, obj).appendTo($wheel_design).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('coupon_card_background', {
type: 'color',
label: azd.i18n.coupon_card_background,
default: '#DA3F3F',
}, obj).appendTo($wheel_design).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
azd.create_parameter('teaser_background', {
type: 'color',
label: azd.i18n.teaser_background,
default: '#DA3F3F',
}, obj).appendTo($wheel_design).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
var $trigger_open = azd.create_parameter('trigger_open', {
type: 'radio',
label: azd.i18n.trigger_open_when,
options: {
loaded: azd.i18n.after_page_loaded,
time: azd.i18n.after_specific_time,
scrolling: azd.i18n.after_scrolling_down,
leaving: azd.i18n.user_is_leaving_the_website,
},
default: 'loaded'
}, obj).appendTo($display_settings).on('change', function () {
$open_specific_time.hide();
switch ($trigger_open.find('[name="trigger_open"]:checked').attr('value')) {
case 'time':
$open_specific_time.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $open_specific_time = azd.create_parameter('open_specific_time', {
type: 'number',
units: 'seconds',
min: '1',
default: '5',
}, obj).appendTo($display_settings);
$trigger_open.trigger('change');
azd.create_parameter('display_on', {
type: 'radio',
label: azd.i18n.display_on,
options: {
all_pages: azd.i18n.all_pages,
home_page: azd.i18n.home_page_only,
},
default: 'all_pages'
}, obj).appendTo($display_settings).find('.azd-radio').addClass('azd-vertical');
azd.create_parameter('repeat_open', {
type: 'dropdown',
label: azd.i18n.repeat_open_automatically,
description: azd.i18n.repeat_open_description,
options: {
no_repeat: azd.i18n.no_repeat,
every_3_mins: azd.i18n.every_3_mins,
every_5_mins: azd.i18n.every_5_mins,
every_10_mins: azd.i18n.every_10_mins,
every_15_mins: azd.i18n.every_15_mins,
every_30_mins: azd.i18n.every_30_mins,
every_1_hr: azd.i18n.every_1_hr,
every_6_hrs: azd.i18n.every_6_hrs,
every_12_hrs: azd.i18n.every_12_hrs,
every_day: azd.i18n.every_day,
every_3_days: azd.i18n.every_3_days,
every_week: azd.i18n.every_week,
every_2_week: azd.i18n.every_2_week,
every_month: azd.i18n.every_month,
},
default: 'every_day'
}, obj).appendTo($display_settings);
azd.create_parameter('activate_teaser', {
type: 'checkbox',
label: azd.i18n.activate_teaser,
default: true,
}, obj).appendTo($teaser_settings);
azd.create_parameter('teaser_position', {
type: 'radio',
label: azd.i18n.teaser_position,
options: {
left: azd.i18n.left,
right: azd.i18n.right,
},
default: 'left'
}, obj).appendTo($teaser_settings).find('.azd-radio').addClass('azd-vertical');
azd.create_parameter('prizes', {
type: 'group',
label: '',
description: azd.i18n.prizes_description,
fields: {
name: {
type: 'text',
label: azd.i18n.prize_name,
},
coupon: {
type: 'text',
label: azd.i18n.discount_code,
},
color: {
type: 'color',
label: azd.i18n.color,
},
chance: {
type: 'number',
step: '1',
min: '0',
max: '100',
label: azd.i18n.chance_to_win,
},
},
default: [
{
name: '10% OFF',
coupon: '10_OFF',
color: '#DA3F3F',
chance: '1',
},
{
name: 'Free shipping',
coupon: 'freeship',
color: '#E49686',
chance: '1',
},
{
name: 'No luck',
coupon: '',
color: '#DA3F3F',
chance: '1',
},
{
name: '20% OFF',
coupon: '20_OFF',
color: '#E49686',
chance: '1',
},
{
name: '30% OFF',
coupon: '30_OFF',
color: '#DA3F3F',
chance: '1',
},
{
name: 'No luck',
coupon: '',
color: '#E49686',
chance: '1',
},
]
}, obj).appendTo($prizes_list).on('change', function () {
window.azexo_init(preview, {'lucky-wheel': obj});
});
window.azexo_init(preview, {'lucky-wheel': obj});
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=lucky-wheel", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#popup').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=popup", function (result) {
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('> .azd-content');
var $visibility = $content.find('.azd-visibility').empty();
var $type = $content.find('.azd-type').empty();
var $form_settings = $content.find('.azd-form-settings').empty();
var $popup_design = $content.find('.azd-popup-design').empty();
var $display_settings = $content.find('.azd-display-settings').empty();
var $teaser_settings = $content.find('.azd-teaser-settings').empty();
var popup = $dialog.find('.sh-popup-form').get(0);
var preview = $content.find('.azd-preview').get(0);
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active,
}, obj).appendTo($visibility);
azd.create_parameter('show_on_mobile', {
type: 'checkbox',
label: azd.i18n.show_on_mobile,
}, obj).appendTo($visibility);
var $popup_type = azd.create_parameter('type', {
type: 'radio',
label: azd.i18n.choose_goal_for_your_promo_popup,
options: {
collect: azd.i18n.collect_leads,
give_a_coupon: azd.i18n.give_a_discount_code,
subscribe_for_coupon: azd.i18n.subscribe_to_get_discount,
announcement: azd.i18n.announcement,
},
default: 'collect'
}, obj).appendTo($type).on('change', function () {
$form_button.hide();
$form_email_placeholder.hide();
$thank_you_message.hide();
$coupon.hide();
$form_button_link.hide();
switch ($popup_type.find('[name="type"]:checked').attr('value')) {
case 'collect':
$form_button.show();
$form_email_placeholder.show();
$thank_you_message.show();
break;
case 'give_a_coupon':
$form_email_placeholder.show();
$coupon.show();
break;
case 'subscribe_for_coupon':
$form_button.show();
$form_email_placeholder.show();
$thank_you_message.show();
$coupon.show();
break;
case 'announcement':
$form_button.show();
$form_button_link.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
azd.create_parameter('form_title', {
type: 'text',
label: azd.i18n.title,
default: 'Don\'t want to miss anything?',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
azd.create_parameter('form_description', {
type: 'textarea',
label: azd.i18n.description,
default: 'Be the first to see new arrivals, exclusive deals and much more.',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
var $form_button = azd.create_parameter('form_button', {
type: 'text',
label: azd.i18n.button,
default: 'Subscribe',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
var $form_email_placeholder = azd.create_parameter('form_email_placeholder', {
type: 'text',
label: azd.i18n.email_placeholder,
default: 'Enter your email',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
var $thank_you_message = azd.create_parameter('thank_you_message', {
type: 'text',
label: azd.i18n.thank_you_message,
default: 'Congratulation! You\'ve successfully joined our list. Stay tuned for future updates.',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
var $coupon = azd.create_parameter('coupon', {
type: 'text',
label: azd.i18n.discount_code,
default: '10_OFF',
description: azd.i18n.discount_code_description,
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
var $form_button_link = azd.create_parameter('form_button_link', {
type: 'text',
label: azd.i18n.button_link,
default: 'https://',
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
$popup_type.trigger('change');
azd.create_parameter('text_color', {
type: 'color',
label: azd.i18n.text_color,
default: '#000',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
azd.create_parameter('popup_background', {
type: 'color',
label: azd.i18n.popup_background,
default: '#F1F1F1',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
azd.create_parameter('field_background', {
type: 'color',
label: azd.i18n.field_background,
default: '#fff',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
azd.create_parameter('button_color', {
type: 'color',
label: azd.i18n.button_color,
default: '#000',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
azd.create_parameter('teaser_background', {
type: 'color',
label: azd.i18n.teaser_background,
default: '#DA3F3F',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
var $trigger_open = azd.create_parameter('trigger_open', {
type: 'radio',
label: azd.i18n.trigger_open_when,
options: {
loaded: azd.i18n.after_page_loaded,
time: azd.i18n.after_specific_time,
scrolling: azd.i18n.after_scrolling_down,
leaving: azd.i18n.user_is_leaving_the_website,
},
default: 'loaded'
}, obj).appendTo($display_settings).on('change', function () {
$open_specific_time.hide();
switch ($trigger_open.find('[name="trigger_open"]:checked').attr('value')) {
case 'time':
$open_specific_time.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $open_specific_time = azd.create_parameter('open_specific_time', {
type: 'number',
units: 'seconds',
min: '1',
default: '5',
}, obj).appendTo($display_settings);
$trigger_open.trigger('change');
azd.create_parameter('display_on', {
type: 'radio',
label: azd.i18n.display_on,
options: {
all_pages: azd.i18n.all_pages,
home_page: azd.i18n.home_page_only,
},
default: 'all_pages'
}, obj).appendTo($display_settings).find('.azd-radio').addClass('azd-vertical');
azd.create_parameter('repeat_open', {
type: 'dropdown',
label: azd.i18n.repeat_open_automatically,
description: azd.i18n.repeat_open_description,
options: {
no_repeat: azd.i18n.no_repeat,
every_3_mins: azd.i18n.every_3_mins,
every_5_mins: azd.i18n.every_5_mins,
every_10_mins: azd.i18n.every_10_mins,
every_15_mins: azd.i18n.every_15_mins,
every_30_mins: azd.i18n.every_30_mins,
every_1_hr: azd.i18n.every_1_hr,
every_6_hrs: azd.i18n.every_6_hrs,
every_12_hrs: azd.i18n.every_12_hrs,
every_day: azd.i18n.every_day,
every_3_days: azd.i18n.every_3_days,
every_week: azd.i18n.every_week,
every_2_week: azd.i18n.every_2_week,
every_month: azd.i18n.every_month,
},
default: 'every_day'
}, obj).appendTo($display_settings);
azd.create_parameter('activate_teaser', {
type: 'checkbox',
label: azd.i18n.activate_teaser,
default: true,
}, obj).appendTo($teaser_settings);
azd.create_parameter('teaser_position', {
type: 'radio',
label: azd.i18n.teaser_position,
options: {
left: azd.i18n.left,
right: azd.i18n.right,
},
default: 'left'
}, obj).appendTo($teaser_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
}).find('.azd-radio').addClass('azd-vertical');
azd.create_parameter('teaser_title', {
type: 'text',
label: azd.i18n.title,
default: 'Get a discount',
}, obj).appendTo($teaser_settings).on('change', function () {
window.azexo_init(preview, {'popup': obj});
});
window.azexo_init(preview, {'popup': obj});
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=popup", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#back-in-stock').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=back-in-stock", function (result) {
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('> .azd-content');
var $visibility = $content.find('.azd-visibility').empty();
var $form_settings = $content.find('.azd-form-settings').empty();
var $popup_design = $content.find('.azd-popup-design').empty();
var popup = $dialog.find('.sh-popup-form').get(0);
var preview = $content.find('.azd-preview').get(0);
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active,
}, obj).appendTo($visibility);
azd.create_parameter('name', {
type: 'checkbox',
label: azd.i18n.show_name_field,
default: true,
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'back-in-stock': obj});
});
azd.create_parameter('phone', {
type: 'checkbox',
label: azd.i18n.show_phone_number_field,
default: true,
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'back-in-stock': obj});
});
azd.create_parameter('note', {
type: 'checkbox',
label: azd.i18n.show_note_field,
default: true,
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'back-in-stock': obj});
});
azd.create_parameter('newsletter', {
type: 'checkbox',
label: azd.i18n.show_field_signup_newsletter,
default: true,
}, obj).appendTo($form_settings).on('change', function () {
window.azexo_init(preview, {'back-in-stock': obj});
});
azd.create_parameter('text_color', {
type: 'color',
label: azd.i18n.text_color,
default: '#000',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'back-in-stock': obj});
});
azd.create_parameter('popup_background', {
type: 'color',
label: azd.i18n.popup_background,
default: '#F1F1F1',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'back-in-stock': obj});
});
azd.create_parameter('field_background', {
type: 'color',
label: azd.i18n.field_background,
default: '#fff',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'back-in-stock': obj});
});
azd.create_parameter('button_color', {
type: 'color',
label: azd.i18n.button_color,
default: '#000',
}, obj).appendTo($popup_design).on('change', function () {
window.azexo_init(preview, {'back-in-stock': obj});
});
window.azexo_init(preview, {'back-in-stock': obj});
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=back-in-stock", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#size-chart').on('azd-show', function (event, data) {
var $dialog = $(this);
var columns = [
{sName: "id", bVisible: false},
{sName: "preset", bVisible: false},
{sName: "content", bVisible: false},
{sName: "applies_to_products", bVisible: false},
{sName: "applies_to_collection", bVisible: false},
{sName: "title", sTitle: azd.i18n.title, orderable: false},
{sName: "status", sTitle: azd.i18n.status, sClass: 'azd-status', orderable: false},
{sName: "applies_to", sTitle: azd.i18n.applies_to, sClass: 'azd-applies-to', orderable: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-datatable:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-datatable:not(.dataTable)'), columns, azd.ajaxurl + "?action=objects_datatable&type=size-chart", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-status').each(function () {
var row = convert_table_item(this);
if (row.status == 'true') {
$(this).text(azd.i18n.active);
}
if (row.status == 'false') {
$(this).text(azd.i18n.inactive);
}
});
$table.find('tbody tr .azd-applies-to').each(function () {
var row = convert_table_item(this);
switch (row.applies_to) {
case 'all_products':
$(this).text(azd.i18n.all_products);
break;
case 'specific_products':
$(this).text(azd.i18n.specific_products);
break;
case 'specific_collection':
$(this).text(azd.i18n.specific_collection);
break;
}
});
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#create-size-chart"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
sizechart: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=size-chart&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
});
});
} else {
$dialog.find('table.azd-datatable').DataTable().ajax.reload();
}
});
$('#create-size-chart').on('azd-show', function (event, data) {
var $dialog = $(this);
var sizechart = {};
if (data && data.data && data.data.sizechart) {
sizechart = $.extend({}, data.data.sizechart);
$dialog.find('.azd-dialog-header .azd-page-title span').text(sizechart.title);
} else {
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.i18n.create_size_chart);
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_object&type=size-chart", {
object: sizechart
}, function (result) {
$('.azd-loader').fadeOut();
//sizechart = JSON.parse(result);
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
});
if(data.data) {
data.data.sizechart = sizechart;
}
});
var $content = $dialog.find('> .azd-content');
var $details = $content.find('.azd-details').empty();
var $chart_content = $content.find('.azd-chart-content').empty();
var $applies_to = $content.find('.azd-applies-to').empty();
var $preview = $content.find('.azd-preview');
var $sizechart = $preview.find('.sh-size-chart');
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active
}, sizechart).appendTo($details);
azd.create_parameter('title', {
type: 'text',
label: azd.i18n.title
}, sizechart).appendTo($details);
var $preset = azd.create_parameter('preset', {
type: 'radio',
label: azd.i18n.choose_preset,
options: {
none: azd.i18n.none,
mens_top: azd.i18n.mens_top,
mens_bottom: azd.i18n.mens_bottom,
mens_shoes: azd.i18n.mens_shoes,
womens_top: azd.i18n.womens_top,
womens_bottom: azd.i18n.womens_bottom,
womens_shoes: azd.i18n.womens_shoes,
boys_top: azd.i18n.boys_top,
boys_bottom: azd.i18n.boys_bottom,
girls_top: azd.i18n.girls_top,
girls_bottom: azd.i18n.girls_bottom,
kids_shoes: azd.i18n.kids_shoes,
},
default: 'none'
}, sizechart).appendTo($chart_content).on('change', function () {
switch ($preset.find('[name="preset"]:checked').attr('value')) {
case 'none':
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent('');
$preview.find('.sh-size-chart .sh-content').html('');
sizechart.content = '';
break;
case 'mens_top':
$.get(azd.app_url + '/files/size-chart-preset-mens-top.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'mens_bottom':
$.get(azd.app_url + '/files/size-chart-preset-mens-bottom.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'mens_shoes':
$.get(azd.app_url + '/files/size-chart-preset-mens-shoes.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'womens_top':
$.get(azd.app_url + '/files/size-chart-preset-womens-top.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'womens_bottom':
$.get(azd.app_url + '/files/size-chart-preset-womens-bottom.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'womens_shoes':
$.get(azd.app_url + '/files/size-chart-preset-womens-shoes.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'boys_top':
$.get(azd.app_url + '/files/size-chart-preset-boys-top.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'boys_bottom':
$.get(azd.app_url + '/files/size-chart-preset-boys-bottom.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'girls_top':
$.get(azd.app_url + '/files/size-chart-preset-girls-top.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'girls_bottom':
$.get(azd.app_url + '/files/size-chart-preset-girls-bottom.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
case 'kids_shoes':
$.get(azd.app_url + '/files/size-chart-preset-kids-shoes.html', function (result) {
tinymce.get($('[data-parameter="content"] textarea').attr('id')).setContent(result);
$preview.find('.sh-size-chart .sh-content').html(result);
sizechart.content = result;
});
break;
}
});
var $chart = azd.create_parameter('content', {
type: 'textarea',
}, sizechart).appendTo($chart_content);
tinymce.init({
selector: '[data-parameter="content"] textarea',
plugins: 'table autoresize',
menubar: 'table',
toolbar: 'table tabledelete | tableprops tablerowprops tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',
setup: function (ed) {
ed.on('change', function (e) {
$preview.find('.sh-size-chart .sh-content').html(tinymce.get($('[data-parameter="content"] textarea').attr('id')).getContent());
sizechart.content = tinymce.get($('[data-parameter="content"] textarea').attr('id')).getContent();
init_size_chart($sizechart);
});
}
});
var $applies_to_parameter = azd.create_parameter('applies_to', {
type: 'radio',
label: azd.i18n.applies_to,
options: {
all_products: azd.i18n.all_products,
specific_products: azd.i18n.specific_products,
specific_collection: azd.i18n.specific_collection,
},
default: 'all_products'
}, sizechart).appendTo($applies_to).on('change', function () {
$applies_products.hide();
$applies_collection.hide();
switch ($applies_to_parameter.find('[name="applies_to"]:checked').attr('value')) {
case 'specific_products':
$applies_products.show();
break;
case 'specific_collection':
$applies_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $applies_products = azd.create_parameter('applies_to_products', {
type: 'ajax_multiselect',
label: azd.i18n.select_products,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=products&field=id"
}, sizechart).appendTo($applies_to);
var $applies_collection = azd.create_parameter('applies_to_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, sizechart).appendTo($applies_to);
$applies_to_parameter.trigger('change');
function init_size_chart($sizechart) {
$sizechart.find('.sh-content').html(sizechart.content);
}
init_size_chart($sizechart);
});
$('#facebook-chat').on('azd-show', function (event, data) {
var $dialog = $(this);
});
$(function () {
azd.ways_to_earn = {
order: azd.i18n.place_an_order,
signup: azd.i18n.signup,
birthday: azd.i18n.celebrate_a_birthday
};
azd.ways_to_redeem = {
amount_discount: azd.i18n.amount_discount,
percentage_off: azd.i18n.percentage_off,
free_shipping: azd.i18n.free_shipping
};
azd.referral_customer_rewards = {
amount_discount: azd.i18n.amount_discount,
percentage_off: azd.i18n.percentage_off,
free_shipping: azd.i18n.free_shipping,
points: azd.i18n.points,
};
azd.referral_friend_rewards = {
amount_discount: azd.i18n.amount_discount,
percentage_off: azd.i18n.percentage_off,
free_shipping: azd.i18n.free_shipping,
};
azd.automation_events = {
coming_soon: {
label: azd.i18n.coming_soon,
details: azd.i18n.coming_soon_description,
start_condition: azd.i18n.coming_soon_start_condition,
end_condition: azd.i18n.coming_soon_end_condition,
delay: {
default: '0',
units: 'days',
},
template: {
"preview_text": "You'll be the first to know when we launch.",
"sections": [{
"id": "ETKfYJgMet",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "wGGijxryLI",
"hidden": "false",
"name": "image_with_text_overlay",
"js": "https://azexo.com/shopify/email_sections/image_with_text_overlay.js",
"heading": "Thanks for subscribing!",
"text": "Stay tuned for updates
",
"button_label": "",
"button_link": "",
"button_style": "solid",
"section_height": "extra_small",
"text_size": "medium",
"vertical_alignment": "middle",
"horizontal_alignment": "center",
"background": "rgba(102,102,102,1)",
"text_color": "rgba(255,255,255,1)",
"button_background": "#FFF",
"button_text_color": "#444"
}, {
"id": "JZphLEyels",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "Welcome",
"text": "We really appreciate your interest in our shop and cannot wait to share it with you. Please be patient while we finish up and be on the lookout for another email. You will be the first to know when we open. Thanks again!",
"alignment": "left",
"padding": "true",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "SzPjNeywAc",
"hidden": "false",
"name": "divider",
"js": "https://azexo.com/shopify/email_sections/divider.js",
"style": "solid",
"thickness": "1px",
"width": "100%",
"background": "#FFF"
}, {
"id": "omUZriVcPN",
"hidden": "false",
"name": "text_columns_with_images",
"js": "https://azexo.com/shopify/email_sections/text_columns_with_images.js",
"heading": "Our promise to you",
"items": [{
"heading": "Great selection",
"alt": "",
"text": "",
"button_label": "",
"button_link": ""
}, {
"heading": "Fast shipping",
"alt": "",
"text": "",
"button_label": "",
"button_link": ""
}, {
"heading": "Helpful support",
"alt": "",
"text": "",
"button_label": "",
"button_link": ""
}],
"alignment": "center"
}, {
"id": "DkHmqmEHUS",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "coming_soon",
"delay": "0",
"status": "false",
"subject": "Thanks for subscribing!",
},
},
welcome: {
label: azd.i18n.welcome,
details: azd.i18n.welcome_description,
start_condition: azd.i18n.welcome_start_condition,
end_condition: azd.i18n.welcome_end_condition,
delay: {
default: '0',
units: 'days',
},
template: {
"preview_text": "Thanks for subscribing. We're so happy you're here.",
"sections": [{
"id": "ausnvcEiES",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "mjTrxwWrqd",
"hidden": "false",
"name": "image_with_text_overlay",
"js": "https://azexo.com/shopify/email_sections/image_with_text_overlay.js",
"heading": "Thanks for subscribing!",
"text": "We're so happy you're here
",
"button_label": "Shop now",
"button_link": "https://" + azd.domain,
"button_style": "solid",
"section_height": "extra_small",
"text_size": "medium",
"vertical_alignment": "middle",
"horizontal_alignment": "center",
"background": "rgba(85,85,85,1)",
"text_color": "rgba(255,255,255,1)",
"button_background": "#FFF",
"button_text_color": "#444"
}, {
"id": "AjIvinqHMH",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "Welcome",
"text": "We really appreciate your interest in our shop and hope you like what we have to offer. Take a look around and let us know if you have any questions. Thanks again!",
"alignment": "left",
"padding": "false",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "AYEFCYlbyU",
"hidden": "false",
"name": "featured_collection",
"js": "https://azexo.com/shopify/email_sections/featured_collection.js",
"heading": "Explore our favorites",
"out_of_stock": "false",
"per_row": "4",
"rows": "1",
"title": "false",
"vendor": "false",
"price": "false",
"compare_at_price": "false",
"button": "false",
"view_all": "false",
"collection": azd.default_collection
}, {
"id": "tGWPsGIkxw",
"hidden": "false",
"name": "divider",
"js": "https://azexo.com/shopify/email_sections/divider.js",
"style": "solid",
"thickness": "1px",
"width": "100%",
"background": "#FFF"
}, {
"id": "scpwUaETHy",
"hidden": "false",
"name": "text_columns_with_images",
"js": "https://azexo.com/shopify/email_sections/text_columns_with_images.js",
"heading": "Add title or tagline",
"items": [{
"heading": "Great selection",
"alt": "",
"text": "",
"button_label": "",
"button_link": ""
}, {
"heading": "Fast shipping",
"alt": "",
"text": "",
"button_label": "",
"button_link": ""
}, {
"heading": "Helpful support",
"alt": "",
"text": "",
"button_label": "",
"button_link": ""
}],
"alignment": "center"
}, {
"id": "RJJmjFAnKS",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "welcome",
"delay": "0",
"status": "false",
"subject": "Welcome!",
},
},
discount_reminder: {
label: azd.i18n.discount_reminder,
details: azd.i18n.discount_reminder_description,
start_condition: azd.i18n.discount_reminder_start_condition,
end_condition: azd.i18n.discount_reminder_end_condition,
delay: {
default: '2',
units: 'days',
options: ['1', '2', '3', '7']
},
template: {
"preview_text": "Time is running out so shop now, your personal code is inside.",
"sections": [{
"id": "TOOQyPQxSF",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "hYSLMPRdnn",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "Don't forget your coupon",
"text": "We thought you'd appreciate a friendly reminder with your personal code from our recent promotion. Time is running out though so don't wait much longer or you might miss out.
",
"alignment": "left",
"padding": "true",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "rxZIcxLorF",
"hidden": "false",
"name": "discount_callout",
"js": "https://azexo.com/shopify/email_sections/discount_callout.js",
"heading": "23% off your purchase",
"text": "Click to shop now and automatically apply your code at checkout.",
"coupon": "code",
"button_label": "Shop now with discount",
"button_link": "https://" + azd.domain,
"supplemental_details": "Additional terms and conditions may apply."
}, {
"id": "hOYJsHVkgo",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "discount_reminder",
"delay": "2",
"status": "false",
"subject": "Expiring soon: Don't forget to use your coupon",
},
},
abandoned_checkout: {
label: azd.i18n.abandoned_checkout,
details: azd.i18n.abandoned_checkout_description,
start_condition: azd.i18n.abandoned_checkout_start_condition,
end_condition: azd.i18n.abandoned_checkout_end_condition,
delay: {
default: '1',
units: 'hours',
options: ['1', '6', '24']
},
template: {
"preview_text": "We saved your cart and are here to help. Don't miss out on these great items.",
"sections": [{
"id": "jaIGkdHdXn",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "KtpRTDqpjU",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "You've left something behind",
"text": "Thanks for your interest in our shop! We saved your cart since you started checking out. Be sure to come back and complete your purchase soon. Please contact us with any questions, we're happy to help.
",
"alignment": "left",
"padding": "true",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "wzdNBSqZyC",
"hidden": "false",
"name": "checkout_summary",
"js": "https://azexo.com/shopify/email_sections/checkout_summary.js",
"heading": "Your saved cart",
"vendor": "false",
"sku": "false"
}, {
"id": "TZVMFaRdWO",
"hidden": "false",
"name": "resume_checkout_button",
"js": "https://azexo.com/shopify/email_sections/resume_checkout_button.js",
"label": "Finish shopping",
"alignment": "center",
"type": "primary",
"text_size": "medium"
}, {
"id": "RdiQeeXULI",
"hidden": "false",
"name": "discount_callout",
"js": "https://azexo.com/shopify/email_sections/discount_callout.js",
"heading": "23% off your purchase",
"text": "Click to shop now and automatically apply your code at checkout.",
"coupon": "code",
"button_label": "Shop now with discount",
"button_link": "https://" + azd.domain,
"supplemental_details": "Additional terms and conditions may apply."
}, {
"id": "LPgIwvJhNi",
"hidden": "false",
"name": "featured_collection",
"js": "https://azexo.com/shopify/email_sections/featured_collection.js",
"heading": "Other customer favorites",
"out_of_stock": "false",
"per_row": "4",
"rows": "1",
"title": "true",
"vendor": "false",
"price": "false",
"compare_at_price": "false",
"button": "false",
"view_all": "false",
"collection": azd.default_collection
}, {
"id": "IZwrOuGXlm",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "abandoned_checkout",
"delay": "1",
"status": "false",
"subject": "Thinking it over?",
},
},
new_purchaser: {
label: azd.i18n.new_purchaser,
details: azd.i18n.new_purchaser_description,
start_condition: azd.i18n.new_purchaser_start_condition,
end_condition: azd.i18n.new_purchaser_end_condition,
delay: {
default: '2',
units: 'weeks',
options: ['1', '2', '4']
},
template: {
"preview_text": "We truly appreciate your business and want to thank you.",
"sections": [{
"id": "DFIUvLKWuG",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "SpDSPgiXPE",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "Thank you",
"text": "We really want to thank you for your recent purchase, it means a lot to us. If you have any questions, feedback, or if there's anything else we can do to improve your experience, please do not hesitate to contact us. We would love to hear from you. Thanks again.",
"alignment": "left",
"padding": "false",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "hzoOWlpLFY",
"hidden": "false",
"name": "discount_callout",
"js": "https://azexo.com/shopify/email_sections/discount_callout.js",
"heading": "23% off your purchase",
"text": "Click to shop now and automatically apply your code at checkout.",
"coupon": "code",
"button_label": "Shop now with discount",
"button_link": "https://" + azd.domain,
"supplemental_details": "Additional terms and conditions may apply."
}, {
"id": "doIsgMHQRj",
"hidden": "false",
"name": "featured_collection",
"js": "https://azexo.com/shopify/email_sections/featured_collection.js",
"heading": "You may also like",
"out_of_stock": "false",
"per_row": "4",
"rows": "1",
"title": "true",
"vendor": "false",
"price": "false",
"compare_at_price": "false",
"button": "false",
"view_all": "false",
"collection": azd.default_collection
}, {
"id": "bGeNtVqzgo",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "new_purchaser",
"delay": "2",
"status": "false",
"subject": "Thank you for your recent order",
},
},
repeat_purchaser: {
label: azd.i18n.repeat_purchaser,
details: azd.i18n.repeat_purchaser_description,
start_condition: azd.i18n.repeat_purchaser_start_condition,
end_condition: azd.i18n.repeat_purchaser_end_condition,
delay: {
default: '2',
units: 'weeks',
options: ['1', '2', '4']
},
template: {
"preview_text": "We truly appreciate your business and want to thank you again.",
"sections": [{
"id": "voUTBBWfEX",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "FTNTOETQeG",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "Thank you again!",
"text": "We really want to thank you for your recent purchase. It is so rewarding to see a repeat customer's order come through. If you have any questions, feedback, or if there's anything else we can do to improve your experience, please do not hesitate to contact us. We would love to hear from you and look forward to serving you again in the future. Thanks so much.",
"alignment": "left",
"padding": "false",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "sxhPQdxkZk",
"hidden": "false",
"name": "discount_callout",
"js": "https://azexo.com/shopify/email_sections/discount_callout.js",
"heading": "23% off your purchase",
"text": "Click to shop now and automatically apply your code at checkout.",
"coupon": "code",
"button_label": "Shop now with discount",
"button_link": "https://" + azd.domain,
"supplemental_details": "Additional terms and conditions may apply."
}, {
"id": "OpMltIonJT",
"hidden": "false",
"name": "featured_collection",
"js": "https://azexo.com/shopify/email_sections/featured_collection.js",
"heading": "You may also like",
"out_of_stock": "false",
"per_row": "4",
"rows": "1",
"title": "true",
"vendor": "false",
"price": "false",
"compare_at_price": "false",
"button": "false",
"view_all": "false",
"collection": azd.default_collection
}, {
"id": "cOSTahjisZ",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "repeat_purchaser",
"delay": "2",
"status": "false",
"subject": "Thank you again for your recent order",
},
},
lapsed_purchaser: {
label: azd.i18n.lapsed_purchaser,
details: azd.i18n.lapsed_purchaser_description,
start_condition: azd.i18n.lapsed_purchaser_start_condition,
end_condition: azd.i18n.lapsed_purchaser_end_condition,
delay: {
default: '90',
units: 'days',
options: ['60', '90', '120']
},
template: {
"preview_text": "Come see the latest hot ticket items.",
"sections": [{
"id": "xCybmOLrBF",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "eTDhJmSQqm",
"hidden": "false",
"name": "image_with_text_overlay",
"js": "https://azexo.com/shopify/email_sections/image_with_text_overlay.js",
"heading": "We miss you",
"text": "",
"button_label": "Come back for a visit",
"button_link": "https://" + azd.domain,
"button_style": "solid",
"section_height": "extra_small",
"text_size": "medium",
"vertical_alignment": "middle",
"horizontal_alignment": "center",
"background": "rgba(85,85,85,1)",
"text_color": "rgba(255,255,255,1)",
"button_background": "#FFF",
"button_text_color": "#444"
}, {
"id": "uMlrwIwRcP",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "How are you?",
"text": "We really want to thank you for having purchased from us in the past, it means a lot to us. We have missed seeing you but hope you are well. To entice you to come back, take a look at our latest bestselling items below.
",
"alignment": "left",
"padding": "false",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "yLNwvyZbXN",
"hidden": "false",
"name": "discount_callout",
"js": "https://azexo.com/shopify/email_sections/discount_callout.js",
"heading": "23% off your purchase",
"text": "Click to shop now and automatically apply your code at checkout.",
"coupon": "code",
"button_label": "Shop now with discount",
"button_link": "https://" + azd.domain,
"supplemental_details": "Additional terms and conditions may apply."
}, {
"id": "VYoLjWIyIV",
"hidden": "false",
"name": "featured_collection",
"js": "https://azexo.com/shopify/email_sections/featured_collection.js",
"heading": "Latest bestsellers",
"out_of_stock": "false",
"per_row": "4",
"rows": "1",
"title": "true",
"vendor": "false",
"price": "true",
"compare_at_price": "false",
"button": "false",
"view_all": "false",
"collection": azd.default_collection
}, {
"id": "GoZBUpfIOJ",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "lapsed_purchaser",
"delay": "90",
"status": "false",
"subject": "To put it simply: We miss you.",
},
},
product_purchased: {
label: azd.i18n.product_purchased,
details: azd.i18n.product_purchased_description,
start_condition: azd.i18n.product_purchased_start_condition,
end_condition: azd.i18n.product_purchased_end_condition,
delay: {
default: '10',
units: 'days',
options: ['5', '10', '20']
},
template: {
"preview_text": "You don't need to choose between style or play with this simple tips.",
"sections": [{
"id": "inpTjySPkr",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "jxggNVOuJU",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "product_purchased",
"delay": "10",
"status": "false",
"subject": "Care tips for their new favorite jacket",
},
},
customer_tagged: {
label: azd.i18n.customer_tagged,
details: azd.i18n.customer_tagged_description,
delay: {
default: '0',
units: 'days',
},
template: {
"preview_text": "",
"sections": [{
"id": "ifLxFTILrJ",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "mABqwpiEiE",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "customer_tagged",
"delay": "0",
"status": "false",
"subject": "",
},
},
celebrate_birthday: {
label: azd.i18n.celebrate_birthday,
details: azd.i18n.celebrate_birthday_description,
delay: {
default: '0',
units: 'days',
},
template: {
"preview_text": "",
"sections": [{
"id": "ifLxFTILrJ",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to azexo-dawn.",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "NNuRpjNxnv",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "Happy birthday!",
"text": "We hope you have a great day! To celebrate, we've added {{points_amount}} points to your account. 🎂
",
"alignment": "center",
"padding": "false",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "xWDRfCstLd",
"hidden": "false",
"name": "button",
"js": "https://azexo.com/shopify/email_sections/button.js",
"label": "Spend Now",
"link": "https://" + azd.domain,
"alignment": "center",
"type": "primary",
"text_size": "medium",
"padding": "false",
"background": "#FFF"
}, {
"id": "mABqwpiEiE",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "celebrate_birthday",
"delay": "0",
"status": "false",
"subject": "Happy birthday!",
},
},
referral_completed: {
label: azd.i18n.referral_completed,
details: azd.i18n.referral_completed_description,
delay: {
default: '0',
units: 'days',
},
template: {
"preview_text": "",
"sections": [{
"id": "ifLxFTILrJ",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to azexo-dawn.",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "xeOgqzQjbe",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "Your friend used your referral link",
"text": "{{friend_email}} completed their referral
",
"alignment": "center",
"padding": "false",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "IwtRXKlRAv",
"hidden": "false",
"name": "button",
"js": "https://azexo.com/shopify/email_sections/button.js",
"label": "Use your reward",
"link": "https://" + azd.domain,
"alignment": "center",
"type": "primary",
"text_size": "medium",
"padding": "false",
"background": "#FFF"
}, {
"id": "mABqwpiEiE",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "referral_completed",
"delay": "0",
"status": "false",
"subject": "Referral completed",
},
},
back_in_stock: {
label: azd.i18n.back_in_stock,
details: azd.i18n.back_in_stock_description,
delay: {
default: '0',
units: 'days',
},
template: {
"preview_text": "",
"sections": [{
"id": "ifLxFTILrJ",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "xeOgqzQjbe",
"hidden": "false",
"name": "rich_text",
"js": "https://azexo.com/shopify/email_sections/rich_text.js",
"heading": "Back in stock alert",
"text": "{{product_title}} {{variant_title}} now available.
",
"alignment": "center",
"padding": "false",
"background": "#FFF",
"heading_color": "#3D4246",
"text_color": "#3D4246"
}, {
"id": "IwtRXKlRAv",
"hidden": "false",
"name": "button",
"js": "https://azexo.com/shopify/email_sections/button.js",
"label": "Go to product",
"link": "{{product_url}}",
"alignment": "center",
"type": "primary",
"text_size": "medium",
"padding": "false",
"background": "#FFF"
}, {
"id": "mABqwpiEiE",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}],
"event": "back_in_stock",
"delay": "0",
"status": "false",
"subject": "Back in stock alert",
},
},
// blog_post_published: {
// label: azd.i18n.blog_post_published,
// details: azd.i18n.blog_post_published_description,
// delay: {
// default: '0',
// units: 'days',
// },
// template: {
// "preview_text": "",
// "sections": [{
// "id": "aXUFexloTd",
// "hidden": "false",
// "name": "header",
// "js": "https://azexo.com/shopify/email_sections/header.js",
// "preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
// "logo": "hide",
// "logo_width": "200px"
// }, {
// "id": "JFgtGMLbDU",
// "hidden": "false",
// "name": "footer",
// "js": "https://azexo.com/shopify/email_sections/footer.js",
// "policies": "",
// "reply_email": "false",
// "customer_service_phone": "false"
// }],
// "event": "blog_post_published",
// "delay": "0",
// "status": "false",
// "subject": "",
// },
// },
};
//Price drop
//Automatically inform subscribers of discounts on items in their cart to encourage purchases.
//Send immediately to subscribers who had abandoned cart items in the last 2 days when an item price drops ≥ 20%.
});
function get_earn_summary(earn) {
var summary = '';
summary = summary + '';
switch (earn.way) {
case 'order':
switch (earn.type) {
case 'increments':
summary = summary + 'Customers earn ' + earn.earned + ' points for every 1' + azd.currency + ' spent';
break;
case 'fixed':
summary = summary + earn.awarded + ' points for completing action';
break;
}
break;
case 'signup':
summary = summary + earn.awarded + ' points for completing action';
break;
case 'birthday':
summary = summary + earn.awarded + ' points for completing action';
break;
}
summary = summary + ' ';
summary = summary + ' ';
return summary;
}
function get_reward_summary(reward) {
var summary = '';
summary = summary + '';
var type = false;
if (reward.reward) {
type = reward.reward;
}
if (reward.way) {
type = reward.way;
}
var applies_to = '';
if (reward.applies_to == 'entire_order') {
applies_to = 'entire order';
}
if (reward.applies_to == 'specific_collection') {
applies_to = 'collection';
}
switch (type) {
case 'amount_discount':
if (reward.type) {
switch (reward.type) {
case 'fixed':
summary = summary + reward.discount_value + azd.currency + ' ' + 'off' + ' ' + applies_to;
break;
case 'increments':
summary = summary + 'Customers earn ' + reward.customer_gets + azd.currency + ' off ' + applies_to + ' for every ' + reward.customer_redeems_increment + ' points redeemed';
break;
}
} else {
summary = summary + reward.discount_value + azd.currency + ' ' + 'off' + ' ' + applies_to;
}
break;
case 'percentage_off':
summary = summary + reward.discount_value + '% ' + 'off' + ' ' + applies_to;
break;
case 'free_shipping':
if ((reward.set_maximum_shipping_amount === 'true' || reward.set_maximum_shipping_amount === true) && reward.maximum_shipping_amount) {
summary = summary + 'Free shipping off entire order, up to a maximum shipping amount of ' + reward.maximum_shipping_amount + azd.currency;
} else {
summary = summary + 'Free shipping off entire order';
}
break;
case 'points':
summary = summary + 'Customers will be rewarded ' + reward.points_value + ' points';
break;
}
summary = summary + ' ';
if (reward.minimum_requirement) {
summary = summary + '';
switch (reward.minimum_requirement) {
case 'none':
summary = summary + 'Applies to orders of any amount';
break;
case 'minimum_purchase_amount':
if (reward.minimum_purchase_amount) {
summary = summary + 'Applies to orders over ' + reward.minimum_purchase_amount + azd.currency;
} else {
summary = summary + 'Applies to orders of any amount';
}
break;
}
summary = summary + ' ';
}
summary = summary + ' ';
return summary;
}
$('#points').on('azd-show', function (event, data) {
var $dialog = $(this);
var earn_columns = [
{sName: "way", sTitle: azd.i18n.way, sClass: 'azd-way', orderable: false},
{sName: "id", sTitle: azd.i18n.summary, sClass: 'azd-summary', orderable: false},
{sName: "status", sTitle: azd.i18n.status, sClass: 'azd-status', orderable: false},
{sName: "type", bVisible: false},
{sName: "earned", bVisible: false},
{sName: "awarded", bVisible: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-ways-to-earn:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-ways-to-earn:not(.dataTable)'), earn_columns, azd.ajaxurl + "?action=objects_datatable&type=way-to-earn", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
earn_columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-way').each(function () {
var row = convert_table_item(this);
$(this).text(azd.ways_to_earn[row.way]);
});
$table.find('tbody tr .azd-summary').each(function () {
var row = convert_table_item(this);
$(this).html(get_earn_summary(row));
});
$table.find('tbody tr .azd-status').each(function () {
var row = convert_table_item(this);
if (row.status == 'true') {
$(this).text(azd.i18n.active);
}
if (row.status == 'false') {
$(this).text(azd.i18n.inactive);
}
});
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#add-way-to-earn"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
way_to_earn: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=way-to-earn&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
});
}, true);
} else {
$dialog.find('table.azd-ways-to-earn').DataTable().ajax.reload();
}
var redeem_columns = [
{sName: "way", sTitle: azd.i18n.way, sClass: 'azd-way', orderable: false},
{sName: "id", sTitle: azd.i18n.summary, sClass: 'azd-summary', orderable: false},
{sName: "status", sTitle: azd.i18n.status, sClass: 'azd-status', orderable: false},
{sName: "type", bVisible: false},
{sName: "points_cost", bVisible: false},
{sName: "discount_value", bVisible: false},
{sName: "customer_redeems_increment", bVisible: false},
{sName: "customer_gets", bVisible: false},
{sName: "set_minimum_points", bVisible: false},
{sName: "minimum_points", bVisible: false},
{sName: "set_maximum_points", bVisible: false},
{sName: "maximum_points", bVisible: false},
{sName: "applies_to", bVisible: false},
{sName: "specific_collection", bVisible: false},
{sName: "minimum_requirement", bVisible: false},
{sName: "minimum_purchase_amount", bVisible: false},
{sName: "add_coupon_prefix", bVisible: false},
{sName: "coupon_prefix", bVisible: false},
{sName: "set_maximum_shipping_amount", bVisible: false},
{sName: "maximum_shipping_amount", bVisible: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-ways-to-redeem:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-ways-to-redeem:not(.dataTable)'), redeem_columns, azd.ajaxurl + "?action=objects_datatable&type=way-to-redeem", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
redeem_columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-way').each(function () {
var row = convert_table_item(this);
$(this).text(azd.ways_to_redeem[row.way]);
});
$table.find('tbody tr .azd-summary').each(function () {
var row = convert_table_item(this);
$(this).html(get_reward_summary(row));
});
$table.find('tbody tr .azd-status').each(function () {
var row = convert_table_item(this);
if (row.status == 'true') {
$(this).text(azd.i18n.active);
}
if (row.status == 'false') {
$(this).text(azd.i18n.inactive);
}
});
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#add-way-to-redeem"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
way_to_redeem: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=way-to-redeem&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
});
}, true);
} else {
$dialog.find('table.azd-ways-to-redeem').DataTable().ajax.reload();
}
var points = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=points", function (result) {
function save() {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=points", {
object: points
}, function (result) {
$('.azd-loader').fadeOut();
});
}
$('.azd-loader').fadeOut();
points = JSON.parse(result);
var $status = $dialog.find('.azd-points-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active,
}, points).appendTo($status).on('change', save);
var $branding = $dialog.find('.azd-points-branding').empty();
azd.create_parameter('plural', {
type: 'text',
default: 'Points',
label: azd.i18n.plural,
}, points).appendTo($branding).on('change', save);
azd.create_parameter('singular', {
type: 'text',
default: 'Point',
label: azd.i18n.singular,
}, points).appendTo($branding).on('change', save);
});
});
$('.azd-add-way-to-earn').on('click', function () {
azd.open_simple_modal({
title: azd.i18n.add_way_to_earn,
options: azd.ways_to_earn
}, '', function (way) {
$('[href="#add-way-to-earn"].azd-dialog-toggle').trigger('click', {
way_to_earn: {way: way}
});
});
return false;
});
$('#add-way-to-earn').on('azd-show', function (event, data) {
var $dialog = $(this);
var way_to_earn = {};
if (data && data.data && data.data.way_to_earn) {
way_to_earn = $.extend({}, data.data.way_to_earn);
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.ways_to_earn[way_to_earn.way]);
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_object&type=way-to-earn", {
object: way_to_earn
}, function (result) {
$('.azd-loader').fadeOut();
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
});
if(data.data) {
data.data.way_to_earn = way_to_earn;
}
});
var $summary = $dialog.find('.azd-summary').empty();
var $status = $dialog.find('.azd-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active,
}, way_to_earn).appendTo($status);
var $earning = $dialog.find('.azd-earning').empty();
switch (way_to_earn.way) {
case 'order':
var $type = azd.create_parameter('type', {
type: 'radio',
label: azd.i18n.earning_type,
options: {
increments: azd.i18n.increments_of_points_recommended,
fixed: azd.i18n.fixed_amount_of_points,
},
default: 'increments'
}, way_to_earn).appendTo($earning).on('change', function () {
$summary.html(get_earn_summary(way_to_earn));
$earned.hide();
$awarded.hide();
switch ($type.find('[name="type"]:checked').attr('value')) {
case 'increments':
$earned.show();
break;
case 'fixed':
$awarded.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $earned = azd.create_parameter('earned', {
type: 'number',
default: '5',
units: azd.i18n.points,
label: azd.i18n.points_earned_for_every_1_spent.replace('{{currency}}', azd.currency),
}, way_to_earn).appendTo($earning).on('change', function () {
$summary.html(get_earn_summary(way_to_earn));
});
var $awarded = azd.create_parameter('awarded', {
type: 'number',
default: '100',
units: azd.i18n.points,
label: azd.i18n.points_awarded,
}, way_to_earn).appendTo($earning).on('change', function () {
$summary.html(get_earn_summary(way_to_earn));
});
$type.trigger('change');
break;
case 'signup':
azd.create_parameter('awarded', {
type: 'number',
default: '200',
units: azd.i18n.points,
label: azd.i18n.points_awarded,
}, way_to_earn).appendTo($earning).on('change', function () {
$summary.html(get_earn_summary(way_to_earn));
}).trigger('change');
break;
case 'birthday':
azd.create_parameter('awarded', {
type: 'number',
default: '200',
units: azd.i18n.points,
label: azd.i18n.points_awarded,
}, way_to_earn).appendTo($earning).on('change', function () {
$summary.html(get_earn_summary(way_to_earn));
}).trigger('change');
break;
}
});
$('.azd-add-way-to-redeem').on('click', function () {
azd.open_simple_modal({
title: azd.i18n.add_way_to_redeem,
options: azd.ways_to_redeem
}, '', function (way) {
$('[href="#add-way-to-redeem"].azd-dialog-toggle').trigger('click', {
way_to_redeem: {way: way}
});
});
return false;
});
$('#add-way-to-redeem').on('azd-show', function (event, data) {
var $dialog = $(this);
var way_to_redeem = {};
if (data && data.data && data.data.way_to_redeem) {
way_to_redeem = $.extend({}, data.data.way_to_redeem);
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.ways_to_redeem[way_to_redeem.way]);
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_object&type=way-to-redeem", {
object: way_to_redeem
}, function (result) {
$('.azd-loader').fadeOut();
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
});
if(data.data) {
data.data.way_to_redeem = way_to_redeem;
}
});
var $summary = $dialog.find('.azd-summary').empty();
var $status = $dialog.find('.azd-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active,
}, way_to_redeem).appendTo($status);
var $reward = $dialog.find('.azd-reward').empty();
switch (way_to_redeem.way) {
case 'amount_discount':
var $type = azd.create_parameter('type', {
type: 'radio',
label: azd.i18n.points_redemption_style,
options: {
fixed: azd.i18n.fixed_amount_of_points,
increments: azd.i18n.increments_of_points,
},
default: 'fixed'
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
$points_cost.hide();
$discount_value.hide();
$customer_redeems_increment.hide();
$customer_gets.hide();
$set_minimum_points.hide();
$set_maximum_points.hide();
switch ($type.find('[name="type"]:checked').attr('value')) {
case 'fixed':
$points_cost.show();
$discount_value.show();
break;
case 'increments':
$customer_redeems_increment.show();
$customer_gets.show();
$set_minimum_points.show();
$set_maximum_points.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $points_cost = azd.create_parameter('points_cost', {
type: 'number',
default: '500',
units: azd.i18n.points,
label: azd.i18n.points_cost,
}, way_to_redeem).appendTo($reward);
var $discount_value = azd.create_parameter('discount_value', {
type: 'number',
default: '5',
units: azd.currency,
label: azd.i18n.discount_value,
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
});
var $customer_redeems_increment = azd.create_parameter('customer_redeems_increment', {
type: 'number',
default: '100',
units: azd.i18n.points,
label: azd.i18n.customer_redeems_increment_of,
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
});
var $customer_gets = azd.create_parameter('customer_gets', {
type: 'number',
default: '1',
units: azd.currency,
label: azd.i18n.customer_gets,
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
});
var $set_minimum_points = azd.create_parameter('set_minimum_points', {
type: 'checkbox',
label: azd.i18n.set_a_minimum_amount_of_points_required_to_redeem_this_reward,
}, way_to_redeem).appendTo($reward).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$minimum_points.show();
} else {
$minimum_points.hide();
}
});
var $minimum_points = azd.create_parameter('minimum_points', {
type: 'number',
default: '100',
units: azd.i18n.points,
}, way_to_redeem).appendTo($reward);
var $set_maximum_points = azd.create_parameter('set_maximum_points', {
type: 'checkbox',
label: azd.i18n.set_a_maximum_amount_of_points_the_customer_can_spend_on_this_reward,
}, way_to_redeem).appendTo($reward).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$maximum_points.show();
} else {
$maximum_points.hide();
}
});
var $maximum_points = azd.create_parameter('maximum_points', {
type: 'number',
default: '200',
units: azd.i18n.points,
}, way_to_redeem).appendTo($reward);
$set_minimum_points.trigger('change');
$set_maximum_points.trigger('change');
$type.trigger('change');
var $applies_to = azd.create_parameter('applies_to', {
type: 'radio',
label: azd.i18n.applies_to,
options: {
entire_order: azd.i18n.entire_order,
specific_collection: azd.i18n.specific_collection,
},
default: 'entire_order'
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
$specific_collection.hide();
switch ($applies_to.find('[name="applies_to"]:checked').attr('value')) {
case 'entire_order':
break;
case 'specific_collection':
$specific_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $specific_collection = azd.create_parameter('specific_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, way_to_redeem).appendTo($reward);
$applies_to.trigger('change');
var $minimum_requirement = azd.create_parameter('minimum_requirement', {
type: 'radio',
label: azd.i18n.minimum_requirement,
options: {
none: azd.i18n.none,
minimum_purchase_amount: azd.i18n.minimum_purchase_amount,
},
default: 'none'
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
$minimum_purchase_amount.hide();
switch ($minimum_requirement.find('[name="minimum_requirement"]:checked').attr('value')) {
case 'none':
break;
case 'minimum_purchase_amount':
$minimum_purchase_amount.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $minimum_purchase_amount = azd.create_parameter('minimum_purchase_amount', {
type: 'number',
units: azd.currency,
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
});
$minimum_requirement.trigger('change');
var $add_coupon_prefix = azd.create_parameter('add_coupon_prefix', {
type: 'checkbox',
label: azd.i18n.add_a_prefix_to_discount_codes,
}, way_to_redeem).appendTo($reward).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$coupon_prefix.show();
} else {
$coupon_prefix.hide();
}
});
var $coupon_prefix = azd.create_parameter('coupon_prefix', {
type: 'text',
placeholder: 'e.g. $10OFF-',
description: azd.i18n.coupon_prefix_description
}, way_to_redeem).appendTo($reward);
$add_coupon_prefix.trigger('change');
break;
case 'percentage_off':
var $points_cost = azd.create_parameter('points_cost', {
type: 'number',
default: '500',
units: azd.i18n.points,
label: azd.i18n.points_cost,
}, way_to_redeem).appendTo($reward);
var $discount_value = azd.create_parameter('discount_value', {
type: 'number',
default: '5',
units: '%',
label: azd.i18n.discount_value,
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
});
var $applies_to = azd.create_parameter('applies_to', {
type: 'radio',
label: azd.i18n.applies_to,
options: {
entire_order: azd.i18n.entire_order,
specific_collection: azd.i18n.specific_collection,
},
default: 'entire_order'
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
$specific_collection.hide();
switch ($applies_to.find('[name="applies_to"]:checked').attr('value')) {
case 'entire_order':
break;
case 'specific_collection':
$specific_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $specific_collection = azd.create_parameter('specific_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, way_to_redeem).appendTo($reward);
$applies_to.trigger('change');
var $minimum_requirement = azd.create_parameter('minimum_requirement', {
type: 'radio',
label: azd.i18n.minimum_requirement,
options: {
none: azd.i18n.none,
minimum_purchase_amount: azd.i18n.minimum_purchase_amount,
},
default: 'none'
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
$minimum_purchase_amount.hide();
switch ($minimum_requirement.find('[name="minimum_requirement"]:checked').attr('value')) {
case 'none':
break;
case 'minimum_purchase_amount':
$minimum_purchase_amount.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $minimum_purchase_amount = azd.create_parameter('minimum_purchase_amount', {
type: 'number',
units: azd.currency,
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
});
$minimum_requirement.trigger('change');
var $add_coupon_prefix = azd.create_parameter('add_coupon_prefix', {
type: 'checkbox',
label: azd.i18n.add_a_prefix_to_discount_codes,
}, way_to_redeem).appendTo($reward).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$coupon_prefix.show();
} else {
$coupon_prefix.hide();
}
});
var $coupon_prefix = azd.create_parameter('coupon_prefix', {
type: 'text',
placeholder: 'e.g. $10OFF-',
description: azd.i18n.coupon_prefix_description
}, way_to_redeem).appendTo($reward);
$add_coupon_prefix.trigger('change');
break;
case 'free_shipping':
var $points_cost = azd.create_parameter('points_cost', {
type: 'number',
default: '500',
units: azd.i18n.points,
label: azd.i18n.points_cost,
}, way_to_redeem).appendTo($reward);
var $set_maximum_shipping_amount = azd.create_parameter('set_maximum_shipping_amount', {
type: 'checkbox',
label: azd.i18n.set_a_maximum_shipping_amount_this_reward_can_be_applied_to,
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$maximum_shipping_amount.show();
} else {
$maximum_shipping_amount.hide();
}
});
var $maximum_shipping_amount = azd.create_parameter('maximum_shipping_amount', {
type: 'number',
default: '25',
units: azd.currency,
}, way_to_redeem).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(way_to_redeem));
});
$set_maximum_shipping_amount.trigger('change');
var $add_coupon_prefix = azd.create_parameter('add_coupon_prefix', {
type: 'checkbox',
label: azd.i18n.add_a_prefix_to_discount_codes,
}, way_to_redeem).appendTo($reward).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$coupon_prefix.show();
} else {
$coupon_prefix.hide();
}
});
var $coupon_prefix = azd.create_parameter('coupon_prefix', {
type: 'text',
placeholder: 'e.g. $10OFF-',
description: azd.i18n.coupon_prefix_description
}, way_to_redeem).appendTo($reward);
$add_coupon_prefix.trigger('change');
break;
}
});
$('#referrals').on('azd-show', function (event, data) {
var $dialog = $(this);
var referrals = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=referrals", function (result) {
function save() {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=referrals", {
object: referrals
}, function (result) {
$('.azd-loader').fadeOut();
});
}
$('.azd-loader').fadeOut();
referrals = JSON.parse(result);
if (referrals.customer !== false && referrals.customer !== 'false' && referrals.customer) {
$dialog.find('.azd-customer-reward').show();
$dialog.find('.azd-customer-reward .azd-reward-details').html(get_reward_summary(referrals.customer));
$dialog.find('.azd-add-customer-reward').hide();
} else {
$dialog.find('.azd-customer-reward').hide();
$dialog.find('.azd-add-customer-reward').show();
}
$dialog.find('.azd-add-customer-reward .azd-btn').off('click').on('click', function () {
azd.open_simple_modal({
title: azd.i18n.select_customer_reward,
options: azd.referral_customer_rewards
}, '', function (reward) {
referrals.customer = {reward: reward};
$('[href="#add-referral-reward"].azd-dialog-toggle').trigger('click', {
type: 'customer',
referrals: referrals
});
});
return false;
});
$dialog.find('.azd-customer-reward .azd-actions .azd-edit').off('click').on('click', function () {
$('[href="#add-referral-reward"].azd-dialog-toggle').trigger('click', {
type: 'customer',
referrals: referrals
});
return false;
});
$dialog.find('.azd-customer-reward .azd-actions .azd-delete').off('click').on('click', function () {
referrals.customer = false;
save();
$('.azd-customer-reward').hide();
$('.azd-add-customer-reward').show();
return false;
});
if (referrals.friend !== false && referrals.friend !== 'false' && referrals.friend) {
$dialog.find('.azd-friend-reward').show();
$dialog.find('.azd-friend-reward .azd-reward-details').html(get_reward_summary(referrals.friend));
$dialog.find('.azd-add-friend-reward').hide();
} else {
$dialog.find('.azd-friend-reward').hide();
$dialog.find('.azd-add-friend-reward').show();
}
$dialog.find('.azd-add-friend-reward .azd-btn').off('click').on('click', function () {
azd.open_simple_modal({
title: azd.i18n.select_friend_reward,
options: azd.referral_friend_rewards
}, '', function (reward) {
referrals.friend = {reward: reward};
$('[href="#add-referral-reward"].azd-dialog-toggle').trigger('click', {
type: 'friend',
referrals: referrals
});
});
return false;
});
$dialog.find('.azd-friend-reward .azd-actions .azd-edit').off('click').on('click', function () {
$('[href="#add-referral-reward"].azd-dialog-toggle').trigger('click', {
type: 'friend',
referrals: referrals
});
return false;
});
$dialog.find('.azd-friend-reward .azd-actions .azd-delete').off('click').on('click', function () {
referrals.friend = false;
save();
$('.azd-friend-reward').hide();
$('.azd-add-friend-reward').show();
return false;
});
var $status = $dialog.find('.azd-referrals-status').empty();
azd.create_parameter('status', {
type: 'checkbox',
label: azd.i18n.active,
}, referrals).appendTo($status).on('change', save);
});
});
$('#add-referral-reward').on('azd-show', function (event, data) {
var $dialog = $(this);
var referrals = {};
var type = false;
if (data && data.data && data.data.referrals) {
referrals = $.extend({}, data.data.referrals);
}
if (data && data.data && data.data.type) {
type = data.data.type;
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=referrals", {
object: referrals
}, function (result) {
$('.azd-loader').fadeOut();
$('[href="#referrals"].azd-dialog-toggle').trigger('click');
});
data.data.referrals = referrals;
});
switch (type) {
case 'customer':
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.referral_customer_rewards[referrals.customer.reward]);
break;
case 'friend':
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.referral_friend_rewards[referrals.friend.reward]);
break;
}
var $summary = $dialog.find('.azd-summary').empty();
var $reward = $dialog.find('.azd-reward').empty();
switch (referrals[type].reward) {
case 'percentage_off':
case 'amount_discount':
azd.create_parameter('discount_value', {
type: 'number',
default: '5',
units: ((referrals[type].reward == 'percentage_off') ? '%' : azd.currency),
label: azd.i18n.discount_value,
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
});
var $applies_to = azd.create_parameter('applies_to', {
type: 'radio',
label: azd.i18n.applies_to,
options: {
entire_order: azd.i18n.entire_order,
specific_collection: azd.i18n.specific_collection,
},
default: 'entire_order'
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
$specific_collection.hide();
switch ($applies_to.find('[name="applies_to"]:checked').attr('value')) {
case 'entire_order':
break;
case 'specific_collection':
$specific_collection.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $specific_collection = azd.create_parameter('specific_collection', {
type: 'ajax_dropdown',
label: azd.i18n.select_collection,
placeholder: azd.i18n.search,
url: azd.ajaxurl + "?action=ajax-dropdown&type=custom_collections|smart_collections&field=id"
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
});
$applies_to.trigger('change');
var $minimum_requirement = azd.create_parameter('minimum_requirement', {
type: 'radio',
label: azd.i18n.minimum_requirement,
options: {
none: azd.i18n.none,
minimum_purchase_amount: azd.i18n.minimum_purchase_amount,
},
default: 'none'
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
$minimum_purchase_amount.hide();
switch ($minimum_requirement.find('[name="minimum_requirement"]:checked').attr('value')) {
case 'none':
break;
case 'minimum_purchase_amount':
$minimum_purchase_amount.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $minimum_purchase_amount = azd.create_parameter('minimum_purchase_amount', {
type: 'number',
units: azd.currency,
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
});
$minimum_requirement.trigger('change');
var $add_coupon_prefix = azd.create_parameter('add_coupon_prefix', {
type: 'checkbox',
label: azd.i18n.add_a_prefix_to_discount_codes,
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$coupon_prefix.show();
} else {
$coupon_prefix.hide();
}
});
var $coupon_prefix = azd.create_parameter('coupon_prefix', {
type: 'text',
placeholder: 'e.g. $10OFF-',
description: azd.i18n.coupon_prefix_description
}, referrals[type]).appendTo($reward);
$add_coupon_prefix.trigger('change');
break;
case 'free_shipping':
var $set_maximum_shipping_amount = azd.create_parameter('set_maximum_shipping_amount', {
type: 'checkbox',
label: azd.i18n.set_a_maximum_shipping_amount_this_reward_can_be_applied_to,
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$maximum_shipping_amount.show();
} else {
$maximum_shipping_amount.hide();
}
});
var $maximum_shipping_amount = azd.create_parameter('maximum_shipping_amount', {
type: 'number',
default: '25',
units: azd.currency,
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
});
$set_maximum_shipping_amount.trigger('change');
var $add_coupon_prefix = azd.create_parameter('add_coupon_prefix', {
type: 'checkbox',
label: azd.i18n.add_a_prefix_to_discount_codes,
}, referrals[type]).appendTo($reward).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$coupon_prefix.show();
} else {
$coupon_prefix.hide();
}
});
var $coupon_prefix = azd.create_parameter('coupon_prefix', {
type: 'text',
placeholder: 'e.g. $10OFF-',
description: azd.i18n.coupon_prefix_description
}, referrals[type]).appendTo($reward);
$add_coupon_prefix.trigger('change');
break;
case 'points':
azd.create_parameter('points_value', {
type: 'number',
default: '5',
units: azd.i18n.points,
label: azd.i18n.points_value,
}, referrals[type]).appendTo($reward).on('change', function () {
$summary.html(get_reward_summary(referrals[type]));
}).trigger('change');
break;
}
});
$('#customers').on('azd-show', function (event, data) {
var $dialog = $(this);
var columns = [
{sName: "first_name", sTitle: azd.i18n.first_name, orderable: false},
{sName: "last_name", sTitle: azd.i18n.last_name, orderable: false},
{sName: "email", sTitle: azd.i18n.email, orderable: false},
{sName: "points", sTitle: azd.i18n.points, sClass: 'azd-points', orderable: false},
{sName: "referrals", sTitle: azd.i18n.referrals, sClass: 'azd-referrals', orderable: false},
{sName: "id", sTitle: azd.i18n.referral_url, sClass: 'azd-referral-url', orderable: false},
];
if ($dialog.find('table.azd-datatable:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-datatable:not(.dataTable)'), columns, azd.ajaxurl + "?action=get_datatable_all&type=customer&metafields=yes", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-points').each(function () {
var row = convert_table_item(this);
var $points = $(this);
if (row.points) {
row.points = JSON.parse(row.points);
} else {
row.points = {total: 0};
}
$points.empty();
$(' ').appendTo($points).on('change', function () {
$.post(azd.ajaxurl + "?action=set_user_points", {
user_id: row.id,
points: $(this).val()
}, function (result) {
});
});
});
$table.find('tbody tr .azd-referrals').each(function () {
var row = convert_table_item(this);
var $referrals = $(this);
if (row.referrals) {
row.referrals = JSON.parse(row.referrals);
} else {
row.referrals = {friends: []};
}
var referrals = 0;
if(row.referrals.friends) {
referrals = row.referrals.friends.length;
}
$referrals.text(referrals);
});
$table.find('tbody tr .azd-referral-url').each(function () {
var row = convert_table_item(this);
$(this).html('https://' + azd.domain + '?ref=' + row.id + ' ');
});
});
} else {
$dialog.find('table.azd-datatable').DataTable().ajax.reload();
}
});
$('#widget-styles').on('azd-show', function (event, data) {
var $dialog = $(this);
var obj = {};
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=get_single_object&type=widget-styles", function (result) {
function refresh_css() {
var widget_css = azexo_templates['widget-css'];
widget_css = window.azexo_prepare_css(widget_css, obj);
style.innerHTML = '';
style.appendChild(document.createTextNode(widget_css));
}
function refresh_button() {
container.querySelector('#launcher-wrapper').style.bottom = obj.bottom_padding;
container.querySelector('.sh-messenger-frame').style.bottom = 'calc(70px + ' + obj.bottom_padding + ')';
switch (obj.placement) {
case 'bottom_left':
container.querySelector('#launcher-wrapper').style.left = obj.side_padding;
container.querySelector('#launcher-wrapper').style.right = 'auto';
container.querySelector('.sh-messenger-frame').style.left = obj.side_padding;
container.querySelector('.sh-messenger-frame').style.right = 'auto';
break;
case 'bottom_right':
container.querySelector('#launcher-wrapper').style.left = 'auto';
container.querySelector('#launcher-wrapper').style.right = obj.side_padding;
container.querySelector('.sh-messenger-frame').style.left = 'auto';
container.querySelector('.sh-messenger-frame').style.right = obj.side_padding;
break;
}
}
$('.azd-loader').fadeOut();
obj = JSON.parse(result);
var $content = $dialog.find('> .azd-content');
var $colors = $content.find('.azd-colors').empty();
var $button = $content.find('.azd-button').empty();
var preview = $content.find('.azd-preview').get(0);
preview.innerHTML = '';
var host = document.createElement('div');
var shadow = host.attachShadow({mode: 'open'});
var container = document.createElement('div');
container.innerHTML = azexo_templates['widget'];
shadow.appendChild(container);
var style = document.createElement('style');
style.type = 'text/css';
container.prepend(style);
refresh_css();
container.style.height = '1000px';
container.style['pointer-events'] = 'none';
preview.append(host);
window.azexo_widget_init(container);
azd.create_parameter('header_background', {
type: 'color',
label: azd.i18n.header_background,
default: '#8224E3',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('header_text_color', {
type: 'color',
label: azd.i18n.header_text_color,
default: '#FFF',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('title_color', {
type: 'color',
label: azd.i18n.title_color,
default: '#212B36',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('description_color', {
type: 'color',
label: azd.i18n.description_color,
default: '#737376',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('button_background', {
type: 'color',
label: azd.i18n.button_background,
default: '#8224E3',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('button_text_color', {
type: 'color',
label: azd.i18n.button_text_color,
default: '#FFF',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('widget_button_background', {
type: 'color',
label: azd.i18n.widget_button_background,
default: '#8224E3',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('widget_button_text_color', {
type: 'color',
label: azd.i18n.widget_button_text_color,
default: '#FFF',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('link_color', {
type: 'color',
label: azd.i18n.link_color,
default: '#8224E3',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('icon_color', {
type: 'color',
label: azd.i18n.icon_color,
default: '#3A3A3A',
}, obj).appendTo($colors).on('change', function () {
refresh_css();
});
azd.create_parameter('placement', {
type: 'radio',
label: azd.i18n.placement,
options: {
bottom_left: azd.i18n.bottom_left,
bottom_right: azd.i18n.bottom_right,
},
default: 'bottom_right'
}, obj).appendTo($button).find('.azd-radio').addClass('azd-vertical').on('change', function () {
refresh_button();
});
azd.create_parameter('side_padding', {
type: 'integer',
units: 'px',
step: '1',
min: '0',
default: '20px',
label: azd.i18n.side_padding
}, obj).appendTo($button).on('change', function () {
refresh_button();
});
azd.create_parameter('bottom_padding', {
type: 'integer',
units: 'px',
step: '1',
min: '0',
default: '20px',
label: azd.i18n.bottom_padding
}, obj).appendTo($button).on('change', function () {
refresh_button();
});
});
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
$.post(azd.ajaxurl + "?action=save_single_object&type=widget-styles", {
object: obj
}, function (result) {
$('.azd-loader').fadeOut();
});
});
});
$('#newsletters').on('azd-show', function (event, data) {
var $dialog = $(this);
var columns = [
{sName: "id", bVisible: false},
{sName: "preview_text", bVisible: false},
{sName: "sections", bVisible: false},
{sName: "sent", bVisible: false},
{sName: "delivery", bVisible: false},
{sName: "open", bVisible: false},
{sName: "click", bVisible: false},
{sName: "unsubscribe", bVisible: false},
{sName: "complaint", bVisible: false},
{sName: "bounce", bVisible: false},
{sName: "schedule", bVisible: false},
{sName: "schedule_time", bVisible: false},
{sName: "recipients", bVisible: false},
{sName: "recipients_groups", bVisible: false},
{sName: "subject", sTitle: azd.i18n.subject, orderable: false},
{sName: "status", sTitle: azd.i18n.status, orderable: false},
{sName: "actions", sTitle: azd.i18n.actions, sClass: 'azd-actions', orderable: false}
];
if ($dialog.find('table.azd-datatable:not(.dataTable)').length) {
azd.init_datatable($dialog.find('table.azd-datatable:not(.dataTable)'), columns, azd.ajaxurl + "?action=objects_datatable&type=newsletter", function ($table, datatable) {
function convert_table_item(tr) {
var columns_index = {};
columns.map(function (column, i) {
columns_index[column.sName] = i;
});
var item = {};
for (var name in columns_index) {
item[name] = datatable.row(tr).data()[columns_index[name]];
}
return item;
}
$table.find('tbody tr .azd-actions').each(function () {
var row = convert_table_item(this);
var $actions = $(this);
$(' ' + azd.i18n.edit + ' ').appendTo($actions).on('click', function () {
$('[href="#create-newsletter"].azd-dialog-toggle').trigger('click', {
datatable: datatable,
newsletter: row
});
return false;
});
if (row.status == 'sent') {
$.get(azd.ajaxurl + "?action=get_marketing_event&type=newsletter&id=" + row.id, function (data) {
data = JSON.parse(data);
if (data) {
$(' ' + azd.i18n.view_report + ' ').appendTo($actions);
}
});
} else {
$(' ' + azd.i18n.customize + ' ').appendTo($actions).on('click', function () {
azd.open_dialog('#customize-email', {}, {
datatable: datatable,
type: 'newsletter',
email: row
});
return false;
});
$(' ' + azd.i18n.delete + ' ').appendTo($actions).on('click', function () {
$.get(azd.ajaxurl + "?action=delete_object&type=newsletter&id=" + row.id, function (data) {
datatable.ajax.reload();
});
return false;
});
}
});
});
} else {
$dialog.find('table.azd-datatable').DataTable().ajax.reload();
}
});
$('#create-newsletter').on('azd-show', function (event, data) {
function show_customize_button() {
$dialog.find('.azd-dialog-header .azd-customize').off('click').on('click', function () {
azd.open_dialog('#customize-email', {}, {
datatable: false,
type: 'newsletter',
email: newsletter
});
return false;
}).show();
}
var $dialog = $(this);
var newsletter = {};
if (data && data.data && data.data.newsletter) {
newsletter = $.extend({}, data.data.newsletter);
$dialog.find('.azd-dialog-header .azd-page-title span').text(newsletter.subject);
} else {
$dialog.find('.azd-dialog-header .azd-page-title span').text(azd.i18n.create_newsletter);
newsletter.sections = [{
"id": "ifLxFTILrJ",
"hidden": "false",
"name": "header",
"js": "https://azexo.com/shopify/email_sections/header.js",
"preheader_text": "Thanks for being subscribed to " + azd.shop_name + ".",
"logo": "hide",
"logo_width": "200px"
}, {
"id": "mABqwpiEiE",
"hidden": "false",
"name": "footer",
"js": "https://azexo.com/shopify/email_sections/footer.js",
"policies": "",
"reply_email": "false",
"business_address": "true",
"customer_service_phone": "false"
}];
}
if (newsletter.status == 'draft') {
show_customize_button();
} else {
$dialog.find('.azd-dialog-header .azd-customize').hide();
}
$dialog.find('.azd-dialog-header .azd-save').off('click').on('click', function () {
$('.azd-loader').fadeIn();
if (!newsletter.status) {
newsletter.status = 'draft';
}
$.post(azd.ajaxurl + "?action=save_object&type=newsletter", {
object: newsletter
}, function (result) {
$('.azd-loader').fadeOut();
if (data && data.data && data.data.datatable) {
data.data.datatable.ajax.reload();
}
if (!newsletter.id) {
result = JSON.parse(result);
for (var k in result) {
newsletter[k] = result[k];
}
}
if (newsletter.status == 'draft') {
show_customize_button();
if (newsletter.schedule === true || newsletter.schedule === 'true') {
$.get(azd.ajaxurl + "?action=email_schedule&type=newsletter&id=" + newsletter.id + '&time=' + newsletter.schedule_time);
} else {
$.get(azd.ajaxurl + "?action=email_unschedule&type=newsletter&id=" + newsletter.id);
}
}
});
if (data && data.data) {
data.data.newsletter = newsletter;
}
});
var $content = $dialog.find('> .azd-content');
if (newsletter.sent && parseFloat(newsletter.sent) > 0) {
$dialog.find('.azd-delivery-rate').text(Math.floor(parseFloat(newsletter.delivery ? newsletter.delivery : 0) / parseFloat(newsletter.sent) * 100) + '%');
$dialog.find('.azd-open-rate').text(Math.floor(parseFloat(newsletter.open ? newsletter.open : 0) / parseFloat(newsletter.sent) * 100) + '%');
$dialog.find('.azd-click-rate').text(Math.floor(parseFloat(newsletter.click ? newsletter.click : 0) / parseFloat(newsletter.sent) * 100) + '%');
$dialog.find('.azd-unsubscribe-rate').text(Math.floor(parseFloat(newsletter.unsubscribe ? newsletter.unsubscribe : 0) / parseFloat(newsletter.sent) * 100) + '%');
$dialog.find('.azd-complaint-rate').text(Math.floor(parseFloat(newsletter.complaint ? newsletter.complaint : 0) / parseFloat(newsletter.sent) * 100) + '%');
$dialog.find('.azd-bounce-rate').text(Math.floor(parseFloat(newsletter.bounce ? newsletter.bounce : 0) / parseFloat(newsletter.sent) * 100) + '%');
} else {
$dialog.find('.azd-delivery-rate').text('0%');
$dialog.find('.azd-open-rate').text('0%');
$dialog.find('.azd-click-rate').text('0%');
$dialog.find('.azd-unsubscribe-rate').text('0%');
$dialog.find('.azd-complaint-rate').text('0%');
$dialog.find('.azd-bounce-rate').text('0%');
}
var $details = $content.find('.azd-details').empty();
sections_preview($content.find('.azd-prevew'), newsletter.sections, azd.email_styles);
azd.create_parameter('subject', {
type: 'text',
label: azd.i18n.subject
}, newsletter).appendTo($details);
azd.create_parameter('preview_text', {
type: 'text',
label: azd.i18n.preview_text
}, newsletter).appendTo($details);
var $schedule = azd.create_parameter('schedule', {
type: 'checkbox',
label: azd.i18n.schedule_time_to_send_newsletter,
}, newsletter).appendTo($details).on('change', function () {
if ($(this).find('input[type="checkbox"]').prop('checked')) {
$schedule_time.show();
} else {
$schedule_time.hide();
}
});
var $schedule_time = azd.create_parameter('schedule_time', {
type: 'datetime',
}, newsletter).appendTo($details);
$schedule.trigger('change');
var $recipients = azd.create_parameter('recipients', {
type: 'radio',
label: azd.i18n.recipients,
description: azd.i18n.recipients_description,
options: {
all: azd.i18n.all_customers,
groups: azd.i18n.specific_groups_of_customers,
},
default: 'all'
}, newsletter).appendTo($details).on('change', function () {
switch ($recipients.find('[name="recipients"]:checked').attr('value')) {
case 'all':
$recipients_groups.hide();
break;
case 'groups':
$recipients_groups.show();
break;
}
}).find('.azd-radio').addClass('azd-vertical');
var $recipients_groups = $('
').appendTo($details);
if (!newsletter['recipients_groups']) {
newsletter['recipients_groups'] = {};
}
azd.customer_saved_searches.forEach(function (customer_saved_search) {
azd.create_parameter(customer_saved_search.name, {
type: 'checkbox',
label: customer_saved_search.name,
}, newsletter['recipients_groups']).appendTo($recipients_groups);
});
$recipients.trigger('change');
$('' + azd.i18n.send_now + ' ').appendTo($details).on('click', function () {
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=email_send_now&type=newsletter&id=" + newsletter.id, function (result) {
$('.azd-loader').fadeOut();
});
});
$('' + azd.i18n.send_test_email + ' ').appendTo($details).on('click', function () {
$('.azd-loader').fadeIn();
$.get(azd.ajaxurl + "?action=email_test&type=newsletter&id=" + newsletter.id, function (result) {
$('.azd-loader').fadeOut();
});
});
});
setTimeout(function () {
azd.email_sections.forEach(function (section) {
if (!section.js_included) {
$('head').append('