Skip to content

Commit

Permalink
sendtestmail.js code refactor (#10953)
Browse files Browse the repository at this point in the history
* Modified sendtestmail to be testable

* Fixed missing callback function pass

* Fixed $ = jQuery

* Modified minified version
  • Loading branch information
Ruchiranga authored and wilsonge committed Jul 25, 2016
1 parent 82dd2b9 commit c00c8cc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
74 changes: 39 additions & 35 deletions media/system/js/sendtestmail-uncompressed.js
Expand Up @@ -7,45 +7,49 @@
/**
* Calls the sending process of the config class
*/
jQuery(document).ready(function ($)
var sendTestMail = function ()
{
$('#sendtestmail').click(function ()
{
var email_data = {
smtpauth : $('input[name="jform[smtpauth]"]:checked').val(),
smtpuser : $('input[name="jform[smtpuser]"]').val(),
smtppass : $('input[name="jform[smtppass]"]').val(),
smtphost : $('input[name="jform[smtphost]"]').val(),
smtpsecure: $('select[name="jform[smtpsecure]"]').val(),
smtpport : $('input[name="jform[smtpport]"]').val(),
mailfrom : $('input[name="jform[mailfrom]"]').val(),
fromname : $('input[name="jform[fromname]"]').val(),
mailer : $('select[name="jform[mailer]"]').val(),
mailonline: $('input[name="jform[mailonline]"]:checked').val()
};
$ = jQuery;

// Remove js messages, if they exist.
Joomla.removeMessages();
var email_data = {
smtpauth : $('input[name="jform[smtpauth]"]:checked').val(),
smtpuser : $('input[name="jform[smtpuser]"]').val(),
smtppass : $('input[name="jform[smtppass]"]').val(),
smtphost : $('input[name="jform[smtphost]"]').val(),
smtpsecure: $('select[name="jform[smtpsecure]"]').val(),
smtpport : $('input[name="jform[smtpport]"]').val(),
mailfrom : $('input[name="jform[mailfrom]"]').val(),
fromname : $('input[name="jform[fromname]"]').val(),
mailer : $('select[name="jform[mailer]"]').val(),
mailonline: $('input[name="jform[mailonline]"]:checked').val()
};

$.ajax({
method: "POST",
url: document.getElementById('sendtestmail').getAttribute('data-ajaxuri'),
data: email_data,
dataType: "json"
})
.fail(function (jqXHR, textStatus, error) {
Joomla.renderMessages(Joomla.ajaxErrorsMessages(jqXHR, textStatus, error));
// Remove js messages, if they exist.
Joomla.removeMessages();

window.scrollTo(0, 0);
})
.done(function (response) {
// Render messages, if any.
if (typeof response.messages == 'object' && response.messages !== null)
{
Joomla.renderMessages(response.messages);
$.ajax({
method: "POST",
url: document.getElementById('sendtestmail').getAttribute('data-ajaxuri'),
data: email_data,
dataType: "json"
})
.fail(function (jqXHR, textStatus, error) {
Joomla.renderMessages(Joomla.ajaxErrorsMessages(jqXHR, textStatus, error));

window.scrollTo(0, 0);
}
});
window.scrollTo(0, 0);
})
.done(function (response) {
// Render messages, if any.
if (typeof response.messages == 'object' && response.messages !== null)
{
Joomla.renderMessages(response.messages);

window.scrollTo(0, 0);
}
});
};

jQuery(document).ready(function ($)
{
$('#sendtestmail').click(sendTestMail);
});
2 changes: 1 addition & 1 deletion media/system/js/sendtestmail.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c00c8cc

Please sign in to comment.