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-ai-mcp.js
198 lines
| 1 | 'use strict'; |
| 2 | |
| 3 | var WPMailSMTP = window.WPMailSMTP || {}; |
| 4 | WPMailSMTP.Admin = WPMailSMTP.Admin || {}; |
| 5 | |
| 6 | /** |
| 7 | * WP Mail SMTP Admin area AI MCP module. |
| 8 | * |
| 9 | * @since 4.9.0 |
| 10 | */ |
| 11 | WPMailSMTP.Admin.AiMcp = WPMailSMTP.Admin.AiMcp || ( function( document, window, $ ) { |
| 12 | |
| 13 | /** |
| 14 | * Public functions and properties. |
| 15 | * |
| 16 | * @since 4.9.0 |
| 17 | * |
| 18 | * @type {object} |
| 19 | */ |
| 20 | var app = { |
| 21 | |
| 22 | /** |
| 23 | * Start the engine. DOM is not ready yet, use only to init something. |
| 24 | * |
| 25 | * @since 4.9.0 |
| 26 | */ |
| 27 | init: function() { |
| 28 | |
| 29 | $( app.ready ); |
| 30 | }, |
| 31 | |
| 32 | /** |
| 33 | * DOM is fully loaded. |
| 34 | * |
| 35 | * @since 4.9.0 |
| 36 | */ |
| 37 | ready: function() { |
| 38 | |
| 39 | app.events(); |
| 40 | }, |
| 41 | |
| 42 | /** |
| 43 | * Bind events. |
| 44 | * |
| 45 | * @since 4.9.0 |
| 46 | */ |
| 47 | events: function() { |
| 48 | |
| 49 | $( document ) |
| 50 | .on( 'click', '.wp-mail-smtp-ai-mcp-wpvibe-button[data-action="install"]', app.onInstallClick ) |
| 51 | .on( 'click', '.wp-mail-smtp-ai-mcp-wpvibe-button[data-action="activate"]', app.onActivateClick ); |
| 52 | }, |
| 53 | |
| 54 | /** |
| 55 | * POST to the WP Mail SMTP admin-ajax dispatcher with the nonce attached. |
| 56 | * |
| 57 | * @since 4.9.0 |
| 58 | * |
| 59 | * @param {object} extra Task-specific fields merged into the request. |
| 60 | * |
| 61 | * @returns {object} The jQuery jqXHR promise. |
| 62 | */ |
| 63 | post: function( extra ) { |
| 64 | |
| 65 | var data = $.extend( { |
| 66 | action: 'wp_mail_smtp_ajax', |
| 67 | nonce: window.wp_mail_smtp.nonce, |
| 68 | }, extra || {} ); |
| 69 | |
| 70 | return $.post( window.wp_mail_smtp.ajax_url, data ); |
| 71 | }, |
| 72 | |
| 73 | /** |
| 74 | * Install button: install & activate WPVibe, then reload. |
| 75 | * |
| 76 | * @since 4.9.0 |
| 77 | * |
| 78 | * @param {object} event The click event. |
| 79 | */ |
| 80 | onInstallClick: function( event ) { |
| 81 | |
| 82 | event.preventDefault(); |
| 83 | |
| 84 | app.runInstallerTask( $( event.currentTarget ), 'about_plugin_install' ); |
| 85 | }, |
| 86 | |
| 87 | /** |
| 88 | * Activate button: activate WPVibe, then reload. |
| 89 | * |
| 90 | * @since 4.9.0 |
| 91 | * |
| 92 | * @param {object} event The click event. |
| 93 | */ |
| 94 | onActivateClick: function( event ) { |
| 95 | |
| 96 | event.preventDefault(); |
| 97 | |
| 98 | app.runInstallerTask( $( event.currentTarget ), 'about_plugin_activate' ); |
| 99 | }, |
| 100 | |
| 101 | /** |
| 102 | * Run an install/activate task, then reload on success or surface an |
| 103 | * inline error on failure. A reload lets PHP re-render the next state's |
| 104 | * CTA. WP returns logical failures with HTTP 200 + success:false, so a |
| 105 | * failed task lands in .done and must be checked explicitly. |
| 106 | * |
| 107 | * @since 4.9.0 |
| 108 | * |
| 109 | * @param {object} $button Button element that was clicked. |
| 110 | * @param {string} task AJAX task — install or activate. |
| 111 | */ |
| 112 | runInstallerTask: function( $button, task ) { |
| 113 | |
| 114 | app.clearError( $button ); |
| 115 | app.setLoading( $button ); |
| 116 | |
| 117 | app.post( { task: task, plugin: $button.data( 'plugin' ) } ) |
| 118 | .done( function( response ) { |
| 119 | |
| 120 | if ( response && response.success ) { |
| 121 | window.location.reload(); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | // Install partially succeeded (installed but activation failed): |
| 126 | // the plugin state changed, so reload to render the activate CTA. |
| 127 | if ( task === 'about_plugin_install' && response && response.data && response.data.basename ) { |
| 128 | window.location.reload(); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | app.showError( $button ); |
| 133 | } ) |
| 134 | .fail( function() { |
| 135 | |
| 136 | app.showError( $button ); |
| 137 | } ); |
| 138 | }, |
| 139 | |
| 140 | /** |
| 141 | * Show the loading spinner on the button. |
| 142 | * |
| 143 | * @since 4.9.0 |
| 144 | * |
| 145 | * @param {object} $button Button element. |
| 146 | */ |
| 147 | setLoading: function( $button ) { |
| 148 | |
| 149 | $button |
| 150 | .addClass( 'wp-mail-smtp-btn-loading' ) |
| 151 | .prop( 'disabled', true ); |
| 152 | }, |
| 153 | |
| 154 | /** |
| 155 | * Restore the button to its initial state and show the inline error. |
| 156 | * |
| 157 | * @since 4.9.0 |
| 158 | * |
| 159 | * @param {object} $button Button element. |
| 160 | */ |
| 161 | showError: function( $button ) { |
| 162 | |
| 163 | $button |
| 164 | .removeClass( 'wp-mail-smtp-btn-loading' ) |
| 165 | .prop( 'disabled', false ); |
| 166 | |
| 167 | var $row = $button.closest( '.wp-mail-smtp-ai-mcp-cta-row' ); |
| 168 | var $error = $row.siblings( '.wp-mail-smtp-ai-mcp-install-error' ); |
| 169 | |
| 170 | if ( ! $error.length ) { |
| 171 | $error = $( '<p class="wp-mail-smtp-ai-mcp-install-error" role="alert"></p>' ); |
| 172 | $row.after( $error ); |
| 173 | } |
| 174 | |
| 175 | $error.text( window.wp_mail_smtp_ai_mcp.error_text ); |
| 176 | }, |
| 177 | |
| 178 | /** |
| 179 | * Remove a previously shown inline error before a new attempt. |
| 180 | * |
| 181 | * @since 4.9.0 |
| 182 | * |
| 183 | * @param {object} $button Button element. |
| 184 | */ |
| 185 | clearError: function( $button ) { |
| 186 | |
| 187 | $button |
| 188 | .closest( '.wp-mail-smtp-ai-mcp-cta-row' ) |
| 189 | .siblings( '.wp-mail-smtp-ai-mcp-install-error' ) |
| 190 | .remove(); |
| 191 | }, |
| 192 | }; |
| 193 | |
| 194 | return app; |
| 195 | }( document, window, jQuery ) ); |
| 196 | |
| 197 | WPMailSMTP.Admin.AiMcp.init(); |
| 198 |