From 823d71ced9b4947b1a5a5ade7245d521ed490061 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 7 Jun 2016 15:17:49 +0200 Subject: * renaming php directory --- app/frontend/web/TemplateControl.php | 176 +++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 app/frontend/web/TemplateControl.php (limited to 'app/frontend/web/TemplateControl.php') diff --git a/app/frontend/web/TemplateControl.php b/app/frontend/web/TemplateControl.php new file mode 100644 index 0000000..aa95d75 --- /dev/null +++ b/app/frontend/web/TemplateControl.php @@ -0,0 +1,176 @@ +_getControlScriptPath(get_class($this)); + if (file_exists($scriptFile)) { + $this->_registerScriptFile($scriptFile); + } + $styleFile = $this->_getControlStylePath(get_class($this)); + if (file_exists($styleFile)) { + $this->_registerStyleFile($styleFile); + } + } + + protected function getExternalScriptDependencies() { + return []; + } + + protected function getLibScriptDependencies() { + return []; + } + + protected function getPradoScriptDependencies() { + return []; + } + + protected function getControlScriptDependencies() { + 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 + . $className + . '.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 + . $identifier + . $extension; + } + + 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) + ); + } + + private function _registerExternalScriptDependencies(array $dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerHeadScriptFile( + $dependency, $dependency + ); + } + } + + private function _registerLibScriptDependencies(array $dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerScriptFile( + 'LibScript.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getLibPath($dependency, '.js') + ) + ); + } + } + + private function _registerPradoScriptDependencies(array $dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerPradoScript($dependency); + } + } + + private function _registerControlScriptDependencies(array $dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerScriptFile( + 'TemplateControl.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getControlScriptPath($dependency) + ) + ); + } + } + + private function _registerStyleFile($styleFile) { + $this->_registerExternalStyleDependencies( + $this->getExternalStyleDependencies() + ); + $this->_registerLibStyleDependencies( + $this->getLibStyleDependencies() + ); + $this->_registerControlStyleDependencies( + $this->getControlStyleDependencies() + ); + if (method_exists($this->Page->ClientScript, 'registerThemeStyleSheetFile')) { + $this->Page->ClientScript->registerThemeStyleSheetFile( + 'TemplateControl.' . get_class($this), + $this->Application->AssetManager->publishFilePath($styleFile) + ); + } else { + $this->Page->ClientScript->registerStyleSheetFile( + 'TemplateControl.' . get_class($this), + $this->Application->AssetManager->publishFilePath($styleFile) + ); + } + } + + private function _registerExternalStyleDependencies(array $dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + $dependency, $dependency + ); + } + } + + private function _registerLibStyleDependencies(array $dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + 'LibStyle.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getLibPath($dependency, '.css') + ) + ); + } + } + + private function _registerControlStyleDependencies(array $dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + 'TemplateControl.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getControlStylePath($dependency) + ) + ); + } + } + +} + +?> -- cgit v1.2.3