From d6940ce6e0ae4424d32efd66edc743d337dc3cf8 Mon Sep 17 00:00:00 2001 From: arno Date: Wed, 25 Aug 2010 22:11:34 +0200 Subject: [PATCH] list of javascript files set in config --- application/configs/medias.ini | 12 ++++++++++ application/controllers/AccountController.php | 4 +--- application/controllers/ContactController.php | 4 +--- application/controllers/IdxController.php | 10 ++------ application/controllers/ListController.php | 5 +--- application/controllers/LoginController.php | 4 +--- application/controllers/NewpwdController.php | 4 +--- application/controllers/helpers/SyjMedias.php | 24 +++++++++++++++++++ 8 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 application/configs/medias.ini create mode 100644 application/controllers/helpers/SyjMedias.php diff --git a/application/configs/medias.ini b/application/configs/medias.ini new file mode 100644 index 0000000..22a984a --- /dev/null +++ b/application/configs/medias.ini @@ -0,0 +1,12 @@ +; This file is part of Syj, Copyright (c) 2010 Arnaud Renevier, +; and is published under the AGPL license. */ +[production] +scripts.idx = OpenLayers, ModifiablePath, prototype, simplebox, utils, syj +scripts.rawidx = OpenLayers, syjraw +scripts.login = prototype, utils, login +scripts.contact = prototype, utils, contact +scripts.newpwd = prototype, utils, newpwd +scripts.list = OpenLayers, prototype, utils, list +scripts.account = prototype, utils, account + +[development:production] diff --git a/application/controllers/AccountController.php b/application/controllers/AccountController.php index c9c986e..5f20cc7 100644 --- a/application/controllers/AccountController.php +++ b/application/controllers/AccountController.php @@ -7,10 +7,8 @@ class AccountController extends Zend_Controller_Action public function init() { $this->_helper->SyjSession->needsLogin(); + $this->_helper->SyjMedias->addScripts('account'); - $this->view->headScript()->appendFile('js/prototype.js'); - $this->view->headScript()->appendFile('js/utils.js'); - $this->view->headScript()->appendFile('js/account.js'); $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); $this->view->headLink()->appendStylesheet('css/account.css', 'all'); $this->view->headTitle($this->view->translate("my account")); diff --git a/application/controllers/ContactController.php b/application/controllers/ContactController.php index 3e82c7d..9520a67 100644 --- a/application/controllers/ContactController.php +++ b/application/controllers/ContactController.php @@ -6,9 +6,7 @@ class ContactController extends Zend_Controller_Action { public function init() { - $this->view->headScript()->appendFile('js/prototype.js'); - $this->view->headScript()->appendFile('js/utils.js'); - $this->view->headScript()->appendFile('js/contact.js'); + $this->_helper->SyjMedias->addScripts('contact'); $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); $this->view->headLink()->appendStylesheet('css/contact.css', 'all'); $this->view->headTitle($this->view->translate("contact form")); diff --git a/application/controllers/IdxController.php b/application/controllers/IdxController.php index 4f5fedd..77153c1 100644 --- a/application/controllers/IdxController.php +++ b/application/controllers/IdxController.php @@ -6,12 +6,7 @@ class IdxController extends Zend_Controller_Action { public function init() { - $this->view->headScript()->appendFile('js/OpenLayers.js'); - $this->view->headScript()->appendFile('js/ModifiablePath.js'); - $this->view->headScript()->appendFile('js/prototype.js'); - $this->view->headScript()->appendFile('js/simplebox.js'); - $this->view->headScript()->appendFile('js/utils.js'); - $this->view->headScript()->appendFile('js/syj.js'); + $this->_helper->SyjMedias->addScripts('idx'); $this->view->headLink()->appendStylesheet('css/openlayers/style.css', "all"); $this->view->headLink()->appendStylesheet('css/generic.css', "all"); $this->view->headLink()->appendStylesheet('css/syj.css', "all"); @@ -19,11 +14,10 @@ class IdxController extends Zend_Controller_Action public function rawmode(Syj_Model_Path $path) { $this->_helper->SyjReset->resetPlaceHolders(); + $this->_helper->SyjMedias->addScripts('syjraw'); $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); $this->view->headLink()->appendStylesheet('css/syjraw.css', 'all'); - $this->view->headScript()->appendFile('js/OpenLayers.js'); - $this->view->headScript()->appendFile('js/syjraw.js'); $this->view->headTitle($path->displayTitle); $this->_jsRawLocaleStrings(); diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index c02f19c..cda08aa 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -8,10 +8,7 @@ class ListController extends Zend_Controller_Action public function init() { $this->_helper->SyjSession->needsLogin(); - $this->view->headScript()->appendFile('js/OpenLayers.js'); - $this->view->headScript()->appendFile('js/prototype.js'); - $this->view->headScript()->appendFile('js/utils.js'); - $this->view->headScript()->appendFile('js/list.js'); + $this->_helper->SyjMedias->addScripts('list'); $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); $this->view->headLink()->appendStylesheet('css/list.css', 'all'); diff --git a/application/controllers/LoginController.php b/application/controllers/LoginController.php index a6c7b46..cb9543d 100644 --- a/application/controllers/LoginController.php +++ b/application/controllers/LoginController.php @@ -6,9 +6,7 @@ class LoginController extends Zend_Controller_Action { public function init() { $this->view->headTitle($this->view->translate("login")); - $this->view->headScript()->appendFile('js/prototype.js'); - $this->view->headScript()->appendFile('js/utils.js'); - $this->view->headScript()->appendFile('js/login.js'); + $this->_helper->SyjMedias->addScripts('login'); $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); $this->view->headLink()->appendStylesheet('css/login.css', 'all'); } diff --git a/application/controllers/NewpwdController.php b/application/controllers/NewpwdController.php index de8ec3b..dc9ff5d 100644 --- a/application/controllers/NewpwdController.php +++ b/application/controllers/NewpwdController.php @@ -6,9 +6,7 @@ class NewpwdController extends Zend_Controller_Action { public function init() { - $this->view->headScript()->appendFile('js/prototype.js'); - $this->view->headScript()->appendFile('js/newpwd.js'); - $this->view->headScript()->appendFile('js/utils.js'); + $this->_helper->SyjMedias->addScripts('newpwd'); $this->view->headLink()->appendStylesheet('css/generic.css', 'all'); $this->view->headLink()->appendStylesheet('css/newpwd.css', 'all'); } diff --git a/application/controllers/helpers/SyjMedias.php b/application/controllers/helpers/SyjMedias.php new file mode 100644 index 0000000..a7e15a3 --- /dev/null +++ b/application/controllers/helpers/SyjMedias.php @@ -0,0 +1,24 @@ +_config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/medias.ini', APPLICATION_ENV); + } + + public function addScripts($action) { + $view = $this->getActionController()->view; + if (APPLICATION_ENV == "production") { + $view->headScript()->appendFile('js/' . $action . '.js'); + return; + } + $scripts = explode(',', $this->_config->get('scripts')->get($action)); + foreach ($scripts as $name) { + $view->headScript()->appendFile('js/' . trim($name) . '.js'); + } + } +} -- 2.39.2