Fix bug 492069 - Lightning corrupts ATTENDEE / ORGANIZER with CN parameter that contains a comma. r=decathlon
authorPhilipp Kewisch <mozilla@kewis.ch>
Tue, 07 Jun 2011 15:32:06 +0200
changeset 7898 8d78eb1a21728c213cbe6cc250c6cd6947a75487
parent 7897 2aaa39c691fe3ecd32389fc7639f4e481ae3b1e5
child 7899 0155789c1e3c908ae603d128cc957c06bd4247c8
push id6067
push usermozilla@kewis.ch
push dateTue, 07 Jun 2011 13:40:50 +0000
treeherdercomm-central@8d78eb1a2172 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdecathlon
bugs492069
Fix bug 492069 - Lightning corrupts ATTENDEE / ORGANIZER with CN parameter that contains a comma. r=decathlon
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
@@ -68,16 +68,17 @@
                          type="autocomplete"
                          flex="1"
                          autocompletesearch="addrbook"
                          timeout="300"
                          maxrows="4"
                          completedefaultindex="true"
                          forcecomplete="true"
                          minresultsforpopup="1"
+                         onblur="if (this.localName == 'textbox') document.getBindingParent(this).onBlurInput(event);"
                          ignoreblurwhilesearching="true"
                          oninput="this.setAttribute('dirty', 'true');">
               <xul:image class="person-icon" onclick="this.parentNode.select();"/>
             </xul:textbox>
           </xul:listcell>
         </xul:listitem>
       </xul:listbox>
     </content>
@@ -381,28 +382,32 @@
           this.updateTooltip(icon);
 
           return true;
         ]]></body>
       </method>
 
       <method name="appendNewRow">
         <parameter name="aSetFocus"/>
+        <parameter name="aInsertAfter"/>
         <body><![CDATA[
           var listbox =
               document.getAnonymousElementByAttribute(
                   this, "anonid", "listbox");
           var listitem1 = this.getListItem(1);
+          var newNode = null;
 
           if (listbox && listitem1) {
               var newAttendee = this.createAttendee();
               var nextDummy = this.getNextDummyRow();
-              var newNode = listitem1.cloneNode(true);
+              newNode = listitem1.cloneNode(true);
 
-              if (nextDummy) {
+              if (aInsertAfter) {
+                  listbox.insertBefore(newNode, aInsertAfter.nextSibling);
+              } else if (nextDummy) {
                   listbox.replaceChild(newNode, nextDummy);
               } else {
                   listbox.appendChild(newNode);
               }
 
               var input =
                   document.getAnonymousElementByAttribute(
                       newNode, "anonid", "input");
@@ -454,24 +459,24 @@
 
               // this copies the autocomplete sessions list from first attendee
               if (this.mLDAPSession && this.mSessionAdded) {
                   input.syncSessions(document.getAnonymousElementByAttribute(this, "id", 'attendeeCol2#1'));
               }
 
               // focus on new input widget
               if (aSetFocus) {
-                  this.setFocus(this.mMaxAttendees);
+                  this.setFocus(newNode);
               }
-
-              this.onModify();
           }
+          return newNode;
         ]]></body>
       </method>
 
+
       <property name="attendees">
         <getter><![CDATA[
           var attendees = [];
 
           var inputField;
           for (var i = 1; inputField = this.getInputElement(i); i++) {
               var fieldValue = inputField.value;
               if (fieldValue != "") {
@@ -573,16 +578,42 @@
                   }
               }
           }
 
           return null;
         ]]></getter>
       </property>
 
+      <method name="onBlurInput">
+        <parameter name="event"/>
+        <body><![CDATA[
+          if (this.mHeaderParser) {
+              var emailAddresses = {};
+              var names = {};
+              var fullNames = {};
+              this.mHeaderParser.parseHeadersWithArray(
+                    event.target.value,
+                    emailAddresses,
+                    names,
+                    fullNames);
+              if (emailAddresses.value.length > 1) {
+                  let firstFullName = fullNames.value.shift();
+                  event.target.value = firstFullName;
+                  let insertAfterItem = this.getListItem(this.getRowByInputElement(event.target));
+                  for each (let full in fullNames.value) {
+                      insertAfterItem = this.appendNewRow(false, insertAfterItem);
+                      let textinput = this.getInputFromListitem(insertAfterItem);
+                      textinput.value = full;
+                  }
+              }
+          }
+        ]]></body>
+      </method>
+
       <method name="onModify">
         <body><![CDATA[
           var list = [];
           for (var i = 1; i <= this.mMaxAttendees; i++) {
               // retrieve the string from the appropriate row
               var input = this.getInputElement(i);
               var fieldValue = input.value;
 
@@ -777,16 +808,23 @@
               if (listitems && listitems.length >= aRow) {
                   return listitems[aRow - 1];
               }
           }
           return 0;
         ]]></body>
       </method>
 
+      <method name="getInputFromListitem">
+        <parameter name="aListItem"/>
+        <body><![CDATA[
+          return aListItem.getElementsByTagNameNS("*", "textbox")[0];
+        ]]></body>
+      </method>
+
       <method name="getRowByInputElement">
         <parameter name="aElement"/>
         <body><![CDATA[
           var row = 0;
           while (aElement && aElement.localName != "listitem") {
               aElement = aElement.parentNode;
           }
           if (aElement) {
@@ -824,18 +862,24 @@
         ]]></body>
       </method>
 
       <method name="setFocus">
         <parameter name="aRow"/>
         <body><![CDATA[
           var self = this;
           var set_focus = function() {
+              var node;
+              if (typeof aRow == 'number') {
+                node = self.getListItem(aRow);
+              } else {
+                node = aRow;
+              }
+
               // do we need to scroll in order to see the selected row?
-              var node = self.getListItem(aRow);
               var listbox =
                   document.getAnonymousElementByAttribute(
                       self, "anonid", "listbox");
               var firstVisibleRow = listbox.getIndexOfFirstVisibleRow();
               var numOfVisibleRows = listbox.getNumberOfVisibleRows();
               if (aRow <= firstVisibleRow) {
                   listbox.scrollToIndex(aRow - 1);
               } else {