| 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: | |
| 26: | |
| 27: | |
| 28: | |
| 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: | |
| 40: | |
| 41: | public function RenderImpl() { |
| 42: | parent::RenderImpl(); |
| 43: | |
| 44: | |
| 45: | if ($this->disabled == true) { |
| 46: | $this->setAttribute("href", ""); |
| 47: | |
| 48: | return; |
| 49: | } |
| 50: | if ($this->event == null) { |
| 51: | $this->setAttribute("href", ""); |
| 52: | |
| 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 . " ↑"); |
| 72: | } else { |
| 73: | if ($this->dir == "desc") { |
| 74: | $HtmlTag->html($content . " ↓"); |
| 75: | } else { |
| 76: | $HtmlTag->text($content); |
| 77: | } |
| 78: | } |
| 79: | |
| 80: | |
| 81: | } |
| 82: | |
| 83: | |
| 84: | |
| 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: | |
| 99: | } |
| 100: | |
| 101: | |
| 102: | |
| 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: | |
| 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: | |