Files
piratepoet/views/settings/mta.html
2018-07-30 22:10:38 -04:00

1150 lines
37 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<% set intervals = [1, 2, 5, 10, 15, 30] %>
<% set mss_key_valid = settings.mta.mailpoet_api_key_state.state == "valid" %>
<% set default_frequency = {
'website': {
'emails': 25,
'interval': 5
},
'smtp': {
'emails': 100,
'interval': 5
}
} %>
<!-- mta: group -->
<input
type="hidden"
id="mta_group"
name="mta_group"
value="<%= settings.mta_group %>"
/>
<input
type="hidden"
id="mailpoet_smtp_provider"
name="mailpoet_smtp_provider"
value="<%= settings.smtp_provider %>"
/>
<!-- mta: method -->
<input
type="hidden"
id="mta_method"
name="mta[method]"
value="<%= settings.mta.method %>"
/>
<!-- mta: sending frequency -->
<input
type="hidden"
id="mta_frequency_emails"
name="mta[frequency][emails]"
value="<%= settings.mta.frequency.emails %>"
/>
<input
type="hidden"
id="mta_frequency_interval"
name="mta[frequency][interval]"
value="<%= settings.mta.frequency.interval %>"
/>
<!-- mta: mailpoet sending service key -->
<input
type="hidden"
id="mailpoet_api_key"
name="mta[mailpoet_api_key]"
value="<%=- settings.mta.mailpoet_api_key -%>"
/>
<!-- smtp: available sending methods -->
<ul class="mailpoet_sending_methods">
<li
data-group="mailpoet"
class="<% if(settings.mta_group == 'mailpoet') %> mailpoet_active <% endif %> <% if(not mss_key_valid) %> mailpoet_invalid_key <% endif %>"
>
<div class="mailpoet_sending_method_description">
<h3>
<%= __('MailPoet Sending Service') %>
</h3>
<div class="mailpoet_description">
<span class="<% if(settings.mta_group != 'mailpoet') %> mailpoet_hidden<% endif %>" id="mailpoet_sending_method_active_text">
<strong><%= __("You're now sending with MailPoet!") %></strong>
</span>
<span class="<% if(settings.mta_group == 'mailpoet') %> mailpoet_hidden<% endif %>" id="mailpoet_sending_method_inactive_text">
<strong><%= __("Solve all of your sending problems!") %></strong>
</span>
<ul class="sending-method-benefits mailpoet_success">
<li class="mailpoet_success_item"><%= __('Reach the inbox, not the spam box.') %></li>
<li class="mailpoet_success_item"><%= __('Easy configuration: enter a key to activate the sending service.') %></li>
<li class="mailpoet_success_item"><%= __('Super fast: send up to 50,000 emails per hour.') %></li>
<li class="mailpoet_success_item"><%= __('All emails are signed with SPF & DKIM.') %></li>
<li class="mailpoet_success_item"><%= __('Automatically remove invalid and bounced addresses (bounce handling) to keep your lists clean.') %></li>
</ul>
<p class="mailpoet_sending_methods_help">
<% set badgeClassName = (is_new_user == true) ? 'mailpoet_badge mailpoet_badge_video' : 'mailpoet_badge mailpoet_badge_video mailpoet_badge_video_grey' %>
<%= __('[link]%s See video guide[/link]')
|format('<span class="dashicons dashicons-format-video"></span>')
|replaceLinkTags('https://beta.docs.mailpoet.com/article/235-video-guide-sending-options', {'class' : badgeClassName, 'target' : '_blank'}, 'link')
|raw
%>
</p>
</div>
</div>
<div class="mailpoet_status <% if(settings.mta_group != 'mailpoet' or not mss_key_valid) %> mailpoet_invalid_key <% endif %>">
<div class="mailpoet_activated <% if(settings.mta_group != 'mailpoet' or not mss_key_valid) %> mailpoet_hidden <% endif %>">
<span><%= __('Activated') %></span>
</div>
<div class="mailpoet_actions">
<div class="mailpoet_invalid_key <% if(mss_key_valid) %> mailpoet_hidden <% endif %>">
<a class="button-primary" href="https://www.mailpoet.com/free-plan/" rel="noopener noreferrer" target="_blank"><%= __('Get a free key') %></a>
or
<%=
__("[link]enter your key[/link]")
|replaceLinkTags('#premium')
|raw
%>
</div>
<div class="mailpoet_valid_key <% if(not mss_key_valid or settings.mta_group == 'mailpoet') %> mailpoet_hidden <% endif %>">
<button type="button" class="mailpoet_sending_service_activate button-primary"><%= __('Activate') %></button>
</div>
</div>
</li>
<li
data-group="other"
<% if(settings.mta_group != 'mailpoet') %>class="mailpoet_active"<% endif %>
>
<div class="mailpoet_sending_method_description">
<h3><%= __('Other') %></h3>
<div class="mailpoet_description">
<strong><%= __('Send emails via your host (not recommended!) or via a third-party sender.') %></strong>
<ul class="sending-method-benefits mailpoet_error">
<li class="mailpoet_error_item"><%= __("Unless you're a pro, youll probably end up in spam.") %></li>
<li class="mailpoet_error_item"><%= __("Sending speed is limited by your host and/or your third-party (with a 2,000 per hour maximum).") %></li>
<li class="mailpoet_error_item"><%= __("Manual configuration of SPF and DKIM required.") %></li>
<li class="mailpoet_error_item"><%=
__("Bounce handling is available, but only with an extra [link]add-on[/link].")
|replaceLinkTags('https://wordpress.org/plugins/bounce-handler-mailpoet/', {'target' : '_blank'})
|raw
%>
</li>
</ul>
</div>
</div>
<div class="mailpoet_status">
<span><%= __('Activated') %></span>
<div class="mailpoet_actions">
<% if(settings.mta_group == 'mailpoet') %>
<a class="button-primary mailpoet_other_sending_method_action" href="#mta/other"><%= __('Activate') %></a>
<% else %>
<a class="button-secondary mailpoet_other_sending_method_action" href="#mta/other"><%= __('Configure') %></a>
<% endif %>
</div>
</div>
</li>
</ul>
<div id="mailpoet_sending_method_setup">
<!-- Sending Method: Other -->
<div class="mailpoet_sending_method" data-group="other" style="display:none;">
<table class="form-table">
<tr>
<th scope="row">
<label for="mailpoet_smtp_method">
<%= __('Method') %>
</label>
</th>
<td>
<!-- smtp provider -->
<select
id="mailpoet_smtp_method"
name="smtp_provider"
>
<option data-interval="5" data-emails="25" value="server">
<%= __('Your web host / web server') %>
</option>
<option data-interval="5" data-emails="100" value="manual"
<%
if settings.mta_group == "smtp"
%>
selected="selected"
<% endif %>
>
<%= __('SMTP') %>
</option>
<!-- providers -->
<optgroup label="<%= __('Select your provider') %>">
<% for host_key, host in hosts.smtp %>
<option
value="<%= host_key %>"
data-emails="<%= host.emails %>"
data-interval="<%= host.interval %>"
data-fields="<%= host.fields | join(',') %>"
<% if(settings.smtp_provider == host_key) %>
selected="selected"
<% endif %>
><%= host.name %></option>
<% endfor %>
</optgroup>
</select>
</td>
</tr>
<tr id="mailpoet_sending_method_host"
<%
if settings.mta_group == "smtp"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="mailpoet_web_host">
<%= __('Your web host') %>
</label>
</th>
<td>
<p>
<!-- sending frequency -->
<select
id="mailpoet_web_host"
name="web_host"
>
<!-- web hosts -->
<option
value="manual"
data-emails="25"
data-interval="5"
label="<%= __('Not listed (default)') %>"
>
<% for host_key, host in hosts.web %>
<option
value="<%= host_key %>"
data-emails="<%= host.emails %>"
data-interval="<%= host.interval %>"
<% if(settings.web_host == host_key) %>
selected="selected"
<% endif %>
><%= host.name %></option>
<% endfor %>
</select>
</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="mailpoet_web_host">
<%= __('Sending frequency') %>
</label>
</th>
<td>
<p>
<!-- sending frequency -->
<select
id="mailpoet_sending_frequency"
name="mailpoet_sending_frequency"
>
<option value="auto">
<%= __('Recommended') %>
</option>
<option value="manual"
<%
if not(settings.mailpoet_sending_frequency == 'auto')
%>
selected="selected"
<% endif %>
>
<%= __("I'll set my own frequency") %>
</option>
</select>
<span id="mailpoet_recommended_daily_emails"></span>
</p>
<div id="mailpoet_sending_frequency_manual"
<%
if settings.mailpoet_sending_frequency == 'auto'
%>
style="display: none"
<% endif %>
>
<p>
<input
id="other_frequency_emails"
type="number"
min="1"
max="1000"
<% if(settings.mta.frequency.emails) %>
value="<%= settings.mta.frequency.emails %>"
<% else %>
value="<%= default_frequency.website.emails %>"
<% endif %>
/>
<%= __('emails') %>
<select id="other_frequency_interval">
<% for interval in intervals %>
<option
value="<%= interval %>"
<%
if not(settings.mta.frequency.interval)
and (interval == default_frequency.website.interval)
%>
selected="selected"
<% endif %>
<% if(settings.mta.frequency.interval == interval) %>
selected="selected"
<% endif %>
>
<%= sending_frequency(interval) %>
<% if(interval == default_frequency.website.interval) %>
(<%= __('recommended') %>)
<% endif %>
</option>
<% endfor %>
</select>
<span id="mailpoet_other_daily_emails"></span>
</p>
<br />
<p>
<%= __('<strong>Warning!</strong> You may break the terms of your web host or provider by sending more than the recommended emails per day. Contact your host if you want to send more.') %>
</p>
</div>
</td>
</tr>
<tr class="mailpoet_smtp_field" data-field="host"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "manual"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_host]">
<%= __('SMTP Hostname') %>
</label>
<p class="description">
<%= __('e.g.: smtp.mydomain.com') %>
</p>
</th>
<td>
<input
type="text"
class="regular-text"
id="settings[mta_host]"
name="mta[host]"
value="<%= settings.mta.host %>" />
</td>
</tr>
<!-- smtp: port -->
<tr class="mailpoet_smtp_field" data-field="port"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "manual"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_port]">
<%= __('SMTP Port') %>
</label>
</th>
<td>
<input
type="number"
max="65535"
min="1"
maxlength="5"
style="width:5em;"
id="settings[mta_port]"
name="mta[port]"
value="<%= settings.mta.port %>"
/>
</td>
</tr>
<!-- smtp: amazon region -->
<tr class="mailpoet_aws_field" data-field="region"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "AmazonSES"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_region]">
<%= __('Region') %>
</label>
</th>
<td>
<select
id="settings[mta_region]"
name="mta[region]"
value="<% if(settings.mta_group == 'smtp') %>
<%=- settings.mta.region -%>
<% endif %>"
>
<% for region, server in hosts.smtp.AmazonSES.regions %>
<option
value="<%= server %>"
<% if(settings.mta.region == server) %>
selected="selected"
<% endif %>
>
<%= region %>
</option>
<% endfor %>
</select>
</td>
</tr>
<!-- smtp: amazon access_key -->
<tr class="mailpoet_aws_field" data-field="access_key"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "AmazonSES"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_access_key]">
<%= __('Access Key') %>
</label>
</th>
<td>
<input
type="text"
class="regular-text"
id="settings[mta_access_key]"
name="mta[access_key]"
value="<% if(settings.mta_group == 'smtp') %>
<%=- settings.mta.access_key -%>
<% endif %>"
/>
</td>
</tr>
<!-- smtp: amazon secret_key -->
<tr class="mailpoet_aws_field" data-field="secret_key"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "AmazonSES"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_secret_key]">
<%= __('Secret Key') %>
</label>
</th>
<td>
<input
type="text"
class="regular-text"
id="settings[mta_secret_key]"
name="mta[secret_key]"
value="<% if(settings.mta_group == 'smtp') %>
<%=- settings.mta.secret_key -%>
<% endif %>"
/>
</td>
</tr>
<!-- smtp: api key -->
<tr class="mailpoet_sendgrid_field" data-field="api_key"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "SendGrid"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_api_key]">
<%= __('API Key') %>
</label>
</th>
<td>
<input
type="text"
class="regular-text"
id="settings[mta_api_key]"
name="mta[api_key]"
value="<%=- settings.mta.api_key -%>"
/>
</td>
</tr>
<!-- smtp: login -->
<tr id="mta_login" class="mailpoet_smtp_field" data-field="login"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "manual"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_login]">
<%= __('Login') %>
</label>
</th>
<td>
<input
type="text"
class="regular-text"
id="settings[mta_login]"
name="mta[login]"
value="<%= settings.mta.login %>"
/>
</td>
</tr>
<!-- smtp: password -->
<tr id="mta_password" class="mailpoet_smtp_field" data-field="password"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "manual"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_password]">
<%= __('Password') %>
</label>
</th>
<td>
<input
type="password"
class="regular-text"
id="settings[mta_password]"
name="mta[password]"
value="<%= settings.mta.password %>"
/>
</td>
</tr>
<!-- smtp: security protocol -->
<tr class="mailpoet_smtp_field" data-field="encryption"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "manual"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label for="settings[mta_encryption]">
<%= __('Secure Connection') %>
</label>
</th>
<td>
<select id="settings[mta_encryption]" name="mta[encryption]">
<option value=""><%= __('No') %></option>
<option
value="ssl"
<% if(settings.mta.encryption == 'ssl') %>
selected="selected"
<% endif %>
>SSL</option>
<option
value="tls"
<% if(settings.mta.encryption == 'tls') %>
selected="selected"
<% endif %>
>TLS</option>
</select>
</td>
</tr>
<!-- smtp: authentication -->
<tr class="mailpoet_smtp_field" data-field="authentication"
<%
if settings.mta_group != "smtp" or settings.smtp_provider != "manual"
%>
style="display:none;"
<% endif %>
>
<th scope="row">
<label>
<%= __('Authentication') %>
</label>
<p class="description">
<%= __('Leave this option set to Yes. Only a tiny portion of SMTP services prefer Authentication to be turned off.') %>
</p>
</th>
<td>
<label>
<input
type="radio"
value="1"
name="mta[authentication]"
<%
if not(settings.mta.authentication)
or (settings.mta.authentication == "1") %>
checked="checked"
<% endif %>
/><%= __('Yes') %>
</label>
&nbsp;
<label>
<input
type="radio"
value="-1"
name="mta[authentication]"
<% if(settings.mta.authentication == "-1") %>
checked="checked"
<% endif %>
/><%= __('No') %>
</label>
</td>
</tr>
</tbody>
</table>
<table class="form-table">
<tbody>
<!-- SPF -->
<tr id="mailpoet_mta_spf">
<th scope="row">
<label>
<%= __('SPF Signature (Highly recommended!)') %>
</label>
<p class="description">
<%= __("This improves your delivery rate by verifying that you're allowed to send emails from your domain.") %>
</p>
</th>
<td>
<p>
<%= __("SPF is set up in your DNS. Read your host's support documentation for more information.") %>
</p>
</td>
</tr>
<!-- test method -->
<tr>
<th scope="row">
<label for="mailpoet_mta_test_email">
<%= __('Test the sending method') %>
</label>
</th>
<td>
<p>
<input
type="text"
id="mailpoet_mta_test_email"
class="regular-text"
value="<%= current_user.user_email %>"
/>
<a
id="mailpoet_mta_test"
class="button-secondary"
><%= __('Send a test email') %></a>
<span id="tooltip-test"></span>
</p>
</td>
</tr>
<!-- activate or cancel -->
<tr>
<th scope="row">
<p>
<a
href="javascript:;"
class="mailpoet_mta_setup_save button button-primary"
><%= __('Activate') %></a>
&nbsp;
<a
href="javascript:;"
class="mailpoet_mta_setup_cancel"
><%= __('or Cancel') %></a>
</p>
</th>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<script type="text/javascript">
jQuery(function($) {
var tooltip = '<%= __("Didn't receive the test email? Read our [link]quick guide[/link] to sending issues.")
|replaceLinkTags('http://beta.docs.mailpoet.com/article/146-my-newsletters-are-not-being-received', {'target' : '_blank'})
|escape('js') %>'
MailPoet.helpTooltip.show(document.getElementById("tooltip-test"), {
tooltipId: "tooltip-settings-test",
tooltip: tooltip,
});
var sending_frequency_template =
Handlebars.compile($('#mailpoet_sending_frequency_template').html());
// om dom loaded
$(function() {
// constrain number type inputs
$('input[type="number"]').on('keyup', function() {
var currentValue = $(this).val();
if(!currentValue) return;
var minValue = $(this).attr('min');
var maxValue = $(this).attr('max');
$(this).val(Math.min(Math.max(minValue, currentValue), maxValue));
});
// testing sending method
$('#mailpoet_mta_test').on('click', function() {
// get test email and include it in data
var recipient = $('#mailpoet_mta_test_email').val();
var settings = jQuery('#mailpoet_settings_form').mailpoetSerializeObject();
var mailer = settings.mta;
mailer.method = getMethodFromGroup($('#mailpoet_smtp_method').val());
// check that we have a from address
if(settings.sender.address.length === 0) {
// validation
return MailPoet.Notice.error(
'<%= __('The email could not be sent. Make sure the option "Email notifications" has a FROM email address in the Basics tab.') | escape('js') %>',
{ scroll: true, static: true }
);
}
MailPoet.Modal.loading(true);
MailPoet.Ajax.post({
api_version: window.mailpoet_api_version,
endpoint: 'mailer',
action: 'send',
data: {
mailer: mailer,
newsletter: {
subject: "<%= __('This is a Sending Method Test') %>",
body: {
html: "<p><%= __('Yup, it works! You can start blasting away emails to the moon.') %></p>",
text: "<%= __('Yup, it works! You can start blasting away emails to the moon.') %>"
}
},
subscriber: recipient
}
}).always(function() {
MailPoet.Modal.loading(false);
}).done(function(response) {
MailPoet.Notice.success(
"<%= __('The email has been sent! Check your inbox.') | escape('js') %>",
{ scroll: true }
);
trackTestEmailSent(mailer, true);
}).fail(function(response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return _.escape(error.message); }),
{ scroll: true }
);
}
trackTestEmailSent(mailer, false);
});
});
// sending frequency update based on selected provider
$('#mailpoet_web_host').on('change keyup', renderHostSendingFrequency);
// update manual sending frequency when values are changed
$('#other_frequency_emails').on('change keyup', function() {
updateSendingFrequency('other');
});
$('#other_frequency_interval').on('change keyup', function() {
updateSendingFrequency('other');
});
// save configuration of a sending method
$('.mailpoet_sending_service_activate').on('click', function(e, navigateToTab) {
$('#mta_group').val('mailpoet');
saveSendingMethodConfiguration('mailpoet', navigateToTab);
});
$('.mailpoet_mta_setup_save').on('click', function() {
$('#mailpoet_smtp_method').trigger("change");
$('#other_frequency_emails').trigger("change");
// get selected method
var group = $('.mailpoet_sending_method:visible').data('group');
saveSendingMethodConfiguration(group);
});
$('#mailpoet_smtp_method').on('change keyup', renderHostsSelect);
$('#mailpoet_sending_frequency').on('change keyup', sendingFrequencyMethodUpdated);
<% if(settings.mta_group != 'mailpoet') %>
$('#mailpoet_smtp_method').trigger("change");
$('#other_frequency_emails').trigger("change");
<% endif %>
function saveSendingMethodConfiguration(group, navigateToTab) {
// set sending method
if(group === undefined) {
MailPoet.Notice.error(
"<%= __('You have selected an invalid sending method.') | escape('js') %>"
);
} else {
// set new sending method active
setSendingMethodGroup(group);
// enforce signup confirmation depending on selected group
setSignupConfirmation(group);
// back to selection of sending methods
if (navigateToTab === undefined || navigateToTab === true) {
MailPoet.Router.navigate('mta', { trigger: true });
}
// save settings
$('.mailpoet_settings_submit > input').trigger('click');
if (group === 'mailpoet') {
updateMSSActivationUI()
}
}
}
function setSignupConfirmation(group) {
if (group === 'mailpoet') {
// force signup confirmation (select "Yes")
$('.mailpoet_signup_confirmation[value="1"]').attr('checked', true);
$('.mailpoet_signup_confirmation[value=""]').attr('checked', false);
// hide radio inputs
$('#mailpoet_signup_confirmation_input').hide();
// show mailpoet specific notice
$('#mailpoet_signup_confirmation_notice').show();
// show signup confirmation options
$('#mailpoet_signup_options').show();
} else {
// show radio inputs
$('#mailpoet_signup_confirmation_input').show();
// hide mailpoet specific notice
$('#mailpoet_signup_confirmation_notice').hide();
}
}
function setSendingMethodGroup(group) {
// deactivate other sending methods
$('.mailpoet_sending_methods .mailpoet_active')
.removeClass('mailpoet_active');
// set active sending method
$('.mailpoet_sending_methods li[data-group="'+group+'"]')
.addClass('mailpoet_active');
var method = getMethodFromGroup($('#mta_group').val());
$('#mta_method').val(method);
// set MailPoet method description
$('#mailpoet_sending_method_active_text')
.toggleClass('mailpoet_hidden', group !== 'mailpoet');
$('#mailpoet_sending_method_inactive_text')
.toggleClass('mailpoet_hidden', group === 'mailpoet');
// Hide server error notices
$('.mailpoet_notice_server').hide();
updateMSSActivationUI();
}
function getMethodFromGroup(group) {
var group = group || 'website';
switch(group) {
case 'mailpoet':
return 'MailPoet';
break;
case 'server':
case 'website':
return 'PHPMail';
break;
case 'manual':
case 'smtp':
var method = $('#mailpoet_smtp_provider').val();
if(method === 'manual') {
return 'SMTP';
}
return method;
break;
default:
return group;
}
}
// cancel configuration of a sending method
$('.mailpoet_mta_setup_cancel').on('click', function() {
// back to selection of sending methods
MailPoet.Router.navigate('mta', { trigger: true });
});
// render sending frequency form
$('#mailpoet_smtp_provider').trigger('change');
$('#mailpoet_web_host').trigger('change');
function trackTestEmailSent(mailer, success) {
MailPoet.trackEvent(
'User has sent a test email from Settings',
{
'Sending was successful': !!success,
'Sending method type': mailer.method,
'MailPoet Free version': window.mailpoet_version
}
);
}
$('.mailpoet_sending_methods_help a').on('click', function() {
MailPoet.trackEvent(
'User has clicked to view the sending comparison table',
{'MailPoet Free version': window.mailpoet_version}
);
});
});
function setProviderForm() {
// check provider
var provider = $(this).find('option:selected').first();
var fields = provider.data('fields');
if(fields === undefined) {
fields = [
'host',
'port',
'login',
'password',
'authentication',
'encryption'
];
} else {
fields = fields.split(',');
}
$('.mailpoet_smtp_field').hide();
fields.map(function(field) {
$('.mailpoet_smtp_field[data-field="'+field+'"]').show();
});
// update sending frequency
renderSMTPSendingFrequency(provider);
}
function renderSMTPSendingFrequency() {
// set sending frequency
var emails = $('#smtp_frequency_emails').val();
var interval = $('#smtp_frequency_interval').val();
setSendingFrequency({
output: '#mailpoet_smtp_daily_emails',
only_daily: true,
emails: emails,
interval: interval
});
$('#mta_frequency_emails').val(emails);
$('#mta_frequency_interval').val(interval);
}
function sendingFrequencyMethodUpdated() {
var method = $(this).find('option:selected').first();
var sendingMethod = $('#mailpoet_smtp_method').find('option:selected').first().val();
if(method.val() === "manual") {
$('#mailpoet_sending_frequency_manual').show();
$('#mailpoet_recommended_daily_emails').hide();
$('#other_frequency_emails').trigger("change");
} else {
$('#mailpoet_sending_frequency_manual').hide();
if(sendingMethod !== "server") {
$('#mailpoet_recommended_daily_emails').show();
}
$('#mailpoet_smtp_method').trigger("change");
}
}
function renderHostsSelect() {
var method = $(this).find('option:selected').first();
var val = method.val();
if(val === "server") {
$('#mailpoet_sending_method_host').show();
$('#mta_group').val('website');
} else {
$('#mailpoet_sending_method_host').hide();
}
if(val === "manual") {
$('.mailpoet_smtp_field').show();
$('#mta_group').val('smtp');
$('#mailpoet_smtp_provider').val('manual');
} else {
$('.mailpoet_smtp_field').hide();
}
if(val === "AmazonSES") {
$('.mailpoet_aws_field').show();
$('#mta_group').val('smtp');
$('#mailpoet_smtp_provider').val('AmazonSES');
} else {
$('.mailpoet_aws_field').hide();
}
if(val === "SendGrid") {
$('.mailpoet_sendgrid_field').show();
$('#mta_group').val('smtp');
$('#mailpoet_smtp_provider').val('SendGrid');
} else {
$('.mailpoet_sendgrid_field').hide();
}
var emails = method.data('emails');
var interval = method.data('interval');
if(val === "server") {
emails = $('#mailpoet_web_host').find('option:selected').first().data('emails');
interval = $('#mailpoet_web_host').find('option:selected').first().data('interval');
}
const frequencyMethod = $('#mailpoet_sending_frequency').find('option:selected').first().val();
if(frequencyMethod === "manual") {
$('#mailpoet_recommended_daily_emails').hide();
emails = $('#other_frequency_emails').val();
interval = $('#other_frequency_interval').val();
} else {
$('#mailpoet_recommended_daily_emails').show();
}
setSendingFrequency({
output: '#mailpoet_recommended_daily_emails',
only_daily: false,
emails: emails,
interval: interval
});
$('#mta_frequency_emails').val(emails);
$('#mta_frequency_interval').val(interval);
}
function renderHostSendingFrequency() {
var host = $(this).find('option:selected').first();
var frequencyType = $("#mailpoet_sending_frequency").find('option:selected').first().val();
var emails =
host.data('emails') || <%= default_frequency.website.emails %>;
var interval =
host.data('interval') || <%= default_frequency.website.interval %>;
var fields =
host.data('fields') || '';
if (frequencyType === "manual") {
return;
} else {
setSendingFrequency({
output: '#mailpoet_recommended_daily_emails',
only_daily: false,
emails: emails,
interval: interval
});
}
$('#mta_frequency_emails').val(emails);
$('#mta_frequency_interval').val(interval);
}
function updateSendingFrequency(method) {
// get emails
var options = {
only_daily: true,
emails: $('#'+method+'_frequency_emails').val(),
interval: $('#'+method+'_frequency_interval').val()
};
var MINUTES_PER_DAY = 1440;
var SECONDS_PER_DAY = 86400;
options.daily_emails = ~~(
(MINUTES_PER_DAY / options.interval) * options.emails
);
options.emails_per_second = (~~(
((options.daily_emails) / 86400) * 10)
) / 10;
// format daily emails number according to locale
options.daily_emails = options.daily_emails.toLocaleString();
$('#mailpoet_'+method+'_daily_emails').html(
sending_frequency_template(options)
);
// update actual sending frequency values
$('#mta_frequency_emails').val(options.emails);
$('#mta_frequency_interval').val(options.interval);
}
function setSendingFrequency(options) {
options.daily_emails = ~~((1440 / options.interval) * options.emails);
// format daily emails number according to locale
options.daily_emails = options.daily_emails.toLocaleString();
$(options.output).html(
sending_frequency_template(options)
);
}
Handlebars.registerHelper('format_time', function(value, block) {
var label = null;
var labels = {
minute: "<%= __('every minute') %>",
minutes: "<%= __('every %1$d minutes') %>",
hour: "<%= __('every hour') %>",
hours: "<%= __('every %1$d hours') %>"
};
// cast time as int
value = ~~(value);
// format time depending on the value
if(value >= 60) {
// we're dealing with hours
if(value === 60) {
label = labels.hour;
} else {
label = labels.hours;
}
value /= 60;
} else {
// we're dealing with minutes
if(value === 1) {
label = labels.minute;
} else {
label = labels.minutes;
}
}
if(label !== null) {
return label.replace('%1$d', value);
} else {
return value;
}
});
});
// enable/disable MSS method activate button and notice
function updateMSSActivationUI() {
var $ = jQuery;
var group = $('.mailpoet_sending_methods .mailpoet_active').data('group');
var key_valid = !$('.mailpoet_mss_key_valid').hasClass('mailpoet_hidden');
if (group !== 'mailpoet') {
$('.mailpoet_actions .mailpoet_invalid_key').toggleClass('mailpoet_hidden', key_valid);
$('.mailpoet_actions .mailpoet_valid_key').toggleClass('mailpoet_hidden', !key_valid);
$('.mailpoet_other_sending_method_action').removeClass('button-primary').addClass('button-secondary').text('<%= __('Configure') %>');
} else {
$('.mailpoet_actions .mailpoet_valid_key').addClass('mailpoet_hidden');
$('.mailpoet_activated').toggleClass('mailpoet_hidden', !key_valid);
$('.mailpoet_other_sending_method_action').removeClass('button-secondary').addClass('button-primary').text('<%= __('Activate') %>');
$('.mailpoet_invalid_key').toggleClass('mailpoet_hidden', key_valid);
$('.mailpoet_sending_methods li[data-group="'+group+'"], .mailpoet_sending_methods li[data-group="'+group+'"] > .mailpoet_status').toggleClass('mailpoet_invalid_key', !key_valid)
}
if (key_valid) {
$('.mailpoet_mss_activate_notice').toggle(group !== 'mailpoet');
}
};
</script>
<%= partial(
'mailpoet_sending_frequency_template',
'settings/templates/sending_frequency.hbs'
) %>