1: | <?php |
2: | |
3: | namespace Zippy\Html\Form; |
4: | |
5: | use Zippy\WebApplication; |
6: | use Zippy\Exceptions\Exception; |
7: | use Zippy\Event; |
8: | use Zippy\Html\HtmlComponent; |
9: | use Zippy\Interfaces\ClickListener; |
10: | use Zippy\Interfaces\Requestable; |
11: | use Zippy\Interfaces\EventReceiver; |
12: | |
13: | |
14: | |
15: | |
16: | class Button extends HtmlComponent implements ClickListener, Requestable |
17: | { |
18: | private $event; |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | public function __construct($id, EventReceiver $receiver = null, $handler = null, $ajax = true) { |
27: | parent::__construct($id); |
28: | |
29: | if (is_object($receiver) && strlen($handler) > 0) { |
30: | $this->onClick($receiver, $handler, $ajax); |
31: | } |
32: | $this->setAttribute("name", $this->id); |
33: | } |
34: | |
35: | |
36: | |
37: | |
38: | public function RenderImpl() { |
39: | $this->setAttribute("type", 'button'); |
40: | if ($this->event == null) { |
41: | return; |
42: | } |
43: | |
44: | if ($this->event->isajax == false) { |
45: | $url = $this->owner->getURLNode() . "::" . $this->id; |
46: | $this->setAttribute("onclick", "if(beforeZippy('{$this->id}') ==false) return false;window.location='{$url}';"); |
47: | } else { |
48: | $url = $this->owner->getURLNode() . "::" . $this->id . "&ajax=true"; |
49: | $this->setAttribute("onclick", "if(beforeZippy('{$this->id}') ==false) return false;getUpdate('{$url}');"); |
50: | } |
51: | } |
52: | |
53: | |
54: | |
55: | |
56: | public function RequestHandle() { |
57: | $this->onEvent(); |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | public function onClick(EventReceiver $receiver, $handler, $ajax = false) { |
64: | $this->event = new Event($receiver, $handler); |
65: | $this->event->isajax = $ajax; |
66: | } |
67: | |
68: | |
69: | |
70: | |
71: | public function onEvent() { |
72: | if ($this->event != null) { |
73: | $this->event->onEvent($this); |
74: | } |
75: | } |
76: | |
77: | } |
78: | |