diff options
author | emkael <emkael@tlen.pl> | 2016-04-29 14:48:49 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-04-29 14:48:49 +0200 |
commit | 4077c281a95b9f53a52678e7f39e77f7e93544e2 (patch) | |
tree | 7c8e75e8479583c59965a7afbc5117252c34f17d /app | |
parent | 19bae03b6f86776599d0f95b521d739ba66d5e76 (diff) |
* TemplateControl dependencies registration refactored
Diffstat (limited to 'app')
-rw-r--r-- | app/php/web/TemplateControl.php | 114 |
1 files changed, 71 insertions, 43 deletions
diff --git a/app/php/web/TemplateControl.php b/app/php/web/TemplateControl.php index a397f6f..952bd4f 100644 --- a/app/php/web/TemplateControl.php +++ b/app/php/web/TemplateControl.php @@ -2,6 +2,30 @@ class TemplateControl extends TTemplateControl { + public function onPreRender($param) { + parent::onPreRender($param); + $scriptFile = $this->_getControlScriptPath(get_class($this)); + if (file_exists($scriptFile)) { + $this->_registerScriptFile($scriptFile); + } + } + + protected function getExternalScriptDependencies() { + return []; + } + + protected function getLibScriptDependencies() { + return []; + } + + protected function getPradoScriptDependencies() { + return []; + } + + protected function getControlScriptDependencies() { + return []; + } + private function _getControlScriptPath($className) { return Prado::getPathOfNamespace('Application.controls.scripts') . DIRECTORY_SEPARATOR @@ -9,62 +33,66 @@ class TemplateControl extends TTemplateControl { . '.js'; } - private function _getLibScriptPath($identifier) { + private function _getLibPath($identifier, $extension = '') { return Prado::getPathOfNamespace('Lib') . DIRECTORY_SEPARATOR . $identifier - . '.js'; + . $extension; } - public function onPreRender($param) { - parent::onPreRender($param); - $scriptFile = $this->_getControlScriptPath(get_class($this)); - if (file_exists($scriptFile)) { - foreach ($this->getExternalScriptDependencies() as $dependency) { - $this->Page->ClientScript->registerHeadScriptFile( - $dependency, $dependency - ); - } - foreach ($this->getLibScriptDependencies() as $dependency) { - $this->Page->ClientScript->registerScriptFile( - 'LibScript.' . $dependency, - $this->Application->AssetManager->publishFilePath( - $this->_getLibScriptPath($dependency) - ) - ); - } - 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) - ) - ); - } - $this->Page->ClientScript->registerScriptFile( - 'TemplateControl.' . get_class($this), - $this->Application->AssetManager->publishFilePath($scriptFile) - ); - } + private function _registerScriptFile($scriptFile) { + $this->_registerExternalScriptDependencies( + $this->getExternalScriptDependencies() + ); + $this->_registerLibScriptDependencies( + $this->getLibScriptDependencies() + ); + $this->_registerPradoScriptDependencies( + $this->getPradoScriptDependencies() + ); + $this->_registerControlScriptDependencies( + $this->getControlScriptDependencies() + ); + $this->Page->ClientScript->registerScriptFile( + 'TemplateControl.' . get_class($this), + $this->Application->AssetManager->publishFilePath($scriptFile) + ); } - protected function getPradoScriptDependencies() { - return []; + private function _registerExternalScriptDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerHeadScriptFile( + $dependency, $dependency + ); + } } - protected function getControlScriptDependencies() { - return []; + private function _registerLibScriptDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerScriptFile( + 'LibScript.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getLibPath($dependency, '.js') + ) + ); + } } - protected function getLibScriptDependencies() { - return []; + private function _registerPradoScriptDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerPradoScript($dependency); + } } - protected function getExternalScriptDependencies() { - return []; + private function _registerControlScriptDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerScriptFile( + 'TemplateControl.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getControlScriptPath($dependency) + ) + ); + } } } |