Updates the look & design of the reminder oneboxes.
authorVincent Zanotti <vincent.zanotti@m4x.org>
Mon, 1 Jun 2009 22:54:48 +0000 (00:54 +0200)
committerVincent Zanotti <vincent.zanotti@m4x.org>
Thu, 4 Jun 2009 12:48:55 +0000 (14:48 +0200)
Signed-off-by: Vincent Zanotti <vincent.zanotti@m4x.org>
18 files changed:
include/reminder.inc.php
include/reminder/ax_letter.inc.php
include/reminder/email_backup.inc.php
include/reminder/email_warning.inc.php
include/reminder/gapps.inc.php
include/reminder/ml.inc.php
include/reminder/nl.inc.php
include/reminder/no_redirection.inc.php
include/reminder/profile_update.inc.php
include/reminder/promotion_ml.inc.php
modules/events.php
modules/reminder.php
templates/events/index.tpl
templates/reminder/base.tpl
templates/reminder/email_warning.tpl
templates/reminder/ml.tpl
templates/reminder/no_redirection.tpl
templates/reminder/profile_update.tpl

index 5143842..a28d839 100644 (file)
@@ -101,31 +101,37 @@ abstract class Reminder
     // method below).
     abstract public function HandleAction($action);
 
-    // Returns the content of the onebox reminder. Default implementation displays
-    // a text and three links (yes, no, dismiss); it uses the text from method
-    // GetDisplayText.
-    public function Display(&$page)
+    // Displays the reminder as a standalone html snippet. It should be used
+    // when the reminder is the only output of a page.
+    public function DisplayStandalone(&$page)
     {
         header('Content-Type: text/html; charset=utf-8');
-        $page->changeTpl('reminder/default.tpl', NO_SKIN);
-        $page->assign('text', $this->GetDisplayText());
-        $page->assign('baseurl', $this->GetBaseUrl());
+        $page->changeTpl('reminder/base.tpl', NO_SKIN);
+        $this->Prepare($page);
     }
 
-    // Helper for returning the content as a string, instead of using the existing
-    // globale XorgPage instance.
-    public function GetDisplayAsString()
+    // Prepares the display by assigning template variables.
+    public function Prepare(&$page)
     {
-        $page = new XorgPage();
-        $this->Display($page);
-        return $page->raw();
+        $page->assign_by_ref('reminder', $this);
     }
 
-    // Returns the text to display in the onebox.
-    abstract protected function GetDisplayText();
+    // Returns the name of the inner template, or null if a simple text obtained
+    // from GetText should be printed.
+    public function template() { return null; }
+
+    // Returns the text to display in the onebox, or null if a
+    public function text() { return ''; }
+
+    // Returns the title of the onebox.
+    public function title() { return ''; }
+
+    // Should return true if this onebox needs to be considered as a warning and
+    // not just as a subscription offer.
+    public function warning() { return false; }
 
     // Returns the base url for the reminder module.
-    protected function GetBaseUrl()
+    public function baseurl()
     {
         return 'ajax/reminder/' . $this->name;
     }
@@ -195,7 +201,7 @@ abstract class Reminder
     // the class.
     private static function GetClassName($name)
     {
-        @include_once "reminder/$name.inc.php";
+        include_once "reminder/$name.inc.php";
         $class = 'Reminder' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name)));
         return (class_exists($class) ? $class : null);
     }
index 3e0cdf2..b0b112e 100644 (file)
@@ -38,11 +38,15 @@ class ReminderAxLetter extends Reminder
         }
     }
 
-    protected function GetDisplayText()
+    public function text()
     {
         return "La lettre de l'AX te permet de recevoir régulièrement les
             informations importantes de l'AX.";
     }
