1: | <?php |
2: | |
3: | namespace Zippy\Html\Form; |
4: | |
5: | use Zippy\WebApplication; |
6: | use Zippy\Binding\PropertyBinding; |
7: | use Zippy\Interfaces\Binding; |
8: | use Zippy\Interfaces\ChangeListener; |
9: | use Zippy\Interfaces\Requestable; |
10: | use Zippy\Interfaces\EventReceiver; |
11: | use Zippy\Event; |
12: | |
13: | |
14: | |
15: | |
16: | class RadioButton extends HtmlFormDataElement implements ChangeListener, Requestable |
17: | { |
18: | private $itemvalue; |
19: | private $event; |
20: | private $groupname; |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | public function __construct($id, PropertyBinding $binding, $itemvalue, $groupname = null) { |
31: | parent::__construct($id); |
32: | $this->setValue($binding); |
33: | $this->itemvalue = $itemvalue; |
34: | $this->groupname = $groupname != null ? $groupname : $this->value->getPropertyName(); |
35: | } |
36: | |
37: | |
38: | |
39: | |
40: | public function RenderImpl() { |
41: | $v = $this->getValue(); |
42: | if ($v !== null && $v == $this->itemvalue) { |
43: | $this->setAttribute("checked", "checked"); |
44: | } else { |
45: | $this->setAttribute("checked", null); |
46: | } |
47: | |
48: | |
49: | $this->setAttribute("name", $this->groupname); |
50: | $this->setAttribute("value", $this->itemvalue); |
51: | |
52: | if ($this->event != null) { |
53: | $formid = $this->getFormOwner()->id; |
54: | $url = $this->owner->getURLNode() . '::' . $this->id; |
55: | $url = substr($url, 2 + strpos($url, 'q=')); |
56: | if ($this->event->isajax == false) { |
57: | |
58: | $this->setAttribute("onchange", "javascript:{ $('#" . $formid . "_q').attr('value','" . $url . "');$('#" . $formid . "_s').trigger('click');}"); |
59: | } else { |
60: | $_BASEURL = WebApplication::$app->getResponse()->getHostUrl(); |
61: | $this->setAttribute("onchange", " $('#" . $formid . "_q').attr('value','" . $url . "'); submitForm('{$formid}','{$_BASEURL}/?ajax=true');"); |
62: | } |
63: | } |
64: | } |
65: | |
66: | |
67: | |
68: | |
69: | public function getRequestData() { |
70: | |
71: | $this->setValue($_REQUEST[$this->groupname]); |
72: | } |
73: | |
74: | |
75: | |
76: | |
77: | public function RequestHandle() { |
78: | $this->OnEvent(); |
79: | } |
80: | |
81: | |
82: | |
83: | |
84: | public function onChange(EventReceiver $receiver, $handler, $ajax = true) { |
85: | |
86: | $this->event = new Event($receiver, $handler); |
87: | $this->event->isajax = $ajax; |
88: | } |
89: | |
90: | |
91: | |
92: | |
93: | public function OnEvent() { |
94: | if ($this->event != null) { |
95: | $this->event->onEvent($this); |
96: | } |
97: | } |
98: | |
99: | public function clean() { |
100: | $this->setValue(-1); |
101: | } |
102: | } |
103: | |