MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
buttoncontrols.class
Ir para a documentação deste ficheiro.
1<?php
2
3class MButton extends MFormControl
4{
5 public $action;
6 public $event;
7 public $onclick;
8 public $target = '_self';
9 public $type;
10 public $image;
11
12 private $showLoading = true;
13
14
15 public function __construct( $name = '', $label = '', $action = NULL, $image = NULL )
16 {
17 parent::__construct( $name, '', $label );
18
19 $this->action = $action ? $action : 'submit';
20 $this->event = '';
21 $this->onclick = '';
22 $this->image = $image;
23 $this->SetClass('m-button btn btn-default');
24 }
25
26
27 public function __set( $name, $value )
28 {
29 switch ( $name )
30 {
31 case 'padding':
32 case 'width':
33 case 'height':
34 case 'visibility':
35 $this->_addStyle( $name, $value );
36 break;
37
38 default:
39 parent::__set( $name, $value );
40 break;
41 }
42 }
43
44
45 public function setImage( $location )
46 {
47 $this->image = $location;
48 }
49
50
51 public function setOnClick( $onclick )
52 {
53 $this->onclick = $onclick;
54 }
55
56 public function setAction( $action )
57 {
58 $this->action = $action;
59 }
60
61 public function setTarget( $target )
62 {
63 $this->target = $target;
64 }
65
66 public function getTarget( )
67 {
68 return $this->target;
69 }
70
71 public function generateButton()
72 {
73 $action = strtoupper($this->action);
74
75 if ( $action == 'SUBMIT' )
76 {
77 $type = 'submit';
78
79 if ( count($this->eventHandlers) )
80 {
81 $param = $this->eventHandlers['click']['param'];
82 $onclick = "return _doPostBack('{$this->name}:click','{$param}', '$this->target' )";
83 }
84 elseif ( $this->event != '' )
85 {
86 $eventTokens = explode( ';', $this->event );
87 $onclick = "return _doPostBack('{$eventTokens[0]}','{$eventTokens[1]}', '$this->target' )";
88 }
89 else
90 {
91 if ( $this->name != '' )
92 {
93 $onclick = "return _doPostBack('{$this->name}:click','', '$this->target');";
94 }
95 }
96 }
97 else if ( $action == 'RESET' )
98 {
99 $type = 'reset';
100 }
101 else if ( $action == 'PRINT' )
102 {
103 $type = 'button';
104 $onclick = "_doPrintForm();";
105 }
106 else if ($action == 'REPORT')
107 {
108 $type = 'button';
109
110 if ( $this->name != '' )
111 {
112 $onclick = "return _doPostBack('{$this->name}:click',''); _doPrintFile();";
113 }
114 }
115 else if ( $action == 'PDF' )
116 {
117 $type = 'button';
118
119 if ( $this->name != '' )
120 {
121 $onclick = "return _doPostBack('{$this->name}:click',''); _doShowPDF();";
122 }
123 }
124 else if ( $action == 'RETURN' )
125 {
126 global $history;
127
128 $type = 'button';
129 $href = $history->back('action');
130 $onclick = "GotoURL('$href');";
131 }
132 else if ( $action == 'NONE' )
133 {
134 $type = 'button';
135 $onclick = "";
136 }
137 else if ( substr($action, 0, 7) == 'HTTP://' OR substr($action, 0, 8) == 'HTTPS://' )
138 {
139 if ( $this->onclick != '' )
140 {
141 $this->action = $this->action . "&onclick=$this->onclick";
142 }
143
144 $type = 'button';
145 $onclick = "GotoURL('$this->action');";
146 }
147 else
148 {
149 $type = 'button';
151 }
152
153 if ( ( $this->value = $this->label ) == '' )
154 {
155 $this->value = 'Enviar';
156 }
157
158 if ( !$this->type )
159 {
160 $this->type = $type;
161 }
162
163 if ( !$this->showLoading )
164 {
165 $onclick = 'MIOLO_showLoading = false; ' . $onclick . '; MIOLO_showLoading = true;';
166 }
167
168 if ( !$this->onclick )
169 {
170 $this->onclick = $onclick;
171 }
172 $this->label = '';
173 }
174
175
176 public function generateInner()
177 {
178 if ( $this->visible )
179 {
180 $this->generateButton();
181 $this->inner = $this->generateLabel() . $this->getRender('button');
182 }
183 }
184
185 public function getShowLoading()
186 {
187 return $this->showLoading;
188 }
189
190 public function setShowLoading($showLoading)
191 {
192 $this->showLoading = $showLoading;
193 }
194}
195
196
198{
199 public function generateInner()
200 {
201 parent::generateButton();
202 $this->value = '';
203 $this->inner = $this->generateLabel() . $this->getRender('button');
204 }
205}
206
207?>
setTarget( $target)
setOnClick( $onclick)
setImage( $location)
setAction( $action)
setShowLoading($showLoading)
__set( $name, $value)
__construct( $name='', $label='', $action=NULL, $image=NULL)
getRender( $method)
Definição mcontrol.class:833