Hi,

A while ago I posted an article about creating a drag-and-drop interface using Script.aculo.us and Drupal, many were interested in a more functional module especially that Drupal 5.0 provides better JavaScript support with the inclusion of jQuery. Mark recommended integrating this drag/drop functionality into your panels module, I checked the module and indeed I found it to be an excellent backend for my work.

Because of its extensibility, I was able to create a drag/drop layout for panels without hacking the module itself, you may check it here. However, this module doesn't save user settings or allow users to add content dynamically, to implement these features, I either have to hack panels.module or duplicate its functionality in my module, because of this, I decided to check with you and see if you are actually interested in ajaxifying your module.

What I have in mind right now is creating two types of panels, public panels which are very similar to what your module currently offers, admins create them and they are accessible by everyone, the new type that I'd like to introduce into panels is private panels, with these, privileged users will be able to create and maintain their own panels, a private panel is only accessible by its owner, implementing such a thing shouldn't take that much effort, I experimented with adding a "uid" field to panels_info table and it's working, users will be able to create and customize their private panels through the traditional static interface or JavaScript.

Another modification I need to have in panels in unifying how blocks are theme'ed, the drag/drop JavaScript code uses CSS classes to detect blocks and their titles and content, but unfortunately panel.module's block structure depends on active theme and block content type, for example bluemarine uses H2 for block titles, whereas Pushbutton uses H3, block and node content is marked by the ".content" CSS class, while the custom panel type doesn't have a div that wraps content, and so on. I can work around this with complex selectors, but it's always better to have more general solutions.

Of course, JavaScript functionality will be in a separate module, so those who don't want it won't complain. If you are not interested, is it possible to provide additional hooks so I can implement the above in my module? Needless to say, I'm not asking you to do the work for me, what I want is your insight and approval :)

I believe that such a module will be a very nice demonstration of what Drupal 5.0 can do on the Ajax front.

One last thing, thanks for this impressive module :)

-Ayman

CommentFileSizeAuthor
#8 panels-dnd-new.tar.gz189.48 KBmerlinofchaos

Comments

merlinofchaos’s picture

Excuse me while I take this moment to pick up my jaw. =)

Yes, I am all for ajaxifying panels.

I will comment further after I've looked at the module and read this a couple more times. (Jetlagged and feeling kind of dense just now; but seriously this is something I've wanted to do for awhile, and I have even bigger plans than what you've mentioned here. There will be more soonish)

merlinofchaos’s picture

Ok, I set up a test and played around with this. I very much like where this is going. There are, I think, some complications with what you want to do but none of them are insurmountable.

1) Not all content should be available to all users, so we will need to introduce some kind of permissions for what content is available.

2) This may also be true of configuration for content, but each content_type.inc will probably have to handle that by its own self.

3) Would simply wrapping the content be enough? It'd be nice if panels didn't have to force a content type into a particular layout, but I can see your point about this when I add a view, which doesn't work quite right.

4) The landing area for the drag and drop is kind of difficult to find; I keep having to move above where I instinctively think the landing area is going to be. It may just be that the area is too small or maybe where it's located.

5) You have my permission and blessing to redo the entire panels admin page using this; as long as it degrades gracefully I'll be extremely happy. I'd been thinking that the config should not be in a collapsible fieldset, but instead be in something like a lightbox -- i.e, when you open it it comes up like a dialog and dims the rest of the display; and also doesn't limit the gadgets in the config to the size of the panel.

Patches will be gratefully accepted and we can probably get a few people who'd be willing to help test this. If I have my way, this system will completely replace block management in Drupal, and with your ideas we can have user-controlled panels too.

merlinofchaos’s picture

For those interested in the issue, I have set up a test of what ayman posted here:

http://test.logrus.com/dnd_test

Ayman’s picture

I'm pleased to know that you are interested in the idea :)

1+2) I agree that not all content should be available to all users, for example, admins should be able to specify what blocks are available (I did something like this in my Script.aculo.us implementation), and users shouldn't be able to add or see nodes they don't have access to.

3) Here is what I think: all of the current content types have title and content parts, but each one present them differently, I'm sorry perhaps I wasn't clear, but I'm not saying that we restrict the drag/drop panel to one content type, we only need a way to identify the portlet's title and content in JavaScript, for example, by making sure that all content types apply a CSS class to titles, and another one to content. From what I've seen, not all themes do so to nodes or blocks, and panels doesn't do this either to its custom content type. Wrapping content is one option, the advantage here is that portlets will have a consistent look.

