The menu page should include some of the same functionality enhancements that block module received, making it easier to organize weights in a menu. The UI for this could prove more troublesome that the blocks page, as the possible parents for each menu item is quite a long list.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mlncn’s picture

+1

AHAH reorder of weights under only one parent would be great (provided all the children come along, of course.)

Subscribing.

ben Agaric Design Collective

quicksketch’s picture

Title: AHAH enable menu module » Drag and drop menu structure
Assigned: Unassigned » quicksketch
FileSize
22.39 KB

Well... the reordering of things by AHAH may have been short lived. Rather, let's focus on the drag and drop enhancements started in this issue: http://drupal.org/node/181066

With the blocks page already pretty much squared away by drag and drop, we can use this issue to focus on menu-specific implementation. I've already got the menu page changed into a form to allow us to change it, and I'm working on the parenting behavior (pretty much done also).

What's not done is the ability to move an entire group of rows simultaneously. If moving a parent, it should move all the children also. I've attached a screenshot of how this will look when finished.

Secondly, we need the ability to move an item horizontally as well, adding or removing indentation and finding a different parent as necessary. I intend to do this through the use of an 'indent' DIV element, which we'll duplicate once for every level inward. Setting a background image on the element will allow us to have the tree-like lines indicating a child relationship.

quicksketch’s picture

Status: Active » Needs work
FileSize
8.71 KB

Here's the first revision of the drag and drop menu structure. While this actually does work, the submit button is missing and has the limitations noted in #2.

This patch is dependent on #28 in the drag and drop issue.

stBorchert’s picture

Hi.
Perhaps http://interface.eyecon.ro/demos/drag_drop_tree.html would be a good starting point for moving a complete group.
Something like this:

table = $('#menu-overview');
$('tr', table.get(0)).each(
  function()
  {
    // select all <tr> that start with same class/id as the current <tr>
    subbranch = $('...');
    if (subbranch.size() > 0) {
      // add these "child" <tr> to the items that needs to be dragged and do all other magic...
    }
  }
);

I have to do some testing but it should be possible somehow.

chx’s picture

Thanks for making this a form I am using this to patch http://drupal.org/node/178608 . But please note that you have removed the pager from the overview form -- this is not going to work, the menu links table can have hundreds of thousands of items in it for any given menu.

chx’s picture

Then again, I am wrong, the pager_query is still there just the theme pager is not. Sorry.

quicksketch’s picture

chx: Feel free to reroll as necessary to make the form actually work properly. I'd prefer to keep the titles as links personally, rather than turning them into textfields. Adding an 'enabled' (and possibly 'expanded') checkbox on the other hand, sounds like a great idea. Most of the development changes are going on in tabledrag.js, very few additional changes will be needed to add the dragging behavior to menu.admin.inc.

quicksketch’s picture

FileSize
11.5 KB

Here's an updated patch that turns the 'enable' link into a checkbox to fix http://drupal.org/node/178608. This version is functionally complete for drag and drop arrangement! The submit and validate handlers for the form have not yet been written, though I believe chx is handling that portion of the patch.

To see it in action: http://quicksketch.org/sites/quicksketch.org/files/FirefoxScreenSnapz004...

This patch is dependent on #38 in the drag and drop issue.

Wim Leers’s picture

Bah, didn't figure out immediately that I needed to rebuild my menu.

It works very nicely.

The same problem as for the blocks dnd applies: no auto-scroll at the top. Another concern is that you have to point below a valid parent to be able to drag a menu item or a tree of menu items to another location, i.e. for as long as no valid parent has been pointed at, you don't get much feedback about what exactly is happening. Ideally, you'd see the menu tree being dragged along. But I'm not sure that's possible.

quicksketch’s picture

Looks like http://drupal.org/node/178608 (make the page a form) has been committed. This will make this patch much smaller and easier I hope. I'll wait on a reroll until we get the block version in (http://drupal.org/node/181066).

Stefan Nagtegaal’s picture

