Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Send Test Mail] Use json MimeType, send data via POST method and catch json response errors #9685

Merged
merged 14 commits into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public function execute()
$this->app->redirect('index.php');
}

$this->app->mimeType = 'application/json';
$this->app->setHeader('Content-Type', $this->app->mimeType . '; charset=' . $this->app->charSet);
$this->app->sendHeaders();

$model = new ConfigModelApplication;
echo new JResponseJson($model->sendTestMail());
JFactory::getApplication()->close();
$this->app->close();
}
}
7 changes: 7 additions & 0 deletions administrator/components/com_config/view/application/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public function render()

$this->userIsSuperAdmin = $user->authorise('core.admin');

// Add strings for translations in Javascript.
JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_CONNECTION_ABORT');
JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_NO_CONTENT');
JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_OTHER');
JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_PARSE');
JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_TIMEOUT');

$this->addToolbar();

return parent::render();
Expand Down
5 changes: 5 additions & 0 deletions administrator/language/en-GB/en-GB.com_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ COM_CONFIG_SAVE_SUCCESS="Configuration successfully saved."
COM_CONFIG_SENDMAIL_ACTION_BUTTON="Send Test Mail"
COM_CONFIG_SENDMAIL_BODY="This is a test mail sent using "_QQ_"%s"_QQ_". If you receive it, then your email settings are correct!"
COM_CONFIG_SENDMAIL_ERROR="Test mail could not be sent."
COM_CONFIG_SENDMAIL_JS_ERROR_CONNECTION_ABORT="A connection abort as occured while fetching the JSON data."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAS not AS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all corrected

COM_CONFIG_SENDMAIL_JS_ERROR_NO_CONTENT="No content has returned."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WAS not HAS

COM_CONFIG_SENDMAIL_JS_ERROR_OTHER="An error as occured while fetching the JSON data: HTTP %s status code."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAS not AS

COM_CONFIG_SENDMAIL_JS_ERROR_PARSE="A parse error as occured while processing the following JSON data:<br/><code style="_QQ_"color:inherit;white-space:pre;padding:0;margin:0;border:0;background:inherit;"_QQ_">%s</code>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAS not AS

COM_CONFIG_SENDMAIL_JS_ERROR_TIMEOUT="A timeout as occured while fetching the JSON data."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAS not AS

COM_CONFIG_SENDMAIL_METHOD_MAIL="PHP Mail"
COM_CONFIG_SENDMAIL_METHOD_SENDMAIL="Sendmail"
COM_CONFIG_SENDMAIL_METHOD_SMTP="SMTP"
Expand Down
70 changes: 52 additions & 18 deletions media/system/js/sendtestmail-uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,77 @@ jQuery(document).ready(function ($)
};

$.ajax({
url: sendtestmail_url,
data: email_data
})
method: "POST",
url: sendtestmail_url,
data: email_data,
dataType: "json"
})
.fail(function (jqXHR, textStatus, error) {
var msg = {};

if (textStatus == 'parsererror')
{
// Html entity encode.
var encodedJson = jqXHR.responseText.trim();

var buf = [];
for (var i = encodedJson.length-1; i >= 0; i--) {
buf.unshift( [ '&#', encodedJson[i].charCodeAt(), ';' ].join('') );
}

.done(function (response)
{
var data_response = $.parseJSON(response);
encodedJson = buf.join('');

msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_PARSE').replace('%s', encodedJson) ];
}
else if (textStatus == 'nocontent')
{
msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_NO_CONTENT') ];
}
else if (textStatus == 'timeout')
{
msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_TIMEOUT') ];
}
else if (textStatus == 'abort')
{
msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_CONNECTION_ABORT') ];
}
else
{
msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_OTHER').replace('%s', jqXHR.status) ];
}

Joomla.renderMessages(msg);
})
.done(function (response) {
var msg = {};

if (data_response.data)
if (response.data)
{
if (typeof data_response.messages == 'object')
if (typeof response.messages == 'object')
{
if (typeof data_response.messages.success != 'undefined' && data_response.messages.success.length > 0)
if (typeof response.messages.success != 'undefined' && response.messages.success.length > 0)
{
msg.success = [data_response.messages.success];
msg.success = [response.messages.success];
}
}

}
else
{
if (typeof data_response.messages == 'object')
if (typeof response.messages == 'object')
{
if (typeof data_response.messages.error != 'undefined' && data_response.messages.error.length > 0)
if (typeof response.messages.error != 'undefined' && response.messages.error.length > 0)
{
msg.error = [data_response.messages.error];
msg.error = [response.messages.error];
}

if (typeof data_response.messages.notice != 'undefined' && data_response.messages.notice.length > 0)
if (typeof response.messages.notice != 'undefined' && response.messages.notice.length > 0)
{
msg.notice = [data_response.messages.notice];
msg.notice = [response.messages.notice];
}

if (typeof data_response.messages.message != 'undefined' && data_response.messages.message.length > 0)
if (typeof response.messages.message != 'undefined' && response.messages.message.length > 0)
{
msg.message = [data_response.messages.message];
msg.message = [response.messages.message];
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions media/system/js/sendtestmail.js

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