+    public function title()
+    {
+        return "Inscription à la lettre de l'AX";
+    }
 
     public static function IsCandidate(User &$user, $candidate)
     {
index dca3b0e..cdf266e 100644 (file)
@@ -25,8 +25,7 @@ class ReminderEmailBackup extends Reminder
     {
         if ($action == 'yes') {
             require_once 'emails.inc.php';
-            $user = S::user();
-            $storage = new EmailStorage($user, 'imap');
+            $storage = new EmailStorage($this->user, 'imap');
             $storage->activate();
 
             $this->UpdateOnYes();
@@ -41,12 +40,16 @@ class ReminderEmailBackup extends Reminder
         }
     }
 
-    protected function GetDisplayText()
+    public function text()
     {
         return "Tu peux bénéficier d'une sauvegarde des emails. Cela permet
             d'avoir un accès de secours aux 30 derniers jours d'emails reçus
             sur ton adresse Polytechnique.org.";
     }
+    public function title()
+    {
+        return 'Sauvegarde de tes emails';
+    }
 
     public static function IsCandidate(User &$user, $candidate)
     {
index f20cdb5..1b8f901 100644 (file)
@@ -28,13 +28,17 @@ class ReminderEmailWarning extends Reminder
         }
     }
 
-    protected function GetDisplayText() {}
-
-    public function Display(&$page)
+    public function template()
+    {
+        return 'reminder/email_warning.tpl';
+    }
+    public function title()
+    {
+        return "Problème avec ta redirections d'emails";
+    }
+    public function warning()
     {
-        header('Content-Type: text/html; charset=utf-8');
-        $page->changeTpl('reminder/email_warning.tpl', NO_SKIN);
-        $page->assign('baseurl', $this->GetBaseUrl());
+        return true;
     }
 
     public static function IsCandidate(User &$user, $candidate)
index aa4921d..8df4c46 100644 (file)
@@ -39,13 +39,17 @@ class ReminderGapps extends Reminder
         }
     }
 
-    protected function GetDisplayText()
+    public function text()
     {
         return "Polytechnique.org te fournit un compte Google Apps qui te permet
             de disposer des applications web de Google (GMail, Google Calendar,
             Google Docs, et bien d'autres) sur ton adresse Polytechnique.org
             habituelle (en savoir plus).";
     }
+    public function title()
+    {
+        return "Création d'un compte Google Apps";
+    }
 
     public static function IsCandidate(User &$user, $candidate)
     {
index 7e4b297..9732bb2 100644 (file)
@@ -59,13 +59,9 @@ class ReminderMl extends Reminder
         }
     }
 
-    protected function GetDisplayText() {}
-
-    public function Display(&$page)
+    public function Prepare(&$page)
     {
-        header('Content-Type: text/html; charset=utf-8');
-        $page->changeTpl('reminder/ml.tpl', NO_SKIN);
-        $page->assign('baseurl', $this->GetBaseUrl());
+        parent::Prepare($page);
 
         $res = XDB::iterRow("SELECT  sub, domain
                                FROM  register_subs
@@ -85,12 +81,21 @@ class ReminderMl extends Reminder
         $page->assign_by_ref('lists', $lists);
     }
 
+    public function template()
+    {
+        return 'reminder/ml.tpl';
+    }
+    public function title()
+    {
+        return "Inscription aux listes de diffusion";
+    }
+
     public static function IsCandidate(User &$user, $candidate)
     {
-        $res = XDB::execute("SELECT  COUNT(*) AS lists
-                               FROM  register_subs
-                              WHERE  uid = {?} AND type = 'list'",
-                            $user->id());
+        $res = XDB::query("SELECT  COUNT(*) AS lists
+                             FROM  register_subs
+                            WHERE  uid = {?} AND type = 'list'",
+                          $user->id());
 
         $mlCount = $res->fetchOneCell();
         if (!$mlCount) {
index f5d38c8..ba924c4 100644 (file)
@@ -38,12 +38,16 @@ class ReminderNl extends Reminder
         }
     }
 
-    protected function GetDisplayText()
+    public function text()
     {
         return "La lettre mensuelle de Polytechnique.org te permet de recevoir
             chaque mois des informations sur les activités et nouvelles de la
             communauté des X.";
     }
+    public function title()
+    {
+        return "Inscription à la lettre mensuelle";
+    }
 
     public static function IsCandidate(User &$user, $candidate)
     {
index 9555959..706bfb2 100644 (file)
@@ -28,13 +28,17 @@ class ReminderNoRedirection extends Reminder
         }
     }
 
-    protected function GetDisplayText() {}
-
-    public function Display(&$page)
+    public function template()
+    {
+        return 'reminder/no_redirection.tpl';
+    }
+    public function title()
+    {
+        return "Problème avec ta redirection d'emails";
+    }
+    public function warning()
     {
-        header('Content-Type: text/html; charset=utf-8');
-        $page->changeTpl('reminder/no_redirection.tpl', NO_SKIN);
-        $page->assign('baseurl', $this->GetBaseUrl());
+        return true;
     }
 
     public static function IsCandidate(User &$user, $candidate)
