1: | <?php |
2: | |
3: | namespace Zippy\Html\Link; |
4: | |
5: | use Zippy\WebApplication; |
6: | use Zippy\Interfaces\EventReceiver; |
7: | use Zippy\Interfaces\ClickListener; |
8: | use Zippy\Interfaces\Requestable; |
9: | use Zippy\Event; |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | class SubmitLink extends AbstractLink implements ClickListener, Requestable |
16: | { |
17: | private $event; |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | public function __construct($id, EventReceiver $receiver = null, $handler = null, $ajax = false) { |
26: | parent::__construct($id); |
27: | |
28: | if (is_object($receiver) && strlen($handler) > 0) { |
29: | $this->onClick($receiver, $handler, $ajax); |
30: | } |
31: | } |
32: | |
33: | |
34: | |
35: | |
36: | public function RenderImpl() { |
37: | parent::RenderImpl(); |
38: | if ($this->getFormOwner() == null) { |
39: | throw new \Zippy\Exception("Element '" . $this->id . "' outside FORM tag"); |
40: | } |
41: | $formid = $this->getFormOwner()->id; |
42: | |
43: | if ($this->disabled == true) { |
44: | $this->setAttribute("href", ""); |
45: | $this->setAttribute("onclick", ""); |
46: | return; |
47: | } |
48: | |
49: | $url = $this->owner->getURLNode() . '::' . $this->id; |
50: | $url = substr($url, 2 + strpos($url, 'q=')); |
51: | if ($this->event->isajax == false) { |
52: | $this->setAttribute("onclick", "javascript:{if(beforeZippy('{$this->id}') ==false) return false; $('#" . $formid . "_q').attr('value','" . $url . "'); $('#" . $formid . "').submit();event.returnValue=false; return false;}"); |
53: | } else { |
54: | $_BASEURL = WebApplication::$app->getResponse()->getHostUrl(); |
55: | $this->setAttribute("onclick", "if(beforeZippy('{$this->id}') ==false) return false; $('#" . $formid . "_q').attr('value','" . $url . "'); submitForm('{$formid}','{$_BASEURL}/?ajax=true');"); |
56: | } |
57: | |
58: | |
59: | |
60: | } |
61: | |
62: | |
63: | |
64: | |
65: | public function RequestHandle() { |
66: | $this->OnEvent(); |
67: | } |
68: | |
69: | |
70: | |
71: | |
72: | public function OnEvent() { |
73: | if ($this->event != null) { |
74: | $this->event->onEvent($this); |
75: | } |
76: | } |
77: | |
78: | public function onClick(EventReceiver $receiver, $handler, $ajax = false) { |
79: | $this->event = new Event($receiver, $handler); |
80: | $this->event->isajax = $ajax; |
81: | } |
82: | |
83: | } |
84: | |