Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

298 righe
13 KiB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Tree &mdash; Documentation</title>
  7. <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '',
  12. VERSION: '',
  13. COLLAPSE_MODINDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/doctools.js"></script>
  20. <link rel="top" title="Documentation" href="index.html" />
  21. <link rel="up" title="4. Client Side API" href="client_side_widgets.html" />
  22. <link rel="next" title="Tabbed Page" href="tabbed_page.html" />
  23. <link rel="prev" title="Listing" href="listing.html" />
  24. </head>
  25. <body>
  26. <div style="background-color: #FFF; text-align: left; padding: 8px 0px"><img src="_static/banner300910.gif"></div>
  27. <div class="related">
  28. <h3>Navigation</h3>
  29. <ul>
  30. <li class="right" style="margin-right: 10px">
  31. <a href="genindex.html" title="General Index"
  32. accesskey="I">index</a></li>
  33. <li class="right" >
  34. <a href="modindex.html" title="Global Module Index"
  35. accesskey="M">modules</a> |</li>
  36. <li class="right" >
  37. <a href="tabbed_page.html" title="Tabbed Page"
  38. accesskey="N">next</a> |</li>
  39. <li class="right" >
  40. <a href="listing.html" title="Listing"
  41. accesskey="P">previous</a> |</li>
  42. <li><a href="index.html">Documentation</a> &raquo;</li>
  43. <li><a href="client_side_widgets.html" accesskey="U">4. Client Side API</a> &raquo;</li>
  44. </ul>
  45. </div>
  46. <div class="sphinxsidebar">
  47. <div class="sphinxsidebarwrapper">
  48. <h3><a href="index.html">Table Of Contents</a></h3>
  49. <ul>
  50. <li><a class="reference external" href="">Tree</a><ul>
  51. <li><a class="reference external" href="#tree-treenode-classes">Tree &amp; TreeNode Classes</a></li>
  52. <li><a class="reference external" href="#example">Example</a></li>
  53. </ul>
  54. </li>
  55. </ul>
  56. <h4>Previous topic</h4>
  57. <p class="topless"><a href="listing.html"
  58. title="previous chapter">Listing</a></p>
  59. <h4>Next topic</h4>
  60. <p class="topless"><a href="tabbed_page.html"
  61. title="next chapter">Tabbed Page</a></p>
  62. <h3>This Page</h3>
  63. <ul class="this-page-menu">
  64. <li><a href="_sources/tree.txt"
  65. rel="nofollow">Show Source</a></li>
  66. </ul>
  67. <div id="searchbox" style="display: none">
  68. <h3>Quick search</h3>
  69. <form class="search" action="search.html" method="get">
  70. <input type="text" name="q" size="18" />
  71. <input type="submit" value="Go" />
  72. <input type="hidden" name="check_keywords" value="yes" />
  73. <input type="hidden" name="area" value="default" />
  74. </form>
  75. <p class="searchtip" style="font-size: 90%">
  76. Enter search terms or a module, class or function name.
  77. </p>
  78. </div>
  79. <script type="text/javascript">$('#searchbox').show(0);</script>
  80. </div>
  81. </div>
  82. <div class="document">
  83. <div class="documentwrapper">
  84. <div class="bodywrapper">
  85. <div class="body">
  86. <div class="section" id="tree">
  87. <h1>Tree<a class="headerlink" href="#tree" title="Permalink to this headline">¶</a></h1>
  88. <p>Tree widget renders a hierarchical tree where child nodes can be queried on demand. It can be useful to show
  89. folder like structures, hierarchical menus etc.</p>
  90. <div class="section" id="tree-treenode-classes">
  91. <h2>Tree &amp; TreeNode Classes<a class="headerlink" href="#tree-treenode-classes" title="Permalink to this headline">¶</a></h2>
  92. <dl class="class">
  93. <dt id="Tree">
  94. <em class="property">class </em><tt class="descname">Tree</tt><big>(</big><em>parent</em>, <em>width</em>, <em>do_animate</em><big>)</big><a class="headerlink" href="#Tree" title="Permalink to this definition">¶</a></dt>
  95. <dd><p>Creates a new tree widget in the <cite>parent</cite>.
  96. if <cite>do_animate</cite> is set, it will animate the expansion and closing of the tree</p>
  97. <dl class="attribute">
  98. <dt id="Tree.nodes">
  99. <tt class="descname">nodes</tt><a class="headerlink" href="#Tree.nodes" title="Permalink to this definition">¶</a></dt>
  100. <dd>dictionary of root nodes</dd></dl>
  101. <dl class="attribute">
  102. <dt id="Tree.allnodes">
  103. <tt class="descname">allnodes</tt><a class="headerlink" href="#Tree.allnodes" title="Permalink to this definition">¶</a></dt>
  104. <dd>dictionary of all nodes in the tree</dd></dl>
  105. <dl class="method">
  106. <dt id="Tree.addNode">
  107. <tt class="descname">addNode</tt><big>(</big><em>parent</em>, <em>id</em>, <em>imagesrc</em>, <em>onclick</em>, <em>onexpand</em>, <em>opts</em>, <em>label</em><big>)</big><a class="headerlink" href="#Tree.addNode" title="Permalink to this definition">¶</a></dt>
  108. <dd><p>create a new TreeNode</p>
  109. <ul class="simple">
  110. <li><cite>parent</cite> - parent TreeNode which the node is to be created. <cite>null</cite> for root node</li>
  111. <li><cite>id</cite> - label (if not separately specified) of the new node</li>
  112. <li><cite>imagesrc</cite> - icon of the node</li>
  113. <li><cite>onclick</cite> - event to be called when node is clicked (selected)</li>
  114. <li><cite>onexpand</cite> - event to ba called when node is expanded</li>
  115. <li><cite>opts</cite> - node style options</li>
  116. <li><cite>label</cite> - if label is separate from id</li>
  117. </ul>
  118. </dd></dl>
  119. <dl class="method">
  120. <dt id="Tree.collapse_all">
  121. <tt class="descname">collapse_all</tt><big>(</big><big>)</big><a class="headerlink" href="#Tree.collapse_all" title="Permalink to this definition">¶</a></dt>
  122. <dd>Collapse all nodes</dd></dl>
  123. </dd></dl>
  124. <dl class="class">
  125. <dt id="TreeNode">
  126. <em class="property">class </em><tt class="descname">TreeNode</tt><big>(</big><em>tree</em>, <em>parent</em>, <em>id</em>, <em>imagesrc</em>, <em>onclick</em>, <em>onexpand</em>, <em>opts</em>, <em>label</em><big>)</big><a class="headerlink" href="#TreeNode" title="Permalink to this definition">¶</a></dt>
  127. <dd><p>This class is instantiated by <a title="Tree.addNode" class="reference internal" href="#Tree.addNode"><tt class="xref docutils literal"><span class="pre">Tree.addNode()</span></tt></a></p>
  128. <dl class="attribute">
  129. <dt id="TreeNode.parent">
  130. <tt class="descname">parent</tt><a class="headerlink" href="#TreeNode.parent" title="Permalink to this definition">¶</a></dt>
  131. <dd>Parent node or the Tree (in case of root node)</dd></dl>
  132. <dl class="attribute">
  133. <dt id="TreeNode.nodes">
  134. <tt class="descname">nodes</tt><a class="headerlink" href="#TreeNode.nodes" title="Permalink to this definition">¶</a></dt>
  135. <dd>Dictionary of child nodes by id</dd></dl>
  136. <dl class="attribute">
  137. <dt id="TreeNode.opts">
  138. <tt class="descname">opts</tt><a class="headerlink" href="#TreeNode.opts" title="Permalink to this definition">¶</a></dt>
  139. <dd><p>Style of the node. Default <cite>opts</cite> is:</p>
  140. <div class="highlight-python"><div class="highlight"><pre><span class="n">opts</span> <span class="o">=</span> <span class="p">{</span>
  141. <span class="n">show_exp_img</span><span class="p">:</span><span class="mi">1</span>
  142. <span class="p">,</span><span class="n">show_icon</span><span class="p">:</span><span class="mi">1</span>
  143. <span class="p">,</span><span class="n">label_style</span><span class="p">:{</span><span class="n">padding</span><span class="p">:</span><span class="s">&#39;2px&#39;</span><span class="p">,</span> <span class="n">cursor</span><span class="p">:</span> <span class="s">&#39;pointer&#39;</span><span class="p">,</span> <span class="n">fontSize</span><span class="p">:</span><span class="s">&#39;11px&#39;</span><span class="p">}</span>
  144. <span class="p">,</span><span class="n">onselect_style</span><span class="p">:{</span><span class="n">fontWeight</span><span class="p">:</span> <span class="s">&#39;bold&#39;</span><span class="p">}</span>
  145. <span class="p">,</span><span class="n">ondeselect_style</span><span class="p">:{</span><span class="n">fontWeight</span><span class="p">:</span> <span class="s">&#39;normal&#39;</span><span class="p">}</span>
  146. <span class="p">}</span>
  147. </pre></div>
  148. </div>
  149. </dd></dl>
  150. <dl class="method">
  151. <dt id="TreeNode.select">
  152. <tt class="descname">select</tt><big>(</big><big>)</big><a class="headerlink" href="#TreeNode.select" title="Permalink to this definition">¶</a></dt>
  153. <dd>Select the node</dd></dl>
  154. <dl class="method">
  155. <dt id="TreeNode.deselect">
  156. <tt class="descname">deselect</tt><big>(</big><big>)</big><a class="headerlink" href="#TreeNode.deselect" title="Permalink to this definition">¶</a></dt>
  157. <dd>Deselect the node</dd></dl>
  158. <dl class="method">
  159. <dt id="TreeNode.show_selected">
  160. <tt class="descname">show_selected</tt><big>(</big><big>)</big><a class="headerlink" href="#TreeNode.show_selected" title="Permalink to this definition">¶</a></dt>
  161. <dd>Show the style as selected</dd></dl>
  162. <dl class="method">
  163. <dt id="TreeNode.setlabel">
  164. <tt class="descname">setlabel</tt><big>(</big><em>t</em><big>)</big><a class="headerlink" href="#TreeNode.setlabel" title="Permalink to this definition">¶</a></dt>
  165. <dd>Set the label of the node</dd></dl>
  166. <dl class="method">
  167. <dt id="TreeNode.setcolor">
  168. <tt class="descname">setcolor</tt><big>(</big><em>c</em><big>)</big><a class="headerlink" href="#TreeNode.setcolor" title="Permalink to this definition">¶</a></dt>
  169. <dd>Set background color of the node</dd></dl>
  170. <dl class="method">
  171. <dt id="TreeNode.clear_child_nodes">
  172. <tt class="descname">clear_child_nodes</tt><big>(</big><big>)</big><a class="headerlink" href="#TreeNode.clear_child_nodes" title="Permalink to this definition">¶</a></dt>
  173. <dd>Remove all child nodes</dd></dl>
  174. </dd></dl>
  175. </div>
  176. <div class="section" id="example">
  177. <h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
  178. <p>Example showing a tree in which the child nodes are queried from the server <cite>onexpand</cite>:</p>
  179. <div class="highlight-python"><pre>// Tree
  180. // ----------
  181. pscript.load_cat_tree = function(){
  182. //create category tree
  183. if(!pscript.cat_tree){
  184. pscript.make_cat_tree();
  185. }
  186. pscript.get_parent_category();
  187. }
  188. pscript.get_parent_category = function(){
  189. if (pscript.cat_tree){
  190. pscript.cat_tree.innerHTML = '';
  191. }
  192. var callback1 = function(r,rt){
  193. cl = r.message;
  194. var has_children = true; var imgsrc = 'images/icons/page.gif';
  195. for(i=0; i&lt;cl.length;i++){
  196. 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]);
  197. n.rec = cl[i]; n.rec.name = cl[i][0]; n.rec.label = cl[i][1];
  198. n.rec.parent_category = '';
  199. }
  200. }
  201. $c_obj('Ticket Control','get_root_category','',callback1);
  202. }
  203. pscript.make_cat_tree = function() {
  204. var tree = new Tree(pscript.faq_cat_tree, '100%');
  205. pscript.cat_tree = tree;
  206. // on click
  207. pscript.cat_tree.std_onclick = function(node) {
  208. pscript.cur_node = node;
  209. pscript.cur_node_val = node.rec.name;
  210. //make faq list
  211. pscript.make_faq_lst('frm_node');
  212. }
  213. // on expand
  214. pscript.cat_tree.std_onexp = function(node) {
  215. if(node.expanded_once)return;
  216. $ds(node.loading_div);
  217. var callback = function(r,rt) {
  218. $dh(node.loading_div);
  219. var n = pscript.cat_tree.allnodes[r.message.parent_category];
  220. var cl = r.message.category;
  221. for(var i=0;i&lt;cl.length;i++) {
  222. var imgsrc='images/icons/page.gif';
  223. var has_children = true;
  224. 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);
  225. t.rec = cl[i];
  226. t.rec.name = cl[i].name;
  227. t.rec.label = cl[i].category_name;
  228. t.parent_category = r.message.parent_category; //alert(t)
  229. }
  230. }
  231. var arg = {}
  232. arg['category'] = node.rec.name;
  233. $c_obj('Ticket Control','get_categories',docstring(arg),callback);
  234. }
  235. }</pre>
  236. </div>
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. </div>
  242. <div class="clearer"></div>
  243. </div>
  244. <div class="related">
  245. <h3>Navigation</h3>
  246. <ul>
  247. <li class="right" style="margin-right: 10px">
  248. <a href="genindex.html" title="General Index"
  249. >index</a></li>
  250. <li class="right" >
  251. <a href="modindex.html" title="Global Module Index"
  252. >modules</a> |</li>
  253. <li class="right" >
  254. <a href="tabbed_page.html" title="Tabbed Page"
  255. >next</a> |</li>
  256. <li class="right" >
  257. <a href="listing.html" title="Listing"
  258. >previous</a> |</li>
  259. <li><a href="index.html">Documentation</a> &raquo;</li>
  260. <li><a href="client_side_widgets.html" >4. Client Side API</a> &raquo;</li>
  261. </ul>
  262. </div>
  263. <div class="footer">
  264. &copy; Copyright 2010, Rushabh Mehta.
  265. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
  266. </div>
  267. </body>
  268. </html>