1: <?php
2:
3: namespace Zippy\Html\Link;
4:
5: use Zippy\WebApplication;
6: use Zippy\Interfaces\ClickListener;
7: use Zippy\Interfaces\EventReceiver;
8:
9: use Zippy\Interfaces\Requestable;
10: use Zippy\Event;
11:
12: /**
13: * Ссылка вызыващая обработчик не имеющая возможности копирования адреса ссылки
14: *
15: */
16: class ClickLink extends AbstractLink implements ClickListener, Requestable
17: {
18: protected $event;
19:
20: /**
21: * Конструктор
22: * @param string ID компонента
23: * @param EventReceiver Объект с методом обработки события
24: * @param string Имя метода-обработчика
25: */
26: public function __construct($id, $receiver = null, $handler = null, $ajax = false) {
27: parent::__construct($id);
28:
29: if (is_object($receiver) && $handler != null) {
30: $this->onClick($receiver, $handler, $ajax);
31: }
32: }
33:
34: /**
35: * @see HtmlComponent
36: */
37: public function RenderImpl() {
38: parent::RenderImpl();
39:
40:
41: if ($this->disabled == true) {
42: $this->setAttribute("href", "");
43: //$this->setAttribute("onclick", "");
44: return;
45: }
46: if ($this->event == null) {
47: $this->setAttribute("href", "");
48: // $this->setAttribute("onclick", "");
49: return;
50: }
51:
52: $this->setAttribute("href", "javascript:void(0);");
53: if ($this->event->isajax == false) {
54: $url = $this->owner->getURLNode() . "::" . $this->id;
55: $this->setAttribute("onclick", "if(beforeZippy('{$this->id}') ==false) return false;window.location='{$url}';event.returnValue=false; return false;");
56: } else {
57: $url = $this->owner->getURLNode() . "::" . $this->id . "&ajax=true";
58: $this->setAttribute("onclick", "if(beforeZippy('{$this->id}') ==false) return false;getUpdate('{$url}');event.returnValue=false; return false;");
59: }
60: }
61:
62: /**
63: * @see Requestable
64: */
65: public function RequestHandle() {
66: $this->OnEvent();
67: // WebApplication::getApplication()->setReloadPage();
68: }
69:
70: /**
71: * @see ClickListener
72: */
73: public function onClick(EventReceiver $receiver, $handler, $ajax = false) {
74: $this->event = new Event($receiver, $handler);
75: $this->event->isajax = $ajax;
76: }
77:
78: /**
79: * @see ClickListener
80: */
81: public function OnEvent() {
82: if ($this->event != null) {
83: $this->event->onEvent($this);
84: }
85: }
86:
87: }
88: