diff --git a/mailnews/addrbook/public/nsIAbDirectory.idl b/mailnews/addrbook/public/nsIAbDirectory.idl index 9a11bfc29e8f..41de20c9cdb3 100644 --- a/mailnews/addrbook/public/nsIAbDirectory.idl +++ b/mailnews/addrbook/public/nsIAbDirectory.idl @@ -64,6 +64,7 @@ interface nsIAbDirectory : nsISupports { void addAddressToList(in nsIAbCard card); void addMailListToDatabase(in string uri); void editMailListToDatabase(in string uri); + void removeEmailAddressAt(in unsigned long aIndex); [noscript] void clearDatabase(); [noscript] void notifyDirItemAdded(in nsISupports item); diff --git a/mailnews/addrbook/resources/content/abListOverlay.xul b/mailnews/addrbook/resources/content/abListOverlay.xul index d1376ad84c5f..511d94282bd6 100644 --- a/mailnews/addrbook/resources/content/abListOverlay.xul +++ b/mailnews/addrbook/resources/content/abListOverlay.xul @@ -62,10 +62,14 @@ Rights Reserved. - + + + + + + diff --git a/mailnews/addrbook/resources/content/abMailListDialog.js b/mailnews/addrbook/resources/content/abMailListDialog.js index fb74046c8d27..d203a0c77b5b 100644 --- a/mailnews/addrbook/resources/content/abMailListDialog.js +++ b/mailnews/addrbook/resources/content/abMailListDialog.js @@ -61,39 +61,39 @@ function GetListValue(mailList, doAdd) var cardproperty = Components.classes["component://netscape/addressbook/cardproperty"].createInstance(); else var cardproperty = mailList.addressLists.GetElementAt(pos); - if (cardproperty) + + if (fieldValue == "") + { + if (doAdd == false && cardproperty) + mailList.removeEmailAddressAt(pos); + } + else if (cardproperty) { cardproperty = cardproperty.QueryInterface(Components.interfaces.nsIAbCard); if (cardproperty) { - if (fieldValue != "") + var beginpos = fieldValue.search('<'); + var endpos = fieldValue.search('>'); + if (beginpos != -1) { - var beginpos = fieldValue.search('<'); - var endpos = fieldValue.search('>'); - if (beginpos != -1) - { - beginpos++; - var newValue = fieldValue.slice(beginpos, endpos); - cardproperty.primaryEmail = newValue; - } - else - cardproperty.primaryEmail = fieldValue; - if (doAdd || (doAdd == false && pos >= oldTotal)) - mailList.addressLists.AppendElement(cardproperty); - pos++; + beginpos++; + var newValue = fieldValue.slice(beginpos, endpos); + cardproperty.primaryEmail = newValue; } else - { - if (doAdd == false) - { - cardproperty.primaryEmail = fieldValue; - pos++; - } - } + cardproperty.primaryEmail = fieldValue; + if (doAdd || (doAdd == false && pos >= oldTotal)) + mailList.addressLists.AppendElement(cardproperty); + pos++; } } i++; } + if (doAdd == false && i < oldTotal) + { + for (j = i; j < oldTotal; j++) + mailList.addressLists.RemoveElementAt(j); + } return true; } @@ -159,6 +159,8 @@ function OnLoadMailList() } } + AppendnewRowAndSetFocus(); + // focus on first name var listName = document.getElementById('ListName'); if ( listName ) @@ -198,30 +200,34 @@ function OnLoadEditList() document.getElementById('ListNickName').value = editList.listNickName; document.getElementById('ListDescription').value = editList.description; - var treeChildren = document.getElementById('addressList'); - var newTreeChildrenNode = treeChildren.cloneNode(false); - var templateNode = treeChildren.firstChild; - top.MAX_RECIPIENTS = 0; - if (editList.addressLists) { var total = editList.addressLists.Count(); dump("*** editList.Count = "+total+"\n"); - for ( var i = 0; i < total; i++ ) + if (total) { - var card = editList.addressLists.GetElementAt(i); - card = card.QueryInterface(Components.interfaces.nsIAbCard); - var address; - if (card.name.length) - address = card.name + " <" + card.primaryEmail + ">"; - else - address = card.primaryEmail; - SetInputValue(address, newTreeChildrenNode, templateNode); - } + var treeChildren = document.getElementById('addressList'); + var newTreeChildrenNode = treeChildren.cloneNode(false); + var templateNode = treeChildren.firstChild; + + top.MAX_RECIPIENTS = 0; + for ( var i = 0; i < total; i++ ) + { + var card = editList.addressLists.GetElementAt(i); + card = card.QueryInterface(Components.interfaces.nsIAbCard); + var address; + if (card.name.length) + address = card.name + " <" + card.primaryEmail + ">"; + else + address = card.primaryEmail; + SetInputValue(address, newTreeChildrenNode, templateNode); + } + var parent = treeChildren.parentNode; + parent.replaceChild(newTreeChildrenNode, treeChildren); + } } - var parent = treeChildren.parentNode; - parent.replaceChild(newTreeChildrenNode, treeChildren); + AppendnewRowAndSetFocus(); // focus on first name var listName = document.getElementById('ListName'); @@ -229,6 +235,15 @@ dump("*** editList.Count = "+total+"\n"); listName.focus(); } +function AppendnewRowAndSetFocus() +{ + var lastInput = awGetInputElement(top.MAX_RECIPIENTS); + if ( lastInput && lastInput.value ) + awAppendNewRow(true); + else + awSetFocus(top.MAX_RECIPIENTS, lastInput); +} + function SetInputValue(inputValue, parentNode, templateNode) { top.MAX_RECIPIENTS++; @@ -259,8 +274,11 @@ function awNotAnEmptyArea(event) event.preventBubble(); } -function awClickEmptySpace(setFocus) +function awClickEmptySpace(targ, setFocus) { + if (targ.localName != 'treechildren') + return; + dump("awClickEmptySpace\n"); var lastInput = awGetInputElement(top.MAX_RECIPIENTS); diff --git a/mailnews/addrbook/src/nsAbDirProperty.cpp b/mailnews/addrbook/src/nsAbDirProperty.cpp index 463a513ecc05..7cc316d26685 100644 --- a/mailnews/addrbook/src/nsAbDirProperty.cpp +++ b/mailnews/addrbook/src/nsAbDirProperty.cpp @@ -219,6 +219,10 @@ NS_IMETHODIMP nsAbDirProperty::RemoveElementsFromAddressList() { return NS_OK; } +NS_IMETHODIMP +nsAbDirProperty::RemoveEmailAddressAt(PRUint32 aIndex) +{ return NS_OK; } + nsresult nsAbDirProperty::GetAttributeName(PRUnichar **aName, nsString& value) { if (aName) diff --git a/mailnews/addrbook/src/nsAbDirectory.cpp b/mailnews/addrbook/src/nsAbDirectory.cpp index 39ca44695c27..42d611dc77ab 100644 --- a/mailnews/addrbook/src/nsAbDirectory.cpp +++ b/mailnews/addrbook/src/nsAbDirectory.cpp @@ -421,6 +421,16 @@ NS_IMETHODIMP nsAbDirectory::RemoveElementsFromAddressList() return NS_OK; } +NS_IMETHODIMP nsAbDirectory::RemoveEmailAddressAt(PRUint32 aIndex) +{ + if (m_AddressList) + { + return m_AddressList->RemoveElementAt(aIndex); + } + else + return NS_ERROR_FAILURE; +} + nsresult nsAbDirectory::RemoveCardFromAddressList(const nsIAbCard* card) { nsresult rv = NS_OK; @@ -477,7 +487,31 @@ NS_IMETHODIMP nsAbDirectory::DeleteCards(nsISupportsArray *cards) if (card) { if (IsMailingList()) + { mDatabase->DeleteCardFromMailList(this, card, PR_TRUE); + + PRUint32 cardTotal; + PRInt32 i; + rv = m_AddressList->Count(&cardTotal); + for (i = cardTotal - 1; i >= 0; i--) + { + nsISupports* pSupport = m_AddressList->ElementAt(i); + if (!pSupport) + continue; + + nsCOMPtr arrayCard(do_QueryInterface(pSupport, &rv)); + if (arrayCard) + { + PRUint32 tableID, rowID, cardTableID, cardRowID; + arrayCard->GetDbTableID(&tableID); + arrayCard->GetDbRowID(&rowID); + card->GetDbTableID(&cardTableID); + card->GetDbRowID(&cardRowID); + if (tableID == cardTableID && rowID == cardRowID) + m_AddressList->RemoveElementAt(i); + } + } + } else { mDatabase->DeleteCard(card, PR_TRUE); diff --git a/mailnews/addrbook/src/nsAbDirectory.h b/mailnews/addrbook/src/nsAbDirectory.h index c61c46da5fbc..ae1425ad4a8d 100644 --- a/mailnews/addrbook/src/nsAbDirectory.h +++ b/mailnews/addrbook/src/nsAbDirectory.h @@ -69,6 +69,7 @@ public: NS_IMETHOD ClearDatabase(); NS_IMETHOD NotifyDirItemAdded(nsISupports *item) { return NotifyItemAdded(item);} NS_IMETHOD RemoveElementsFromAddressList(); + NS_IMETHOD RemoveEmailAddressAt(PRUint32 aIndex); PRBool IsMailingList(){ return (mIsMailingList == 1); }