Patch needs a re-roll and probably some simplification because of the blocks patch got committed..

Quicksketch, I'm looking forward to test this! :-)

catch’s picture

subscribing.

profix898’s picture

Drag'n'drop for reordering of menu items is even more exciting than the block admin stuff. (subscribing)

Crell’s picture

Subscribing. Poke me when you need Konqueror testing and I'll see what I can do. :-)

Gábor Hojtsy’s picture

OK, get this rolling! I think it is important to have consistent UI elements in Drupal, so it would be great to have table DND for menus. I am also looking forward of this patch fixing the UI issues I mentioned in http://drupal.org/node/178608 which are admittedly not critical, but make the page look ugly when wide.

dmitrig01’s picture

Assigned: quicksketch » dmitrig01
Status: Needs work » Needs review
FileSize
6.1 KB

Here's the re-roll!

This works as expected. Please test!

catch’s picture

Status: Needs review » Needs work

In firefox and IE7:

I have to click and hold on an item to drag it, then release and click again to drop it in place, otherwise it keeps dragging even though I've let go of the mouse button. This is different to the blocks implementation (and the blocks implementation seems right to me).

Also, do we still want manual weight settings in admin/build/menu/item/121/edit? Do we still want drop-down parent items there with the full menu tree? I'd expect weight to be hidden unless I had js disabled, and I'd expect parent items to be a select list of "Naviagation, Primary Links, Secondary Links" to swap items between menus. There may be good reasons for keeping them as they are though so those are minor complaints.

BioALIEN’s picture

Subscribing. This will bring so much usability magic to D6!

quicksketch’s picture

Assigned: dmitrig01 » quicksketch
Status: Needs work » Needs review
FileSize
7.14 KB
25.17 KB
27.51 KB

Thanks dmitrig01 for the reroll! Since my patch in #8 the parameters for drupal_add_tabledrag() were switched around to put NULL values at the end. So the when moving an item it was throwing a javascript error (and not letting go).

This version does a couple things, including address centering the checkboxes in the columns.

- Drag and drop completely works, no javascript changes from the original patch. Woohoo!
- Changes are properly saved!
- There is no validation hook, but invalid changes are impossible to make accidentally (with javascript enabled). If an invalid change is made via Firebug, the changed menu item is not saved by menu_link_save(). Since validation logic here is fairly complex and involves a few SQL queries, leaving it in menu_link_save() is fine, IMO.
- This centers the headers for checkboxes by adding classes for td.checkbox and th.checkbox to system.css. It's something that we should probably use on the access control page also (see shots).

Let's test the crap out of this one too! Though I'm feeling relatively confident that we knocked out the javascript issues in the blocks patch.

quicksketch’s picture

I split a copy of the centered checkboxes off into this patch: http://drupal.org/node/192659, to affect the access control and module page forms. They both contain the td.checkbox and th.checkbox classes, so which ever one gets committed first we'll need to reroll the other.

quicksketch’s picture

FileSize
5.71 KB

Minor changes here. I accidentally slipped in an assignment by reference that doesn't need to be there. Removed an extra new line in theme_menu_overview_form().

quicksketch’s picture

FileSize
7.1 KB

Er, crud. Didn't include the change to common.inc in that last patch. Here's a clean and sparkly patch.

webchick’s picture

Status: Needs review » Needs work

Ok. Been putting this through the paces. Overall this looks *really* solid, which tells me we did a good job testing the original drag and drop patch. :)

Two minor issues. For testing purposes, I have the following hierarchy:

My account
  - Content Management
    - Content
      - Post settings

a) I can't move anything under "My account" above "My account" with the mouse. "My account is the first menu item in the list.
b) Using the keyboard shortcuts to move "Post settings" further up the page, it is staying indented at the same level, not outdenting appropriately as I move it up the tree. Ironically, it *will* let me move Post settings above "My account", though, with the keyboard. Weird.

