Just like it says, I know that the tabledrag creator at Drupalcon Boston said that ajax saving of the reweighed / restructured values created via tabledrag.js would be cool functionality to add so I'm proposing it be rolled into 7. It's a very simple process and I've actually achieved it in D6 via the outline designer module (see demo for example of drag/drop ajax saving -- https://elearning.psu.edu/demos/outline_designer/
This is the code that I've overloaded in order to accomplish this atm --
/**
* Overload tabledrag onDrop event so that it ajax saves the new parent for the node
*/
Drupal.tableDrag.prototype.onDrop = function() {
//row object so we don't have to call it all the time
var row_obj = this.rowObject.element;
//get the id of what was dragged
var drag_nid = $(row_obj).find('img').attr('id').replace('node-','').replace('-icon','');
//get the parent id based on the indentations, this equation is a bit evil...
var p_nid;
var weight = $("#edit-table-book-admin-"+ drag_nid +"-weight").val();
var active_indent = Math.max($('.indentation', row_obj).size());
//if we're at level 0 then the node is at the book root
if(active_indent != 0){
var tmp_indent = -1;
var tmp_obj = row_obj;
//keep walking backwards until we find the node we need
while (tmp_indent != (active_indent-1) ) {
tmp_obj = $(tmp_obj).prev();
tmp_indent = Math.max($('.indentation', tmp_obj).size());
}
p_nid = $(tmp_obj).find('img').attr('id').replace('node-','').replace('-icon','');
} else {
p_nid = ROOT_NID;
}
$.ajax({
type: "POST",
url: AJAX_PATH + "drag_drop/" + drag_nid + "/" + p_nid + "/" + weight,
success: function(msg){
//could implement some kind of history / undo list here if we want to
od_response_msg(msg);
}
});
return null;
};
The drag drop function on the other side just changes the parent / weight for the drag_nid that it's been given. jQuery ajax is how I handle it though I'm sure if we work through it we can come up with the appropriate way to make this work with anything (right now this code is just for book based transactions).
Function on the other side backend does this for the drag_drop case
case 'drag_drop':
$nid = $var1;
$parent_nid = $var2;
$weight = $var3;
//load the parent / active node
$node = node_load($nid);
$parent = node_load($parent_nid);
//set parent
$node->book['plid'] = $parent->book['mlid'];
$node->book['weight'] = $weight;
$node->revision = 1;
$node->log = "Outline Designer -- nid:$nid parent nid changed to $parent_nid";
node_save($node);
print "Node nid:$nid parent nid changed to $parent_nid";
break;
This should be easy enough to convert into allowing for block tabledrags or anything else to come across and be set correctly, even if it involes sending weight=, bid=, pid=, region= type of statements.
http://drupal.org/project/outline_designer/ for the actual module that uses this stuff
Thoughts?
Comments
Comment #1
bcn commentedcan you roll this into a patch?
Comment #2
btopro commentedShould be able to, just need to wait till I get home (currently on the road). Wanted to at least get this out in the open and see if others thought it was worth investigating / patching in if possible. Only thing I'll need to think more about is how to make this work with any implementation of table-drag instead of just books (as it is now). Is there anything that uses tabledrag other then books / menus / blocks in core/core-optional? If not then this could be applied only to the books / menu / blocks cases and hopefully someone could look into making it extensible past that should others want to implement it.
Comment #3
btopro commentedThis seems almost like it needs it's own ajax API for committing drupal operations on the fly (or at least seems like it would benefit from it significantly). I tap into something like /function/node/data in terms of my formatting but it seems like it would be best served by something listening backend similar to the hook_ system but launching the hook system for system updates.
Are there any plans for a ajax api or anything like that?
Comment #4
sun.core commentedProper status.
Comment #5
sun.core commentedComment #6
danillonunes commentedThat would be nice. Subscribe.
Comment #7
btopro commentedI agree, hopefully once I upgrade outline designer to drupal 7 I can make a patch. Anyone know about plans for the book module? I know there's always talk of removing it from core
Comment #8
nod_Let's put that on the table.
Comment #9
btopro commentedD7 version of outline designer is currently in alpha but now has support for hooking in other projects and overriding the interface of books and menus. Needs some love associated with refreshing the screen from the AJAX request (port from D6 AHAH method harder then expected). The overlay in D7 would be perfect for popping up nodes over top of the book outline while working on it.
Comment #10
nod_closing this for #504378: Auto-save draggable forms