Problem/Motivation
After seeing the issue http://drupal.org/node/682000 , I thought whether to post this issue or not but, in that issue, there is still discussion going on about allowing other module to provide the limit. So I thought it will be good post the issue.
Steps to reproduce the issue.
- Create shortcuts more than 8, lets say 9. When you add more than 7 shortcuts, the 7th menu will be replaced by the new, and the old menu will be added disabled section.
- Go to Edit Shortcuts
- Drag all the shortcuts from Disabled to Enabled. When u drag and drop, it appears that Enabled section always have 7.
- Save
- You will see more than 7 shortcuts on the shortcuts bar.
Please check the attached screen shots of the issue.
Proposed resolution
We have to make sure that what we see when we drag drop, should be saved as it is.
Comments
Comment #1
pflame commentedHere the problem is with the javascript.
When a element is swapped to disabled section, it is not marked as disabled and status is not changed. I fixed this issue by changing the status when the element is swapped. Please check the attached patch
Comment #2
JacobSingh commentedI didn't get a chance to properly review this, but I tested it and see the issue. The fix looks appropriate, and reducing the use of an anonymous closure is anyway a good thing IMO.
I do think the coding standards are to use camelCase though for JS functions instead of an underscore "._row_status_change". I'm not sure about that though.
Also, the whitespace thing below.
Whitespace above tableDrag._row_status_change.
Comment #3
David_Rothstein commentedLooks like a nice fix.
Not being familiar with how tabledrag works, I have no idea what this code does, so it seems like it could use a code comment...
Also, are we sure it's necessary to even get the full row object here? (The new helper function added by this patch looks like it only uses rowObject.element, so in that case maybe the full object is never needed?)
Comment #4
pflame commented@JacobSingh, @David_Rothstein Thanks for reviewing patch and providing feedback.
1. I changed ._row_status_change function name to rowStatusChange and did not assign this function to tableDrag object.
2. Provided comments.
3. Yes, there should be validation at server-side, better to raise another issue, will raise another issue.
Please check the attached patch
Comment #5
JacobSingh commentedDavid said "Also, are we sure it's necessary to even get the full row object here? (The new helper function added by this patch looks like it only uses rowObject.element, so in that case maybe the full object is never needed?)"
I'm also not sure, but I don't think it matters much. THe code is clean and the performance difference would be negligible I imagine.
I think this is ready to go.
Comment #6
xjmThis patch needs a little minor code style cleanup before it goes in... there's trailing whitespace and a comment line over 80 chars. Also, comments need to end with a period (and "Swapped" should not be capitalized midsentence). Thanks, and sorry; I know these are very trivial things. :)
Also, would it be possible to test? We can't test the actual drag-and-drop, obviously, but could we emulate it?
Comment #7
JacobSingh commentedYou can test it. I tested it w/ and w/o the patch.
Comment #8
JacobSingh commentedOh you mean automated test? Not without selenium :)
Comment #9
xjmSo there's absolutely no server-side component to this and the extra shortcuts disappear on a page reload? Edit: Are you sure? What happens when "Save" is clicked? Sounds like something is not being enforced properly server-side.
Comment #10
pflame commented@JacobSingh,
Yes, I used tableDrag.row object's element property to mark the element as changed. I can copy the markChanged code here as another function, but it will not be neat. Creating an object does not cost much here, and we can make use of existing functions.
Regarding the test, we can't write test scripts with simpletest here, but we can test with selenium. I will try to provide selenium tests. I know how to create selenium tests using Selenium IDE from firefox. Is this the same what you are expecting?
@xjm,
I did the white space and comment related changes and provided new patch.
Regarding server-side component, I created another issue http://drupal.org/node/1358140
Comment #11
xjmI think we should probably fix #1358140: Drag and Drop of shortcuts between Enable and Disable should have server side validation for shortcut links limit in this issue as well.
Comment #12
David_Rothstein commentedRegarding the object issue, I wasn't thinking of it in terms of performance, just in terms of simplifying code. Basically, I was wondering if these two lines could be removed entirely:
Playing around with it a little now, I guess I can see why you added them; normally, Drupal only marks the row that was actually dragged with the asterisk (indicating that it was changed), but here you want to do it to the other row too because we're forcing one of its properties (enabled vs disabled) to change as well. I can buy that, I suppose.
If so, can we turn that explanation into a code comment?... In general, I think the code comments in this patch could be improved in the following way: Right now they're talking about what the code is doing, but it's better to use code comments to explain why. For example, here:
I think the code comment can be left out, since what it says is more-or-less obvious from the code.
Whereas here:
This is a good start, but it's still just telling me what the code does. As per above, this would be the place to explain why it is that we want to go out of our way to mark this particular row as changed (when the tableDrag system doesn't normally do that). Does that make sense?
Overall this patch is looking very good. Like I said in #3, I'm not sure whether we should merge #1358140: Drag and Drop of shortcuts between Enable and Disable should have server side validation for shortcut links limit with this or not.... Normally I'd say yes, but in this case I don't care as much since we want to remove the limit anyway, so if people can sneak their way around it, it really doesn't bother me that much :) The reason the JavaScript version of the bug (i.e. this issue) is worse is that you see one thing on the screen when you drag and drop, but then something totally different happens after you save.
Comment #13
pflame commentedDavid_Rothstein,
I understood and fully agree with your point about the comments, I changed the comments and mentioned why I wrote those 2 lines of code.
This issue is more about what we see on the screen is not saved when we save, so this patch should go in even when there is a support to let the user add the shortcut limit.
I am not sure whether #1358140: Drag and Drop of shortcuts between Enable and Disable should have server side validation for shortcut links limit issue is still required when the limit is removed. So it is better to keep separate.
Comment #14
JacobSingh commented+1 Nice work Prajwala!
Here's an attached version which just fixes the grammar a tiny bit.
Comment #15
David_Rothstein commentedThis looks much better, but I think it needs one more rewrite. There's a typo ("br") and words like Disabled shouldn't be capitalized. Plus, the last couple of sentences duplicate each other a bit and aren't totally clear. Maybe something along the lines of this (feel free to tweak the wording):
Comment #16
pflame commentedThanks JacobSingh and David_Rothstein for helping to create patch :).
I have updated the patch with updated comments.
Comment #17
David_Rothstein commentedThanks!
I was going to mark it RTBC, but.... trying out the patch, it doesn't seem to work always? I found that if I drag something from "disabled" to a place near the bottom of the enabled list, it works as intended. But if I drag from "disabled" all the way to the top (or close to the top), the swap doesn't happen correctly and you still wind up with 8 enabled shortcuts after you save (even though you only see 7 on the screen before you save).
Can anyone else reproduce this?
Comment #18
David_Rothstein commentedLooking at the tabledrag code, it also occurs to me that 'mouse' probably isn't right here. How do we know they are using a mouse as opposed to the keyboard?
The tabledrag.js code itself always seems to check before calling this.
Comment #19
pflame commentedI am able to reproduce the bug. It happened when I drag items from disabled to enabled section very fast. I am working on it.
Comment #20
David_Rothstein commentedIf that bug proves too hard to fix, we could probably just get this patch committed without it (and leave the remaining work for a followup)..... as is, the patch still represents a big improvement over the current behavior.
However, I think we do need to clarify the 'mouse' vs 'keyboard' issue I raised in #18. It's important to make sure this patch doesn't cause any harm for people who are doing drag-and-drop via the tab+arrow keys rather than a mouse.
Comment #21
pflame commentedThe bug is bit complicated. It seems the problem is with tabledrag.js. I am still finding efficient way to solve the problem. As you said, we can commit the existing patch and continue work on this bug.
+ swappedRowObject = new tableDrag.row(swappedRow, 'mouse', self.indentEnabled, self.maxDepth, true);In the above line, there will not be any difference if we use 'mouse' or 'keyboard'. I tested with both 'mouse' and 'keyboard'. Because we are creating this object just to mark the row as changed and swapping of row is happening automatically by shortcut module so using 'mouse' or 'keyboard' does not make difference.
Comment #22
David_Rothstein commentedGood point.
I had some issues when I tried this with a keyboard (could not drag something up from the disabled section to enabled) which I thought were due to this patch, but you're right, they're not, and there's no reason they could be. The same thing happens without the patch, so it's a preexisting bug.
Nice work!
Comment #23
pflame commentedYes, I too noticed the issue with keyboard(unable to move from disabled section to enabled section) but it is not related this bug, so did not mention here. I raised another issue for it http://drupal.org/node/1372862.
Comment #24
catchPlease open a follow-up for the remaining JavaScript bug so that doesn't get lost. I'm OK with not fixing everything in one patch but there's already two follow-ups spun off this one.
Comment #25
David_Rothstein commented#16: edit_shortcuts_drag_drop_issue-1344752-16.patch queued for re-testing.
Comment #26
David_Rothstein commentedCreated #1386514: Dragging and dropping a shortcut from disabled to enabled doesn't switch the status if the dragging happens fast. I think there's nothing that can be done there until this one is committed though.
Comment #27
catchThanks! Committed/pushed to 8.x.
This wasn't tagged for backport, but seems like it should be?
Comment #28
aspilicious commentedComment #30
aspilicious commentedLet's try again...
Comment #31
David_Rothstein commentedPatch looks good, and it works fine in Drupal 7 also.
Comment #32
webchickCool. This can't be unit tested, so good to go.
Committed and pushed to 7.x. Thanks!
Comment #33
pflame commentedThe issue discussed in the comments #17, #19 and #21 is fixed and provided patch at issue Dragging and dropping a shortcut from disabled to enabled doesn't switch the status if the dragging happens fast. Please review.