MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mtreemenu.class
Ir para a documentação deste ficheiro.
1<?php
2class MTreeMenu extends MControl
3{
4 static $order = 0;
5 private $nOrder;
6 private $template;
7 private $action;
8 private $target;
9 private $items;
10 private $jsItems;
11 private $arrayItems;
12
13 function __construct($name = '', $template = 0, $action = '', $target = '_blank')
14 {
15 parent::__construct($name);
17 $this->AddStyleFile('m_treemenu.css');
18 $page->AddScript('tigra/tree.js');
19 // $page->AddScript('tigra/tree_items.js');
20 $this->items = NULL;
21 $this->template = $template;
22 $page->AddScript("tigra/tree{$this->template}_tpl.js");
23 $this->action = $action;
24 $this->target = $target;
25 $this->nOrder = MTreeMenu::$order++;
26 }
27
28 private function GetJsItems($items)
29 {
30 if ($items != NULL)
31 {
32 foreach ($items as $it)
33 {
34 $i .= "['{$it[1]}'";
35 $i .= ($it[0] !== NULL ? ",'{$it[0]}'" : ',null');
36
37 if ($this->action != '')
38 {
39 $it[2] = str_replace('#', $it[0], $this->action);
40 }
41
42 $i .= ($it[2] != NULL ? ",'{$it[2]}'" : ',null') . ',';
43 $i .= $this->GetJsItems($this->items[(int)$it[0]]);
44 $i .= "],";
45 }
46
47 return $i;
48 }
49 }
50
51 function SetItemsFromArray($array, $key = '3', $data = '0,1,2')
52 {
53 $this->arrayItems = array();
54 foreach ($array as $a)
55 {
56 $this->arrayItems[$a[0]] = $a;
57 }
58
59 $o = new MTreeArray($array, $key, $data);
60 $this->items = $o->tree;
61 $this->jsItems = $this->GetJsItems($this->items['root']);
62 }
63
64 function SetItemsFromResult($result, $basename, $key = '3', $data = '0,1,2')
65 {
66 $o = new MTreeArray($result, $key, $data);
67 $this->items['root'][] = array
68 (
69 0,
70 $basename,
71 ''
72 );
73 foreach ($o->tree as $key => $tree)
74 {
75 $this->items[0][] = array
76 (
77 $key,
78 $key,
79 ''
80 );
81
82 $this->items[$key] = $tree;
83 }
84
85 $this->jsItems = $this->GetJsItems($this->items['root']);
86 }
87
88 function getItems()
89 {
90 return $this->arrayItems;
91 }
92
93 function SetSelectEvent($jsCode)
94 {
95 $tree = $this->nOrder;
96 $code = "trees[$tree].selectevent = function (n_id, item_id) { $jsCode };\n";
97 $this->page->AddJsCode($code);
98 }
99
100 function SetEventHandler($eventHandler = '')
101 {
102 $tree = $this->nOrder;
103
104 if ($eventHandler != '')
105 $this->attachEventHandler('click', $eventHandler);
106
107 $code = "trees[$tree].selectevent = function (n_id, item_id) { _doPostBack('{$this->name}:click', item_id); document.forms[0].submit(); };\n";
108 $this->page->AddJsCode($code);
109 }
110
111 function GenerateInner()
112 {
113 $tree = $this->nOrder;
115 $form = ($this->form == NULL) ? $page->name : $this->form->name;
116 $html = "<script language=\"JavaScript\">\n";
117 $html .= "<!--\n";
118 $html .= "var TREE_ITEMS_{$tree} = [ " . $this->jsItems . "];\n";
119 $html .= "tree{$this->template}_tpl['target'] = '{$this->target}';\n";
120 $html .= "new tree (TREE_ITEMS_{$tree}, tree{$this->template}_tpl);\n";
121 $html .= "//-->\n";
122 $html .= "</script>\n";
123 $this->inner = $html;
124 }
125}
126?>
attachEventHandler( $name, $handler, $param=NULL)
Definição mcontrol.class:771
__construct($name='', $template=0, $action='', $target='_blank')
Definição mtreemenu.class:13
SetItemsFromResult($result, $basename, $key='3', $data='0, 1, 2')
Definição mtreemenu.class:64
SetEventHandler($eventHandler='')
static $order
Definição mtreemenu.class:4
SetSelectEvent($jsCode)
Definição mtreemenu.class:93
SetItemsFromArray($array, $key='3', $data='0, 1, 2')
Definição mtreemenu.class:51