2020-05-04 15:57:12 +00:00
|
|
|
/* globals wp_mail_smtp, ajaxurl */
|
|
|
|
'use strict';
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
var WPMailSMTP = window.WPMailSMTP || {};
|
|
|
|
WPMailSMTP.Admin = WPMailSMTP.Admin || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WP Mail SMTP Admin area module.
|
|
|
|
*
|
|
|
|
* @since 1.6.0
|
|
|
|
*/
|
2020-05-04 15:57:12 +00:00
|
|
|
WPMailSMTP.Admin.Settings = WPMailSMTP.Admin.Settings || ( function( document, window, $ ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Public functions and properties.
|
|
|
|
*
|
|
|
|
* @since 1.6.0
|
|
|
|
*
|
2020-05-04 15:57:12 +00:00
|
|
|
* @type {object}
|
2020-04-07 13:03:04 +00:00
|
|
|
*/
|
|
|
|
var app = {
|
2020-05-04 15:57:12 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
/**
|
|
|
|
* State attribute showing if one of the plugin settings
|
|
|
|
* changed and was not yet saved.
|
|
|
|
*
|
2020-05-04 15:57:12 +00:00
|
|
|
* @since 1.9.0
|
2020-04-07 13:03:04 +00:00
|
|
|
*
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
pluginSettingsChanged: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the engine. DOM is not ready yet, use only to init something.
|
|
|
|
*
|
|
|
|
* @since 1.6.0
|
|
|
|
*/
|
2020-05-04 15:57:12 +00:00
|
|
|
init: function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
// Do that when DOM is ready.
|
|
|
|
$( document ).ready( app.ready );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOM is fully loaded.
|
|
|
|
*
|
|
|
|
* @since 1.6.0
|
|
|
|
*/
|
2020-05-04 15:57:12 +00:00
|
|
|
ready: function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
app.pageHolder = $( '.wp-mail-smtp-tab-settings' );
|
|
|
|
|
|
|
|
// If there are screen options we have to move them.
|
|
|
|
$( '#screen-meta-links, #screen-meta' ).prependTo( '#wp-mail-smtp-header-temp' ).show();
|
|
|
|
|
|
|
|
app.bindActions();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process all generic actions/events, mostly custom that were fired by our API.
|
|
|
|
*
|
|
|
|
* @since 1.6.0
|
|
|
|
*/
|
2020-05-04 15:57:12 +00:00
|
|
|
bindActions: function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
// Mailer selection.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( '.wp-mail-smtp-mailer-image', app.pageHolder ).click( function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
$( this ).parents( '.wp-mail-smtp-mailer' ).find( 'input' ).trigger( 'click' );
|
|
|
|
} );
|
|
|
|
|
2020-05-04 15:57:12 +00:00
|
|
|
$( '.wp-mail-smtp-mailer input', app.pageHolder ).click( function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
var $input = $( this );
|
|
|
|
|
|
|
|
if ( $input.prop( 'disabled' ) ) {
|
2020-05-04 15:57:12 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Educational Popup.
|
|
|
|
if ( $input.hasClass( 'educate' ) ) {
|
|
|
|
app.education.upgradeMailer( $input );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deselect the current mailer.
|
|
|
|
$( '.wp-mail-smtp-mailer', app.pageHolder ).removeClass( 'active' );
|
2020-05-04 15:57:12 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Select the correct one.
|
|
|
|
$( this ).parents( '.wp-mail-smtp-mailer' ).addClass( 'active' );
|
|
|
|
|
|
|
|
// Hide all mailers options and display for a currently clicked one.
|
|
|
|
$( '.wp-mail-smtp-mailer-option', app.pageHolder ).addClass( 'hidden' ).removeClass( 'active' );
|
|
|
|
$( '.wp-mail-smtp-mailer-option-' + $( this ).val(), app.pageHolder ).addClass( 'active' ).removeClass( 'hidden' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
app.mailers.smtp.bindActions();
|
|
|
|
|
|
|
|
// Dismiss Pro banner at the bottom of the page.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( '#wp-mail-smtp-pro-banner-dismiss', app.pageHolder ).on( 'click', function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
$.ajax( {
|
2020-05-04 15:57:12 +00:00
|
|
|
url: ajaxurl,
|
|
|
|
dataType: 'json',
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
action: 'wp_mail_smtp_ajax',
|
|
|
|
task: 'pro_banner_dismiss'
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.always( function() {
|
|
|
|
$( '#wp-mail-smtp-pro-banner', app.pageHolder ).fadeOut( 'fast' );
|
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
} );
|
|
|
|
|
2020-05-04 15:57:12 +00:00
|
|
|
// Dissmis educational notices for certain mailers.
|
|
|
|
$( '.js-wp-mail-smtp-mailer-notice-dismiss', app.pageHolder ).on( 'click', function( e ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var $btn = $( this ),
|
|
|
|
$notice = $btn.parents( '.inline-notice' );
|
|
|
|
|
|
|
|
if ( $btn.hasClass( 'disabled' ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax( {
|
2020-05-04 15:57:12 +00:00
|
|
|
url: ajaxurl,
|
|
|
|
dataType: 'json',
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
action: 'wp_mail_smtp_ajax',
|
|
|
|
task: 'notice_dismiss',
|
|
|
|
notice: $notice.data( 'notice' ),
|
|
|
|
mailer: $notice.data( 'mailer' )
|
|
|
|
},
|
|
|
|
beforeSend: function() {
|
|
|
|
$btn.addClass( 'disabled' );
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.always( function() {
|
|
|
|
$notice.fadeOut( 'fast', function() {
|
|
|
|
$btn.removeClass( 'disabled' );
|
|
|
|
} );
|
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Show/hide debug output.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( '#wp-mail-smtp-debug .error-log-toggle' ).on( 'click', function( e ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$( '#wp-mail-smtp-debug .error-log-toggle' ).find( '.dashicons' ).toggleClass( 'dashicons-arrow-right-alt2 dashicons-arrow-down-alt2' );
|
|
|
|
$( '#wp-mail-smtp-debug .error-log' ).slideToggle();
|
|
|
|
$( '#wp-mail-smtp-debug .error-log-note' ).toggle();
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Remove mailer connection.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( '.js-wp-mail-smtp-provider-remove', app.pageHolder ).on( 'click', function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
return confirm( wp_mail_smtp.text_provider_remove );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Copy input text to clipboard.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( '.wp-mail-smtp-setting-copy', app.pageHolder ).click( function( e ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var target = $( '#' + $( this ).data( 'source_id' ) ).get( 0 );
|
|
|
|
|
|
|
|
target.select();
|
|
|
|
|
|
|
|
document.execCommand( 'Copy' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
app.triggerExitNotice();
|
2020-06-20 17:12:03 +00:00
|
|
|
app.beforeSaveChecks();
|
2020-04-07 13:03:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
education: {
|
2020-05-04 15:57:12 +00:00
|
|
|
upgradeMailer: function( $input ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
$.alert( {
|
|
|
|
backgroundDismiss: true,
|
|
|
|
escapeKey: true,
|
|
|
|
animationBounce: 1,
|
|
|
|
theme: 'modern',
|
2020-06-20 17:12:03 +00:00
|
|
|
type: 'blue',
|
2020-04-07 13:03:04 +00:00
|
|
|
animateFromElement: false,
|
|
|
|
draggable: false,
|
|
|
|
closeIcon: true,
|
|
|
|
useBootstrap: false,
|
|
|
|
title: wp_mail_smtp.education.upgrade_title.replace( /%name%/g, $input.siblings( 'label' ).text().trim() ),
|
|
|
|
icon: '"></i>' + wp_mail_smtp.education.upgrade_icon_lock + '<i class="',
|
|
|
|
content: $( '.wp-mail-smtp-mailer-options .wp-mail-smtp-mailer-option-' + $input.val() + ' .wp-mail-smtp-setting-field' ).html(),
|
|
|
|
boxWidth: '550px',
|
2020-05-04 15:57:12 +00:00
|
|
|
onOpenBefore: function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
this.$btnc.after( '<div class="discount-note">' + wp_mail_smtp.education.upgrade_bonus + wp_mail_smtp.education.upgrade_doc + '</div>' );
|
|
|
|
},
|
|
|
|
buttons: {
|
|
|
|
confirm: {
|
|
|
|
text: wp_mail_smtp.education.upgrade_button,
|
|
|
|
btnClass: 'btn-confirm',
|
|
|
|
keys: [ 'enter' ],
|
2020-05-04 15:57:12 +00:00
|
|
|
action: function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
window.open( wp_mail_smtp.education.upgrade_url + '&utm_content=' + encodeURI( $input.val() ), '_blank' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Individual mailers specific js code.
|
|
|
|
*
|
|
|
|
* @since 1.6.0
|
|
|
|
*/
|
|
|
|
mailers: {
|
|
|
|
smtp: {
|
2020-05-04 15:57:12 +00:00
|
|
|
bindActions: function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
// Hide SMTP-specific user/pass when Auth disabled.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( '#wp-mail-smtp-setting-smtp-auth' ).change( function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
$( '#wp-mail-smtp-setting-row-smtp-user, #wp-mail-smtp-setting-row-smtp-pass' ).toggleClass( 'inactive' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Port default values based on encryption type.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( '#wp-mail-smtp-setting-row-smtp-encryption input' ).change( function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
var $input = $( this ),
|
|
|
|
$smtpPort = $( '#wp-mail-smtp-setting-smtp-port', app.pageHolder );
|
|
|
|
|
|
|
|
if ( 'tls' === $input.val() ) {
|
|
|
|
$smtpPort.val( '587' );
|
|
|
|
$( '#wp-mail-smtp-setting-row-smtp-autotls' ).addClass( 'inactive' );
|
2020-05-04 15:57:12 +00:00
|
|
|
} else if ( 'ssl' === $input.val() ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
$smtpPort.val( '465' );
|
|
|
|
$( '#wp-mail-smtp-setting-row-smtp-autotls' ).removeClass( 'inactive' );
|
2020-05-04 15:57:12 +00:00
|
|
|
} else {
|
2020-04-07 13:03:04 +00:00
|
|
|
$smtpPort.val( '25' );
|
|
|
|
$( '#wp-mail-smtp-setting-row-smtp-autotls' ).removeClass( 'inactive' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exit notice JS code when plugin settings are not saved.
|
|
|
|
*
|
2020-05-04 15:57:12 +00:00
|
|
|
* @since 1.9.0
|
2020-04-07 13:03:04 +00:00
|
|
|
*/
|
2020-05-04 15:57:12 +00:00
|
|
|
triggerExitNotice: function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
var $settingPages = $( '.wp-mail-smtp-page-general:not( .wp-mail-smtp-tab-test )' );
|
|
|
|
|
|
|
|
// Display an exit notice, if settings are not saved.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( window ).on( 'beforeunload', function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
if ( app.pluginSettingsChanged ) {
|
|
|
|
return wp_mail_smtp.text_settings_not_saved;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Set settings changed attribute, if any input was changed.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( ':input:not( #wp-mail-smtp-setting-license-key )', $settingPages ).on( 'change', function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
app.pluginSettingsChanged = true;
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Clear the settings changed attribute, if the settings are about to be saved.
|
2020-05-04 15:57:12 +00:00
|
|
|
$( 'form', $settingPages ).on( 'submit', function() {
|
2020-04-07 13:03:04 +00:00
|
|
|
app.pluginSettingsChanged = false;
|
|
|
|
} );
|
2020-06-20 17:12:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform any checks before the settings are saved.
|
|
|
|
*
|
|
|
|
* Checks:
|
|
|
|
* - warn users if they try to save the settings with the default (PHP) mailer selected.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*/
|
|
|
|
beforeSaveChecks: function() {
|
|
|
|
|
|
|
|
$( 'form', app.pageHolder ).on( 'submit', function() {
|
|
|
|
if ( $( '.wp-mail-smtp-mailer input:checked', app.pageHolder ).val() === 'mail' ) {
|
|
|
|
var $thisForm = $( this );
|
|
|
|
|
|
|
|
$.alert( {
|
|
|
|
backgroundDismiss: false,
|
|
|
|
escapeKey: false,
|
|
|
|
animationBounce: 1,
|
|
|
|
theme: 'modern',
|
|
|
|
type: 'orange',
|
|
|
|
animateFromElement: false,
|
|
|
|
draggable: false,
|
|
|
|
closeIcon: false,
|
|
|
|
useBootstrap: false,
|
|
|
|
icon: '"></i><img src="' + wp_mail_smtp.plugin_url + '/assets/images/font-awesome/exclamation-circle-solid-orange.svg" style="width: 40px; height: 40px;" alt="' + wp_mail_smtp.default_mailer_notice.icon_alt + '"><i class="',
|
|
|
|
title: wp_mail_smtp.default_mailer_notice.title,
|
|
|
|
content: wp_mail_smtp.default_mailer_notice.content,
|
|
|
|
boxWidth: '550px',
|
|
|
|
buttons: {
|
|
|
|
confirm: {
|
|
|
|
text: wp_mail_smtp.default_mailer_notice.save_button,
|
|
|
|
btnClass: 'btn-confirm',
|
|
|
|
keys: [ 'enter' ],
|
|
|
|
action: function() {
|
|
|
|
$thisForm.off( 'submit' ).submit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cancel: {
|
|
|
|
text: wp_mail_smtp.default_mailer_notice.cancel_button,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Provide access to public functions/properties.
|
|
|
|
return app;
|
2020-05-04 15:57:12 +00:00
|
|
|
}( document, window, jQuery ) );
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
// Initialize.
|
|
|
|
WPMailSMTP.Admin.Settings.init();
|