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

Conversation

NunoLopesPT
Copy link
Contributor

@NunoLopesPT NunoLopesPT commented Apr 14, 2017

Summary of Changes

Replace the JS alert() for the Joomla alerts in standart buttons where are no boxes checked

Testing Instructions

Go Components -> Banners -> Banners

Without any box checked, hit publish item

Expected result

screenshot from 2017-04-14 22-40-40

Also, I think the close button is white because the class is not completed, here is where the class is called:
https://github.com/joomla/joomla-cms/blob/4.0-dev/media/system/js/core.js#L333

Actual result

screenshot from 2017-04-14 22-43-52

Documentation Changes Required

none

@NunoLopesPT NunoLopesPT changed the title replace js alerts for joomla alerts [4.0] Replace js alerts for joomla alerts Apr 14, 2017
@zero-24 zero-24 added this to the Joomla 4.0 milestone Apr 14, 2017
@zero-24
Copy link
Contributor

zero-24 commented Apr 14, 2017

/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/cms/pagination/JPaginationTest.php:749
5) JToolbarButtonTest::testRender
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '
-<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">
+<button onclick="if (document.adminForm.boxchecked.value == 0) { Joomla.renderMessages({'warning': ['JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST', '<h4>Warning</h4>']}) } else { Joomla.submitbutton(''); }" class="btn btn-sm btn-outline-primary">
 	<span class="icon-test"></span>
 	</button>
 '

https://travis-ci.org/joomla/joomla-cms/jobs/222232149

Looks good to me 👍 and is working well. Can you fix the travis error above. The other ones are not realted to your PR. I'm going to open a new issue for that.

@C-Lodder
Copy link
Member

@NunoLopes96 - that last commit you just made in incorrect. This is PHP, not JS ;)

@zero-24
Copy link
Contributor

zero-24 commented Apr 15, 2017

@NunoLopes96 in Order to fix the test you need to edit the test itself your code was correct before the last commit ;)

@NunoLopesPT
Copy link
Contributor Author

Ok I'm sorry never used travis before I need to research first a little bit, any tip?

@zero-24
Copy link
Contributor

zero-24 commented Apr 15, 2017

@NunoLopes96 please check this file + line in your branch: https://github.com/NunoLopes96/joomla-cms/blob/replaceJSalerts/tests/unit/suites/libraries/cms/toolbar/JToolbarButtonTest.php#L126

There is the expeced value stored. So this value needs to be changed as we want to change the output.

@NunoLopesPT
Copy link
Contributor Author

@zero-24 I just changed that, that error no longer appears on travis, thank you for the help

@jreys
Copy link
Contributor

jreys commented Apr 15, 2017

I have tested this item ✅ successfully on 746f8d1


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15315.

@rjcf18
Copy link
Contributor

rjcf18 commented Apr 15, 2017

I have tested this item ✅ successfully on 746f8d1

The Joomla alert appears normally after clicking publish item with no item selected after the patch.

Before patch:

deepinscreenshot20170415025640

After patch:

deepinscreenshot20170415025216

System information

Joomla! 4.0.0-dev
OS: Linux Deepin 15.3
Kernel: 4.4.0-3-deepin-amd64
Google Chrome: 56.0.2924.76 (64 bit)
PHP: 7.0.12-2


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15315.

@joomla-cms-bot joomla-cms-bot removed this from the Joomla 4.0 milestone Apr 15, 2017
@ghost
Copy link

ghost commented Apr 15, 2017

RTC after two successful tests.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Apr 15, 2017
@joomdonation
Copy link
Contributor

joomdonation commented Apr 15, 2017

Please remove RTC label. You cannot simply change JText::script to JText::_ as look like JText::script has some code to deal with special character in string

For example, with this change, you can edit the file , change administrator\language\en-GB\en-GB.lib_joomla.ini, change the language item

JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST="Please first make a selection from the list."

To:

JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST="Please first ' make a selection from the list."

(note the special character ' in the change string). You will get javascript error. Note that the original code works well with this special character in language string

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 15, 2017

$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 = 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

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Apr 15, 2017

I am against this.
There should not be any inline scripts in J4 in order to satisfy CSP requirements.
So we have to create a toolbar.js file with the logic needed and then pass form the PHP side the config options, e.g. JFactory->getDocument()->addScriptOptions('Toolbar', $optionsArray).

Please DO NO MERGE this!
It's not the right approach!

@brianteeman
Copy link
Contributor

brianteeman commented Apr 15, 2017 via email

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Apr 15, 2017

@brianteeman
Copy link
Contributor

brianteeman commented Apr 15, 2017 via email

@joomla-cms-bot joomla-cms-bot added the Language Change This is for Translators label Apr 15, 2017
@NunoLopesPT
Copy link
Contributor Author

NunoLopesPT commented Apr 15, 2017

Replaced the JText::_ for JText::script and while doing that found that when adding the JText::script('WARNING'); appeared 2x Warning, so I removed the text with <h4> tags and now the title is higher:

Actual:
screenshot from 2017-04-15 14-01-19

Before:
screenshot from 2017-04-14 22-14-55

@@ -431,7 +431,7 @@ JLIB_HTML_MOVE_UP="Move Up"
JLIB_HTML_NO_PARAMETERS_FOR_THIS_ITEM="There are no parameters for this item."
JLIB_HTML_NO_RECORDS_FOUND="No records found."
JLIB_HTML_PAGE_CURRENT_OF_TOTAL="Page %s of %s"
JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST="Please first make a selection from the list."
JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST="Please first ' make a selection from the list."
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be here

@joomla-cms-bot joomla-cms-bot removed the Language Change This is for Translators label Apr 15, 2017
@NunoLopesPT
Copy link
Contributor Author

Sorry, done

@wilsonge wilsonge merged commit e4c212a into joomla:4.0-dev Apr 15, 2017
@wilsonge wilsonge added this to the Joomla 4.0 milestone Apr 15, 2017
@wilsonge
Copy link
Contributor

Merged - thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet