Bug 1233827 - Event dialog: change context menu for attendee and attachment boxes;r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Wed, 30 Dec 2015 14:05:49 +0100
changeset 26625 8dc9b27d183ad393e37a51ba70a1c8a6c2ce5b63
parent 26624 d34da274dae03c12f2ba8d818961c3811ea59406
child 26626 54de083be103ab49f292c00c543d42b7608dbe2d
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1233827
Bug 1233827 - Event dialog: change context menu for attendee and attachment boxes;r=philipp
calendar/base/content/dialogs/calendar-event-dialog.js
calendar/base/content/dialogs/calendar-event-dialog.xul
--- a/calendar/base/content/dialogs/calendar-event-dialog.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog.js
@@ -2284,43 +2284,61 @@ function copyAttachment() {
     let clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
                               .getService(Components.interfaces.nsIClipboardHelper);
     clipboard.copyString(attURI);
 }
 
 /**
  * Handler function to handle pressing keys in the attachment listbox.
  *
- * @param event     The DOM event caused by the key press.
+ * @param aEvent     The DOM event caused by the key press.
  */
-function attachmentLinkKeyPress(event) {
+function attachmentLinkKeyPress(aEvent) {
     const kKE = Components.interfaces.nsIDOMKeyEvent;
-    switch (event.keyCode) {
+    switch (aEvent.keyCode) {
         case kKE.DOM_VK_BACK_SPACE:
         case kKE.DOM_VK_DELETE:
             deleteAttachment();
             break;
         case kKE.DOM_VK_RETURN:
             openAttachment();
             break;
     }
 }
 
 /**
- * Handler function to take care of clicking on an attachment
+ * Handler function to take care of double clicking on an attachment
  *
- * @param event     The DOM event caused by the clicking.
+ * @param aEvent     The DOM event caused by the clicking.
  */
-function attachmentLinkDblClicked(event) {
-    if (event.originalTarget.localName == "listitem") {
+function attachmentDblClick(aEvent) {
+    // left double click on a list item
+    if (aEvent.originalTarget.localName == "listitem" && aEvent.button == 0) {
         openAttachment();
     }
 }
 
 /**
+ * Handler function to take care of right clicking on an attachment or the attachment list
+ *
+ * @param aEvent     The DOM event caused by the clicking.
+ */
+function attachmentClick(aEvent) {
+    // we take only care about right clicks
+    if (aEvent.button != 2) {
+        return;
+    }
+    let attachmentPopup = document.getElementById("attachment-popup");
+    for (let node of attachmentPopup.childNodes) {
+        (aEvent.originalTarget.localName == "listitem" ||
+         node.id == "attachment-popup-attachPage") ? showElement(node) : hideElement(node);
+    }
+}
+
+/**
  * Helper function to show a notification in the event-dialog's notificationBox
  *
  * @param aMessage     the message text to show
  * @param aValue       string identifying the notification
  * @param aPriority    (optional) the priority of the warning (info, critical), default is 'warn'
  * @param aImage       (optional) URL of image to appear on the notification
  * @param aButtonset   (optional) array of button descriptions to appear on the notification
  * @param aCallback    (optional) a function to handle events from the notificationBox
@@ -3561,63 +3579,70 @@ function updateRepeatDetails() {
  */
 function isAttendeeUndecided(aAttendee) {
     return aAttendee.participationStatus != "ACCEPTED" &&
            aAttendee.participationStatus != "DECLINED" &&
            aAttendee.participationStatus != "DELEGATED";
 }
 
 /**
+ * Event handler for dblclick on attendee items.
+ *
+ * @param aEvent         The popupshowing event
+ */
+function attendeeDblClick(aEvent) {
+    // left mouse button
+    if (aEvent.button == 0) {
+        editAttendees();
+    }
+    return;
+}
+
+/**
  * Event handler to set up the attendee-popup. This builds the popup menuitems.
  *
- * @param event         The popupshowing event
+ * @param aEvent         The popupshowing event
  */
-function showAttendeePopup(event) {
-    function countUndecided(aAttendee) {
-        // Count attendees that have done something.
-        if (!isAttendeeUndecided(aAttendee)) {
-            responsiveAttendees++;
-        }
-    }
-
-    if (event.button != 2) {
-        // open attendee dialog on double click
-        if (event.button == 0 && event.detail == 2) {
-            editAttendees();
-        }
+function attendeeClick(aEvent) {
+    // we need to handle right clicks only to display the context menu
+    if (aEvent.button != 2) {
         return;
     }
 
-    // determine whether there are attendees without decision
-    let responsiveAttendees = 0;
-    window.attendees.forEach(countUndecided);
-
-    let popup = document.getElementById("attendee-popup");
-    let mailto = document.getElementById("attendee-popup-emailattendee-menuitem");
-    let remove = document.getElementById("attendee-popup-removeattendee-menuitem");
-    let attId = event.target.parentNode.getAttribute("attendeeid");
-    let attendee = window.attendees.find(aAtt => aAtt.id == attId);
-    if (attendee) {
-        mailto.setAttribute("label", attendee.toString());
-        mailto.attendee = attendee;
-        remove.attendee = attendee;
+    if (window.attendees.length == 0) {
+        // we just need the option to open the attendee dialog in this case
+        let popup = document.getElementById("attendee-popup");
+        let invite = document.getElementById("attendee-popup-invite-menuitem");
+        for (let node of popup.childNodes) {
+            (node == invite) ? showElement(node) : hideElement(node);
+        }
+    } else {
+        // setup attendee specific menu items if appropriate otherwise hide respective  menu items
+        let mailto = document.getElementById("attendee-popup-emailattendee-menuitem");
+        let remove = document.getElementById("attendee-popup-removeattendee-menuitem");
+        let separator = document.getElementById("attendee-popup-second-separator");
+        let attId = aEvent.target.parentNode.getAttribute("attendeeid");
+        let attendee = window.attendees.find(aAtt => aAtt.id == attId);
+        if (attendee) {
+            [mailto, remove, separator].forEach(showElement);
+            mailto.setAttribute("label", attendee.toString());
+            mailto.attendee = attendee;
+            remove.attendee = attendee;
+        } else {
+            [mailto, remove, separator].forEach(hideElement);
+        }
+
+        if (window.attendees.some(isAttendeeUndecided)) {
+            document.getElementById("cmd_email_undecided")
+                    .removeAttribute("disabled");
+        } else {
+            document.getElementById("cmd_email_undecided")
+                    .setAttribute("disabled", "true");
+        }
     }
-
-    // set up the unanswered attendees item.
-    if (responsiveAttendees == window.attendees.length) {
-        document.getElementById("cmd_email_undecided")
-                .setAttribute("disabled", "true");
-    } else {
-        document.getElementById("cmd_email_undecided")
-                .removeAttribute("disabled");
-    }
-
-    // Show the popup.
-    var attendeeList = document.getElementById("attendee-list");
-    popup.openPopup(attendeeList, "after_start", event.clientX, event.clientY, true);
 }
 
 /**
  * Removes the selected attendee from the window
  * @param aAttendee
  */
 function removeAttendee(aAttendee) {
     if (aAttendee) {
--- a/calendar/base/content/dialogs/calendar-event-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-event-dialog.xul
@@ -1184,17 +1184,18 @@
                 <tabpanel id="event-grid-tabpanel-attachements">
                     <vbox flex="1">
                       <listbox id="attachment-link"
                                context="attachment-popup"
                                rows="3"
                                flex="1"
                                disable-on-readonly="true"
                                onkeypress="attachmentLinkKeyPress(event)"
-                               ondblclick="attachmentLinkDblClicked(event);"/>
+                               onclick="attachmentClick(event);"
+                               ondblclick="attachmentDblClick(event);"/>
                     </vbox>
                 </tabpanel>
                 <tabpanel id="event-grid-tabpanel-attendees"
                           collapsed="true">
                   <vbox flex="1">
                     <hbox id="item-organizer-row"
                           collapsed="true"
                           align="top"
@@ -1206,16 +1207,18 @@
                                class="item-attendees-cell-label"
                                crop="right"/>
                       </hbox>
                     </hbox>
                     <hbox flex="1">
                       <vbox id="item-attendees-box"
                             dialog-type="event"
                             flex="1"
+                            context="attendee-popup"
+                            onclick="attendeeClick(event)"
                             disable-on-readonly="true"/>
                     </hbox>
                     <hbox id="notify-options" align="center">
                       <checkbox id="notify-attendees-checkbox"
                                 label="&event.attendees.notify.label;"
                                 oncommand="changeUndiscloseCheckboxStatus();"
                                 pack="start"/>
                       <checkbox id="undisclose-attendees-checkbox"
@@ -1310,42 +1313,42 @@
                hidden="true"/>
         <label id="status-freebusy-busy-label"
                value="&event.freebusy.legend.busy;"
                hidden="true"/>
       </statusbarpanel>
     </statusbar>
 
     <popupset id="event-dialog-popupset">
-      <menupopup id="attendee-popup" position="after_start">
+      <menupopup id="attendee-popup">
         <menuitem id="attendee-popup-invite-menuitem"
                   label="&event.invite.attendees.label;"
                   accesskey="&event.invite.attendees.accesskey;"
                   command="cmd_attendees"
                   disable-on-readonly="true"/>
         <menuitem id="attendee-popup-removeallattendees-menuitem"
                   label="&event.remove.attendees.label;"
                   accesskey="&event.remove.attendees.accesskey;"
                   oncommand="removeAllAttendees()"
                   disable-on-readonly="true"
                   crop="end"/>
         <menuitem id="attendee-popup-removeattendee-menuitem"
                   label="&event.remove.attendee.label;"
                   oncommand="removeAttendee(event.target.attendee)"
                   crop="end"/>
-        <menuseparator id="attendees-popup-menuseparator"/>
+        <menuseparator id="attendee-popup-first-separator"/>
         <menuitem id="attendee-popup-sendemail-menuitem"
                   label="&event.email.attendees.label;"
                   accesskey="&event.email.attendees.accesskey;"
                   command="cmd_email"/>
         <menuitem id="attendee-popup-sendtentativeemail-menuitem"
                   label="&event.email.tentative.attendees.label;"
                   accesskey="&event.email.tentative.attendees.accesskey;"
                   command="cmd_email_undecided"/>
-        <menuseparator id="attendee-popup-separator"/>
+        <menuseparator id="attendee-popup-second-separator"/>
         <menuitem id="attendee-popup-emailattendee-menuitem"
                   oncommand="sendMailToAttendees([event.target.attendee])"
                   crop="end"/>
       </menupopup>
       <menupopup id="attachment-popup">
             <menuitem id="attachment-popup-open"
                       label="&event.attachments.popup.open.label;"
                       accesskey="&event.attachments.popup.open.accesskey;"
@@ -1381,17 +1384,18 @@
     <!-- attendee box template -->
     <vbox id="item-attendees-box-template"
           hidden="true">
       <hbox flex="1" class="item-attendees-row" equalsize="always" hidden="true">
         <box class="item-attendees-cell"
              hidden="true"
              flex="1"
              context="attendee-popup"
-             onclick="showAttendeePopup(event)">
+             ondblclick="attendeeDblClick(event)"
+             onclick="attendeeClick(event)">
           <img class="itip-icon"/>
           <label class="item-attendees-cell-label"
                  crop="end"
                  flex="1"/>
         </box>
         <box hidden="true" flex="1"/>
       </hbox>
     </vbox>