index 5327b6c..c07e741 100644 (file)
@@ -45,37 +45,45 @@ class ReminderProfileUpdate extends Reminder
         }
     }
 
-    protected function GetDisplayText() {}
-
-    public function Display(&$page)
+    public function Prepare(&$page)
     {
-        header('Content-Type: text/html; charset=utf-8');
-        $page->changeTpl('reminder/profile_update.tpl', NO_SKIN);
-        $page->assign('baseurl', $this->GetBaseUrl());
-        $user = S::user();
+        parent::Prepare($page);
 
         $res = XDB::query('SELECT  date < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_profile_old,
-                                   date AS profile_date, p.attach AS photo
+                                   date AS profile_date, LENGTH(p.attach) > 0 AS photo
                              FROM  auth_user_md5 AS u
                         LEFT JOIN  photo         AS p ON (u.user_id = p.uid)
                             WHERE  user_id = {?}',
-                          $user->id());
+                          $this->user->id());
         list($is_profile_old, $profile_date, $has_photo) = $res->fetchOneRow();
 
-        $profile_date = $is_profile_old ? $profile_date : null;
-        $page->assign('profile_update', $profile_date);
-        $page->assign('needs_photo', $has_photo);
+        $page->assign('profile_incitation', $is_profile_old);
+        $page->assign('profile_last_update', $profile_date);
+        $page->assign('photo_incitation', $has_photo);
 
         require_once 'geoloc.inc.php';
-        $res = localize_addresses($user->id());
+        $res = localize_addresses($this->user->id());
         $page->assign('geocoding_incitation', count($res));
 
         $page->assign('incitations_count',
                       ($is_profile_old ? 1 : 0) +
-                      ($has_photo ? 1 : 0) +
+                      ($has_photo ? 0 : 1) +
                       (count($res) > 0 ? 1 : 0));
     }
 
+    public function template()
+    {
+        return 'reminder/profile_update.tpl';
+    }
+    public function title()
+    {
+        return "Mise à jour de ton profil";
+    }
+    public function warning()
+    {
+        return true;
+    }
+
     public static function IsCandidate(User &$user, $candidate)
     {
         $res = XDB::query('SELECT  date < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_profile_old,
index aee6747..4cac8e7 100644 (file)
@@ -49,13 +49,17 @@ class ReminderPromotionMl extends Reminder
         }
     }
 
-    protected function GetDisplayText()
+    public function text()
     {
         return "La liste de diffusion de ta promotion permet de recevoir les
             informations plus spécifiques de ta promotion pour pouvoir
             participer plus facilement aux événements qu'elle organise. Tu
             seras aussi inscrit dans le groupe de la promotion " .
-            S::user()->promo() . '.';
+            $this->user->promo() . '.';
+    }
+    public function title()
+    {
+        return "Inscription à la liste de diffusion de ta promotion";
     }
 
     public static function IsCandidate(User &$user, $candidate)
@@ -73,7 +77,7 @@ class ReminderPromotionMl extends Reminder
         if ($mlCount) {
             Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
         }
-        return ($mlCount > 0);
+        return ($mlCount == 0);
     }
 }
 
index 44e75b3..5ee7b81 100644 (file)
@@ -106,10 +106,11 @@ class EventsModule extends PLModule
         $page->addJsLink('ajax.js');
         $page->assign('tips', $this->get_tips());
 
-        require_once 'reminder.inc.php';
+        // Adds a reminder onebox to the page.
         $user = S::user();
