Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Tree
  2. ====
  3. Tree widget renders a hierarchical tree where child nodes can be queried on demand. It can be useful to show
  4. folder like structures, hierarchical menus etc.
  5. Tree & TreeNode Classes
  6. -----------------------
  7. .. class:: Tree(parent, width, do_animate)
  8. Creates a new tree widget in the `parent`.
  9. if `do_animate` is set, it will animate the expansion and closing of the tree
  10. .. attribute:: nodes
  11. dictionary of root nodes
  12. .. attribute:: allnodes
  13. dictionary of all nodes in the tree
  14. .. method:: addNode(parent, id, imagesrc, onclick, onexpand, opts, label)
  15. create a new TreeNode
  16. * `parent` - parent TreeNode which the node is to be created. `null` for root node
  17. * `id` - label (if not separately specified) of the new node
  18. * `imagesrc` - icon of the node
  19. * `onclick` - event to be called when node is clicked (selected)
  20. * `onexpand` - event to ba called when node is expanded
  21. * `opts` - node style options
  22. * `label` - if label is separate from id
  23. .. method:: collapse_all()
  24. Collapse all nodes
  25. .. class:: TreeNode(tree, parent, id, imagesrc, onclick, onexpand, opts, label)
  26. This class is instantiated by :meth:`Tree.addNode`
  27. .. attribute:: parent
  28. Parent node or the Tree (in case of root node)
  29. .. attribute:: nodes
  30. Dictionary of child nodes by id
  31. .. attribute:: opts
  32. Style of the node. Default `opts` is::
  33. opts = {
  34. show_exp_img:1
  35. ,show_icon:1
  36. ,label_style:{padding:'2px', cursor: 'pointer', fontSize:'11px'}
  37. ,onselect_style:{fontWeight: 'bold'}
  38. ,ondeselect_style:{fontWeight: 'normal'}
  39. }
  40. .. method:: select()
  41. Select the node
  42. .. method:: deselect()
  43. Deselect the node
  44. .. method:: show_selected()
  45. Show the style as selected
  46. .. method:: setlabel(t)
  47. Set the label of the node
  48. .. method:: setcolor(c)
  49. Set background color of the node
  50. .. method:: clear_child_nodes()
  51. Remove all child nodes
  52. Example
  53. -------
  54. Example showing a tree in which the child nodes are queried from the server `onexpand`::
  55. // Tree
  56. // ----------
  57. pscript.load_cat_tree = function(){
  58. //create category tree
  59. if(!pscript.cat_tree){
  60. pscript.make_cat_tree();
  61. }
  62. pscript.get_parent_category();
  63. }
  64. pscript.get_parent_category = function(){
  65. if (pscript.cat_tree){
  66. pscript.cat_tree.innerHTML = '';
  67. }
  68. var callback1 = function(r,rt){
  69. cl = r.message;
  70. var has_children = true; var imgsrc = 'images/icons/page.gif';
  71. for(i=0; i<cl.length;i++){
  72. var n = pscript.cat_tree.addNode(null, cl[i][1],imgsrc, pscript.cat_tree.std_onclick, has_children ? pscript.cat_tree.std_onexp : null, null, cl[i][0]);
  73. n.rec = cl[i]; n.rec.name = cl[i][0]; n.rec.label = cl[i][1];
  74. n.rec.parent_category = '';
  75. }
  76. }
  77. $c_obj('Ticket Control','get_root_category','',callback1);
  78. }
  79. pscript.make_cat_tree = function() {
  80. var tree = new Tree(pscript.faq_cat_tree, '100%');
  81. pscript.cat_tree = tree;
  82. // on click
  83. pscript.cat_tree.std_onclick = function(node) {
  84. pscript.cur_node = node;
  85. pscript.cur_node_val = node.rec.name;
  86. //make faq list
  87. pscript.make_faq_lst('frm_node');
  88. }
  89. // on expand
  90. pscript.cat_tree.std_onexp = function(node) {
  91. if(node.expanded_once)return;
  92. $ds(node.loading_div);
  93. var callback = function(r,rt) {
  94. $dh(node.loading_div);
  95. var n = pscript.cat_tree.allnodes[r.message.parent_category];
  96. var cl = r.message.category;
  97. for(var i=0;i<cl.length;i++) {
  98. var imgsrc='images/icons/page.gif';
  99. var has_children = true;
  100. var t = pscript.cat_tree.addNode(n, cl[i].name, imgsrc, pscript.cat_tree.std_onclick, has_children ? pscript.cat_tree.std_onexp : null, null, cl[i].category_name);
  101. t.rec = cl[i];
  102. t.rec.name = cl[i].name;
  103. t.rec.label = cl[i].category_name;
  104. t.parent_category = r.message.parent_category; //alert(t)
  105. }
  106. }
  107. var arg = {}
  108. arg['category'] = node.rec.name;
  109. $c_obj('Ticket Control','get_categories',docstring(arg),callback);
  110. }
  111. }