1: | <?php |
2: | |
3: | namespace Zippy\Html; |
4: | |
5: | use Zippy\Binding\SimpleBinding; |
6: | use Zippy\Interfaces\Binding; |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | class Label extends HtmlComponent |
13: | { |
14: | private $value; |
15: | |
16: | private $html = false; |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | public function __construct($id, $text = null, $html = false) { |
24: | parent::__construct($id); |
25: | |
26: | $this->value = $text; |
27: | $this->html = $html; |
28: | |
29: | } |
30: | |
31: | |
32: | |
33: | |
34: | public function RenderImpl() { |
35: | |
36: | |
37: | if ($this->getText() === null) { |
38: | return; |
39: | } |
40: | |
41: | $HtmlTag = $this->getTag(); |
42: | if ($this->html) { |
43: | $HtmlTag->html($this->getText()); |
44: | } else { |
45: | $HtmlTag->text($this->getText()); |
46: | } |
47: | } |
48: | |
49: | |
50: | |
51: | |
52: | |
53: | |
54: | public function setText($text, $html = false) { |
55: | $this->value = $text; |
56: | $this->html = $html; |
57: | |
58: | if(\Zippy\WebApplication::$app->getRequest()->isAjaxRequest()) { |
59: | $js= "$('#{$this->id}').text('{$text}')" ; |
60: | if ($this->html) { |
61: | $js= "$('#{$this->id}').html('{$text}')"; |
62: | } |
63: | |
64: | |
65: | |
66: | \Zippy\WebApplication::$app->getResponse()->addAjaxResponse($js) ; |
67: | } |
68: | |
69: | |
70: | |
71: | } |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | public function getText() { |
78: | if ($this->value instanceof Binding) { |
79: | return ''.$this->value->getValue(); |
80: | } else { |
81: | return ''.$this->value; |
82: | } |
83: | } |
84: | |
85: | |
86: | |
87: | } |
88: | |