// ---------
$(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");
});