Fixes Bug 233036 In <abCardOverlay.js>, Warning: reference to undefined property window.arguments[0].QueryInterface (tb version). patch by Serge Gautherie gautheri@noos.fr, r+sr=bienvenu,a=asa

This commit is contained in:
bugzilla%standard8.demon.co.uk 2005-07-14 16:58:11 +00:00
Родитель 5e7db39b5d
Коммит 1f6b7fabd6
1 изменённых файлов: 74 добавлений и 98 удалений

Просмотреть файл

@ -36,7 +36,7 @@
# #
# ***** END LICENSE BLOCK ***** # ***** END LICENSE BLOCK *****
var editCard; var gEditCard;
var gOnSaveListeners = new Array; var gOnSaveListeners = new Array;
var gOkCallback = null; var gOkCallback = null;
var gAddressBookBundle; var gAddressBookBundle;
@ -46,22 +46,19 @@ function OnLoadNewCard()
{ {
InitEditCard(); InitEditCard();
var cardproperty; gEditCard.card =
(("arguments" in window) && (window.arguments.length > 0) &&
// if one is passed in, use it (window.arguments[0] instanceof Components.interfaces.nsIAbCard))
try { ? window.arguments[0]
cardproperty = window.arguments[0].QueryInterface(Components.interfaces.nsIAbCard); : Components.classes["@mozilla.org/addressbook/cardproperty;1"]
} .createInstance(Components.interfaces.nsIAbCard);
catch (ex) { gEditCard.titleProperty = "newCardTitle";
cardproperty = Components.classes["@mozilla.org/addressbook/cardproperty;1"].createInstance(Components.interfaces.nsIAbCard); gEditCard.selectedAB = "";
}
editCard.card = cardproperty;
editCard.titleProperty = "newCardTitle";
editCard.selectedAB = "";
if ("arguments" in window && window.arguments[0]) if ("arguments" in window && window.arguments[0])
{ {
gEditCard.selectedAB = kPersonalAddressbookURI;
if ("selectedAB" in window.arguments[0]) { if ("selectedAB" in window.arguments[0]) {
// check if selected ab is a mailing list // check if selected ab is a mailing list
var abURI = window.arguments[0].selectedAB; var abURI = window.arguments[0].selectedAB;
@ -69,53 +66,41 @@ function OnLoadNewCard()
var directory = GetDirectoryFromURI(abURI); var directory = GetDirectoryFromURI(abURI);
if (directory.isMailList) { if (directory.isMailList) {
var parentURI = GetParentDirectoryFromMailingListURI(abURI); var parentURI = GetParentDirectoryFromMailingListURI(abURI);
if (parentURI) { if (parentURI)
editCard.selectedAB = parentURI; gEditCard.selectedAB = parentURI;
}
else {
// it's a mailing list, but we failed to determine the parent directory
// use the personal addressbook
editCard.selectedAB = kPersonalAddressbookURI;
}
} }
else if (!(directory.operations & directory.opWrite)) { else if (directory.operations & directory.opWrite)
editCard.selectedAB = kPersonalAddressbookURI; gEditCard.selectedAB = window.arguments[0].selectedAB;
}
else {
editCard.selectedAB = window.arguments[0].selectedAB;
}
}
else {
editCard.selectedAB = kPersonalAddressbookURI;
} }
// we may have been given properties to pre-initialize the window with.... // we may have been given properties to pre-initialize the window with....
// we'll fill these in here... // we'll fill these in here...
if ("primaryEmail" in window.arguments[0]) if ("primaryEmail" in window.arguments[0])
editCard.card.primaryEmail = window.arguments[0].primaryEmail; gEditCard.card.primaryEmail = window.arguments[0].primaryEmail;
if ("displayName" in window.arguments[0]) { if ("displayName" in window.arguments[0]) {
editCard.card.displayName = window.arguments[0].displayName; gEditCard.card.displayName = window.arguments[0].displayName;
// if we've got a display name, don't generate // if we've got a display name, don't generate
// a display name (and stomp on the existing display name) // a display name (and stomp on the existing display name)
// when the user types a first or last name // when the user types a first or last name
if (editCard.card.displayName.length) if (gEditCard.card.displayName.length)
editCard.generateDisplayName = false; gEditCard.generateDisplayName = false;
} }
if ("aimScreenName" in window.arguments[0]) if ("aimScreenName" in window.arguments[0])
editCard.card.aimScreenName = window.arguments[0].aimScreenName; gEditCard.card.aimScreenName = window.arguments[0].aimScreenName;
if ("okCallback" in window.arguments[0]) if ("okCallback" in window.arguments[0])
gOkCallback = window.arguments[0].okCallback; gOkCallback = window.arguments[0].okCallback;
if ("escapedVCardStr" in window.arguments[0]) { if ("escapedVCardStr" in window.arguments[0]) {
// hide non vcard values // hide non vcard values
HideNonVcardFields(); HideNonVcardFields();
var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook); var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook);
editCard.card = addressbook.escapedVCardToAbCard(window.arguments[0].escapedVCardStr); gEditCard.card =
addressbook.escapedVCardToAbCard(window.arguments[0].escapedVCardStr);
} }
if ("titleProperty" in window.arguments[0]) if ("titleProperty" in window.arguments[0])
editCard.titleProperty = window.arguments[0].titleProperty; gEditCard.titleProperty = window.arguments[0].titleProperty;
if ("hideABPicker" in window.arguments[0]) if ("hideABPicker" in window.arguments[0])
gHideABPicker = window.arguments[0].hideABPicker; gHideABPicker = window.arguments[0].hideABPicker;
@ -123,7 +108,7 @@ function OnLoadNewCard()
// set popup with address book names // set popup with address book names
var abPopup = document.getElementById('abPopup'); var abPopup = document.getElementById('abPopup');
abPopup.value = editCard.selectedAB || kPersonalAddressbookURI; abPopup.value = gEditCard.selectedAB || kPersonalAddressbookURI;
if (gHideABPicker && abPopup) { if (gHideABPicker && abPopup) {
abPopup.hidden = true; abPopup.hidden = true;
@ -131,19 +116,16 @@ function OnLoadNewCard()
abPopupLabel.hidden = true; abPopupLabel.hidden = true;
} }
SetCardDialogTitle(editCard.card.displayName); SetCardDialogTitle(gEditCard.card.displayName);
GetCardValues(editCard.card, document); GetCardValues(gEditCard.card, document);
// FIX ME - looks like we need to focus on both the text field and the tab widget // FIX ME - looks like we need to focus on both the text field and the tab widget
// probably need to do the same in the addressing widget // probably need to do the same in the addressing widget
// focus on first or last name based on the pref // focus on first or last name based on the pref
var focus; var focus = document.getElementById(gEditCard.displayLastNameFirst
if (editCard.displayLastNameFirst) ? "LastName" : "FirstName");
focus = document.getElementById('LastName');
else
focus = document.getElementById('FirstName');
if ( focus ) { if ( focus ) {
// XXX Using the setTimeout hack until bug 103197 is fixed // XXX Using the setTimeout hack until bug 103197 is fixed
setTimeout( function(firstTextBox) { firstTextBox.focus(); }, 0, focus ); setTimeout( function(firstTextBox) { firstTextBox.focus(); }, 0, focus );
@ -158,7 +140,7 @@ function findCardIndex(directory)
var listCardsCount = directory.addressLists.Count(); var listCardsCount = directory.addressLists.Count();
for ( var i = 0; i < listCardsCount; i++ ) { for ( var i = 0; i < listCardsCount; i++ ) {
var card = directory.addressLists.QueryElementAt(i, Components.interfaces.nsIAbCard); var card = directory.addressLists.QueryElementAt(i, Components.interfaces.nsIAbCard);
if (editCard.card.equals(card)) { if (gEditCard.card.equals(card)) {
index = i; index = i;
break; break;
} }
@ -172,12 +154,12 @@ function EditCardOKButton()
// See if this card is in any mailing list // See if this card is in any mailing list
// if so then we need to update the addresslists of those mailing lists // if so then we need to update the addresslists of those mailing lists
var index = -1; var index = -1;
var directory = GetDirectoryFromURI(editCard.abURI); var directory = GetDirectoryFromURI(gEditCard.abURI);
// if the directory is a mailing list we need to search all the mailing lists // if the directory is a mailing list we need to search all the mailing lists
// in the parent directory if the card exists. // in the parent directory if the card exists.
if (directory.isMailList) { if (directory.isMailList) {
var parentURI = GetParentDirectoryFromMailingListURI(editCard.abURI); var parentURI = GetParentDirectoryFromMailingListURI(gEditCard.abURI);
directory = GetDirectoryFromURI(parentURI); directory = GetDirectoryFromURI(parentURI);
} }
@ -196,14 +178,14 @@ function EditCardOKButton()
} }
} }
SetCardValues(editCard.card, document); SetCardValues(gEditCard.card, document);
editCard.card.editCardToDatabase(editCard.abURI); gEditCard.card.editCardToDatabase(gEditCard.abURI);
for (i=0; i<foundDirectoriesCount; i++) { for (i=0; i<foundDirectoriesCount; i++) {
// Update the addressLists item for this card // Update the addressLists item for this card
foundDirectories[i].directory.addressLists. foundDirectories[i].directory.addressLists.
SetElementAt(foundDirectories[i].index, editCard.card); SetElementAt(foundDirectories[i].index, gEditCard.card);
} }
NotifySaveListeners(); NotifySaveListeners();
@ -218,30 +200,31 @@ function OnLoadEditCard()
{ {
InitEditCard(); InitEditCard();
editCard.titleProperty = "editCardTitle"; gEditCard.titleProperty = "editCardTitle";
if (window.arguments && window.arguments[0]) if (window.arguments && window.arguments[0])
{ {
if ( window.arguments[0].card ) if ( window.arguments[0].card )
editCard.card = window.arguments[0].card; gEditCard.card = window.arguments[0].card;
if ( window.arguments[0].okCallback ) if ( window.arguments[0].okCallback )
gOkCallback = window.arguments[0].okCallback; gOkCallback = window.arguments[0].okCallback;
if ( window.arguments[0].abURI ) if ( window.arguments[0].abURI )
editCard.abURI = window.arguments[0].abURI; gEditCard.abURI = window.arguments[0].abURI;
} }
// set global state variables // set global state variables
// if first or last name entered, disable generateDisplayName // if first or last name entered, disable generateDisplayName
if ( editCard.generateDisplayName && (editCard.card.firstName.length + if (gEditCard.generateDisplayName &&
editCard.card.lastName.length + (gEditCard.card.firstName.length +
editCard.card.displayName.length > 0) ) gEditCard.card.lastName.length +
gEditCard.card.displayName.length > 0))
{ {
editCard.generateDisplayName = false; gEditCard.generateDisplayName = false;
} }
GetCardValues(editCard.card, document); GetCardValues(gEditCard.card, document);
SetCardDialogTitle(editCard.card.displayName); SetCardDialogTitle(gEditCard.card.displayName);
// check if selectedAB is a writeable // check if selectedAB is a writeable
// if not disable all the fields // if not disable all the fields
@ -280,7 +263,7 @@ function NotifySaveListeners()
if (gOnSaveListeners.length) { if (gOnSaveListeners.length) {
// the save listeners might have tweaked the card // the save listeners might have tweaked the card
// in which case we need to commit it. // in which case we need to commit it.
editCard.card.editCardToDatabase(editCard.abURI); gEditCard.card.editCardToDatabase(gEditCard.abURI);
} }
} }
@ -314,18 +297,20 @@ function InitEditCard()
InitPhoneticFields(); InitPhoneticFields();
gAddressBookBundle = document.getElementById("bundle_addressBook"); gAddressBookBundle = document.getElementById("bundle_addressBook");
// create editCard object that contains global variables for editCard.js // Create gEditCard object that contains global variables for the current js
editCard = new Object; // file.
gEditCard = new Object;
editCard.prefs = gPrefs; gEditCard.prefs = gPrefs;
// get specific prefs that editCard will need // get specific prefs that gEditCard will need
try { try {
var displayLastNameFirst = var displayLastNameFirst =
gPrefs.getComplexValue("mail.addr_book.displayName.lastnamefirst", gPrefs.getComplexValue("mail.addr_book.displayName.lastnamefirst",
Components.interfaces.nsIPrefLocalizedString).data; Components.interfaces.nsIPrefLocalizedString).data;
editCard.displayLastNameFirst = (displayLastNameFirst == "true"); gEditCard.displayLastNameFirst = (displayLastNameFirst == "true");
editCard.generateDisplayName = gPrefs.getBoolPref("mail.addr_book.displayName.autoGeneration"); gEditCard.generateDisplayName =
gPrefs.getBoolPref("mail.addr_book.displayName.autoGeneration");
} }
catch (ex) { catch (ex) {
dump("ex: failed to get pref" + ex + "\n"); dump("ex: failed to get pref" + ex + "\n");
@ -336,9 +321,9 @@ function NewCardOKButton()
{ {
if (gOkCallback) if (gOkCallback)
{ {
SetCardValues(editCard.card, document); SetCardValues(gEditCard.card, document);
var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook); var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook);
gOkCallback(addressbook.abCardToEscapedVCard(editCard.card)); gOkCallback(addressbook.abCardToEscapedVCard(gEditCard.card));
return true; // close the window return true; // close the window
} }
@ -353,17 +338,17 @@ function NewCardOKButton()
return false; // don't close window return false; // don't close window
// ----- // -----
if ( editCard.card ) if (gEditCard.card)
{ {
SetCardValues(editCard.card, document); SetCardValues(gEditCard.card, document);
var directory = GetDirectoryFromURI(uri); var directory = GetDirectoryFromURI(uri);
// replace editCard.card with the card we added // replace gEditCard.card with the card we added
// so that save listeners can get / set attributes on // so that save listeners can get / set attributes on
// the card that got created. // the card that got created.
var addedCard = directory.addCard(editCard.card); var addedCard = directory.addCard(gEditCard.card);
editCard.card = addedCard; gEditCard.card = addedCard;
NotifySaveListeners(); NotifySaveListeners();
} }
} }
@ -429,8 +414,9 @@ function GetCardValues(cardproperty, doc)
} }
} }
// when the ab card dialog is being loaded to show a vcard, hide the fields which aren't supported // when the ab card dialog is being loaded to show a vCard,
// by vcard so the user does not try to edit them. // hide the fields which aren't supported
// by vCard so the user does not try to edit them.
function HideNonVcardFields() function HideNonVcardFields()
{ {
document.getElementById('nickNameContainer').collapsed = true; document.getElementById('nickNameContainer').collapsed = true;
@ -514,19 +500,9 @@ function CleanUpWebPage(webPage)
return(webPage); return(webPage);
} }
function NewCardCancelButton()
{
top.window.close();
}
function EditCardCancelButton()
{
top.window.close();
}
function GenerateDisplayName() function GenerateDisplayName()
{ {
if ( editCard.generateDisplayName ) if (gEditCard.generateDisplayName)
{ {
var displayName; var displayName;
@ -535,10 +511,9 @@ function GenerateDisplayName()
var displayNameField = document.getElementById('DisplayName'); var displayNameField = document.getElementById('DisplayName');
if (lastNameField.value && firstNameField.value) { if (lastNameField.value && firstNameField.value) {
if ( editCard.displayLastNameFirst ) displayName = (gEditCard.displayLastNameFirst)
displayName = gAddressBookBundle.getFormattedString("lastFirstFormat",[ lastNameField.value, firstNameField.value ]); ? gAddressBookBundle.getFormattedString("lastFirstFormat", [lastNameField.value, firstNameField.value])
else : gAddressBookBundle.getFormattedString("firstLastFormat", [firstNameField.value, lastNameField.value]);
displayName = gAddressBookBundle.getFormattedString("firstLastFormat",[ firstNameField.value, lastNameField.value ]);
} }
else { else {
// one (or both) of these is empty, so this works. // one (or both) of these is empty, so this works.
@ -554,13 +529,14 @@ function GenerateDisplayName()
function DisplayNameChanged() function DisplayNameChanged()
{ {
// turn off generateDisplayName if the user changes the display name // turn off generateDisplayName if the user changes the display name
editCard.generateDisplayName = false; gEditCard.generateDisplayName = false;
var displayName = document.getElementById('DisplayName').value; SetCardDialogTitle(document.getElementById("DisplayName").value);
SetCardDialogTitle(displayName);
} }
function SetCardDialogTitle(displayName) function SetCardDialogTitle(displayName)
{ {
document.title = displayName ? gAddressBookBundle.getFormattedString(editCard.titleProperty + "WithDisplayName", [displayName]) : gAddressBookBundle.getString(editCard.titleProperty); document.title = displayName
? gAddressBookBundle.getFormattedString(gEditCard.titleProperty + "WithDisplayName", [displayName])
: gAddressBookBundle.getString(gEditCard.titleProperty);
} }