summaryrefslogtreecommitdiff
path: root/app/frontend/web/TemplateControl.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/frontend/web/TemplateControl.php')
-rw-r--r--app/frontend/web/TemplateControl.php176
1 files changed, 176 insertions, 0 deletions
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 @@
+<?php
+
+class TemplateControl extends TTemplateControl {
+
+ public function onPreRender($param) {
+ parent::onPreRender($param);
+ $scriptFile = $this->_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)
+ )
+ );
+ }
+ }
+
+}
+
+?>