Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG Updating node would position wrong, Sort isnt === offset

  • Loading branch information...
commit 22d6c7afa4f4c0f86df60ad371206858bde8e671 1 parent 120de7c
@hafriedlander hafriedlander authored
Showing with 28 additions and 5 deletions.
  1. +14 −1 admin/code/LeftAndMain.php
  2. +14 −4 admin/javascript/LeftAndMain.Tree.js
View
15 admin/code/LeftAndMain.php
@@ -748,12 +748,25 @@ public function updatetreenodes($request) {
foreach($ids as $id) {
$record = $this->getRecord($id);
$recordController = ($this->stat('tree_class') == 'SiteTree') ? singleton('CMSPageEditController') : $this;
+
+ // Find the next & previous nodes, for proper positioning (Sort isn't good enough - it's not a raw offset)
+ // TODO: These methods should really be in hierarchy - for a start it assumes Sort exists
+ $next = $prev = null;
+
+ $className = $this->stat('tree_class');
+ $next = DataObject::get($className, 'ParentID = '.$record->ParentID.' AND Sort > '.$record->Sort)->first();
+ if (!$next) {
+ $prev = DataObject::get($className, 'ParentID = '.$record->ParentID.' AND Sort < '.$record->Sort)->reverse()->first();
+ }
+
$link = Controller::join_links($recordController->Link("show"), $record->ID);
$html = LeftAndMain_TreeNode::create($record, $link, $this->isCurrentPage($record))->forTemplate() . '</li>';
+
$data[$id] = array(
'html' => $html,
'ParentID' => $record->ParentID,
- 'Sort' => $record->Sort
+ 'NextID' => $next ? $next->ID : null,
+ 'PrevID' => $prev ? $prev->ID : null
);
}
$this->response->addHeader('Content-Type', 'text/json');
View
18 admin/javascript/LeftAndMain.Tree.js
@@ -271,8 +271,11 @@
* (Object) Map of additional data, e.g. ParentID
*/
updateNode: function(node, html, data) {
- var self = this, newNode = $(html), origClasses = node.attr('class'),
- parentNode = data.ParentID ? this.find('li[data-id='+data.ParentID+']') : false;
+ var self = this, newNode = $(html), origClasses = node.attr('class');
+
+ var nextNode = data.NextID ? this.find('li[data-id='+data.NextID+']') : false;
+ var prevNode = data.PrevID ? this.find('li[data-id='+data.PrevID+']') : false;
+ var parentNode = data.ParentID ? this.find('li[data-id='+data.ParentID+']') : false;
// Copy attributes. We can't replace the node completely
// without removing or detaching its children nodes.
@@ -284,8 +287,15 @@
// Replace inner content
node.addClass(origClasses).html(newNode.html());
- // Set correct parent
- this.jstree('move_node', node, parentNode.length ? parentNode : -1, data.Sort);
+ if (nextNode && nextNode.length) {
+ this.jstree('move_node', node, nextNode, 'before');
+ }
+ else if (prevNode && prevNode.length) {
+ this.jstree('move_node', node, prevNode, 'after');
+ }
+ else {
+ this.jstree('move_node', node, parentNode.length ? parentNode : -1);
+ }
},
/**
Please sign in to comment.
Something went wrong with that request. Please try again.