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: * @param string ID компонента
22: * @param EventReceiver Объект с методом обработки события
23: * @param string Имя мтода-обработчика
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: * @see HtmlComponent
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: // $this->setAttribute("onclick","javascript:{ var q = $('#".$formid."_q').attr('value');$('#".$formid."_q').attr('value',q+'::".$this->id."');$('#".$formid."').submit();return false;}");
60: }
61:
62: /**
63: * @see Requestable
64: */
65: public function RequestHandle() {
66: $this->OnEvent();
67: }
68:
69: /**
70: * @see ClickListener
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: