settings.js
104 lines
| 1 | /** |
| 2 | * General |
| 3 | * @author Webcraftic <wordpress.webraftic@gmail.com> |
| 4 | * @copyright (c) 2020, Webcraftic |
| 5 | * @version 1.0 |
| 6 | */ |
| 7 | |
| 8 | (function ($) { |
| 9 | |
| 10 | $(document).on('click', '.wdan-page-restore-notice-link', function () { |
| 11 | var self = $(this), |
| 12 | noticeID = $(this).data('notice-id'), |
| 13 | nonce = $(this).data('nonce'), |
| 14 | counterEl = $('.wbcr-han-adminbar-counter'); |
| 15 | |
| 16 | if (!noticeID) { |
| 17 | alert('Undefinded error. Please report the bug to our support forum.'); |
| 18 | } |
| 19 | |
| 20 | self.hide(); |
| 21 | self.parent().find('.wdan-page-restore-notice-link-loader').show(); |
| 22 | |
| 23 | |
| 24 | $.ajax(ajaxurl, { |
| 25 | type: 'post', |
| 26 | dataType: 'json', |
| 27 | data: { |
| 28 | action: 'wbcr-dan-restore-notice', |
| 29 | security: nonce, |
| 30 | notice_id: noticeID |
| 31 | }, |
| 32 | success: function (response) { |
| 33 | if (!response || !response.success) { |
| 34 | |
| 35 | if (response.data.error_message) { |
| 36 | self.closest('li').show(); |
| 37 | } else { |
| 38 | } |
| 39 | |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | counterEl.text(counterEl.text() - 1); |
| 44 | self.closest('tr').hide(); |
| 45 | self.closest('tr').remove(); |
| 46 | }, |
| 47 | error: function (xhr, ajaxOptions, thrownError) { |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | return false; |
| 52 | }); |
| 53 | |
| 54 | $('.wdan-checkbox.adminbar-items').change(function() { |
| 55 | let menuID = $(this).data('menu-id'), |
| 56 | isChecked = $(this).find('.factory-result').is(":checked"); |
| 57 | |
| 58 | if( !isChecked ) { |
| 59 | $('#wp-admin-bar-' + menuID).hide(); |
| 60 | } else { |
| 61 | $('#wp-admin-bar-' + menuID).show(); |
| 62 | } |
| 63 | |
| 64 | $.ajax(ajaxurl, { |
| 65 | type: 'post', |
| 66 | dataType: 'json', |
| 67 | data: { |
| 68 | action: 'wdan-disable-adminbar-menus', |
| 69 | menu_id: menuID, |
| 70 | enable_menu: isChecked, |
| 71 | _wpnonce: $(this).data('nonce') |
| 72 | }, |
| 73 | success: function(result, textStatus, jqXHR) { |
| 74 | var noticeId, successNoticeID; |
| 75 | |
| 76 | if( !result || !result.success ) { |
| 77 | |
| 78 | if( result.data && result.data.error_message ) { |
| 79 | noticeId = $.wbcr_factory_clearfy_000.app.showNotice(result.data.error_message, 'danger'); |
| 80 | setTimeout(function() { |
| 81 | $.wbcr_factory_clearfy_000.app.hideNotice(noticeId); |
| 82 | }, 5000); |
| 83 | |
| 84 | } |
| 85 | |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | successNoticeID = $.wbcr_factory_clearfy_000.app.showNotice(result.data.success_message, 'success'); |
| 90 | setTimeout(function() { |
| 91 | $.wbcr_factory_clearfy_000.app.hideNotice(successNoticeID); |
| 92 | }, 2000); |
| 93 | |
| 94 | }, |
| 95 | error: function(xhr, ajaxOptions, thrownError) { |
| 96 | |
| 97 | var noticeId = $.wbcr_factory_clearfy_000.app.showNotice('Error: [' + thrownError + '] Status: [' + xhr.status + '] Error massage: [' + xhr.responseText + ']', 'danger'); |
| 98 | } |
| 99 | }); |
| 100 | |
| 101 | }); |
| 102 | |
| 103 | })(jQuery); |
| 104 |