Skip to content

Commit

Permalink
fix: alert on page load
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli authored and julianlam committed Feb 24, 2023
1 parent 3bd9a87 commit 8cf4a6f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
52 changes: 33 additions & 19 deletions public/src/admin/settings/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ define('admin/settings/email', ['ace/ace', 'alerts', 'admin/settings'], function
configureEmailTester();
configureEmailEditor();
handleDigestHourChange();
handleSmtpServiceChange();

$(window).on('action:admin.settingsLoaded action:admin.settingsSaved', handleDigestHourChange);
$(window).on('action:admin.settingsSaved', function () {
socket.emit('admin.user.restartJobs');
});
$('[id="email:smtpTransport:service"]').change(handleSmtpServiceChange);
$(window).off('action:admin.settingsLoaded', onSettingsLoaded)
.on('action:admin.settingsLoaded', onSettingsLoaded);
$(window).off('action:admin.settingsSaved', onSettingsSaved)
.on('action:admin.settingsSaved', onSettingsSaved);
};

function onSettingsLoaded() {
handleDigestHourChange();
handleSmtpServiceChange();
}

function onSettingsSaved() {
handleDigestHourChange();
socket.emit('admin.user.restartJobs');
}

function configureEmailTester() {
$('button[data-action="email.test"]').off('click').on('click', function () {
socket.emit('admin.email.test', { template: $('#test-email').val() }, function (err) {
Expand Down Expand Up @@ -106,20 +114,26 @@ define('admin/settings/email', ['ace/ace', 'alerts', 'admin/settings'], function
}

function handleSmtpServiceChange() {
const isCustom = $('[id="email:smtpTransport:service"]').val() === 'nodebb-custom-smtp';
$('[id="email:smtpTransport:custom-service"]')[isCustom ? 'slideDown' : 'slideUp'](isCustom);

const enabledEl = document.getElementById('email:smtpTransport:enabled');
if (enabledEl) {
if (!enabledEl.checked) {
enabledEl.closest('label').classList.toggle('is-checked', true);
enabledEl.checked = true;
alerts.alert({
message: '[[admin/settings/email:smtp-transport.auto-enable-toast]]',
timeout: 5000,
});
}
function toggleCustomService() {
const isCustom = $('[id="email:smtpTransport:service"]').val() === 'nodebb-custom-smtp';
$('[id="email:smtpTransport:custom-service"]')[isCustom ? 'slideDown' : 'slideUp'](isCustom);
}
toggleCustomService();
$('[id="email:smtpTransport:service"]').change(function () {
toggleCustomService();

const enabledEl = document.getElementById('email:smtpTransport:enabled');
if (enabledEl) {
if (!enabledEl.checked) {
$('label[for="email:smtpTransport:enabled"]').toggleClass('is-checked', true);
enabledEl.checked = true;
alerts.alert({
message: '[[admin/settings/email:smtp-transport.auto-enable-toast]]',
timeout: 5000,
});
}
}
});
}

return module;
Expand Down
2 changes: 1 addition & 1 deletion src/views/admin/settings/email.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
[[admin/settings/email:smtp-transport.gmail-warning2]]
</p>
</div>
<div class="form-group well" id="email:smtpTransport:custom-service" style="display: none">
<div class="form-group well" id="email:smtpTransport:custom-service">
<h5>Custom Service</h5>

<label for="email:smtpTransport:host">[[admin/settings/email:smtp-transport.host]]</label>
Expand Down

0 comments on commit 8cf4a6f

Please sign in to comment.