Skip to content

Commit

Permalink
Make the UP/DOWN buttons work
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnSmith-LT committed May 21, 2014
1 parent 973e8b8 commit e0f0c23
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions editor/js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,14 @@ var EDITOR = (function ($, parent) {
"multiple" : false // Need to disable this just now as nodes could be on different levels
}
})
.one('ready.jstree', function (e, data) {
data.instance.open_node(["treeroot"]);
data.instance.select_node(["treeroot"]);
})
.bind('select_node.jstree', function(event, data) {
showNodeData(data.node.id);
})
.bind("copy_node.jstree", function (e, data) {
.bind("copy_node.jstree", function (event, data) {
var new_id = generate_lo_key(),
original_id = data.original.id,
tree = $('#treeview').jstree(true);
Expand All @@ -285,9 +289,8 @@ var EDITOR = (function ($, parent) {
lo_data[new_id] = lo_data[original_id];
}
})
.one('ready.jstree', function (e, data) {
data.instance.open_node(["treeroot"]);
data.instance.select_node(["treeroot"]);
.bind('move_node.jstree', function(event, data) {
console.log("move node");
});
},

Expand All @@ -300,13 +303,19 @@ var EDITOR = (function ($, parent) {
// Down button handler
down = function() {
console.log("move node down");
move(1);
move(2);
},

// Move the selected node up or down
move = function(dir) {
var tree = $.jstree.reference("#treeview");
var copy_node, new_node, id, ids = tree.get_selected();
var tree = $.jstree.reference("#treeview"),
copy_node,
new_node,
id,
ids = tree.get_selected(),
pos,
new_pos,
count;

if(!ids.length) { return false; } // Something needs to be selected

Expand All @@ -317,27 +326,24 @@ var EDITOR = (function ($, parent) {
return false;
}

current_node = tree.get_node(id, false); //console.log(current_node);
parent_node_id = tree.get_parent(current_node); console.log(parent_node_id);
//parent_node = tree.get_node(parent_node_id, false); console.log(parent_node);

//var pos = (dir > 0) ? 'next' : 'previous';
current_node = tree.get_node(id, false);
$current_node = $("#" + id).closest('li');

//tree.move_node(current_node, parent_node, 2, function(node, parent, position){
// console.log("done");
// Calculate positions and total
pos = $current_node.index();
new_pos = pos + dir;
count = $current_node.siblings().length + 1;

//var copied_node_id = current_node.id;
//var node_id = node.id;
//var new_node_id = generate_lo_key();
// Exit if we are at the top or bottom
if (new_pos < 0 ) return false;
if (new_pos > count) return false;

// Update the id
//node.id = new_node_id;
// Get the parent node
parent_node_id = tree.get_parent(current_node);
parent_node = tree.get_node(parent_node_id, false);

// Copy the lo_data from the old node to the new one
//lo_data[new_node_id] = lo_data[copied_node_id];

//console.log(lo_data[node.id]);
//});
// Do the move
tree.move_node(current_node, parent_node, new_pos);

return true;
},
Expand Down

0 comments on commit e0f0c23

Please sign in to comment.