From 71a753d30ee7d84c81717a570e818f075d78831b Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 8 Jun 2008 16:46:20 +0200 Subject: [PATCH] Cleaner display for 'trig'. This add two kinds of triggers: $page->trigError() $page->trigSuccess() The old $page->trig() takes 2 arguments: - the message to display - the kind of message ('errors' or 'success'), default is errors in order to preserve backward compatibility Plan is to remove all ->trig() calls and switch the trig() method to protected access rights. Signed-off-by: Florent Bruneau --- classes/platalpage.php | 28 +++++++++++++++++++++------- htdocs/css/default.css | 14 ++++++++++++++ htdocs/css/keynote.css | 14 ++++++++++++++ htdocs/css/openweb.css | 14 ++++++++++++++ templates/core/plwizard.tpl | 4 +--- templates/payment/index.tpl | 2 +- templates/search/index.tpl | 2 +- templates/skin/common.content.tpl | 4 +--- templates/skin/common.triggers.tpl | 35 +++++++++++++++++++++++++++++++++++ 9 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 templates/skin/common.triggers.tpl diff --git a/classes/platalpage.php b/classes/platalpage.php index 4072a0a..bfb588e 100644 --- a/classes/platalpage.php +++ b/classes/platalpage.php @@ -48,13 +48,13 @@ abstract class PlatalPage extends Smarty $this->compile_check = !empty($globals->debug); $this->changeTpl($tpl, $type); - $this->_errors = array(); + $this->_errors = array('errors' => array()); $this->_jsonVars = array(); $this->_failure = false; if ($globals->mode != 'rw') { - $this->_errors[] = "En raison d'une maintenance, une partie des fonctionnalités du site sont actuellement" - . " désactivée, en particuliers aucune donnée ne sera sauvegardée"; + $this->trig("En raison d'une maintenance, une partie des fonctionnalités du site sont" + . " actuellement désactivée, en particuliers aucune donnée ne sera sauvegardée"); } $this->register_prefilter('at_to_globals'); $this->addJsLink('xorg.js'); @@ -94,7 +94,8 @@ abstract class PlatalPage extends Smarty $this->register_prefilter('form_force_encodings'); $this->register_prefilter('wiki_include'); $this->register_prefilter('if_has_perms'); - $this->assign('xorg_errors', $this->_errors); + $this->assign('xorg_triggers', $this->_errors); + $this->assign('xorg_errors', $this->nb_errs()); $this->assign('xorg_failure', $this->_failure); $this->assign('globals', $globals); @@ -187,15 +188,28 @@ abstract class PlatalPage extends Smarty public function nb_errs() { - return count($this->_errors); + return count($this->_errors['errors']); } // }}} // {{{ function trig() - public function trig($msg) + public function trig($msg, $type = 'errors') { - $this->_errors[] = $msg; + if (!isset($this->_errors[$type])) { + $this->_errors[$type] = array(); + } + $this->_errors[$type][] = $msg; + } + + public function trigError($msg) + { + $this->trig($msg, 'errors'); + } + + public function trigSuccess($msg) + { + $this->trig($msg, 'success'); } // }}} diff --git a/htdocs/css/default.css b/htdocs/css/default.css index 3fa4eae..04e69ce 100644 --- a/htdocs/css/default.css +++ b/htdocs/css/default.css @@ -73,6 +73,20 @@ p { text-align: justify; } +.errors { + margin-top: 10px; + border: 1px solid #f00; + background-color: #fcc; + width: 98%; +} + +.success { + margin-top: 10px; + border: 1px solid #0d2; + background-color: #cfd; + width: 98%; +} + .erreur { font-weight: bold; color: #ff0000; diff --git a/htdocs/css/keynote.css b/htdocs/css/keynote.css index 482df1b..4f4c040 100644 --- a/htdocs/css/keynote.css +++ b/htdocs/css/keynote.css @@ -88,6 +88,20 @@ p.smaller { text-indent: 0; } +.errors { + width: 98%; + border: 1px solid #f00; + margin-top: 10px; + background-color: #200; +} + +.success { + width: 98%; + border: 1px solid #0d3; + margin-top: 10px; + background-color: #021; +} + .erreur { font-weight: bold; color: #d00; diff --git a/htdocs/css/openweb.css b/htdocs/css/openweb.css index 0dc7744..d45611e 100644 --- a/htdocs/css/openweb.css +++ b/htdocs/css/openweb.css @@ -76,6 +76,20 @@ p { text-align: justify; } +.errors { + margin-top: 10px; + border: 1px solid #f00; + background-color: #fcc; + width: 98%; +} + +.success { + margin-top: 10px; + border: 1px solid #0d2; + background-color: #cfd; + width: 98%; +} + .erreur { font-weight: bold; color: #ff0000; diff --git a/templates/core/plwizard.tpl b/templates/core/plwizard.tpl index ace9510..df409dd 100644 --- a/templates/core/plwizard.tpl +++ b/templates/core/plwizard.tpl @@ -90,9 +90,7 @@
- {foreach from=$xorg_errors item=err} -
{$err|smarty:nodefaults}
- {/foreach} + {include file="skin/common.triggers.tpl"} {include file=$wiz_page}
diff --git a/templates/payment/index.tpl b/templates/payment/index.tpl index 834c768..156a1eb 100644 --- a/templates/payment/index.tpl +++ b/templates/payment/index.tpl @@ -23,7 +23,7 @@

Télépaiements

-{if $smarty.request.op eq "submit" and !$xorg_errors|count} +{if $smarty.request.op eq "submit" and !$xorg_errors} diff --git a/templates/search/index.tpl b/templates/search/index.tpl index 93d1855..0f6d2c9 100644 --- a/templates/search/index.tpl +++ b/templates/search/index.tpl @@ -21,7 +21,7 @@ {**************************************************************************} -{if $formulaire eq 0 and !$xorg_errors|count} +{if $formulaire eq 0 and !$xorg_errors} {if !$simple} {if !$advanced} {include file=search/quick.form.tpl show_js=1} diff --git a/templates/skin/common.content.tpl b/templates/skin/common.content.tpl index d9d1907..fdd8ddb 100644 --- a/templates/skin/common.content.tpl +++ b/templates/skin/common.content.tpl @@ -38,9 +38,7 @@ Nous conseillons très vivement d'utiliser des navigateurs récents, tels {/if} {if !$xorg_no_errors || $xorg_failure} -{foreach from=$xorg_errors item=err} -
{$err|smarty:nodefaults}
-{/foreach} +{include file="skin/common.triggers.tpl"} {/if} {if !$xorg_failure && $xorg_tpl}{include file=$xorg_tpl}{/if} diff --git a/templates/skin/common.triggers.tpl b/templates/skin/common.triggers.tpl new file mode 100644 index 0000000..5a310a3 --- /dev/null +++ b/templates/skin/common.triggers.tpl @@ -0,0 +1,35 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2008 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +{foreach from=$xorg_triggers key=type item=triggers} +{if $triggers|@count} +
+
    + {foreach from=$triggers item=err} +
  • {$err|smarty:nodefaults}
  • + {/foreach} +
+
+{/if} +{/foreach} + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4