Bug 32286 Exception Feature - Edit mailing list in address book, r=putterman

This commit is contained in:
chuang%netscape.com 2000-06-21 19:25:45 +00:00
parent a3d712241d
commit eabc8104c9
6 changed files with 105 additions and 43 deletions

View File

@ -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);

View File

@ -62,10 +62,14 @@ Rights Reserved.
<box orient="vertical" flex="80%">
<tree id="addressListTree"
rows="8"
flex="100%"
onclick="awClickEmptySpace(true)"
onclick="awClickEmptySpace(event.target, true)"
style="border:solid black 1px">
<treechildren id="addressList">
<treecolgroup>
<treecol flex="1"/>
</treecolgroup>
<treechildren flex="1" id="addressList">
<treeitem>
<treerow>
<treecell allowevents="true">

View File

@ -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);

View File

@ -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)

View File

@ -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<nsIAbCard> 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);

View File

@ -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); }