| @@ -2,8 +2,13 @@ | ||
| 2 | 2 | (function ($) { |
| 3 | 3 | 'use strict'; |
| 4 | 4 | jQuery(document).ready(function ($) { |
| 5 | 5 | wdk_dependfields_update('form.wdk-depend-fields'); |
| 6 | + | |
| 7 | + $('.wdk_copy_on_subcategories').on('click', function(e){ | |
| 8 | + e.preventDefault(); | |
| 9 | + wdk_copy_on_subcategories($(this).attr('data-category'), this, $(this).attr('data-wpnonce')); | |
| 10 | + }); | |
| 6 | 11 | }); |
| 7 | 12 | })(jQuery); |
| 8 | 13 | |
| 9 | 14 | var wdk_dependfields_update_jqxhr = null; |
| @@ -66,8 +71,9 @@ | ||
| 66 | 71 | var data = new Array(); |
| 67 | 72 | data.push({ name: 'action', value: "wdk_admin_action" }); |
| 68 | 73 | data.push({ name: 'page', value: "wdk_backendajax" }); |
| 69 | 74 | data.push({ name: 'function', value: "update_depend" }); |
| 75 | + data.push({ name: '_wpnonce', value: this_form.find('input[name="_wpnonce"]').val() }); | |
| 70 | 76 | data.push({ name: 'main_field', value: this_form.find('input[name="main_field"]').val() }); |
| 71 | 77 | data.push({ name: 'field_id', value: this_form.find('input[name="field_id"]').val() }); |
| 72 | 78 | |
| 73 | 79 | this_form.find('input:not(:checked)').each(function(){ |
| @@ -80,8 +86,9 @@ | ||
| 80 | 86 | if (wdk_dependfields_update_jqxhr != null) |
| 81 | 87 | wdk_dependfields_update_jqxhr.abort(); |
| 82 | 88 | |
| 83 | 89 | loading_el.addClass('wdk_btn_load_indicator out'); |
| 90 | + | |
| 84 | 91 | wdk_dependfields_update_jqxhr = jQuery.post(script_dependfields_parameters.ajax_url, data, function (data) { |
| 85 | 92 | |
| 86 | 93 | |
| 87 | 94 | }).always(function(data) { |
| @@ -87,5 +94,32 @@ | ||
| 87 | 94 | }).always(function(data) { |
| 88 | 95 | loading_el.removeClass('wdk_btn_load_indicator out'); |
| 89 | 96 | }); |
| 90 | 97 | }) |
| 98 | + } | |
| 99 | + | |
| 100 | + var wdk_copy_on_subcategories_jqxhr = null; | |
| 101 | + const wdk_copy_on_subcategories = ($category_id = null, el, $_wpnonce) => { | |
| 102 | + | |
| 103 | + if(!$category_id) return false; | |
| 104 | + | |
| 105 | + var el = jQuery(el); | |
| 106 | + | |
| 107 | + //var data = this_form.serializeArray(); | |
| 108 | + var data = new Array(); | |
| 109 | + data.push({ name: 'action', value: "wdk_admin_action" }); | |
| 110 | + data.push({ name: 'page', value: "wdk_backendajax" }); | |
| 111 | + data.push({ name: 'function', value: "depend_copy_on_subcategories" }); | |
| 112 | + data.push({ name: 'category_id', value: $category_id }); | |
| 113 | + data.push({ name: '_wpnonce', value: $_wpnonce }); | |
| 114 | + | |
| 115 | + // and remember the jqxhr object for this request | |
| 116 | + if (wdk_copy_on_subcategories_jqxhr != null) | |
| 117 | + wdk_copy_on_subcategories_jqxhr.abort(); | |
| 118 | + | |
| 119 | + el.addClass('wdk_btn_load_indicator out'); | |
| 120 | + wdk_copy_on_subcategories_jqxhr = jQuery.post(script_dependfields_parameters.ajax_url, data, function (data) { | |
| 121 | + console.log('success copied') | |
| 122 | + }).always(function(data) { | |
| 123 | + el.removeClass('wdk_btn_load_indicator out'); | |
| 124 | + }); | |
| 91 | 125 | } |