-        if (($new_reminder = Reminder::GetCandidateReminder($user))) {
-            $page->assign('reminder', $new_reminder->GetDisplayAsString());
+        require_once 'reminder.inc.php';
+        if (($reminder = Reminder::GetCandidateReminder($user))) {
+            $reminder->Prepare($page);
         }
 
         // Wishes "Happy birthday" when required
index d150f58..d35ef0c 100644 (file)
@@ -44,8 +44,8 @@ class ReminderModule extends PLModule
         // displayed.
         $reminder->HandleAction($action);
 
-        if ($new_reminder = Reminder::GetCandidateReminder($user)) {
-            $new_reminder->Display($page);
+        if (($new_reminder = Reminder::GetCandidateReminder($user))) {
+            $new_reminder->DisplayStandalone($page);
         } else {
             exit;
         }
index 97418f8..2ee8a68 100644 (file)
@@ -42,10 +42,10 @@ Bienvenue {$smarty.session.prenom}{if $birthday}
 {/if}
 
 {if $reminder}
-{$reminder|smarty:nodefaults}
-{/if}
-
+{include file="reminder/base.tpl"}
+{else}
 {include file="include/tips.tpl" full=true}
+{/if}
 
   <table class="tinybicol" id="menu-evts">
     {foreach from=$events name=events key=category item=evenement}
index 7250525..404a306 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-<fieldset id="reminder" class="warnings">
-  <legend>{icon name=information} Information : Titre !
-    <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/dismiss')">
-      {icon name=cross title="Cacher cette information."}
-    </a>
-  </legend>
+<div id="reminder">
+  <fieldset class="warnings">
+    <legend>
+      {if $reminder->warning()}{icon name=error}{else}{icon name=information}{/if}
+      &nbsp;{$reminder->title()}
+    </legend>
 
-  {$text}
-  <div class="center">
-    <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/yes'); return false" style="text-decoration: none">
-      {icon name=add} M'inscrire
-    </a> - 
-    <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/no'); return false" style="text-decoration: none">
-      {icon name=delete} Ne pas m'inscrire
-    </a>
-  </div>
-</fieldset>
+    {if $reminder->template()}
+      {include file=$reminder->template()}
+    {else}
+      <div style="margin-bottom: 0.5em">
+        {$reminder->text()}
+      </div>
+      <div class="center">
+        <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/yes'); return false" style="text-decoration: none">
+          {icon name=add} M'inscrire
+        </a> -
+        <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/no'); return false" style="text-decoration: none">
+          {icon name=delete} Ne pas m'inscrire
+        </a> -
+        <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/dismiss'); return false" style="text-decoration: none">
+          {icon name=cross} Décider plus tard
+        </a>
+      </div>
+    {/if}
+  </fieldset>
+</div>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 28aa0d1..cd04b2a 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-<div class="warnings reminder">
-  <span style="float: right">
-    <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/dismiss')">
-      {icon name=cross title="Cacher cet avertissement."}
-    </a>
-  </span>
-  {icon name=error} Des problèmes sont actuellement recontrés sur tes redirections suivantes&nbsp;:
-  <ul>
-    {foreach from=$smarty.session.mx_failures item=mail}
-    <li>
-      <span class="erreur">{$mail.mail}</span> :
-      <span class="explication">{$mail.text}</span>
-    </li>
-    {/foreach}
-  </ul>
-  <div style="text-align: center"><a href="emails/redirect">Gérer mes adresses de redirection</a></div>
-</div>
+Des problèmes sont actuellement recontrés sur tes redirections suivantes&nbsp;:
+<ul>
+  {foreach from=$smarty.session.mx_failures item=mail}
+  <li>
+    <span class="erreur">{$mail.mail}</span> :
+    <span class="explication">{$mail.text}</span>
+  </li>
+  {/foreach}
+</ul>
+<div style="text-align: center"><a href="emails/redirect">Gérer mes adresses de redirection</a></div>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index a431fe7..8a26ada 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-<div class="warnings reminder">
-  <span style="float: right">
-    <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/dismiss')">
-      {icon name=cross title="Cacher cet avertissement."}
+<form action="{$reminder->baseurl()}/suscribe" method="post">
+  {xsrf_token_field}
+  Des camarades souhaitent que tu t'inscrives aux listes suivantes&nbsp;:
+  <dl>
+    {foreach from=$lists key=list item=details}
+    <dt>
+      <label>
+        <input type='checkbox' value='1' checked="checked" name="sub_ml[{$list}]" />
+        {$list}*&nbsp;: {$details.desc}
+      </label>
+    </dt>
+    {if $details.info}
+    <dd>
+      {$details.info|nl2br}
+    </dd>
+    {/if}
+    {/foreach}
+  </dl>
+
+  <div class="center">
+    <input type="submit" value="M'inscrire aux listes" /> -
+    <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/no'); return false" style="text-decoration: none">
+      {icon name=delete} Ne pas m'inscrire
+    </a> -
+    <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/dismiss'); return false" style="text-decoration: none">
+      {icon name=cross} Décider plus tard
     </a>
-  </span>
-  <form action="{$baseurl}/suscribe" method="post">
-    {xsrf_token_field}
-    Des camarades souhaitent que tu t'inscrives aux listes suivantes&nbsp;:
-    <dl>
-      {foreach from=$lists key=list item=details}
-      <dt>
-        <label>
-          <input type='checkbox' value='1' checked="checked" name="sub_ml[{$list}]" />
-          {$list}*&nbsp;: {$details.desc}
-        </label>
-      </dt>
-      {if $details.info}
-      <dd>
-        {$details.info|nl2br}
-      </dd>
-      {/if}
-      {/foreach}
-    </dl>
-    <input type="submit" value="M'inscrire aux listes choisies." />
-  </form>
-  [<a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/no')">
-    {icon name=delete} Ne pas m'inscrire à ces listes de diffusion.
-  </a>]
-</div>
+  </div>
+</form>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index b27e0fa..a07f2ea 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-<div class="warnings reminder">
-  <span style="float: right">
-    <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/dismiss')">
-      {icon name=cross title="Cacher cet avertissement."}
-    </a>
-  </span>
-  {icon name=error} Tu n'as plus de redirection valide ce qui rend ton adresse Polytechnique.org
-  inutilisable. Rends-toi au plus vite sur <a href="emails/redirect">la page de
-  gestion des emails</a> pour corriger ce problème.
-</div>
+Tu n'as plus de redirection valide ce qui rend ton adresse Polytechnique.org
+inutilisable. Rends-toi au plus vite sur <a href="emails/redirect">la page de
+gestion des emails</a> pour corriger ce problème.
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 3cbb91e..065d949 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-<div class="warnings reminder">
-  <span style="float: right">
-    <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/dismiss')">
-      {icon name=cross title="Cacher cet avertissement."}
-    </a>
-  </span>
-  <ul>
-  {if $profile_date}
-    <li>
-      La dernière mise à jour de ta <a href="profile/{$smarty.session.hruid}" class="popup2">fiche</a>
-      date du {$fiche_incitation|date_format}. Il est possible qu'elle ne soit pas à jour.
-      Si tu souhaites la modifier,
-      {if $incitations_count > 1}
-      <a href="profile/edit">
-      {else}
-      <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/profile')">
-      {/if}
-      clique ici !</a>
-    </li>
-  {/if}
-  {if $photo_incitation}
-    <li>
-      Tu n'as pas mis de photo de toi sur ta fiche, c'est dommage. Clique
-      {if $incitations_count > 1}
-      <a href="photo/change">
-      {else}
-      <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/photo')">
-      {/if}
-      ici</a> si tu souhaites en ajouter une.
-    </li>
-  {/if}
-  {if $geoloc_incitation > 0}
-    <li>
-      Parmi tes adresses, il y en a {$geoloc_incitation} que nous n'avons pas pu localiser. Clique
-      {if $incitations_count > 1}
-      <a href="profile/edit/adresses">
-      {else}
-      <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/geoloc')">
-      {/if}
-      ici</a> pour rectifier.
-    </li>
-  {/if}
-  </ul>
+{if $profile_incitation}
+  La dernière mise à jour de ta <a href="profile/{$smarty.session.hruid}" class="popup2">fiche</a>
+  date du {$profile_last_update|date_format}. Il est possible qu'elle ne soit pas à jour.
+  Si tu souhaites la modifier,
+  <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/profile'); return false" style="text-decoration: none">
+  clique ici !</a>
+{elseif $photo_incitation}
+  Tu n'as pas mis de photo de toi sur ta fiche, c'est dommage. Clique
+  <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/photo'); return false" style="text-decoration: none">
+  ici</a> si tu souhaites en ajouter une.
+{elseif $geocoding_incitation > 0}
+  Parmi tes adresses, il y en a {$geocoding_incitation} que nous n'avons pas pu localiser. Clique
+  <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/geoloc'); return false" style="text-decoration: none">
+  ici</a> pour rectifier.
+{/if}
+
+<div class="right">
+  <a href="" onclick="Ajax.update_html('reminder', '{$reminder->baseurl()}/dismiss'); return false" style="text-decoration: none">
+    {icon name=cross} Mettre à jour plus tard
+  </a>
 </div>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}