4) Yeah I agree, this needs more polishing, frankly getting this right was much easier with Script.aculo.us, but I'm just going to assume that I need to explore the code of jQuery's drag/drop plugins more and try to improve the dropping functionality.

5) Great! The first task is porting the module to 5.0, because jQuery is conflicting with 4.7's drupal.js, next I'll work on Ajaxifying the admin panel, and then research how to implement private panels, of course I'll post patches here for review before committing them.

Looking forward to a fun and productive experience working on this :)

-Ayman

merlinofchaos’s picture

I checked in a 5.0 version last night. How's that for service? =)

nedjo’s picture

Nice work, this is looking great!

I'm idly wondering what it would take to ajax-load the panel content too. In dynamicload.module (part of Javascript Tools) there's relevant code. That would enable the loading of content to be placed in the panels without page refreshing.

merlinofchaos’s picture

I've started some preliminary work on fixing up the admin screens to use this tech for panels 2.0, thanks to Ayman giving some lovely code to work with.

So far I've got it dragging panel bits around. I need to get it to save that state, and do a few other nice things (removing the up/down arrows when javascript is on).

One thing I'd like to do -- and I'll happily take expert help on this -- is to change the 'configure' stuff from a collapsible fieldset to more of a lightbox type thing. So when you click configure, it can use more of the screen than just the panel size. (It can be a real drag to click configure on something on the left in the 25/50/25 panel).

After that I can look into using AJAX to add panel pieces. I don't think it should actually be all *that* hard to get that info, but I don't know. Rendering it might be a little more than my javascript skills can currently do, unless I can somehow basically just paste in some HTML provided by the ajax method. Nedjo, do you know? I know you're a lot better with JS than I am.

merlinofchaos’s picture

StatusFileSize
new189.48 KB

Attached is my preliminary work, which I'm not ready to check in, even remotely.

Also, see my blog post on angrydonuts for a glimpse into how I envision private panels being implemented.

nedjo’s picture

Earl, the available jQuery methods make fetching data through ajax and appending them delightfully easy. Have a look at the 'ajax' entry in the jQuery api docs, http://jquery.com/api/. Basically all you need to do is feed in a url to fetch content from, then instruct the script to append what's returned on success. Here's a hypothetical example (the 'url' here would need more work so as not to assume clean urls):

$.ajax({
  type: "POST",
  url: "my/path",
  data: "panelid=" + panelId,
  success: function(data){
    // On success, append the returned HTML to the panel's element.
    $('#' + panelid).html(data);
  }
});
pyrello’s picture

Title: Drag/Drop and Ajax into Panels? » Drag Drop and Sort API

Hello,
I have already started work on an API to open up drag drop and sort functionality to other modules. The API would attach javascript information to variables that were passed into, allowing for the drag and drop user interface. Changes could be made, the API would re-sort weights and other position information, and the API would then pass the new values out to be sent to the database by the module.

I've been trying to decide how to handle the incoming information. Specifically, I'm trying to make this function broad enough in its scope that it could be applied to any visual element that drupal outputs. I have thought about have 2 optional variables and one required variable.
The required variable would be the weight of an element, for sort within a single container. The 2 optional variables would capture the region on the page, and a container id within each region.

This is what I would like to ask you about: How does panels differentiate between the panels? Would the system I'm proposing work for developing a drag and drop panels interface? If so, what position information would I need to collect coming in? If not, how could I alter it to make it broader in its functionality?

Thanks in advance for your thoughts. I am most likely going to be submitting this as my proposal for SoC and I'd appreciate any feedback you could give me.

majortom’s picture

I have been interested in this type of module for quite some time and I was wondering what your current status was. Any idea when it might be ready to use?

/carmi

merlinofchaos’s picture

Version: 6.x-2.x-dev » 5.x-2.x-dev

This feature is currently in Panels 2, but is probably going to disappear for a bit to be replaced by something without dragging (but hopefully just as usable). The drag & drop code we're using is buggy on several browsers and Not Ready For Primetime, though there is some word that one of our jquery experts is interested in writing specialized javascript code for it.

merlinofchaos’s picture

Status: Active » Fixed

Yea, I think we can call this fixed.

Anonymous’s picture

Status: Fixed » Closed (fixed)