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-about.js
190 lines
| 1 | /* eslint-disable no-prototype-builtins */ |
| 2 | /* global wp_mail_smtp_about */ |
| 3 | 'use strict'; |
| 4 | |
| 5 | var WPMailSMTP = window.WPMailSMTP || {}; |
| 6 | WPMailSMTP.Admin = WPMailSMTP.Admin || {}; |
| 7 | |
| 8 | /** |
| 9 | * WP Mail SMTP Admin area About module. |
| 10 | * |
| 11 | * @since 1.5.0 |
| 12 | */ |
| 13 | WPMailSMTP.Admin.About = WPMailSMTP.Admin.About || ( function( document, window, $ ) { |
| 14 | |
| 15 | /** |
| 16 | * Public functions and properties. |
| 17 | * |
| 18 | * @since 1.5.0 |
| 19 | * |
| 20 | * @type {object} |
| 21 | */ |
| 22 | var app = { |
| 23 | |
| 24 | /** |
| 25 | * Start the engine. DOM is not ready yet, use only to init something. |
| 26 | * |
| 27 | * @since 1.5.0 |
| 28 | */ |
| 29 | init: function() { |
| 30 | |
| 31 | // Do that when DOM is ready. |
| 32 | $( app.ready ); |
| 33 | }, |
| 34 | |
| 35 | /** |
| 36 | * DOM is fully loaded. |
| 37 | * |
| 38 | * @since 1.5.0 |
| 39 | */ |
| 40 | ready: function() { |
| 41 | |
| 42 | app.pageHolder = $( '.wp-mail-smtp-page-about' ); |
| 43 | |
| 44 | app.bindActions(); |
| 45 | |
| 46 | $( '.wp-mail-smtp-page' ).trigger( 'WPMailSMTP.Admin.About.ready' ); |
| 47 | }, |
| 48 | |
| 49 | /** |
| 50 | * Process all generic actions/events, mostly custom that were fired by our API. |
| 51 | * |
| 52 | * @since 1.5.0 |
| 53 | */ |
| 54 | bindActions: function() { |
| 55 | |
| 56 | /* |
| 57 | * Make plugins description the same height. |
| 58 | */ |
| 59 | jQuery( '.wp-mail-smtp-admin-about-plugins .plugin-item .details' ).matchHeight(); |
| 60 | |
| 61 | /* |
| 62 | * Install/Active the plugins. |
| 63 | */ |
| 64 | $( document ).on( 'click', '.wp-mail-smtp-admin-about-plugins .plugin-item .action-button .button', function( e ) { |
| 65 | e.preventDefault(); |
| 66 | |
| 67 | var $btn = $( this ); |
| 68 | |
| 69 | if ( $btn.hasClass( 'disabled' ) || $btn.hasClass( 'loading' ) ) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | var $plugin = $btn.closest( '.plugin-item' ), |
| 74 | plugin = $btn.attr( 'data-plugin' ), |
| 75 | task, |
| 76 | cssClass, |
| 77 | statusText, |
| 78 | buttonText, |
| 79 | successText; |
| 80 | |
| 81 | $btn.addClass( 'loading disabled' ); |
| 82 | $btn.text( wp_mail_smtp_about.plugin_processing ); |
| 83 | |
| 84 | if ( $btn.hasClass( 'status-inactive' ) ) { |
| 85 | |
| 86 | // Activate. |
| 87 | task = 'about_plugin_activate'; |
| 88 | cssClass = 'status-active button button-secondary disabled'; |
| 89 | statusText = wp_mail_smtp_about.plugin_active; |
| 90 | buttonText = wp_mail_smtp_about.plugin_activated; |
| 91 | |
| 92 | } else if ( $btn.hasClass( 'status-download' ) ) { |
| 93 | |
| 94 | // Install & Activate. |
| 95 | task = 'about_plugin_install'; |
| 96 | cssClass = 'status-active button disabled'; |
| 97 | statusText = wp_mail_smtp_about.plugin_active; |
| 98 | buttonText = wp_mail_smtp_about.plugin_activated; |
| 99 | |
| 100 | } else if ( $btn.hasClass( 'status-open' ) ) { |
| 101 | |
| 102 | // Open site in new window. |
| 103 | window.open( $btn.attr( 'href' ), '_blank' ).focus(); |
| 104 | $btn.removeClass( 'loading disabled' ); |
| 105 | $btn.text( wp_mail_smtp_about.plugin_visit ); |
| 106 | |
| 107 | return; |
| 108 | |
| 109 | } else { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | // Setup ajax POST data. |
| 114 | var data = { |
| 115 | action: 'wp_mail_smtp_ajax', |
| 116 | task: task, |
| 117 | nonce : wp_mail_smtp_about.nonce, |
| 118 | plugin: plugin |
| 119 | }; |
| 120 | |
| 121 | $.post( wp_mail_smtp_about.ajax_url, data, function( res ) { |
| 122 | var isInstallSuccessful; |
| 123 | |
| 124 | if ( res.success ) { |
| 125 | isInstallSuccessful = true; |
| 126 | if ( 'about_plugin_install' === task ) { |
| 127 | $btn.attr( 'data-plugin', res.data.basename ); |
| 128 | successText = res.data.msg; |
| 129 | if ( ! res.data.is_activated ) { |
| 130 | cssClass = 'button'; |
| 131 | statusText = wp_mail_smtp_about.plugin_inactive; |
| 132 | buttonText = wp_mail_smtp_about.plugin_activate; |
| 133 | } |
| 134 | } else { |
| 135 | successText = res.data; |
| 136 | } |
| 137 | $plugin.find( '.actions' ).append( '<div class="msg success">' + successText + '</div>' ); |
| 138 | $plugin.find( 'span.status-label' ) |
| 139 | .removeClass( 'status-active status-inactive status-download' ) |
| 140 | .addClass( cssClass ) |
| 141 | .removeClass( 'button button-primary button-secondary disabled' ) |
| 142 | .text( statusText ); |
| 143 | $btn |
| 144 | .removeClass( 'status-active status-inactive status-download' ) |
| 145 | .removeClass( 'button button-primary button-secondary disabled' ) |
| 146 | .addClass( cssClass ).html( buttonText ); |
| 147 | } else { |
| 148 | isInstallSuccessful = false; |
| 149 | |
| 150 | if ( |
| 151 | res.hasOwnProperty( 'data' ) && |
| 152 | res.data.hasOwnProperty( 0 ) && |
| 153 | res.data[ 0 ].hasOwnProperty( 'code' ) |
| 154 | ) { |
| 155 | |
| 156 | // Specific server-returned error. |
| 157 | $plugin.find( '.actions' ).append( '<div class="msg error">' + wp_mail_smtp_about.plugin_install_error + '</div>' ); |
| 158 | } else { |
| 159 | |
| 160 | // Generic error. |
| 161 | $plugin.find( '.actions' ).append( '<div class="msg error">' + res.data + '</div>' ); |
| 162 | } |
| 163 | |
| 164 | $btn.html( wp_mail_smtp_about.plugin_download_btn ); |
| 165 | } |
| 166 | |
| 167 | if ( ! isInstallSuccessful ) { |
| 168 | $btn.removeClass( 'disabled' ); |
| 169 | } |
| 170 | $btn.removeClass( 'loading' ); |
| 171 | |
| 172 | // Automatically clear plugin messages after 3 seconds. |
| 173 | setTimeout( function() { |
| 174 | $( '.plugin-item .msg' ).remove(); |
| 175 | }, 3000 ); |
| 176 | |
| 177 | } ).fail( function( xhr ) { |
| 178 | console.log( xhr.responseText ); |
| 179 | } ); |
| 180 | } ); |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | // Provide access to public functions/properties. |
| 185 | return app; |
| 186 | }( document, window, jQuery ) ); |
| 187 | |
| 188 | // Initialize. |
| 189 | WPMailSMTP.Admin.About.init(); |
| 190 |