Fix bug 1049341 - Cannot edit meeting attendee list once invite created. r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Sat, 09 Aug 2014 23:15:03 +0200
changeset 25465 a131772dfead70d5e9e5a3a6b09bc6eace8a1c47
parent 25464 e186316c0430cdb377621eda5f2ec606a72f3875
child 25466 3a73a2988e74f1c7fe624ba522bf0c722b11b1ef
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
bugs1049341
Fix bug 1049341 - Cannot edit meeting attendee list once invite created. r=philipp
calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
--- a/calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
+++ b/calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
@@ -1104,24 +1104,24 @@
               this.dispatchEvent(event);
           }
         ]]></body>
       </method>
 
       <method name="deleteHit">
         <parameter name="aElement"/>
         <body><![CDATA[
-          // don't delete the row if it's the last one remaining
-          if (this.mMaxAttendees <= 2) {
+          // don't delete the row if only the organizer is remaining
+          if (this.mMaxAttendees <= 1) {
               return;
           }
 
           var row = this.getRowByInputElement(aElement);
           this.deleteRow(row);
-          if (row > 1) {
+          if (row > 0) {
               row = row - 1;
           }
           this.setFocus(row);
           this.onModify();
 
           var event = document.createEvent('Events');
           event.initEvent('rowchange', true, false);
           event.details = row;
@@ -1222,19 +1222,49 @@
       <handler event="keydown"><![CDATA[
         if (this.mIsReadOnly || this.mIsInvitation) {
             return;
         }
         if (event.originalTarget.localName == "input") {
             switch (event.keyCode) {
                 case KeyEvent.DOM_VK_DELETE:
                 case KeyEvent.DOM_VK_BACK_SPACE:
-                    if (!event.originalTarget.value) {
+                    let curRowId = this.getRowByInputElement(event.originalTarget);
+                    let allSelected = (event.originalTarget.textLength ==
+                                       event.originalTarget.selectionEnd -
+                                       event.originalTarget.selectionStart);
+
+                    if (!event.originalTarget.value ||
+                        event.originalTarget.textLength < 2 ||
+                        allSelected) {
+                        // if the user selected the entire attendee string, only one character was
+                        // left or the row was already empty before hitting the key, we remove the
+                        //  entire row to assure the attendee is deleted
                         this.deleteHit(event.originalTarget);
+
+                        // if the last row was removed, we append an empty one which has the focus
+                        // to enable adding a new attendee directly with freebusy information cleared
+                        let targetRowId = (event.keyCode == KeyEvent.DOM_VK_BACK_SPACE && curRowId > 2)
+                                          ? curRowId - 1 : curRowId;
+                        if (this.mMaxAttendees == 1) {
+                            this.appendNewRow(true);
+                        } else {
+                            this.setFocus(targetRowId);
+                        }
+
+                        // set cursor to begin or end of focused input box based on deletion direction
+                        let cPos = 0;
+                        let input = document.getAnonymousElementByAttribute(this.getListItem(targetRowId),
+                                                                            "anonid", "input");
+                        if (targetRowId != curRowId) {
+                            cPos = input.textLength;
+                        }
+                        input.setSelectionRange(cPos, cPos);
                     }
+
                     event.stopPropagation();
                     break;
             }
         }
       ]]></handler>
 
       <handler event="keypress" phase="capturing"><![CDATA[
         // In case we're currently showing the autocompletion popup