greseky
unread,Oct 13, 2010, 6:19:30 AM10/13/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jsTree
Ivan,
I have a problem with getting node id in function
"change_state.jstree".
In addition, I am triggering "change_state" with "select_node" on
default/leaf node type.
(I could change the code and I can get the id in "select_node" on
default/leaf node type...
but it would love to get the node id on every "change_state.jstree",
no matter how node get checked/unchecked)
Any ideas?
The code:
(there is many code, what matters here is "select_node" under types
and binded "change_state" on jstree.)
/* check 'selector' checkbox nodes (selector is string od IDs delim
with comma) */
jQuery.checkColumns = function(id_jstree, selector){
var treeObj = $(id_jstree);
var treeRef = $.jstree._reference(id_jstree);
treeRef.close_all(); //close all before checking
treeObj.jstree("check_node", treeObj.find(selector)); //
checking the nodes
//open the checked folder nodes
//this is now done automaticaly by checkbox plugin, conf.
checked_parent_open option!!
//$.openCheckedColumns(id_jstree, true, selector);
}
---
var div_for_id = jqmWinFirst.find("#selected_column_ID");
var colsJstree = jqmWinFirst.find("#fieldsSelector_jstree");
var selectFirst = jqmWinFirst.find("select:first");
var do_gen_columns_sql = true;
selectFirst.change(function(){
$.jstree._reference(colsJstree).refresh();
});
//JSTREE
//this tree does not have static elements, all are dynamic
colsJstree
.bind("loaded.jstree", function () {
//get query from hidden text input and check columns
do_gen_columns_sql = false; //disable updating query on check/
uncheck node after load
var q = jqmWinFirst.find("input").filter(function() {
return $(this).attr('name').match('query');
}).eq(0).attr('value'); //maybe better selector!
if (q) {
var a = q.split('|');
var ids = '#' + a[a.length-1].split(',').join(',#');
$.checkColumns(colsJstree, ids);
}
})
.bind("change_state.jstree", function (NODE, CHECK) {
if (do_gen_columns_sql == false) { return };
alert($(NODE).attr("id")); //THIS SHOULDN'T BE UNDEFINED!
//TODO: do sth with the id
div_for_id.html(''); //clear "select_node" value
//apply new query on every select == auto apply new query
gen_columns_sql('fieldsSelector_jstree', false); //refreshes input
text for query === 'applySelectionsBtn'
})
.jstree({
"core" : {
"animation" : 200
},
"checkbox" : {
"checked_parent_open" : true
},
"json_data" : {
"ajax" : {
"url" : "async_json_data_jstreeColumns_dynamic.php",
"async" : true,
"cache" : true,
"dataType" : "json",
"data" : function (n) {
var href = selectFirst.find("option:selected").text(); //maybe
better selector
if (href) {
return { "entity" : href, "title" : "1" };
}
}
}
},
"themes" : {
"theme" : "apple",
"dots" : true,
"icons" : false
},
"types" : {
"valid_children" : [ "all" ],
"types" : {
"default" : { //this is leaf
"valid_children" : [ "all" ],
"hover_node" : true,
"select_node" : function (NODE, CHECK) {
colsJstree.jstree("change_state", NODE, CHECK);
return false;
}
},
"folder" : {
"valid_children" : [ "all" ],
"clickable" : true,
"select_node" : function (NODE) {
colsJstree.jstree("toggle_node", $(NODE));
return false; }
}
}
},
"plugins" : [ "themes", "json_data", "types", "checkbox", "ui" ]
}); //endof jsTREE