I'm currently working on dnd-enabling CCK's 'manage fields' tab (the one where you order your fields and nest them in groups).

Unlike menus or taxonomy terms, all rows in this table are not equivalent :
only fields can be nested, only groups can have children.

Attached patch adds these features to tabledrag.js :
rows with the class 'no-child' cannot have child rows
rows with the class 'no-parent' cannot be nested

Mouse manipulation works OK while (AFAICT) not changing the current behaviour on other d-n-d pages.
Still working on keyboard manipulation. Posting what I have now so that people can test (and, er, maybe help)

In order to test this, I have committed a preliminary version of this form in latest CCK HEAD, as a new 'manage field (d-n-d)' tab, keeping the old one in 'manage tabs' for now
- grab latest CCK, enable fieldgroups.module
- create five fields, three fieldsets, and play... (note the d-n-d version doesn't save anything for now)

I'm aware it's late for this addition. However, the field overview in CCK has been longing for drag-n-drop for months, and this wouldl be a major usability boost. People will just not understand if core UI has d-n-d and this page doesn't, and we'll see that in the issue queue :-). Working on this UI is not the most urgent task in the CCK D6 port, but I tried to tackle this asap so that the required additions to tabledrag.js can have a chance of getting in

Comments

yched’s picture

Status: Active » Needs review
StatusFileSize
new6.6 KB

Better patch :
- mouse manipulation work right now (previous patch was flawed)
- keyboard manipulation works OK (I still need to check the autoscroll)

I need to step back a little and check if all the changes are in the patch are really required, but it works as is.
At this point, even if there remains a few TODOS / cleanup, I'd say this is ready for reviewing.

yched’s picture

StatusFileSize
new2.41 KB

Side note : testing via the CCK 'manage fields' tab is limited, since it has only one level of nesting.

To fully test the feature, here is a patch that randomly sets 'no parent' and 'no child' properties to a few rows in the menu overview form in admin/build/menu-customize/navigation.
Green rows cannot have children rows (green leaves, you know...).
Dark rows cannot be nested below other rows.
(Dark green rows have both properties)

This last patch is here for testing purposes only, and not a candidate for being committed, obviously :-)

quicksketch’s picture

Subscribing. I'll take a look at this shortly.

yched’s picture

StatusFileSize
new6.9 KB

New patch, should be complete and ready now.
(Actually takes fewer lines to add the feature than what I expected)

I tried to test this as thoroughly as I could figure, and it seems to behave OK.

yched’s picture

StatusFileSize
new7.72 KB

with PHPdoc update for drupal_add_tabledrag()

yched’s picture

StatusFileSize
new7.77 KB

Minor fix (correct an imprecise variable name)

quicksketch’s picture

StatusFileSize
new7.57 KB

This patch works really well so far! I'm glad to see that this enhancement is much easier than I had thought. I wanted to include this functionality in the original patch, but it seemed daunting at the time.

This reroll removes changes that I don't believe were necessary and updates it to apply after the RTL update went in. Preventing children rows works great, but the no-parent class doesn't seem to work (even before my changes).

yched’s picture

StatusFileSize
new7.67 KB

Fixed the no-parent bug quicksketch pointed.
+ fixed PHPdoc wording as per comment from dmitrig01 on IRC

yched’s picture

StatusFileSize
new7.68 KB

Agreed on better class names with Nate on IRC :
.no-child => .tabledrag-leaf
.no-parent => .tabledrag-root

yched’s picture

StatusFileSize
new2.45 KB

And here is the updated test code for menu customisation page, to match the new class names.
I also updated the code in current CCK HEAD

quicksketch’s picture

StatusFileSize
new7.93 KB

This roll corrects a problem where a leaf could be assigned a child by dragging an already indented row underneath it.

A problem still remains with keyboard support, though mouse support seems to be perfect.

The keyboard issue:

- group
 - group
  - field a
- field b

Using the keyboard to move 'field a' below 'field b' results in this setup, where 'field a' becomes a child of 'field b'. This should not be allowed and the 'field a' row should be un-indented all the way to the left.

- group
 - group
- field b
 - field a
yched’s picture

StatusFileSize
new11.54 KB

OK, different approach.
The code handling indentation rules in tabledrag.js is spread in various places which makes things really complex to follow. Quicksketch and I spent a fair amount of time last night tracking edge cases and adjusting the code, and ended mainly with a headache.
I think I have a fix for this last bug reported above (some code that disappeared from one of my iterations, that I thought was finally not needed), but the overall process is nonetheless hard to follow and secure.

While working on this patch, I figured there was a simpler approach to indentation handling in tabledrag, relying on the fact that for every target position in the table, there is an *interval* of valid indentations. This results in :
- cleaner code, easier to understand (and debug) : hierarchy/indentation rules are in one place (validIndentInterval()), 10 lines of dead-simple code. Adding the 'leaf' and 'root' behaviors is a matter of 100 chars (ok, more, because of optimizations for keyboard), and much less prone to tricky cases.
- smoother UI : mouse-dragging in current HEAD has blind spots, often the row won't drag because your mouse is not at the right x-axis position. The "interval" approach makes it that your row always drags, with x-indentation automatically set to the nearest valid position. Makes reordering even flat lists really faster.

My original plan was to get a minimal-change version of the 'leaf/root' patch in so that CCK can safely start using it, and try to get the new approach in later or for D7. But after last night's session with Nate, we both agreed going for it right now was the best option.

