Add a small tool for ajax wiki preview and use it on email/send and %grp/mail
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 24 Mar 2007 10:39:51 +0000 (10:39 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 24 Mar 2007 10:39:51 +0000 (10:39 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1606 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/miniwiki.php
htdocs/javascript/ajax.js
modules/core.php
modules/xnetgrp.php
templates/core/wiki.help.tpl
templates/emails/send.tpl
templates/xnetgrp/mail.tpl

index 5c0c176..6357d9b 100644 (file)
@@ -155,17 +155,10 @@ class MiniWiki
             unset(MiniWiki::$info[12]);
         }
 
-        $i = 0;
-        $res = '<table class="bicol">' . "\n";
-        $res .= "<tr><th>Syntaxe</th><th>Apparence</th></tr>\n";
+        $res = array();
         foreach (MiniWiki::$info as $value) {
-            $i++;
-            $res .= '<tr class="' . ($i % 2 ? 'impair' : 'pair') . '">';
-            $res .= '<td>' . nl2br(htmlentities($value)) . '</td>';
-            $res .= '<td>' . MiniWiki::wikiToHtml($value, true) . '</td>';
-            $res .= "</tr>\n";
+            $res[$value] = MiniWiki::wikiToHtml($value, true);
         }
-        $res .= '</table>';
 
         if (!$with_title) {
             MiniWiki::$info[12] = $info12;
index 71382a9..bc523d8 100644 (file)
@@ -109,4 +109,20 @@ function showTempMessage(id, message, success)
     setTimeout("_showTempMessage('" + id + "', " + currentTempMessage + ", 20)", 700);
 }
 
+function previewWiki(idFrom, idTo, withTitle, idShow)
+{
+    var text = encodeURIComponent(document.getElementById(idFrom).value);
+    if (text == "") {
+        return false;
+    }   
+    var url  = "wiki_preview";
+    if (!withTitle) {
+        url += "/notitle";
+    }   
+    Ajax.update_html(idTo, url + "?text=" + text);
+    if (idShow != null) {
+        document.getElementById(idShow).style.display = "";
+    }   
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index 9043210..ed58bac 100644 (file)
@@ -30,7 +30,9 @@ class CoreModule extends PLModule
             'send_bug'    => $this->make_hook('bug', AUTH_COOKIE),
             'purge_cache' => $this->make_hook('purge_cache', AUTH_COOKIE, 'admin'),
             'get_rights'  => $this->make_hook('get_rights', AUTH_MDP, 'admin'),
-            'wiki_help'   => $this->make_hook('wiki_help', AUTH_PUBLIC),
+
+            'wiki_help'    => $this->make_hook('wiki_help', AUTH_PUBLIC),
+            'wiki_preview' => $this->make_hook('wiki_preview', AUTH_COOKIE, 'user', NO_AUTH),
 
             'valid.html'  => $this->make_hook('valid', AUTH_PUBLIC),
             'favicon.ico' => $this->make_hook('favicon', AUTH_PUBLIC),
@@ -135,6 +137,15 @@ class CoreModule extends PLModule
         $page->changeTpl('core/wiki.help.tpl', SIMPLE);
         $page->assign('wiki_help', MiniWiki::help($action == 'title'));
     }
+
+    /// Shared handler for wiki syntax result preview
+    function handler_wiki_preview(&$page, $action = 'title')
+    {
+        header('Content-Type: text/html; charset=utf-8');
+        $text = Get::v('text');
+        echo MiniWiki::wikiToHtml($text, $action == 'title');
+        exit;
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index ba86720..4115206 100644 (file)
@@ -290,6 +290,7 @@ class XnetGrpModule extends PLModule
         $mmlist = new MMList(S::v('uid'), S::v('password'),
                            $globals->asso('mail_domain'));
         $page->assign('listes', $mmlist->get_lists());
+        $page->addJsLink('ajax.js');
 
         if (Post::has('send')) {
             $from  = Post::v('from');
index bfb591e..fa417cb 100644 (file)
 
 <h1>Syntaxe wiki</h1>
 
-{$wiki_help|smarty:nodefaults}
+<table class="bicol">
+  <tr><th>Syntaxe</th><th>Apparence</th></tr>
+  {foreach from=$wiki_help key=syntax item=html}
+  <tr class="{cycle values="pair,impair"}">
+    <td>{$syntax|nl2br}</td>
+    <td>{$html|smarty:nodefaults}</td>
+  </tr>
+  {/foreach}
+</table>
 
 {* vim:set et sws=2 sts=2 sw=2 enc=utf-8: *}
index bb8e90e..0c0d1c7 100644 (file)
   function removeCc() {
     _move('cc_contacts', 'contacts');
   }
+
+  function updateWikiView(box) {
+    if (box.checked) {
+      document.getElementById("preview_bt").style.display = "none";
+      document.getElementById("preview").style.display = "none";
+    } else {
+      document.getElementById("preview_bt").style.display = "";
+    }
+  }
   {/literal}
 //]]>
 </script>
     </tr>
     {/if}
   </table>
-
   <fieldset>
     <legend>Sujet&nbsp;:&nbsp;<input type='text' name='sujet' size='60' value="{$smarty.request.sujet}" /></legend>
     <div class="center">
       Tu peux utiliser des <a href="wiki_help" class="popup3">{icon name=information title="Syntaxe wiki"} marqueurs wiki</a> pour formatter ton texte.<br />
-      <small><input type="checkbox" name="nowiki" value="1" {if $smarty.request.nowiki}checked="checked"{/if} />
+      <small><input type="checkbox" name="nowiki" value="1" {if $smarty.request.nowiki}checked="checked"{/if} onchange="updateWikiView(this);" />
       coche cette case pour envoyer le mail en texte brut, sans formattage</small>
     </div>
-    <textarea name='contenu' rows="30" cols="75">
+    <div id="preview" style="display: none">
+      <strong>Aperçu du mail :</strong>
+      <div id="mail_preview">
+      </div>
+      <div class="center">
+        <input type="submit" name="submit" value="Envoyer" />
+      </div>
+    </div>
+    <textarea name='contenu' rows="30" cols="75" id="mail_text">
 {$smarty.request.contenu}
 {if !$smarty.request.contenu}
 -- 
       <input type="file" name="uploaded" />
     </div>
     <div class="center">
+      <input type="submit" name="preview" id="preview_bt" value="Aperçu" onclick="previewWiki('mail_text', 'mail_preview', true, 'preview'); return false;" />
       <input type="submit" name="submit" value="Envoyer" />
     </div>
   </fieldset>
index 6f36260..911201b 100644 (file)
@@ -28,6 +28,19 @@ Ton message peut être personnalisé : si tu rentres les mots &lt;cher&gt;, &lt;
 &lt;nom&gt;, ces mots seront remplacés, pour chacun des destinataires, par "cher" accordé au
 masculin ou féminin, par son prénom, ou son nom.
 </p>
+
+<script type="text/javascript">//<![CDATA[
+  {literal}
+  function updateWikiView(box) {
+    if (!box.checked) {
+      document.getElementById("preview_bt").style.display = "none";
+      document.getElementById("preview").style.display = "none";
+    } else {
+      document.getElementById("preview_bt").style.display = "";
+    }
+  }
+  {/literal}
+//]]></script>
  
 <form action="{$platal->ns}mail" method="post" enctype="multipart/form-data">
   <table class='bicol'>
@@ -90,18 +103,24 @@ masculin ou féminin, par son prénom, ou son nom.
     </tr>
     <tr>
       <td colspan="2" class="smaller">
-        <input type="checkbox" name="wiki" value="1" checked="1" />
+        <input type="checkbox" name="wiki" value="1" checked="1" onchange="updateWikiView(this);" />
         activer <a href="wiki_help" class="popup3">la syntaxe wiki</a> pour le formattage du message
       </td>
     </tr>
+    <tr id="preview" class="pair" style="display: none">
+      <td colspan="2" id="mail_preview">
+        <div id="mail_preview"></div>
+        <div class="center"><input type="submit" name="send" value="Envoyer le message"></div>
+      </td>
+    </tr>
     <tr>
       <td colspan="2" class="center">
-        <textarea name="body" cols="72" rows="25">
+        <textarea name="body" id="mail_text" cols="72" rows="25">
 {if $smarty.request.body}
 {$smarty.request.body}
 {else}
 &lt;cher&gt; &lt;prenom&gt;,
-          
+
 Nous avons le plaisir de t'adresser la lettre mensuelle du groupe {$asso.nom}.
 
 (insérer le texte...)
@@ -120,7 +139,10 @@ Le bureau du groupe {$asso.nom}.
       </td>
     </tr>
     <tr>
-      <td colspan="2" align="center"><input type="submit" name="send" value="Envoyer le message"></td>
+      <td colspan="2" align="center">
+        <input type="submit" name="preview" id="preview_bt" value="Aperçu" onclick="previewWiki('mail_text', 'mail_preview', true, 'preview'); return false;" />
+        <input type="submit" name="send" value="Envoyer le message" />
+      </td>
     </tr>
   </table>
 </form>