One thing I also pointed out, though I'm not sure it's really a bug, is that it's kind of weird that checking checkboxes doesn't trigger the yellow "you changed this row" behaviour. I understand *why* it doesn't do that (it's not JS, and on all other forms you need to click the button to submit it), but it looked a little odd so I figured I'd mention it.

Oh, and the last thing was I added the "Log out" link under "Administer > Help." This effectively hid it from user 2's view. I talked to chx about it and he said the "bubbling" behaviour from Drupal 5 was not carried over to the new menu system, so this is by design, and has nothing to do with this patch.

KentBye’s picture

Just wanted to send a pointer to Tao Starbow's Quick Admin Menu module that tries to address a number of usability issues.
Here is a very brief demo screencast that I did to show how he implemented hierarchical menu sorting: http://blip.tv/file/get/Kentbye_tech-QuickAdminMenuDemo680.mov
On the backend, he actually splits a table row into three sections to see if it should either go before, as a child, or after. He has some interesting hovering UI tricks to make which one your selecting more clear.
He also has some other icons for deleting, disabling & renaming menus. And also a dialog box interface for creating new menus.
He's said that some of his approaches don't degrade well without javascript & he's using some jQuery UI stuff, but it's probably worth checking out some of the work he's done on pushing the envelope on the menu sorting UI.

quicksketch’s picture

Status: Needs work » Needs review
FileSize
10.88 KB

This patch version addresses the two problems webchick brought up in #23, as well as two new issues I found while implementing book drag and drop.

a) I can't move anything under "My account" above "My account" with the mouse. "My account is the first menu item in the list.

We weren't taking into account the mouse position when dealing with the first-row exception. This line corrects that.

