#428744: Make the main page content a real block introduced an alert() that notify the user if a block can't be placed in the region it was dragged to. But right now even if the region is allowed, if the block is not dropped at first in that region the alert is triggered anyway.

The fault is in line 28 of block.js var regionRow = $(dragObject.rowObject.element).prev('tr').get(0);. This line gets the previous row of the one dragged and in line 29 it assumes it has the the class "region-messagege region-[region]message..." which is not the case if the block is not first in the region. After that the condition in line 32 becomes true and the alert is triggered.

The attached patch change line 28 so we look for the previous row (tr) with class "region-message".

On a side note, for me the regexp in line 29 it looks like it could have been done simpler.

Comments

tic2000’s picture

Priority: Normal » Critical

I mark this critical cause right now you can't order the blocks as you'd like, unless you know before hand what is the order and add the blocks in reverse order.

The behavior now is that you get the alert but the block is always placed first in the selected region (unless really it's not allowed to place in that region)

To replicate, just try to change the order of the blocks in left sidebar on a fresh install (or even an old, but updated one).

tic2000’s picture

Title: alert() triggers when the block is not drag/dropped first in the region » Reordering blocks doesn't work as it should

better title

catch’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Quick fix

I can reproduce the bug, patch works, well found.

tic2000’s picture

Not many people are moving blocks yet :)

dries’s picture

Should we write a test case for this?

catch’s picture

I don't think simpletest will see the javascript alert will it?

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new80.68 KB

Good catch, I did make this wrong in D7, right. It probably simplifies the JS if we look for the .region row instead. The region name is also included there in the classname.

Looking at the code, one more thing which should be looked at here IMHO is that region names might have an underscore (although core regions don't have any). Classnames however use dashes, so we should look at whether these are converted properly for the table row classes and if so, we should convert them here so that the select box values are properly checked.

tic2000’s picture

Right now the code looks for the .region-message row. I could change it to look for just .region, but I think it's just the same.
If the region uses an underscore the class will be with an underscore too. The code works if the region is with an underscore or even a dash.

About a test, I don't know to write even a simple test so I don't know if a test to see if the block is dropped where it should and not moved by javascript is even possible.

tic2000’s picture

What do we need here to get this committed?

tic2000’s picture

Status: Needs work » Needs review
dropcube’s picture

I can not find why this feature is required and when it was added. I mean, in what situations the block can't be placed in the region it was dragged to ??? Is this defined somewhere?

tic2000’s picture

If you read the OP you will see a link to the issue where that feature was added and why.
The main goal of it is so you can't remove the main content block. Anyway that is not the topic of this issue.

dropcube’s picture

@tic2000: Ok, to review the patch, I needed to know in what situations the block can't be placed in a region, this is the info I could not find, and was kindly asking.

tic2000’s picture

As I already said, but maybe not clear enough, you can't place the main content block in the "none" region (you can't disable it) and the info is in #428744: Make the main page content a real block.
The effect because of a small javascript bug is that you get a "false positive" every time you drag a block to a position that is not first in a region.

And to explain why I marked this back to CNR.

We can't test javascript (now I know a little about how to write one).
I think it's better to use region-[region_name]-message because you have delimiter before and after the region name.
As I pointed in #8 the code works if the region name has an "_" or even a "-" in it.

Status: Needs review » Needs work

The last submitted patch failed testing.

tic2000’s picture

Status: Needs work » Needs review

Whatever you say bot :)

Status: Needs review » Needs work

The last submitted patch failed testing.

chx’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

tic2000’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

tic2000’s picture

Status: Needs work » Needs review
chx’s picture

StatusFileSize
new964 bytes
chx’s picture

Ps. please do not credit me i am just resetting testing.

gábor hojtsy’s picture

StatusFileSize
new913 bytes

As I've said above, let's simplify this to .region instead of .region-message. Otherwise IMHO it looks good. Let's get this one in, this bug is quite a bad one.

tic2000’s picture

Why do you think using "region" is simplifying?
If you use "region" var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2'); becomes var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)([ ]+[^ ]+)*/, '$2'); because region-{region_var}-message is on another row so in your patch regionName variable will not get the region name but just give all classes like "region region-sidebar_first". Also if you do that you have no start and end "markers" so if some theme adds "region-collapsed" as a class before the "region-$region" class the script will get "collapsed" as being a region name.

Instead of simplifying I think the change would just make the script more prone to match errors.

gábor hojtsy’s picture

Status: Needs review » Needs work

@tic2000: oh, you are right! Can you please add some docs then to the patch, so others would not have the inclination to make this "simplification" in the future. Otherwise your patch makes the blocks page work again, so I'm all with it now.

tic2000’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB

Here it is.

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. At least catch and I tested the same patch minus docs. The docs look good.

Bojhan’s picture

Tested, was working

webchick’s picture

Status: Reviewed & tested by the community » Fixed

My, that is some insanely obtuse code that could really do with some comments to explain what on earth is going on. :)

However, it wasn't invented here, and the patch does indeed fix the bug. I confirm that there is sadly no way currently to test JS. :(

Committed to HEAD. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Quick fix

Automatically closed -- issue fixed for 2 weeks with no activity.