]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActiveHyperLink.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TActiveHyperLink.php
1 <?php
2 /**
3  * TActiveHyperLink class file.
4  *
5  * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6  * @link https://github.com/pradosoft/prado
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9  * @package System.Web.UI.ActiveControls
10  */
11
12 /**
13  * TActiveHyperLink class.
14  *
15  * The active control counterpart of THyperLink component. When
16  * {@link TBaseActiveControl::setEnableUpdate ActiveControl.EnableUpdate}
17  * property is true the during a callback request, setting {@link setText Text}
18  * property will also set the text of the label on the client upon callback
19  * completion. Similarly, for other properties such as {@link setImageUrl ImageUrl},
20  * {@link setNavigateUrl NavigateUrl} and {@link setTarget Target}.
21  *
22  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
23  * @package System.Web.UI.ActiveControls
24  * @since 3.1
25  */
26 class TActiveHyperLink extends THyperLink implements IActiveControl
27 {
28         /**
29          * Creates a new callback control, sets the adapter to
30          * TActiveControlAdapter. If you override this class, be sure to set the
31          * adapter appropriately by, for example, by calling this constructor.
32          */
33         public function __construct()
34         {
35                 parent::__construct();
36                 $this->setAdapter(new TActiveControlAdapter($this));
37         }
38
39         /**
40          * @return TBaseActiveControl basic active control options.
41          */
42         public function getActiveControl()
43         {
44                 return $this->getAdapter()->getBaseActiveControl();
45         }
46
47         /**
48          * On callback response, the inner HTMl of the label is updated.
49          * @param string the text value of the label
50          */
51         public function setText($value)
52         {
53                 if(parent::getText() === $value)
54                         return;
55
56                 parent::setText($value);
57                 if($this->getActiveControl()->canUpdateClientSide())
58                         $this->getPage()->getCallbackClient()->update($this, $value);
59         }
60
61         /**
62          * Sets the location of image file of the THyperLink.
63          * @param string the image file location
64          */
65         public function setImageUrl($value)
66         {
67                 if(parent::getImageUrl() === $value)
68                         return;
69
70                 parent::setImageUrl($value);
71                 if($this->getActiveControl()->canUpdateClientSide() && $value !== '')
72                 {
73                         $textWriter = new TTextWriter;
74                         $renderer = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $textWriter);
75                         $this->createImage($value)->renderControl($renderer);
76                         $this->getPage()->getCallbackClient()->update($this, $textWriter->flush());
77                 }
78         }
79
80         /**
81          * Sets the URL to link to when the THyperLink component is clicked.
82          * @param string the URL
83          */
84         public function setNavigateUrl($value)
85         {
86                 if(parent::getNavigateUrl() === $value)
87                         return;
88
89                 parent::setNavigateUrl($value);
90                 if($this->getActiveControl()->canUpdateClientSide())
91                 {
92                         //replace &amp; with & and urldecode the url (setting the href using javascript is literal)
93                         $url = urldecode(str_replace('&amp;', '&', $value));
94                         $this->getPage()->getCallbackClient()->setAttribute($this, 'href', $url);
95                 }
96         }
97
98         /**
99          * Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
100          * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
101          */
102         public function setTarget($value)
103         {
104                 if(parent::getTarget() === $value)
105                         return;
106
107                 parent::setTarget($value);
108                 if($this->getActiveControl()->canUpdateClientSide())
109                         $this->getPage()->getCallbackClient()->setAttribute($this, 'target', $value);
110         }
111 }
112