From 90125e8b38323ea3fbd856ba565837a801677a7b Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 29 Apr 2016 15:37:31 +0200 Subject: * auto-registered stylesheets for controls --- app/php/web/TemplateControl.php | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'app') diff --git a/app/php/web/TemplateControl.php b/app/php/web/TemplateControl.php index 952bd4f..213a680 100644 --- a/app/php/web/TemplateControl.php +++ b/app/php/web/TemplateControl.php @@ -8,6 +8,10 @@ class TemplateControl extends TTemplateControl { if (file_exists($scriptFile)) { $this->_registerScriptFile($scriptFile); } + $styleFile = $this->_getControlStylePath(get_class($this)); + if (file_exists($styleFile)) { + $this->_registerStyleFile($styleFile); + } } protected function getExternalScriptDependencies() { @@ -26,6 +30,18 @@ class TemplateControl extends TTemplateControl { return []; } + protected function getExternalStyleDependencies() { + return []; + } + + protected function getLibStyleDependencies() { + return []; + } + + protected function getControlStyleDependencies() { + return []; + } + private function _getControlScriptPath($className) { return Prado::getPathOfNamespace('Application.controls.scripts') . DIRECTORY_SEPARATOR @@ -33,6 +49,13 @@ class TemplateControl extends TTemplateControl { . '.js'; } + private function _getControlStylePath($className) { + return Prado::getPathOfNamespace('Application.controls.styles') + . DIRECTORY_SEPARATOR + . $className + . '.css'; + } + private function _getLibPath($identifier, $extension = '') { return Prado::getPathOfNamespace('Lib') . DIRECTORY_SEPARATOR @@ -95,6 +118,52 @@ class TemplateControl extends TTemplateControl { } } + private function _registerStyleFile($styleFile) { + $this->_registerExternalStyleDependencies( + $this->getExternalStyleDependencies() + ); + $this->_registerLibStyleDependencies( + $this->getLibStyleDependencies() + ); + $this->_registerControlStyleDependencies( + $this->getControlStyleDependencies() + ); + $this->Page->ClientScript->registerStyleSheetFile( + 'TemplateControl.' . get_class($this), + $this->Application->AssetManager->publishFilePath($styleFile) + ); + } + + private function _registerExternalStyleDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + $dependency, $dependency + ); + } + } + + private function _registerLibStyleDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + 'LibStyle.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getLibPath($dependency, '.css') + ) + ); + } + } + + private function _registerControlStyleDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + 'TemplateControl.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getControlStylePath($dependency) + ) + ); + } + } + } ?> -- cgit v1.2.3