summaryrefslogtreecommitdiff
path: root/app/php/components/TemplateControl.php
blob: e3c9e26704831b78e37d5ed3c4123e4fe8f7cb47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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 [];
    }

}

?>