Further improvements to contextmenu generation/initialization
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Apr 2010 16:28:27 +0000 (10:28 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Apr 2010 20:43:52 +0000 (14:43 -0600)
imp/js/DimpBase.js
imp/js/DimpCore.js
imp/js/fullmessage-dimp.js

index db2056f..591de15 100644 (file)
@@ -522,9 +522,10 @@ var DimpBase = {
         /* Custom ViewPort events. */
         container.observe('ViewPort:add', function(e) {
             var row = e.memo.identify();
-
-            // Add context menu
-            this._addMouseEvents({ id: row, type: 'message' });
+            DimpCore.addContextMenu({
+                id: row,
+                type: 'message'
+            });
             new Drag(row, this._msgDragConfig);
         }.bindAsEventListener(this));
 
@@ -672,29 +673,6 @@ var DimpBase = {
         });
     },
 
-    _addPopdown: function(p, t)
-    {
-        var elt = new Element('SPAN', { className: 'iconImg popdownImg popdown' });
-        $(p).insert({ after: elt });
-        this._addPopdownContextMenu(elt, t);
-        return elt;
-    },
-
-    _addPopdownContextMenu: function(elt, t)
-    {
-        this._addMouseEvents({
-            id: elt.identify(),
-            left: true,
-            offset: elt.up(),
-            type: t
-        });
-    },
-
-    _addMouseEvents: function(p)
-    {
-        DimpCore.DMenu.addElement(p.id, 'ctx_' + p.type, p);
-    },
-
     _removeMouseEvents: function(elt)
     {
         var d, id = $(elt).readAttribute('id');
@@ -2571,12 +2549,18 @@ var DimpBase = {
         case 'container':
         case 'folder':
             new Drag(li, this._folderDragConfig);
-            this._addMouseEvents({ id: fid, type: ftype });
+            DimpCore.addContextMenu({
+                id: fid,
+                type: ftype
+            });
             break;
 
         case 'scontainer':
         case 'virtual':
-            this._addMouseEvents({ id: fid, type: (ob.v == 2) ? 'vfolder' : 'noactions' });
+            DimpCore.addContextMenu({
+                id: fid,
+                type: (ob.v == 2) ? 'vfolder' : 'noactions'
+            });
             break;
         }
     },
@@ -2937,8 +2921,18 @@ var DimpBase = {
          * list since it may be disabled if we are in a search mailbox. */
         if ($('qsearch')) {
             $('qsearch_input').observe('blur', this._quicksearchOnBlur.bind(this));
-            this._addMouseEvents({ id: 'qsearch_icon', left: true, offset: 'qsearch', type: 'qsearchopts' });
-            this._addMouseEvents({ id: 'qsearch_icon', left: false, offset: 'qsearch', type: 'qsearchopts' });
+            DimpCore.addContextMenu({
+                id: 'qsearch_icon',
+                left: true,
+                offset: 'qsearch',
+                type: 'qsearchopts'
+            });
+            DimpCore.addContextMenu({
+                id: 'qsearch_icon',
+                left: false,
+                offset: 'qsearch',
+                type: 'qsearchopts'
+            });
             DM.addSubMenu('ctx_qsearchopts_by', 'ctx_qsearchby');
             DM.addSubMenu('ctx_qsearchopts_filter', 'ctx_flag');
             DM.addSubMenu('ctx_qsearchopts_filternot', 'ctx_flag');
@@ -2971,10 +2965,8 @@ var DimpBase = {
         this._setQsearchText(true);
 
         /* Add popdown menus. Check for disabled compose at the same time. */
-        this._addPopdown('button_other', 'otheractions');
-        this._addPopdownContextMenu($('button_other'), 'otheractions');
-        this._addPopdown('folderopts_link', 'folderopts');
-        this._addPopdownContextMenu($('folderopts_link'), 'folderopts');
+        DimpCore.addPopdown('button_other', 'otheractions');
+        DimpCore.addPopdown('folderopts_link', 'folderopts');
 
         DM.addSubMenu('ctx_message_reply', 'ctx_reply');
         DM.addSubMenu('ctx_message_forward', 'ctx_forward');
@@ -2989,11 +2981,14 @@ var DimpBase = {
         if (DIMP.conf.disable_compose) {
             $('button_reply', 'button_forward').compact().invoke('up', 'SPAN').concat($('button_compose', 'composelink', 'ctx_contacts_new')).compact().invoke('remove');
         } else {
-            DM.disable(this._addPopdown('button_reply', 'reply').identify(), true, true);
-            DM.disable(this._addPopdown('button_forward', 'forward').identify(), true, true);
+            DimpCore.addPopdown('button_reply', 'reply', true);
+            DimpCore.addPopdown('button_forward', 'forward', true);
         }
 
-        this._addMouseEvents({ id: 'msglistHeader', type: 'mboxsort' });
+        DimpCore.addContextMenu({
+            id: 'msglistHeader',
+            type: 'mboxsort'
+        });
 
         new Drop('dropbase', this._folderDropConfig);
 
index 2708451..e1952b7 100644 (file)
@@ -320,13 +320,41 @@ var DimpCore = {
     toggleButtons: function(elts, disable)
     {
         elts.each(function(b) {
+            var tmp;
             [ b.up() ].invoke(disable ? 'addClassName' : 'removeClassName', 'disabled');
-            if (this.DMenu) {
-                this.DMenu.disable(b.identify() + '_img', true, disable);
+            if (this.DMenu &&
+                (tmp = b.next('.popdown'))) {
+                this.DMenu.disable(tmp.identify(), true, disable);
             }
         }, this);
     },
 
+    // p = (Element) Parent element
+    // t = (string) Context menu type
+    // d = (boolean) Disabled?
+    addPopdown: function(p, t, d)
+    {
+        var elt = new Element('SPAN', { className: 'iconImg popdownImg popdown' });
+        $(p).insert({ after: elt });
+
+        this.addContextMenu({
+            disable: d,
+            id: elt.identify(),
+            left: true,
+            offset: elt.up(),
+            type: t
+        });
+
+        return elt;
+    },
+
+    addContextMenu: function(p)
+    {
+        if (this.DMenu) {
+            this.DMenu.addElement(p.id, 'ctx_' + p.type, p);
+        }
+    },
+
     /* Add dropdown menus to addresses. */
     buildAddressLinks: function(alist, elt)
     {
index f5bf5ce..d49cf11 100644 (file)
@@ -181,14 +181,6 @@ var DimpFullmessage = {
         }
     },
 
-    /* Add a popdown menu to a dimpactions button. */
-    addPopdown: function(bid, ctx)
-    {
-        var bidelt = $(bid);
-        bidelt.insert({ after: new Element('SPAN', { className: 'iconImg popdownImg popdown', id: bid + '_img' }) });
-        DimpCore.DMenu.addElement(bid + '_img', 'ctx_' + ctx, { offset: bidelt.up(), left: true });
-    },
-
     resizeWindow: function()
     {
         var mb = $('msgData').down('DIV.messageBody');
@@ -204,8 +196,8 @@ var DimpFullmessage = {
         if (DIMP.conf.disable_compose) {
             tmp = $('reply_link', 'forward_link').compact().invoke('up', 'SPAN').concat([ $('ctx_contacts_new') ]).compact().invoke('remove');
         } else {
-            this.addPopdown('reply_link', 'replypopdown');
-            this.addPopdown('forward_link', 'forwardpopdown');
+            DimpCore.addPopdown('reply_link', 'replypopdown');
+            DimpCore.addPopdown('forward_link', 'forwardpopdown');
         }
 
         /* Set up address linking. */