diff options
author | emkael <emkael@tlen.pl> | 2016-04-19 13:33:29 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-04-19 13:33:29 +0200 |
commit | d0acd8681d97c863b9b6fec9d286a0aa19abf61e (patch) | |
tree | 65b645f7f74e1bbf2fa4c1bb9c77ff4f0a8699ab /app/php/components | |
parent | 60841b3c92dc630d5d6dd03aadac27705bacdc62 (diff) |
* base class for controls, auto-registering JS scripts
Diffstat (limited to 'app/php/components')
-rw-r--r-- | app/php/components/TemplateControl.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/app/php/components/TemplateControl.php b/app/php/components/TemplateControl.php new file mode 100644 index 0000000..e3c9e26 --- /dev/null +++ b/app/php/components/TemplateControl.php @@ -0,0 +1,53 @@ +<?php + +class TemplateControl extends TTemplateControl { + + private function _getControlScriptPath($className) { + return Prado::getPathOfNamespace('Application.controls.scripts') + . DIRECTORY_SEPARATOR + . $className + . '.js'; + } + + public function onPreRender($param) { + parent::onPreRender($param); + $scriptFile = $this->_getControlScriptPath(get_class($this)); + if (file_exists($scriptFile)) { + foreach ($this->getPradoScriptDependencies() as $dependency) { + $this->Page->ClientScript->registerPradoScript($dependency); + } + foreach ($this->getControlScriptDependencies() as $dependency) { + $this->Page->ClientScript->registerScriptFile( + 'TemplateControl.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getControlScriptPath($dependency) + ) + ); + } + foreach ($this->getExternalScriptDependencies() as $dependency) { + $this->Page->ClientScript->registerHeadScriptFile( + $dependency, $dependency + ); + } + $this->Page->ClientScript->registerScriptFile( + 'TemplateControl.' . get_class($this), + $this->Application->AssetManager->publishFilePath($scriptFile) + ); + } + } + + protected function getPradoScriptDependencies() { + return []; + } + + protected function getControlScriptDependencies() { + return []; + } + + protected function getExternalScriptDependencies() { + return []; + } + +} + +?> |