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

[4.0] Replace js alerts for joomla alerts #15315

Merged
merged 13 commits into from Apr 15, 2017
5 changes: 3 additions & 2 deletions libraries/cms/toolbar/button/standard.php
Expand Up @@ -115,13 +115,14 @@ public function fetchId($type = 'Standard', $name = '', $text = '', $task = '',
*/
protected function _getCommand($name, $task, $list)
{
JText::script('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
$alert = JText::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');

$cmd = "Joomla.submitbutton('" . $task . "');";

if ($list)
{
$alert = "alert(Joomla.JText._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'));";
$messages = "{'warning': ['" . $alert . "', '<h4>" . JText::_('WARNING') . "</h4>']}";
Copy link
Member

Choose a reason for hiding this comment

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

do you sure it will not fail when the translation contain the quote?
and why do not use Joomla.JText._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST')?

Copy link
Member

Choose a reason for hiding this comment

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

please use JText::script and do not do this trap, with hard mix of PHP and JavaScript

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fedik Thank you for the tip, while using your advice I found that no '<h4>" . JText::_('WARNING') . "</h4>' was required if I had a JText::script('WARNING');

$alert = "Joomla.renderMessages(" . $messages . ")";
$cmd = "if (document.adminForm.boxchecked.value == 0) { " . $alert . " } else { " . $cmd . " }";
}

Expand Down
Expand Up @@ -123,9 +123,11 @@ public function testRender()
{
$type = array('Standard', 'test');

$expected = "\n<button onclick=\"if (document.adminForm.boxchecked.value == 0) { alert(Joomla.JText._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST')); } else { Joomla.submitbutton(''); }\" class=\"btn btn-sm btn-outline-primary\">\n"
. "\t<span class=\"icon-test\"></span>\n"
. "\t</button>\n";
$alert = JText::_('WARNING');

$expected = "\n<button onclick=\"if (document.adminForm.boxchecked.value == 0) { Joomla.renderMessages({'warning': ['JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST', '<h4>"
. $alert
Copy link
Member

Choose a reason for hiding this comment

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

same here

. "</h4>']}) } else { Joomla.submitbutton(''); }\" class=\"btn btn-sm btn-outline-primary\">\n\t<span class=\"icon-test\"></span>\n\t</button>\n";

$this->assertEquals(
$expected,
Expand Down