ad-types.js
3 months ago
code-highlighter.js
3 months ago
editing.css
3 months ago
editing.js
3 months ago
listing.css
1 week ago
listing.js
3 months ago
placement-box.js
3 months ago
quick-bulk-edit.js
1 week ago
quick-bulk-edit.js
102 lines
| 1 | import jQuery from 'jquery'; |
| 2 | |
| 3 | /** |
| 4 | * Retrieves ad data for a given ID using AJAX. |
| 5 | * |
| 6 | * @param {number} id - The ID of the ad. |
| 7 | * |
| 8 | * @return {void} |
| 9 | */ |
| 10 | function getAdData(id) { |
| 11 | const adVar = `ad_json_${id}`; |
| 12 | const adData = window[adVar]; |
| 13 | |
| 14 | if (!adData) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | fillInputs(id, adData); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Fills the input fields in the specified row with the provided data. |
| 23 | * |
| 24 | * @param {number} id - The ID of the row. |
| 25 | * @param {Object} data - The data to fill the input fields with. |
| 26 | * |
| 27 | * @return {void} |
| 28 | */ |
| 29 | function fillInputs(id, data) { |
| 30 | const theRow = jQuery(`#edit-${id}`); |
| 31 | theRow.find('.advads-quick-edit').prop('disabled', false); |
| 32 | theRow.find('[name="debugmode"]').prop('checked', data.debug_mode); |
| 33 | |
| 34 | if (data.expiry.expires) { |
| 35 | theRow.find('[name="enable_expiry"]').prop('checked', true); |
| 36 | const inputs = theRow.find('.expiry-inputs').show(); |
| 37 | for (const key in data.expiry.expiry_date) { |
| 38 | inputs.find(`[name="${key}"]`).val(data.expiry.expiry_date[key]); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // Privacy module enabled. |
| 43 | const privacyCheckbox = theRow.find('[name="ignore_privacy"]'); |
| 44 | if (privacyCheckbox.length) { |
| 45 | privacyCheckbox.prop('checked', data.ignore_privacy); |
| 46 | } |
| 47 | |
| 48 | // Ad label. |
| 49 | const adLabel = theRow.find('[name="ad_label"]'); |
| 50 | if (adLabel.length) { |
| 51 | adLabel.val(data.ad_label); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Allow add-ons to do field initialization |
| 56 | */ |
| 57 | wp.hooks.doAction('advanced-ads-quick-edit-fields-init', id, data); |
| 58 | } |
| 59 | |
| 60 | export default function QuickBulkEdit() { |
| 61 | /* eslint-disable no-undef */ |
| 62 | const editCopy = window.inlineEditPost.edit; |
| 63 | |
| 64 | // Replace the default WP function |
| 65 | window.inlineEditPost.edit = function (id) { |
| 66 | /* eslint-enable no-undef */ |
| 67 | // Call the original WP edit function. |
| 68 | editCopy.apply(this, arguments); |
| 69 | |
| 70 | // Now we do our stuff. |
| 71 | if ('object' === typeof id) { |
| 72 | getAdData(parseInt(this.getId(id), 10)); |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | // Show/hide expiry date inputs on bulk edit. |
| 77 | jQuery(document).on( |
| 78 | 'change', |
| 79 | '.advads-bulk-edit [name="expiry_date"]', |
| 80 | function () { |
| 81 | const select = jQuery(this); |
| 82 | select |
| 83 | .closest('fieldset') |
| 84 | .find('.expiry-inputs') |
| 85 | .css('display', 'on' === select.val() ? 'block' : 'none'); |
| 86 | } |
| 87 | ); |
| 88 | |
| 89 | // Show/hide expiry date inputs on quick edit. |
| 90 | jQuery(document).on('click', '[name="enable_expiry"]', function () { |
| 91 | const checkbox = jQuery(this); |
| 92 | checkbox |
| 93 | .closest('fieldset') |
| 94 | .find('.expiry-inputs') |
| 95 | .css('display', checkbox.prop('checked') ? 'block' : 'none'); |
| 96 | }); |
| 97 | |
| 98 | jQuery(function () { |
| 99 | jQuery('.inline-edit-group select option[value="private"]').remove(); |
| 100 | }); |
| 101 | } |
| 102 |