quicksketch’s picture

Wow.

The new approach is SO much better. I was discouraging doing this change at the same time as the leaf/trunk classes, but as it turns out the solution needed to make what we have work were getting to be just about as long just doing it the "right way" and centralizing all the code for swapping rows.

This also solves other complaints about the DND system such as:
- No feedback when moving a row
- Trouble moving a row to new position when the mouse isn't in the exact right location
- Inconsistent behavior between using a keyboard and a mouse, now they act in the same way (moves are almost always allowed).

On top of these benefits, this patch actually works which is better than anything we've been trying. :)

I'm going to do extensive browser testing to ensure this works in all our scenarios (which have gotten to be quite a few).

quicksketch’s picture

StatusFileSize
new12.21 KB

This patch makes 4 minor fixes:

- The taxonomy terms page was broken because a maxDepth of 0 means no limit, so the check on limiting maxDepth needed to be skipped.
- Removed a duplicate maxDepth check that is no longer necessary.
- Removed oldX variable from the tableDrag object. Because the one place it's checked is now removed. Indentations need to be checked even if the position doesn't move horizontally, because the row indentation may need to be adjusted when swapping two rows.
- Moved the onIndent() hook to only fire if a change in indentation is actually made

quicksketch’s picture

Okay, the results of my browser testing:

- Windows: IE6/7, Opera 9, Firefox 2 all okay
- (k)Ubuntu: Firefox 2, Konqueror 3.5.8 both okay
- Mac: Safari 3, Firefox 2, Opera 9 all okay

I switch around the pages I tested between different platforms, but I tried all of the following at least some version of IE and some version of Firefox.
- Book outline
- Taxonomy term outline
- Menu outline
- Block administration
- The CCK HEAD manage fields page

All in all, no problems found. If yched doesn't have any additional concerns or we can't find any other problems, this is RTBC.

Note, http://drupal.org/node/195073 is necessary to correct an existing IE7 problem. The x-axis accuracy can also get a little off as yched reports in http://drupal.org/node/201799, but again, it is an existing issue.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Cool, thanks for the extensive review and crossbrowser testing, Nate !
Nothing to add, RTBC then ?

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

Guys, this shows perfectly again, that adding features like this drag and drop thing so late "drags" our release cycle longer :( We are just gasping the "missing features" now, as some of the contribs are updated, because it was added so late and quick that people did not have the time to look into it. It is very cool stuff, but on the other hand caused bugs appearing around quite a few places, some of which are still open unfortunately, and we are about to add features again? (I am not feeling that happy feeling when looking at drag and drop changes, sorry guys).

Let's make sure that this is (even) better tested. So, who tested that this still works with RTL themes? Looks like indentation code was also affected.

quicksketch’s picture

I should have mentioned I tested RTL in Firefox, Safari and IE (not Opera or Konqueror though). I'll take another round of looks at this, but what'll really be needed will be testing by others on another machine other than my own.

I agree with you Gábor, we are still just now figuring out all the possible use cases for tabledrag.js. Adding or even attempting to fix bugs (like the inability to have 2 tables on the same page) can cause other things to break (like IE7). However, the entire tabledrag.js code is less than 2 months old and written from scratch, and of course there are shortcomings in it. Admittedly, drag and drop may be the feature that extends the release cycle, but it's also become a killer feature of Drupal 6. No one can say a huge feature (tabledrag.js is borderline API even) works in all cases in such a short period of development.

I'd like to push for this enhancement because I feel that by the end of the life of D6, fewer people will understand the concept of "weight" than do now. We've removed the requirement that people understand the term. To leave a major part of Drupal like CCK Fields using weight fields is going to make CCK seem strangely outdated compared with the rest of Drupal.

I'm looking at this as continuing to finish the work we've started. I'll keep hitting these issues hard, I don't want to be the hold up on releasing.

gábor hojtsy’s picture

Status: Needs review » Fixed

Yes, there are always things which will look ugly and old, and the longer we make the development cycle the longer it will look ugly and old. I definitely like to make CCK look top notch and all, but please note that the time is quickly drying up, and the more you modify/rewrite even more late in the cycle, the more possibility there is for untested bugs, and after all people will see the whole drag and drop feature set as a source of bugs, not as a great new feature, if concentration is on adding new stuff and modifying behavior instead of polishing what is there.

Sidenote: as an example, the taxonomy drag and drop patch broken the forums page, broken the taxonomy term delete confirm page which both just got fixed in the last 24 hours, and left confirm forms broken with their help texts: http://drupal.org/node/202061 (which is still open)

Anyway, I have added this change in the hopes that this finally leads us to a stable state with possible bug fixes later, and with the soon upcoming RC1 in mind, which will hopefully make drag and drop better tested in core, even if not with the contrib implementations which will show their bugs only later.

yched’s picture

Thanks Gabor.
While I definitely understand your point of view and the current priorities (and had that in mind all along while working on this), I want to point that, even if the initial motivation was to add a feature for CCK, the main effects of this patch are simplification of the code and a notable improvement of the user experience for every d-n-d tables present in core, which can IMO qualify as 'polishing' and go in the direction of a more stable feature.

quicksketch’s picture

I'll do my part to clean up the cruft caused by my other work and where I can with the other issues.

Thanks again Gábor.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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