Move flag context item creation into javascript
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 24 Sep 2010 17:46:41 +0000 (11:46 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 24 Sep 2010 17:46:54 +0000 (11:46 -0600)
Allows for dynamic addition of flags in the future.
Also allows storage of IMAP flag name in metadata rather than hackish
parameter storage.

imp/js/dimpbase.js
imp/templates/dimp/index.inc
imp/templates/dimp/javascript_defs_dimp.php

index c088abb..8efbaa9 100644 (file)
@@ -643,7 +643,7 @@ var DimpBase = {
             $('ctx_message_setflag', 'oa_setflag').invoke('up').invoke(flags.size() ? 'show' : 'hide');
             if (flags.size()) {
                 $('ctx_flag').childElements().each(function(c) {
-                    [ c ].invoke(flags.include(c.readAttribute('flag')) ? 'show' : 'hide');
+                    [ c ].invoke(flags.include(c.retrieve('flag')) ? 'show' : 'hide');
                 });
             }
         }.bindAsEventListener(this));
@@ -896,11 +896,11 @@ var DimpBase = {
 
         default:
             if (menu.endsWith('_setflag') || menu.endsWith('_unsetflag')) {
-                flag = elt.readAttribute('flag');
+                flag = elt.retrieve('flag');
                 this.flag(flag, this.convertFlag(flag, menu.endsWith('_setflag')));
             } else if (menu.endsWith('_filter') || menu.endsWith('_filternot')) {
                 this.search = {
-                    flag: elt.readAttribute('flag'),
+                    flag: elt.retrieve('flag'),
                     label: this.viewport.getMetaData('label'),
                     mbox: this.folder,
                     not: menu.endsWith('_filternot')
@@ -1010,6 +1010,26 @@ var DimpBase = {
         }
     },
 
+    contextAddFlag: function(flag, f)
+    {
+        var a = new Element('A'),
+            style = {};
+
+        if (f.p) {
+            style.backgroundColor = f.b.escapeHTML();
+        }
+
+        $('ctx_flag').insert(
+            a.insert(
+                new Element('SPAN', { className: 'contextImg' }).addClassName(f.c.escapeHTML()).setStyle(style)
+            ).insert(
+                f.l.escapeHTML()
+            )
+        );
+
+        a.store('flag', flag);
+    },
+
     // nodefer - (boolean) If true, don't defer updating if folder element
     //           does not exist.
     updateTitle: function(nodefer)
@@ -3057,6 +3077,13 @@ var DimpBase = {
         });
         DM.addSubMenu('ctx_folder_setflag', 'ctx_folder_flag');
 
+        /* Create flag entries. */
+        DIMP.conf.flags_o.each(function(f) {
+            if (DIMP.conf.flags[f].s) {
+                this.contextAddFlag(f, DIMP.conf.flags[f]);
+            }
+        }, this);
+
         if (DIMP.conf.disable_compose) {
             $('button_reply', 'button_forward').compact().invoke('up', 'SPAN').concat($('button_compose', 'composelink', 'ctx_contacts_new')).compact().invoke('remove');
         } else {
index ae5fb58..fb0b5a4 100644 (file)
@@ -17,9 +17,6 @@ $has_whitelist = $registry->hasMethod('mail/whitelistFrom');
 // Quota information
 $show_quota = (isset($_SESSION['imp']['imap']['quota']) && is_array($_SESSION['imp']['imap']['quota']));
 
-// Get the list of available IMAP flags
-$flag_list = $injector->getInstance('IMP_Imap_Flags')->getList(array('imap' => true));
-
 // Get application folders list.
 $application_folders = array();
 foreach (IMP_Dimp::menuList() as $app) {
@@ -397,13 +394,11 @@ function _simpleButton($id, $text, $image, $nodisplay = false)
  <a id="ctx_message_resume" style="display:none"><span class="contextImg"></span><?php echo _("Resume Draft") ?></a>
  <a id="ctx_message_reply"><span class="contextImg"></span><?php echo _("Reply") ?></a>
  <a id="ctx_message_forward"><span class="contextImg"></span><?php echo _("Forward") ?></a>
-<?php if (!empty($flag_list)): ?>
- <div>
+ <div id="ctx_message_flagopts" style="display:none">
   <div class="sep"></div>
   <a id="ctx_message_setflag"><span class="contextImg"></span><?php echo _("Mark as") ?>...</a>
   <a id="ctx_message_unsetflag"><span class="contextImg"></span><?php echo _("Unmark as") ?>...</a>
  </div>
-<?php endif; ?>
  <div class="sep"></div>
 <?php if (!empty($conf['spam']['reporting'])): ?>
  <a id="ctx_message_spam"><span class="contextImg"></span><?php echo _("Report as Spam") ?></a>
@@ -448,13 +443,11 @@ function _simpleButton($id, $text, $image, $nodisplay = false)
  <a id="oa_preview_show"><span class="contextImg"></span><?php echo _("Show Preview") ?></a>
  <a id="oa_layout_horiz"><span class="contextImg"></span><?php echo _("Horizontal Layout") ?></a>
  <a id="oa_layout_vert"><span class="contextImg"></span><?php echo _("Vertical Layout") ?></a>
-<?php if (!empty($flag_list)): ?>
- <div>
+ <div id="oa_flagopts" style="display:none">
   <div class="sep"></div>
   <a id="oa_setflag"><span class="contextImg"></span><?php echo _("Mark as") ?>...</a>
   <a id="oa_unsetflag"><span class="contextImg"></span><?php echo _("Unmark as") ?>...</a>
  </div>
-<?php endif; ?>
 <?php if ($has_blacklist || $has_whitelist): ?>
 <?php if ($has_blacklist): ?>
  <div>
@@ -478,13 +471,8 @@ function _simpleButton($id, $text, $image, $nodisplay = false)
 <?php endif; ?>
 </div>
 
-<?php if (!empty($flag_list)): ?>
 <div class="context" id="ctx_flag" style="display:none">
-<?php foreach ($flag_list as $key => $val): ?>
- <a flag="<?php echo htmlspecialchars($key) ?>"><span class="contextImg <?php echo htmlspecialchars($val['c']) ?>"<?php echo ($val['t'] == 'imapp') ? ' style="background:' . htmlspecialchars($val['b']) . '"' : '' ?>></span><?php echo htmlspecialchars($val['l']) ?></a>
-<?php endforeach; ?>
 </div>
-<?php endif; ?>
 
 <div class="context" id="ctx_contacts" style="display:none">
  <a id="ctx_contacts_new"><span class="contextImg"></span><?php echo _("New Message") ?></a>
index 3d3a948..0fbee51 100644 (file)
@@ -33,7 +33,9 @@ foreach ($GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList(array('fgc
         'l' => $val['l'],
         'n' => isset($val['n']) ? $val['n'] : null,
         // Indicate if this is a user *P*ref flag
-        'p' => intval($val['t'] == 'imapp')
+        'p' => intval($val['t'] == 'imapp'),
+        // Indicate if this is a flag that can be *S*earched for
+        's' => intval(in_array($val['t'], array('imapp', 'imapu')))
     ));
 }
 
@@ -61,6 +63,8 @@ $code['conf'] = array_filter(array(
         ? array()
         : array_map(array('IMP_Dimp', 'appendedFolderPref'), $GLOBALS['conf']['server']['fixed_folders']),
     'flags' => $flags,
+    /* Needed to maintain flag ordering. */
+    'flags_o' => array_keys($flags),
     'fsearchid' => IMP_Search::MBOX_PREFIX . IMP_Search::DIMP_FILTERSEARCH,
     'ham_spammbox' => intval(!empty($GLOBALS['conf']['notspam']['spamfolder'])),
     'login_view' => $GLOBALS['prefs']->getValue('dimp_login_view'),