vendor
5 days ago
connect.js
5 days ago
connect.min.js
5 days ago
smtp-about.js
5 days ago
smtp-about.min.js
5 days ago
smtp-activelayer-wc.js
5 days ago
smtp-activelayer-wc.min.js
5 days ago
smtp-admin-notices.js
5 days ago
smtp-admin-notices.min.js
5 days ago
smtp-admin.js
5 days ago
smtp-admin.min.js
5 days ago
smtp-ai-mcp.js
5 days ago
smtp-ai-mcp.min.js
5 days ago
smtp-code-snippets.js
5 days ago
smtp-code-snippets.min.js
5 days ago
smtp-dashboard-widget.js
5 days ago
smtp-dashboard-widget.min.js
5 days ago
smtp-notifications.js
5 days ago
smtp-notifications.min.js
5 days ago
smtp-recommendations.js
5 days ago
smtp-recommendations.min.js
5 days ago
smtp-tools-debug-events.js
5 days ago
smtp-tools-debug-events.min.js
5 days ago
smtp-tools-debug-events.js
361 lines
| 1 | /* global wp_mail_smtp_tools_debug_events, ajaxurl, flatpickr */ |
| 2 | /** |
| 3 | * WPMailSMTP Debug Events functionality. |
| 4 | * |
| 5 | * @since 3.0.0 |
| 6 | */ |
| 7 | |
| 8 | 'use strict'; |
| 9 | |
| 10 | var WPMailSmtpDebugEvents = window.WPMailSmtpDebugEvents || ( function( document, window, $ ) { |
| 11 | |
| 12 | /** |
| 13 | * Elements. |
| 14 | * |
| 15 | * @since 3.0.0 |
| 16 | * |
| 17 | * @type {object} |
| 18 | */ |
| 19 | var el = { |
| 20 | $debugEventsPage: $( '.wp-mail-smtp-tab-tools-debug-events' ), |
| 21 | $dateFlatpickr: $( '.wp-mail-smtp-filter-date-selector' ), |
| 22 | }; |
| 23 | |
| 24 | /** |
| 25 | * Public functions and properties. |
| 26 | * |
| 27 | * @since 3.0.0 |
| 28 | * |
| 29 | * @type {object} |
| 30 | */ |
| 31 | var app = { |
| 32 | |
| 33 | /** |
| 34 | * Start the engine. |
| 35 | * |
| 36 | * @since 3.0.0 |
| 37 | */ |
| 38 | init: function() { |
| 39 | |
| 40 | $( app.ready ); |
| 41 | }, |
| 42 | |
| 43 | /** |
| 44 | * Document ready. |
| 45 | * |
| 46 | * @since 3.0.0 |
| 47 | */ |
| 48 | ready: function() { |
| 49 | |
| 50 | app.initDateRange(); |
| 51 | app.events(); |
| 52 | |
| 53 | // Open debug event popup from the query string. |
| 54 | var searchParams = new URLSearchParams( location.search ); |
| 55 | |
| 56 | if ( searchParams.has( 'debug_event_id' ) ) { |
| 57 | app.openDebugEventPopup( searchParams.get( 'debug_event_id' ) ); |
| 58 | } |
| 59 | }, |
| 60 | |
| 61 | /** |
| 62 | * Register JS events. |
| 63 | * |
| 64 | * @since 3.0.0 |
| 65 | */ |
| 66 | events: function() { |
| 67 | |
| 68 | el.$debugEventsPage.on( 'click', '#wp-mail-smtp-reset-filter .reset', app.resetFilter ); |
| 69 | el.$debugEventsPage.on( 'click', '#wp-mail-smtp-delete-all-debug-events-button', app.deleteAllDebugEvents ); |
| 70 | el.$debugEventsPage.on( 'click', '.js-wp-mail-smtp-debug-event-preview', app.eventClicked ); |
| 71 | }, |
| 72 | |
| 73 | /** |
| 74 | * Init Flatpickr at Date Range field. |
| 75 | * |
| 76 | * @since 3.0.0 |
| 77 | */ |
| 78 | initDateRange: function() { |
| 79 | |
| 80 | var langCode = wp_mail_smtp_tools_debug_events.lang_code, |
| 81 | flatpickrLocale = { |
| 82 | rangeSeparator: ' - ', |
| 83 | }; |
| 84 | |
| 85 | if ( |
| 86 | flatpickr !== 'undefined' && |
| 87 | Object.prototype.hasOwnProperty.call( flatpickr, 'l10ns' ) && |
| 88 | Object.prototype.hasOwnProperty.call( flatpickr.l10ns, langCode ) |
| 89 | ) { |
| 90 | flatpickrLocale = flatpickr.l10ns[ langCode ]; |
| 91 | flatpickrLocale.rangeSeparator = ' - '; |
| 92 | } |
| 93 | |
| 94 | el.$dateFlatpickr.flatpickr( { |
| 95 | altInput : true, |
| 96 | altFormat : 'M j, Y', |
| 97 | dateFormat: 'Y-m-d', |
| 98 | locale : flatpickrLocale, |
| 99 | mode : 'range' |
| 100 | } ); |
| 101 | }, |
| 102 | |
| 103 | /** |
| 104 | * Reset filter handler. |
| 105 | * |
| 106 | * @since 3.0.0 |
| 107 | */ |
| 108 | resetFilter: function() { |
| 109 | |
| 110 | var $form = $( this ).parents( 'form' ); |
| 111 | |
| 112 | $form.find( $( this ).data( 'scope' ) ).find( 'input,select' ).each( function() { |
| 113 | |
| 114 | var $this = $( this ); |
| 115 | if ( app.isIgnoredForResetInput( $this ) ) { |
| 116 | return; |
| 117 | } |
| 118 | app.resetInput( $this ); |
| 119 | } ); |
| 120 | |
| 121 | // Submit the form. |
| 122 | $form.submit(); |
| 123 | }, |
| 124 | |
| 125 | /** |
| 126 | * Reset input. |
| 127 | * |
| 128 | * @since 3.0.0 |
| 129 | * |
| 130 | * @param {object} $input Input element. |
| 131 | */ |
| 132 | resetInput: function( $input ) { |
| 133 | |
| 134 | switch ( $input.prop( 'tagName' ).toLowerCase() ) { |
| 135 | case 'input': |
| 136 | $input.val( '' ); |
| 137 | break; |
| 138 | case 'select': |
| 139 | $input.val( $input.find( 'option' ).first().val() ); |
| 140 | break; |
| 141 | } |
| 142 | }, |
| 143 | |
| 144 | /** |
| 145 | * Input is ignored for reset. |
| 146 | * |
| 147 | * @since 3.0.0 |
| 148 | * |
| 149 | * @param {object} $input Input element. |
| 150 | * |
| 151 | * @returns {boolean} Is ignored. |
| 152 | */ |
| 153 | isIgnoredForResetInput: function( $input ) { |
| 154 | |
| 155 | return [ 'submit', 'hidden' ].indexOf( ( $input.attr( 'type' ) || '' ).toLowerCase() ) !== -1 && |
| 156 | ! $input.hasClass( 'flatpickr-input' ); |
| 157 | }, |
| 158 | |
| 159 | /** |
| 160 | * Process the click on the delete all debug events button. |
| 161 | * |
| 162 | * @since 3.0.0 |
| 163 | * |
| 164 | * @param {object} event jQuery event. |
| 165 | */ |
| 166 | deleteAllDebugEvents: function( event ) { |
| 167 | |
| 168 | event.preventDefault(); |
| 169 | |
| 170 | var $btn = $( event.target ); |
| 171 | |
| 172 | $.confirm( { |
| 173 | backgroundDismiss: false, |
| 174 | escapeKey: true, |
| 175 | animationBounce: 1, |
| 176 | closeIcon: true, |
| 177 | type: 'orange', |
| 178 | icon: app.getModalIcon( 'exclamation-circle-solid-orange' ), |
| 179 | title: wp_mail_smtp_tools_debug_events.texts.notice_title, |
| 180 | content: wp_mail_smtp_tools_debug_events.texts.delete_all_notice, |
| 181 | buttons: { |
| 182 | confirm: { |
| 183 | text: wp_mail_smtp_tools_debug_events.texts.yes, |
| 184 | btnClass: 'btn-confirm', |
| 185 | keys: [ 'enter' ], |
| 186 | action: function() { |
| 187 | app.executeAllDebugEventsDeletion( $btn ); |
| 188 | } |
| 189 | }, |
| 190 | cancel: { |
| 191 | text: wp_mail_smtp_tools_debug_events.texts.cancel, |
| 192 | btnClass: 'btn-cancel', |
| 193 | } |
| 194 | } |
| 195 | } ); |
| 196 | }, |
| 197 | |
| 198 | /** |
| 199 | * Process the click on the event item. |
| 200 | * |
| 201 | * @since 3.0.0 |
| 202 | * |
| 203 | * @param {object} event jQuery event. |
| 204 | */ |
| 205 | eventClicked: function( event ) { |
| 206 | |
| 207 | event.preventDefault(); |
| 208 | |
| 209 | app.openDebugEventPopup( $( this ).data( 'event-id' ) ); |
| 210 | }, |
| 211 | |
| 212 | /** |
| 213 | * Open debug event popup. |
| 214 | * |
| 215 | * @since 3.5.0 |
| 216 | * |
| 217 | * @param {int} eventId Debug event ID. |
| 218 | */ |
| 219 | openDebugEventPopup: function( eventId ) { |
| 220 | |
| 221 | var data = { |
| 222 | action: 'wp_mail_smtp_debug_event_preview', |
| 223 | id: eventId, |
| 224 | nonce: $( '#wp-mail-smtp-debug-events-nonce', el.$debugEventsPage ).val() |
| 225 | }; |
| 226 | |
| 227 | var popup = $.alert( { |
| 228 | backgroundDismiss: true, |
| 229 | escapeKey: true, |
| 230 | animationBounce: 1, |
| 231 | type: 'blue', |
| 232 | icon: app.getModalIcon( 'info-circle-blue' ), |
| 233 | title: false, |
| 234 | content: wp_mail_smtp_tools_debug_events.loader, |
| 235 | boxWidth: '550px', |
| 236 | buttons: { |
| 237 | confirm: { |
| 238 | text: wp_mail_smtp_tools_debug_events.texts.close, |
| 239 | btnClass: 'btn-confirm', |
| 240 | keys: [ 'enter' ] |
| 241 | } |
| 242 | }, |
| 243 | onOpenBefore: function() { |
| 244 | this.$contentPane.addClass( 'no-scroll' ); |
| 245 | } |
| 246 | } ); |
| 247 | |
| 248 | $.post( ajaxurl, data, function( response ) { |
| 249 | if ( response.success ) { |
| 250 | popup.setTitle( response.data.title ); |
| 251 | popup.setContent( response.data.content ); |
| 252 | } else { |
| 253 | popup.setIcon( app.getModalIcon( 'exclamation-circle-regular-red' ) ); |
| 254 | popup.setType( 'red' ); |
| 255 | popup.setContent( response.data ); |
| 256 | } |
| 257 | } ).fail( function() { |
| 258 | popup.setContent( wp_mail_smtp_tools_debug_events.texts.error_occurred ); |
| 259 | } ); |
| 260 | }, |
| 261 | |
| 262 | /** |
| 263 | * AJAX call for deleting all debug events. |
| 264 | * |
| 265 | * @since 3.0.0 |
| 266 | * |
| 267 | * @param {object} $btn jQuery object of the clicked button. |
| 268 | */ |
| 269 | executeAllDebugEventsDeletion: function( $btn ) { |
| 270 | |
| 271 | $btn.prop( 'disabled', true ); |
| 272 | |
| 273 | var data = { |
| 274 | action: 'wp_mail_smtp_delete_all_debug_events', |
| 275 | nonce: $( '#wp-mail-smtp-debug-events-nonce', el.$debugEventsPage ).val() |
| 276 | }; |
| 277 | |
| 278 | $.post( ajaxurl, data, function( response ) { |
| 279 | var message = response.data, |
| 280 | icon, |
| 281 | type, |
| 282 | callback; |
| 283 | |
| 284 | if ( response.success ) { |
| 285 | icon = 'check-circle-solid-green'; |
| 286 | type = 'green'; |
| 287 | callback = function() { |
| 288 | location.reload(); |
| 289 | return false; |
| 290 | }; |
| 291 | } else { |
| 292 | icon = 'exclamation-circle-regular-red'; |
| 293 | type = 'red'; |
| 294 | } |
| 295 | |
| 296 | app.displayModal( message, icon, type, callback ); |
| 297 | $btn.prop( 'disabled', false ); |
| 298 | } ).fail( function() { |
| 299 | app.displayModal( wp_mail_smtp_tools_debug_events.texts.error_occurred, 'exclamation-circle-regular-red', 'red' ); |
| 300 | $btn.prop( 'disabled', false ); |
| 301 | } ); |
| 302 | }, |
| 303 | |
| 304 | /** |
| 305 | * Display the modal with provided text and icon. |
| 306 | * |
| 307 | * @since 3.0.0 |
| 308 | * |
| 309 | * @param {string} message The message to be displayed in the modal. |
| 310 | * @param {string} icon The icon name from /assets/images/font-awesome/ to be used in modal. |
| 311 | * @param {string} type The type of the message (red, green, orange, blue, purple, dark). |
| 312 | * @param {Function} actionCallback The action callback function. |
| 313 | */ |
| 314 | displayModal: function( message, icon, type, actionCallback ) { |
| 315 | |
| 316 | type = type || 'default'; |
| 317 | actionCallback = actionCallback || function() {}; |
| 318 | |
| 319 | $.alert( { |
| 320 | backgroundDismiss: true, |
| 321 | escapeKey: true, |
| 322 | animationBounce: 1, |
| 323 | type: type, |
| 324 | closeIcon: true, |
| 325 | title: false, |
| 326 | icon: icon ? app.getModalIcon( icon ) : '', |
| 327 | content: message, |
| 328 | buttons: { |
| 329 | confirm: { |
| 330 | text: wp_mail_smtp_tools_debug_events.texts.ok, |
| 331 | btnClass: 'wp-mail-smtp-btn wp-mail-smtp-btn-md', |
| 332 | keys: [ 'enter' ], |
| 333 | action: actionCallback |
| 334 | } |
| 335 | } |
| 336 | } ); |
| 337 | }, |
| 338 | |
| 339 | /** |
| 340 | * Returns prepared modal icon. |
| 341 | * |
| 342 | * @since 3.0.0 |
| 343 | * |
| 344 | * @param {string} icon The icon name from /assets/images/font-awesome/ to be used in modal. |
| 345 | * |
| 346 | * @returns {string} Modal icon HTML. |
| 347 | */ |
| 348 | getModalIcon: function( icon ) { |
| 349 | |
| 350 | return '"></i><img src="' + wp_mail_smtp_tools_debug_events.plugin_url + '/assets/images/font-awesome/' + icon + '.svg" style="width: 40px; height: 40px;" alt=""><i class="'; |
| 351 | }, |
| 352 | }; |
| 353 | |
| 354 | // Provide access to public functions/properties. |
| 355 | return app; |
| 356 | |
| 357 | }( document, window, jQuery ) ); |
| 358 | |
| 359 | // Initialize. |
| 360 | WPMailSmtpDebugEvents.init(); |
| 361 |