diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2015-01-20 22:43:54 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2015-01-20 22:43:54 +0100 |
commit | e2d11c31ca2671e812a8206627dffd00bfd192ea (patch) | |
tree | ab5c8a522c8148756e9f87d182ba0411c6af6e26 /framework/Web/UI/JuiControls/TJuiControlAdapter.php | |
parent | 464a235c8c7dc070fb10ac47f2186f24a077ae0d (diff) |
One class per file: framework/Web/UI/JuiControls (continue)
Diffstat (limited to 'framework/Web/UI/JuiControls/TJuiControlAdapter.php')
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiControlAdapter.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/framework/Web/UI/JuiControls/TJuiControlAdapter.php b/framework/Web/UI/JuiControls/TJuiControlAdapter.php new file mode 100644 index 00000000..462927ad --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiControlAdapter.php @@ -0,0 +1,81 @@ +<?php +/** + * TJuiControlAdapter class file. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + +/** + * TJuiControlAdapter class + * + * TJuiControlAdapter is the base adapter class for controls that are + * derived from a jQuery-ui widget. It exposes convenience methods to + * publish jQuery-UI javascript and css assets. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiControlAdapter extends TActiveControlAdapter +{ + const SCRIPT_PATH = 'jquery'; + const CSS_PATH = 'css'; + const BASE_CSS_FILENAME ='jquery-ui.css'; + + /** + * @param string set the jquery-ui style + */ + public function setJuiBaseStyle($value) + { + $this->getControl()->setViewState('JuiBaseStyle', $value, 'base'); + } + + /** + * @return string current jquery-ui style + */ + public function getJuiBaseStyle() + { + return $this->getControl()->getViewState('JuiBaseStyle', 'base'); + } + + /** + * Inject jquery script and styles before render + */ + public function onPreRender($param) + { + parent::onPreRender($param); + $this->getPage()->getClientScript()->registerPradoScript('jqueryui'); + $this->publishJuiStyle(self::BASE_CSS_FILENAME); + } + + /** + * @param string jQuery asset file in the self::SCRIPT_PATH directory. + * @return string jQuery asset url. + */ + protected function getAssetUrl($file='') + { + $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl(); + return $base.'/'.self::SCRIPT_PATH.'/'.$file; + } + + /** + * Publish the jQuery-ui style Css asset file. + * @param file name + * @return string Css file url. + */ + public function publishJuiStyle($file) + { + $url = $this->getAssetUrl(self::CSS_PATH.'/'.$this->getJuiBaseStyle().'/'.$file); + $cs = $this->getPage()->getClientScript(); + if(!$cs->isStyleSheetFileRegistered($url)) + $cs->registerStyleSheetFile($url, $url); + return $url; + } + +}
\ No newline at end of file |