Implement stationery in dimp.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 1 Oct 2010 23:06:42 +0000 (17:06 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sat, 2 Oct 2010 05:24:38 +0000 (23:24 -0600)
imp/docs/CHANGES
imp/js/compose-dimp.js
imp/lib/Ajax/Application.php
imp/lib/Views/Compose.php
imp/templates/dimp/compose/compose.html
imp/templates/dimp/javascript_defs_dimp.php

index 21dd313..8ba91b7 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Implement stationery support in DIMP.
 [mms] Add preference to control displayed content for multipart/alternative
       parts (Request #6711).
 [mms] Allow multiple messages to be forwarded in a single outgoing message
index 315540e..67a5996 100644 (file)
@@ -142,6 +142,22 @@ var DimpCompose = {
                 : l.l;
         }
 
+        /* Stationery switch. */
+        if (id == 's') {
+            DimpCore.doAction('stationery', {
+                html: Number(IMP_Compose_Base.editor_on),
+                id: s,
+                identity: $F('identity'),
+                text: (IMP_Compose_Base.editor_on ? this.rte.getData() : $F('composeMessage'))
+            }, {
+                ajaxopts: { asynchronous: false },
+                callback: function(r) {
+                    this.setBodyText(r.response.text);
+                }.bind(this)
+            });
+            return;
+        }
+
         $(k.opts.input).setValue(s);
         $(k.opts.label).writeAttribute('title', l.escapeHTML()).setText(l.truncate(15)).up(1).show();
 
@@ -1042,6 +1058,15 @@ var DimpCompose = {
             this.setPopdownLabel('e', $F('encrypt'));
         }
 
+        /* Create stationery list. */
+        if (DIMP.conf_compose.stationery) {
+            this.createPopdown('s', {
+                base: $('stationery_label').up(),
+                data: DIMP.conf_compose.stationery,
+                label: 'stationery_label'
+            });
+        }
+
         // Automatically resize compose address fields.
         new TextareaResize('to');
         new TextareaResize('cc');
index 8b90fbc..f0e0c2b 100644 (file)
@@ -1229,6 +1229,41 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
     }
 
     /**
+     * AJAX action: Load stationery.
+     *
+     * Variables used:
+     * <pre>
+     * 'html' - (integer) In HTML compose mode?
+     * 'id' - (integer) The stationery entry to use.
+     * 'identity' - (integer) The current identity.
+     * 'text' - (string) The message body text.
+     * </pre>
+     *
+     * @return object  An object with the following entries:
+     * <pre>
+     * 'text' - (string) The new message text.
+     * </pre>
+     */
+    public function stationery()
+    {
+        global $injector, $notification, $prefs;
+
+        $identity = $injector->getInstance('IMP_Identity');
+        if (isset($this->_vars->identity) &&
+            !$prefs->isLocked('default_identity')) {
+            $identity->setDefault($this->_vars->identity);
+        }
+        $stationery = $injector->getInstance('IMP_Compose_Stationery');
+
+        $result = new stdClass;
+        $result->text = $stationery->getContent($this->_vars->id, $identity, strval($this->_vars->text), $this->_vars->html);
+
+        $notification->push(sprintf(_("Loaded stationery \"%s\"."), $stationery[$this->_vars->id]['n']), 'horde.message');
+
+        return $result;
+    }
+
+    /**
      * AJAX action: Delete a draft.
      *
      * Variables used:
index 60beca6..3bee373 100644 (file)
@@ -149,6 +149,9 @@ class IMP_Views_Compose
                 $t->set('encrypt', IMP::ENCRYPT_NONE);
             }
 
+            $stationery = $GLOBALS['injector']->getInstance('IMP_Compose_Stationery');
+            $t->set('stationery', count($stationery));
+
             $select_list = array();
             foreach ($identity->getSelectList() as $id => $from) {
                 $select_list[] = array(
index 11c1bbb..e07a292 100644 (file)
      <input id="encrypt" name="encrypt" type="hidden" value="<tag:encrypt />" />
     </div>
 </if:encrypt>
+<if:stationery>
+    <div>
+     <gettext>Stationery</gettext><span id="stationery_label"></span>
+    </div>
+</if:stationery>
    </div>
 
    <table>
index cfda7b7..4752f8c 100644 (file)
@@ -225,6 +225,18 @@ if (in_array(basename($_SERVER['PHP_SELF']), array('compose-dimp.php', 'message-
         }
         $code['conf_compose']['encrypt'] = $encrypt;
     }
+
+    $stationery = $GLOBALS['injector']->getInstance('IMP_Compose_Stationery');
+    if (count($stationery)) {
+        $slist = array();
+        foreach ($stationery as $key => $val) {
+            $slist[] = array(
+                'l' => htmlspecialchars($val['n']),
+                'v' => intval($key)
+            );
+        }
+        $code['conf_compose']['stationery'] = $slist;
+    }
 }
 
 Horde::addInlineScript(array(