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 SortLink extends AbstractLink implements ClickListener, Requestable
17: {
18: public $fileld = "";
19: public $dir = "";
20:
21: protected $event;
22:
23: /**
24: * Конструктор
25: * @param string ID компонента
26: * @param fileld поле сортировки
27: * @param EventReceiver Объект с методом обработки события
28: * @param string Имя метода-обработчика
29: */
30: public function __construct($id, $fileld, $receiver = null, $handler = null, $ajax = false) {
31: parent::__construct($id);
32: $this->fileld = $fileld;
33: if (is_object($receiver) && $handler != null) {
34: $this->onClick($receiver, $handler, $ajax);
35: }
36: }
37:
38: /**
39: * @see HtmlComponent
40: */
41: public function RenderImpl() {
42: parent::RenderImpl();
43:
44:
45: if ($this->disabled == true) {
46: $this->setAttribute("href", "");
47: //$this->setAttribute("onclick", "");
48: return;
49: }
50: if ($this->event == null) {
51: $this->setAttribute("href", "");
52: // $this->setAttribute("onclick", "");
53: return;
54: }
55:
56: $this->setAttribute("href", "javascript:void(0);");
57: if ($this->event->isajax == false) {
58: $url = $this->owner->getURLNode() . "::" . $this->id;
59: $this->setAttribute("onclick", "window.location='{$url}';event.returnValue=false; return false;");
60: } else {
61: $url = $this->owner->getURLNode() . "::" . $this->id . "&ajax=true";
62: $this->setAttribute("onclick", "getUpdate('{$url}');event.returnValue=false; return false;");
63: }
64: if (strlen($this->dir) == 0) {
65: return;
66: }
67:
68: $HtmlTag = $this->getTag();
69: $content = $HtmlTag->text();
70: if ($this->dir == "asc") {
71: $HtmlTag->html($content . " &#8593;");
72: } else {
73: if ($this->dir == "desc") {
74: $HtmlTag->html($content . " &#8595;");
75: } else {
76: $HtmlTag->text($content);
77: }
78: }
79:
80:
81: }
82:
83: /**
84: * @see Requestable
85: */
86: public function RequestHandle() {
87: if (strlen($this->dir) == 0) {
88: $this->dir = "asc";
89: } else {
90: if ($this->dir == "asc") {
91: $this->dir = "desc";
92: } else {
93: $this->dir = "asc";
94: }
95: }
96:
97: $this->OnEvent();
98: // WebApplication::getApplication()->setReloadPage();
99: }
100:
101: /**
102: * @see ClickListener
103: */
104: public function onClick(EventReceiver $receiver, $handler, $ajax = false) {
105: $this->event = new Event($receiver, $handler);
106: $this->event->isajax = $ajax;
107: }
108:
109: /**
110: * @see ClickListener
111: */
112: public function OnEvent() {
113: if ($this->event != null) {
114: $this->event->onEvent($this);
115: }
116: }
117:
118: /**
119: * сброс сортировки
120: *
121: */
122: public function Reset() {
123:
124: $this->field = "";
125: $this->dir = "";
126:
127: }
128:
129: }
130: