(function ($) { /** * drag and drop priority maker */ $("#sortable").sortable({ axis: 'y', stop: function (event, ui) { var data = $(this).sortable('serialize'); console.log(data); $.ajax({ data: data, type: 'POST', url: rule_discount.ajax + '?action=aodfw_order_the_rules' }); } }); /** * Conditionorder total */ $(document).on('change', '.order-total-operator', function () { var value = $(this).val(); if (value === "between") { $(".order-min-max-val").addClass('show'); $(".order-total-value").addClass('hidden-field'); } else { $(".order-min-max-val").removeClass('show'); $(".order-total-value").removeClass('hidden-field'); } }); /** * tabs */ $(document).on('click', '.tabs li span', function () { $(".tab-container").hide(); var tab = $(this).data('tab'); $("#tab-" + tab).show(); var tabs = $(this).parents('.tabs').find('li'); tabs.removeClass('active'); $(this).parent('li').addClass('active'); }); $(document).on('click', '.navigate-btn', function () { $(".tab-container").hide(); var tab = $(this).data('show'); $("#tab-" + tab).show(); var tabs = $('.tabs').find('li'); tabs.removeClass('active'); $('#' + tab + '-tab-btn').addClass('active'); }); /** * Changing the status of rule */ $(document).on("change", ".status-btn", function () { var id = $(this).data("rule"); var status = 0; if ($(this).is(':checked')) { status = 1; } $.ajax({ url: rule_discount.ajax, type: 'post', data: {id: id, status: status, action: 'update_rule_status'}, success: function (result) { if (result.error) { notyAlert('error', result.message); } else { notyAlert('success', result.message); } } }) }); /** * remove rule */ $(document).on("click", ".delete-rule-btn", function () { var id = $(this).data("rule"); $.ajax({ url: rule_discount.ajax, type: 'post', data: {id: id, action: 'remove_rule'}, success: function (result) { if (result.error) { notyAlert('error', result.message); } else { notyAlert('success', result.message); } $("#rule-no-" + id).remove(); } }) }); /** * Notify the message */ function notyAlert(type, message) { new Noty({ text: message, theme: 'mint', type: type, layout: "bottomRight", timeout: 4000, }).show(); } /** * Save Rule */ $(document).on("submit", "#waod-rule", function (e) { e.preventDefault(); var path = $(this).data("path"); var button = $('input[name="save_rule"]'); button.attr("disabled", true); button.text(rule_discount.saving); $.ajax({ url: path, type: 'post', data: $(this).serialize(), success: function (result) { $("input[name='ID']").val(result.id); if (result.error) { notyAlert('error', result.message); } else { notyAlert('success', result.message); } button.text(rule_discount.save); button.attr("disabled", false); } }) }); /** * Save settings * */ $(document).on("submit", "#waod-settings", function (e) { e.preventDefault(); var path = $(this).data("path"); var button = $('input[name="save_settings"]'); button.attr("disabled", true); button.text(rule_discount.saving); $.ajax({ url: path, type: 'post', data: $(this).serialize(), success: function (result) { if (result.error) { notyAlert('error', result.message); } else { notyAlert('success', result.message); } button.text(rule_discount.save); button.attr("disabled", false); } }) }); /** * Show date picker */ $(document).ready(function () { let dateInput = $('input[data-datepicker="init"]'); dateInput.daterangepicker({ "autoUpdateInput": false, "timePicker": true, "singleDatePicker": true, "locale": { "format": "YYYY-MM-DD hh:mm:ss", } }); dateInput.on('apply.daterangepicker', function (ev, picker) { $(this).val(picker.startDate.format('YYYY-MM-DD hh:mm:ss')); }); }); /** * get conditions */ $(document).on('click', '.rule-type', function () { let rule_class = $(this).data('class'); let path = rule_discount.ajax; let action = 'get_rule_conditions'; let checkbox_container = $(".condition-checkboxes"); let discount_container = $(".discount-container"); checkbox_container.html(''); discount_container.html(''); $('input[name="class"]').val(rule_class); $('.condition').html(''); showLoader(); $.ajax({ url: path, type: 'post', data: { "action": action, "class": rule_class }, success: function (result) { if (!result.error) { checkbox_container.html(result.message.conditions); discount_container.html(result.message.discounts); } hideLoader(); } }); }); /** * Show loader */ function showLoader() { $(".wcd-preloader").show(); } /** * Hide loader */ function hideLoader() { $(".wcd-preloader").hide(); } /** * Check any conditions choosed */ function isAnyConditionsChoosed() { var anyBoxesChecked = false; $("input[type='checkbox'][name='used_conditions[]']").each(function () { if ($(this).is(":checked")) { anyBoxesChecked = true; } }); if (anyBoxesChecked === false) { $(".no-condition-message").addClass('show'); } else { $(".no-condition-message").removeClass('show'); } if ($('.condition-checkboxes input[type="checkbox"]:checked').length === $('.condition-checkboxes input[type="checkbox"]').length) { $(".no-more-conditions").addClass('show'); } else { $(".no-more-conditions").removeClass('show'); } } isAnyConditionsChoosed(); /** * render discounts and conditions based on rule type */ $(document).on("change", ".available-conditions", function () { let condition = $(this).val(); showLoader(); isAnyConditionsChoosed(); if ($(this).prop("checked") === true) { $("#label-" + condition).addClass('hidden'); let condition_class = $(this).data('class'); let path = rule_discount.ajax; let action = 'get_condition'; let field_container = $(".condition"); $.ajax({ url: path, type: 'post', data: { "action": action, "class": condition_class }, success: function (result) { field_container.append(result.message); hideLoader(); } }); } else { $("#label-" + condition).removeClass('hidden'); $(".box-" + condition).remove(); hideLoader(); } }); /** * Remove conditions */ $(document).on('click', '.remove-condition', function () { let condition = $(this).data('remove'); $(".box-" + condition).remove(); $("#label-" + condition).removeClass('hidden'); $("#input-" + condition).prop('checked', false); isAnyConditionsChoosed(); hideLoader(); }); $(document).on('click', '.clone-btn', function () { var section = $(this).data('clone'); var html_content = $(".cloneable-" + section); var html = html_content.html(); var id = $(this).data('next'); html = html.replace(/{i}/g, id); var content = '