-    if (this.indents > 0 || $(row).is(':not(.draggable)')) {
+    if ((this.indents + indentDiff) > 0 || $(row).is(':not(.draggable)')) {
b) Using the keyboard shortcuts to move "Post settings" further up the page, it is staying indented at the same level, not outdenting appropriately as I move it up the tree. Ironically, it *will* let me move Post settings above "My account", though, with the keyboard. Weird.

Late in the patch cycle the method isValidSwap() had a parameter removed because the parameter became stored internally in the parent object. This line corrects the incorrect method call and this problem when using the keyboard.

-          if (self.rowObject.isValidSwap(previousRow, 'up', 0)) {
+          if (self.rowObject.isValidSwap(previousRow, 0)) {

The other two problems I found when configuring book are ones that would be difficult to find in a large data set, but here they are.

If ALL the items in the entire table are shifted all the way to the left then saved, dragtable.js won't let you move things horizontally any more. This is because it doesn't know the size of the indentation so it can't track horizontal mouse movement. It's fixed with this change:

-  var indents = $('div.indentation', table);
-  this.indentEnabled = indents.size() > 0 ? true : false;
+  // Check if this table contains a parent relationship (and therefore indents).
+  this.indentEnabled = false;
+  for (group in tableSettings) {
+    for (n in tableSettings[group]) {
+      if (tableSettings[group][n]['relationship'] == 'parent') {
+        this.indentEnabled = true;
+      }
+    }
+  }

and

-    this.indentAmount = parseInt(indentSize);
+    this.indentAmount = parseInt($('<div class="indentation"></div>').css('width'));

Basically dragtable.js makes it's own indent to see how wide it's supposed to be, so it's not dependent on one already existing.

Lastly, there was a problem when moving an item to the top row it's parent was not always correctly updated. If moving something from deep in the hierarchy to the first item in the entire list, it would not properly update it's parent. This change corrects the bug:

-        sourceRow = $('tr.draggable:first')[0];
+        sourceRow = $('tr.draggable:first').get(0);
+        // Or if this item IS the first item, check the item that used to be first.
+        if (sourceRow == this.rowObject.element) {
+          sourceRow = $(this.rowObject.group[this.rowObject.group.length - 1]).next('tr.draggable').get(0);
+        }

While fixing the remaining tabledrag issues, I also fixed the reference to '#attributes' in the drupal_add_tabledrag() documentation mentioned in #104 in the original DnD issue.

catch’s picture

Status: Needs review » Needs work

Great work taking this (and book!) on quicksketch. It all looks lovely, tested in the following browsers and found some issues though.

XP:
Firefox: everything's lovely except a minor delay seeing the drag icons when the page loads, equates to a small layout shift when the page fully loads.
IE7: can't drag left or right - only up or down. However using key strokes it works.
IE6 (on win2000 fwiw): Same as IE7, plus some weird shadowing of the draggable icons (increase text size to largest to see this clearly, otherwise it's just a dot).
Opera: same as IE7 but I don't know how to tab to links.
Safari 3: see Opera.

starbow’s picture

Wow, this is really exciting work! Huge congratulations on getting drag & drop into D6 with the blocks patch.

The patch isn't applying cleanly against head this morning, conflicts in common.inc and system.css

Boy, now I am inspirited to see if I can get modal popups in.

KentBye’s picture

I just wanted to follow onto starbow's comment of modal popups, which are demoed at the beginning of this screencast referenced above.

I asked on IRC about any previous discussions about jQueryUI getting into D6, and it looks like it doesn't have much of a chance just because it is such a moving target. The consensus seemed to be to wait until it matured a bit more to prevent having to have a required jQueryUI update module whenever the latest versions come out. jQuery namespacing features could possibly address this, and there'd have to be some pretty compelling UI functionality and wider support for it to happen.

But if modal popups could be achieved without requiring jQuery UI, then I'd say create another issue and see if others here could help support and get it in.

quicksketch’s picture

FileSize
10.37 KB

Thanks catch for pointing out the problem that the last patch only worked in Firefox :D

In most browsers, the sample indentation div needs to be attached to the page before you can get css attributes from it. This patch actually adds the sample div to the page (hidden), checks it's width, then removes it again. It works in IE, Safari, Opera, and Firefox.

quicksketch’s picture

Status: Needs work » Needs review

I'd be very excited about (degradable) modals also. Let's open a new issue to discuss.

catch’s picture

Status: Needs review » Needs work
FileSize
17.5 KB

Patch fixes everything I spotted except this IE6 issue (only noticeable if you increase text size above medium). The duplicate images disappear when you mouseover, if that helps.

catch’s picture

Status: Needs work » Needs review

Sorry cross posted. Minor IE6 issue isn't important enough to stop this getting some more reviews.

Rowanw’s picture

I didn't find any bugs with Minefield 3.0b2pre except that there's no indentations when viewing a fresh page (i.e. when you haven't moved anything around). It feels a bit awkward moving an item up a tree since the "hotspot" seems to change depending on the amount of indentation, can this be improved in any way?

quicksketch’s picture

FileSize
11.13 KB

Webchick found another bug which I also encountered when I was doing the book patch. The same disappearing menu items problem can occur in the navigation structure as well as arranging book outlines. To reproduce, build a waterfall of menu items like this:

 - item 1
  - item 2
   - item 3
     - item 4

Save the changes then re-arrange the times like this:

 - item 3
  - item 4
   - item 1
    - item 2

Item 1 will not be saved under item 4. The reason for this is the order in which we save the menu items. Parents must absolutely be saved before their children. In this case item 1 cannot be moved underneath item 4 because it thinks item 4 is one of it's own children. Even though item 1 is placed below item 4 on the page, it will be saved first because it came earlier in the form array.

To solve this problem we can either:
1. Put items into an order where the new parents are always saved first. Or.
2. Create a new menu_links_save() function that can take all the updated links, put them into the correct order, then save.

Unfortunately there's no way to just update menu_save_link() to work in any order that I can see, because there's no way an item can know it's new children without knowing the new hierarchy.

I went with method 1 here (I tried 2 also, but it imploded my brain, I figured I'd go with 1). Rather than futzing around with looping through the new tree and finding all the parents first, I've used the order of the $_POST array to always find parents first. Then save the form in that order.

  $order = array_flip(array_keys($form['#post']));
  $form = array_merge($order, $form);

  foreach (element_children($form) as $mlid) {
    if (isset($form[$mlid]['hidden'])) {
      ...
    }
  }

Note that no values from $_POST are ever used, only the order of the elements. I'm not positive this is the best solution, but it's simple enough and doesn't require any new functions.

Dries’s picture

quicksketch: most of your explanations in #25 and #34 are invaluable. Move it to the code comments! It really helps one understand what is going on. The existing code comments are not bad, but they could be more verbose. I know it would help me.

I've tested this patch on Firefox and Safari. Spent 15 minutes playing with it. It blows my mind. I want.

I'll look at the code in more detail shortly.

quicksketch’s picture

FileSize
12.51 KB

Thanks Dries. I've updated the patch with clearer documentation in tabledrag.js in places and gotten very verbose in the menu_overview_form_submit() documentation. Because this will be the prototypical place for menu documentation, we certainly don't want someone writing a contrib module which would make the same mistake of saving menu items willy-nilly. A broken menu structure is a very bad thing.

To cut down on duplicated comments, I'm referencing this function with a @see in the book patch.

anders.fajerson’s picture

FileSize
3.75 KB

Tested patch in #34.

Only outstanding issue found in Opera 9 where dragging left/right still doesn't work ("keying" works fine).
IE6 works but freezes for quite a while when dragged. All others (Safari 3, Firefox 2, IE7) works fine. Really cool!

Two UI ideas:
1. Might be useful to get a hint when trying to drag to a disallowed area. Attached an example where the background turns light red. When using keys this could be fired on keypress, and turned back to the previous bgcolor on keyup. And similar when dragging.

2. This idea is inspired by tab drag in IE7. IE is not using a "ghost" version of the tab (like Safari, which I prefer, but technically impossible (?) in our case). Instead an icon follows the cursor when dragging. The move cursor have the same intention (indication a drag) but this could possibly make it more obvious. Unlike block DnD where the row follows the cursor, menu DnD can have quite a distance where the row isn't following the cursor.

quicksketch’s picture

FileSize
12.49 KB

This version corrects the behavior in Opera by not hiding the div when it's added to the page. It's still not noticeable because it's then immediately removed. It also uses the tableDragIndentation theme function. I plainly forgot to use it before.

Dries’s picture

I looked at the code and it looks good to me. If this works on all browsers and if this degrades properly, it's RTBC.

anders.fajerson’s picture

FileSize
13.82 KB

Re-rolled to keep up with HEAD.

Also slightly tweaked CSS. This closes the small gap in Firefox for the the tree image. Adopted the same margin/padding for the handle, which also had a small gap on the menu page (strangely enough not on the block page, but this works there as well in my tests). Finally added height which makes the tree images display correctly in Bluemarine.

Tested in Opera, Safari, Firefox IE6/7 on Win.

Crell’s picture

- Patch in #48 has one hunk fail in menu.admin.inc line 31. It's just a typo change to add a space after an equals sign, so no biggie and trivial to fix.

- Tested in Konqueror. Everything appears to work correctly. I was able to move a menu item to be the parent of its current parent in one go, and it still worked. Assigning menu items to be the first in the page worked, too. If anything, it seems smoother here than it did on the block admin page. I'm assuming everyone else has already tested the hell out of it in other browsers. :-)

- With JS off it all still works, but the "parent" textfield column is very confusing. I don't know if it would be possible to hide it without breaking other things. I do like having weight on this page either way, as that's FAR more sensible and usable than doing it on each menu item edit screen.

Unless someone has a brilliant idea for how to hide the parent textfield from non-JS users, I'd say this is ready to go.

anders.fajerson’s picture

You could use the html.js switch to hide the textfield:

.menu-plid {display:none}
html.js .menu-plid {display:block}

The column would still be there though (doesn't have a class defined) and no menu.css to put it in. quicksketch?

pwolanin’s picture

Status: Needs review » Needs work

testing the patch in #40 - am I missing something? In FF 2.0 and Safari under Mac OS 10.4 on the admin/build/menu-customize/navigation page, all the menu items are aligned to the left - the parent-child relationships are not reflected in the indenting.

starbow’s picture

Status: Needs review » Needs work

I have created a patch that creates modal dialogs and put together some cool uses cases involving the new drag and drop blocks page. I would love to get your feedback.

http://drupal.org/node/193311

ps. This is my first core patch proposal, so please let me know if I made any rookie moves.

quicksketch’s picture

Status: Needs work » Needs review

If we want to hide the parent textfield (I didn't think this was entirely desirable, but it doesn't bother me to hide it), we can not include the column at all in the table and render the textfield as a hidden element in the weight column. This is fine with me, could we get a consensus?

pwolanin, make sure you clear your cache. The theme function that renders indents probably is not registered so everything aligns left without indentation.

anders.fajerson’s picture

Status: Needs work » Needs review

Hidden element sounds like the right approach, and I think it's the right move here. This is sort of an edge case, but as long as the parents are only numbers (and not titles for example) none will use it, and are better off hidden.

quicksketch’s picture

FileSize
16.42 KB

This version of the patch makes the textfield hidden at the theme level, so it's values are still changeable on the client side. It's now included in the weight column so we don't end up with an entirely empty column.

+      // Change the parent field to a hidden. This allows any value but hides the field.
+      $element['plid']['#type'] = 'hidden';

The CSS changes look good to me. Certainly aren't causing any problems.

I found another typo in the documentation which I corrected. The 'sort' method is actually called 'order'.

Lastly, this adds two changes totaling about 8 lines. I added the relationship 'self', so you could potentially match a field inside the same row. And I added the method 'depth', which will update the target field with the current indentation depth of the row. Neither of these features is utilized yet, but I'd like to get all the necessary fixes into tabledrag.js while we're already in the file. These changes will be necessary for the taxonomy drag and drop update.

Rowanw’s picture

I just tested this again in Firefox 2 on Ubuntu and Minefield on Vista, and the menus are not indented at all when viewing a menu list. It indents correctly when dragging things around, but doesn't save. I cleared the cache to be sure, which had no effect.

quicksketch’s picture

Hmm, I'm unable to reproduce the problems in any browsers I have available. Another thing that's a common problem is putting menu_rebuild() in index.php will cause the menu changes not to be saved, because the menu will be rebuilt before the changes can be saved.

Rowanw’s picture

Another thing, the 'Enabled' column should be switched with the 'Expanded' column, since enabled is more important than expanded.

pwolanin’s picture

playing with this more (after fixing the cache problem) - it's a really nice piece of work, but I think the UI is still going to be confusing. The parent-child relationships are not necessarily evident from just the indenting. I almost feel like the connecting lines that show when a parent and children are dragged should show most or all of the time.

quicksketch’s picture

I don't think the complaints being issued are worth holding this patch up in any way. If we want to pit nick about details, let's open separate issues. The patch is currently working well and as it was intended to work.

chx’s picture

Status: Needs review » Reviewed & tested by the community

I tested and liked very much what I see. When the connectin' lines are visible and the order of checkboxes can indeed be discussed as a followup.

Rowanw’s picture

FWIW, I had to disable Page compression to get the indenting to work correctly, it was enabled by default at Site configuration > Performance. It should be safe to turn it back on after the changes take effect.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Tested this patch extensively with all kinds of drag and drop operations, and the operation looks fine. Although I don't like the enable checkbox being on the right (instead on the left of the row), but I understand the drag handles need their attention there, so committed. Great work!

quicksketch’s picture

Status: Fixed » Needs review

Woot! Thanks! We're not done with drag and drop in core yet, so we've got plenty of issues left to sort out smaller concerns:

Book module outline drag and drop: http://drupal.org/node/192736
Taxonomy terms/vocab drag and drop: http://drupal.org/node/193333

Poll: http://drupal.org/node/193076
Upload: http://drupal.org/node/193105

quicksketch’s picture

Status: Needs review » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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