summaryrefslogtreecommitdiff
path: root/app/php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-04-19 13:33:29 +0200
committeremkael <emkael@tlen.pl>2016-04-19 13:33:29 +0200
commitd0acd8681d97c863b9b6fec9d286a0aa19abf61e (patch)
tree65b645f7f74e1bbf2fa4c1bb9c77ff4f0a8699ab /app/php
parent60841b3c92dc630d5d6dd03aadac27705bacdc62 (diff)
* base class for controls, auto-registering JS scripts
Diffstat (limited to 'app/php')
-rw-r--r--app/php/components/TemplateControl.php53
-rw-r--r--app/php/controls/CalendarScaffold.php5
-rw-r--r--app/php/controls/HeaderMenu.php4
-rw-r--r--app/php/controls/LoginBox.php4
-rw-r--r--app/php/controls/PasswordChange.php4
-rw-r--r--app/php/controls/RegistrationForm.php4
-rw-r--r--app/php/controls/TimezoneSelect.php4
-rw-r--r--app/php/controls/UpcomingEvents.php4
-rw-r--r--app/php/controls/UserSelection.php4
9 files changed, 78 insertions, 8 deletions
diff --git a/app/php/components/TemplateControl.php b/app/php/components/TemplateControl.php
new file mode 100644
index 0000000..e3c9e26
--- /dev/null
+++ b/app/php/components/TemplateControl.php
@@ -0,0 +1,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 [];
+ }
+
+}
+
+?>
diff --git a/app/php/controls/CalendarScaffold.php b/app/php/controls/CalendarScaffold.php
index 70efcaa..dd8a80e 100644
--- a/app/php/controls/CalendarScaffold.php
+++ b/app/php/controls/CalendarScaffold.php
@@ -1,11 +1,14 @@
<?php
+Prado::using('Application.components.TemplateControl');
+
Prado::using('System.Web.UI.ActiveControls.TActiveDataGrid');
Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
Prado::using('Application.components.SafeActiveFileUpload');
+
Prado::using('Application.facades.CalendarFacade');
-class CalendarScaffold extends TTemplateControl {
+class CalendarScaffold extends TemplateControl {
public function setFacade(Facade $facade) {
$this->setViewState('Facade', $facade);
diff --git a/app/php/controls/HeaderMenu.php b/app/php/controls/HeaderMenu.php
index bffe4d2..f6b69b9 100644
--- a/app/php/controls/HeaderMenu.php
+++ b/app/php/controls/HeaderMenu.php
@@ -1,8 +1,10 @@
<?php
+Prado::using('Application.components.TemplateControl');
+
Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
-class HeaderMenu extends TTemplateControl {
+class HeaderMenu extends TemplateControl {
public function logoutUser($sender, $param) {
$this->Application->getModule('auth')->logout();
diff --git a/app/php/controls/LoginBox.php b/app/php/controls/LoginBox.php
index 33bbcc1..eb448eb 100644
--- a/app/php/controls/LoginBox.php
+++ b/app/php/controls/LoginBox.php
@@ -1,6 +1,8 @@
<?php
-class LoginBox extends TTemplateControl {
+Prado::using('Application.components.TemplateControl');
+
+class LoginBox extends TemplateControl {
public function loginUser($sender, $param) {
if ($this->Page->IsValid) {
diff --git a/app/php/controls/PasswordChange.php b/app/php/controls/PasswordChange.php
index cd901ca..1c05c64 100644
--- a/app/php/controls/PasswordChange.php
+++ b/app/php/controls/PasswordChange.php
@@ -1,8 +1,10 @@
<?php
+Prado::using('Application.components.TemplateControl');
+
Prado::using('Application.user.DbUser');
-class PasswordChange extends TTemplateControl {
+class PasswordChange extends TemplateControl {
public function getUserToChange() {
return $this->getControlState('user');
diff --git a/app/php/controls/RegistrationForm.php b/app/php/controls/RegistrationForm.php
index 71d4df1..2ffe507 100644
--- a/app/php/controls/RegistrationForm.php
+++ b/app/php/controls/RegistrationForm.php
@@ -1,8 +1,10 @@
<?php
+Prado::using('Application.components.TemplateControl');
+
Prado::using('Application.model.User');
-class RegistrationForm extends TTemplateControl {
+class RegistrationForm extends TemplateControl {
public function checkUsername($sender, $param) {
$param->IsValid = !User::finder()->countByLogin($this->Login->SafeText);
diff --git a/app/php/controls/TimezoneSelect.php b/app/php/controls/TimezoneSelect.php
index 592a9e7..5556f4a 100644
--- a/app/php/controls/TimezoneSelect.php
+++ b/app/php/controls/TimezoneSelect.php
@@ -1,9 +1,11 @@
<?php
+Prado::using('Application.components.TemplateControl');
+
Prado::using('Application.user.DbUser');
Prado::using('Application.dto.TimezoneDTO');
-class TimezoneSelect extends TTemplateControl {
+class TimezoneSelect extends TemplateControl {
public function getUserToChange() {
return $this->getControlState('user');
diff --git a/app/php/controls/UpcomingEvents.php b/app/php/controls/UpcomingEvents.php
index 3b0869a..6d0f9d3 100644
--- a/app/php/controls/UpcomingEvents.php
+++ b/app/php/controls/UpcomingEvents.php
@@ -1,8 +1,10 @@
<?php
+Prado::using('Application.components.TemplateControl');
+
Prado::using('Application.facades.EventFacade');
-class UpcomingEvents extends TTemplateControl {
+class UpcomingEvents extends TemplateControl {
public function setFacade(Facade $facade) {
$this->setViewState('Facade', $facade);
diff --git a/app/php/controls/UserSelection.php b/app/php/controls/UserSelection.php
index 3e2def1..6f9bc9e 100644
--- a/app/php/controls/UserSelection.php
+++ b/app/php/controls/UserSelection.php
@@ -1,8 +1,10 @@
<?php
+Prado::using('Application.components.TemplateControl');
+
Prado::using('Application.facades.CalendarFacade');
-class UserSelection extends TTemplateControl {
+class UserSelection extends TemplateControl {
public function setFacade(Facade $facade) {
$this->setViewState('Facade', $facade);