From comments in #1344752: Drag and Drop of shortcuts between Enable and Disable Does not respect the Shortcuts Limit (note that this bug is probably not reproducible until after that patch is committed; we decide to postpone it to this followup issue instead):

David_Rothstein (comment #17):

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).

pflame (comment #19):

I am able to reproduce the bug. It happened when I drag items from disabled to enabled section very fast. I am working on it.

pflame (comment #21):

The bug is bit complicated. It seems the problem is with tabledrag.js. I am still finding efficient way to solve the problem.

We can start this issue in the Shortcut module queue for now but move it to a tabledrag.js bug if it turns out to be necessary.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pflame’s picture

Status: Active » Needs review
FileSize
1.48 KB

David_Rothstein,

I could able to fix this bug without touching tabledrag.js. Check the attached patch file.

The swappedRow variable that is passed by tabledrag.js to onswap event handler, is not the actual swapped element here. Because here, swapping happens also based on shortcut links limit.

-          disabled.after(disabled.prevAll().filter(':not(.shortcut-slot-empty)').get(0));
-          if ($(swappedRow).hasClass('draggable')) {
+          changedRow = disabled.prevAll().filter(':not(.shortcut-slot-empty)').get(0);
+          disabled.after(changedRow);
+          if ($(changedRow).hasClass('draggable')) {

From the first line of above code, we can notice that, the last element in the enabled selection will be moved as first element to the disabled section. So we need to mark this element as changed element. When I drag and drop slowly this element(changedRow variable) and the swappedRow variable point to same dom element, but if I drag and drop fast they are different.

David_Rothstein’s picture

Huh! Nice work. I think you are right.

It would be great to get a code comment explaining the difference between swappedRow and changedRow (so that someone reading the code can understand why one needs to be used rather than the other).

pflame’s picture

David_Rothstein,

Thanks for the review. Added comments explaining the changedRow. Please check the attached patch.

I have also fixed issue Could Not Drag shortcut link from Disabled Section to Enabled section through Keyboard, but the fix is in the line below, which is changed in this bug. How do I provide patch to this bug. Shell I wait until this patch is committed?

 changedRow = disabled.prevAll().filter(':not(.shortcut-slot-empty)').get(0);

Need to change the above line to

 changedRow = disabled.prevAll().not($(this.element)).filter(':not(.shortcut-slot-empty)').get(0);
pflame’s picture

sorry by mistake attached same patch 2 times in the above comment.

nod_’s picture

FileSize
2.28 KB

Please be careful of not introducing global variables by accident. prevAll() can filter the results, no need for the filter() right after it.

The file could use some cleanup too.

nod_’s picture

Issue tags: +JavaScript

forgot tag

David_Rothstein’s picture

Good catch on the global variables, etc.

I think the patch looks good now, but the code comment still needs a little work. The spacing isn't correct (there should be as many characters on each line as can fit, but not going over 80 characters), and the capitalization isn't quite right... Also, I don't think the second sentence adds much that wasn't in the first?

I'd suggest rewriting the first sentence to say "To maintain the shortcut links limit, we need to move the last element from the enabled section to the disabled section." Then, if it's possible to come up with a second sentence to specifically explain why swappedRow is the wrong thing to use here (i.e., what is the difference between swappedRow and changedRow?), let's add that... If not, the one sentence is probably OK.

I have also fixed issue Could Not Drag shortcut link from Disabled Section to Enabled section through Keyboard, but the fix is in the line below, which is changed in this bug. How do I provide patch to this bug. Shell I wait until this patch is committed?

Nice! I would say either wait until this is committed, or, if it's really just that small of a change on top of the current patch, feel free to roll it into this patch and we could just fix both at once. It's up to you.

If you decide to include it here, you can close the other issue as a duplicate of this one.

pflame’s picture

FileSize
2.19 KB

Hi David_Rothstein,

Thanks for the review. I changed the first line of comment as you suggested. I felt that, if we keep a comment about why swappedRow can not be used, it will be confusing. So I just put 1 sentence and removed the second sentence.

I included the fix to Could Not Drag shortcut link from Disabled Section to Enabled section through Keyboard in this patch and I close other issue as duplicate.

Please check the new patch.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

Works fine for me, keyboard and mouse.

Just need to know if David_Rothstein is ok with the comments and I guess it's good to go.

David_Rothstein’s picture

Yup, looks good to me, and it works when I tested it also.

I did a quick reroll to make the comment wrap at 80 characters (per coding standards, http://drupal.org/node/1354) and am attaching that, but it should be ready to go.

Thanks!

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x and 8.x. Thanks.

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