moving UP/DOWN from outside by click

690 views
Skip to first unread message

Martynas Eskis

unread,
Dec 13, 2010, 11:19:02 AM12/13/10
to jsTree
Hi, I`ve been looking for solution, but nothing.

I tried this:

var selected = $.jstree._focused().get_selected();
var prev = $.jstree._focused()._get_prev(selected, true);

$("#tree").jstree("move_node", function() {
try {
//alert("do");
jQuery.jstree._reference("tree").move_node(selected, prev,
'before'); ;

} catch (err) {
alert(err);
}
});

no error, no action... What could be wrong?

vakata

unread,
Dec 18, 2010, 2:28:49 AM12/18/10
to jsTree
Seems like you are not calling the functions correctly - how about:

var inst = $.jstree._focused(),
slct = inst.get_selected().eq(0),
prev = slct.prev();
if(prev.length) inst.move_node(slct,prev,'before');

I just tested this code and it worked just fine. Keep in mind it will
only reorder children, if you need to "jump out" of the common parent
use inst._get_prev(slct); to get the previous node.

Kindest regards,
Ivan

vakata

unread,
Dec 18, 2010, 3:17:13 PM12/18/10
to jsTree
Well,
I tested with my working copy ... and the demo on jstree.com

May I have a look at your full config, some sample data and the way
you call the code above.

Kindest regards,
Ivan

On 18 дек, 16:48, Martynas Eskis <eskis.marty...@gmail.com> wrote:
> I tried your example, but i get nothing. I checked, prev ant slct
> objects seems to be ok, but when I call function, I get no response
> and no error.
>
> I use different node ids, ex.: page_x, lang_x, folder_x; maybe it
> could cause it ?

Martynas Eskis

unread,
Dec 19, 2010, 6:20:52 AM12/19/10
to jsTree
// ---------
$(document).ready(
function() {
var selectedNode;

$("#reload_tree").click(function() {
$('#tree').jstree('refresh', -1);
return false;
});
$("#search").click(function() {
// alert($("#text").val());
$("#tree").jstree("search", $("#text").val());
});
$("#clear_search").click(function() {
$("#tree").jstree("clear_search");
$("#text").val("");
});

$("#delete_page").click(function() {
// TODO patikrinti ar trina puslapi, neleisti trinti katalogo,
// kalbos
if (confirm('Are you sure?')) {
var obj = $.jstree._focused().get_selected();
var id = obj.attr('id');
var id = id.replace("page_", "");
alert(id);
}
return false;
});
$("#edit_page").click(function() {
var obj = $.jstree._focused().get_selected();
var id = obj.attr('id');
var id = id.replace("page_", "");
window.location.href = "/admin/page/edit/" + id;
return false;
});
$("#disable_page").click(function() {
var obj = $.jstree._focused().get_selected();
$(obj).addClass("disabled");
return false;
});
$("#enable_page").click(function() {
var obj = $.jstree._focused().get_selected();
$(obj).removeClass("disabled");
return false;
});
$("#move_page_up").click(function() {
var inst = $.jstree._focused(), slct = inst
.get_selected().eq(0), prev = slct.prev();
if (prev.length) {
alert("txt");
inst.move_node(slct, prev, "before");
}
return false;
});
$("#move_page_down").click(function() {
return false;
});
$("#create_page").click(function() {
var obj = $.jstree._focused().get_selected();
var id = obj.attr('id');
var id = id.replace("page_", "");
window.location.href = "/admin/page/add/parent/" + id;
return false;
});
});

$(function() {
// Settings up the tree - using $(selector).jstree(options);
// All those configuration options are documented in the _docs folder
$("#tree").jstree(
{
// the list of plugins to include
"plugins" : [ "themes", "json_data", "ui", "crrm", "cookies",
"dnd", "search", "types", "unique" ],
// Plugin configuration

// I usually configure the plugin that handles the data
// first - in
// this case JSON as it is most common
"json_data" : {
// I chose an ajax enabled tree - again - as this is
// most
// common, and maybe a bit more complex
// All the options are the same as jQuery's except
// for `data`
// which CAN (not should) be a function
"ajax" : {
// the URL to fetch the data
"url" : "/admin/ajax/page/tree",
// this function is executed in the instance's
// scope (this
// refers to the tree instance)
// the parameter is the node being loaded (may
// be -1, 0, or
// undefined when loading the root nodes)
"data" : function(n) {
// the result is fed to the AJAX request
// `data` option
return {
"operation" : "get_tree",
"id" : n.attr ? n.attr("id").replace("node_",
"") : "language"
};
}
}
},


// Configuring the search plugin
"search" : {
// As this has been a common question - async search
// Same as above - the `ajax` config option is
// actually jQuery's
// object (only `data` can be a function)
"case_insensitive" : true,
"ajax" : {
"url" : "/admin/ajax/page/tree",
// You get the search string as a parameter
"data" : function(str) {
return {
"operation" : "search",
"search_str" : str
};
}
}
},


"types" : {
"max_depth" : -2,
"max_children" : -2,
"valid_children" : [ "language" ],
"types" : {
// The default type
"default" : {
"valid_children" : [ "default", "folder" ],
"icon" : {
"image" : "/controller/page/page_16.png"
},
"start_drag" : false,
"move_node" : false,
"delete_node" : false,
"remove" : false
},

"folder" : {
"valid_children" : [ "default", "folder" ],
"icon" : {
"image" : "/controller/page/folder_16.png"
}
},
"language" : {
"valid_children" : [ "default", "folder" ],
"icon" : {
"image" : "/controller/page/language_16.png"
},
"select_node" : function() {
return false;
},
"delete_node" : false,
"hover_node" : false
}
}
}
});
$("#tree").jstree("set_theme", "apple");

});

Martynas Eskis

unread,
Dec 29, 2010, 4:51:24 PM12/29/10
to jsTree
Any ideas ?

vakata

unread,
Jan 12, 2011, 6:36:16 AM1/12/11
to jsTree
Do you get any errors in firebug?

On 29 дек 2010, 23:51, Martynas Eskis <eskis.marty...@gmail.com>
wrote:
> Any ideas ?

Martynas Eskis

unread,
Jan 14, 2011, 5:39:34 AM1/14/11
to jsTree
No, that's the point.

Martynas Eskis

unread,
Dec 18, 2010, 9:48:54 AM12/18/10
to jsTree
Reply all
Reply to author
Forward
0 new messages