Bug 233036 JavaScript strict warning: reference to undefined property window.arguments[0].QueryInterface p=gautheri@noos.fr r=me sr=bienvenu

This commit is contained in:
neil%parkwaycc.co.uk 2005-01-18 23:28:16 +00:00
parent 5c5490bfe4
commit d4c2713229

View File

@ -36,7 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
var editCard;
var gEditCard;
var gOnSaveListeners = new Array;
var gOkCallback = null;
var gAddressBookBundle;
@ -46,22 +46,19 @@ function OnLoadNewCard()
{
InitEditCard();
var cardproperty;
// if one is passed in, use it
try {
cardproperty = window.arguments[0].QueryInterface(Components.interfaces.nsIAbCard);
}
catch (ex) {
cardproperty = Components.classes["@mozilla.org/addressbook/cardproperty;1"].createInstance(Components.interfaces.nsIAbCard);
}
editCard.card = cardproperty;
editCard.titleProperty = "newCardTitle";
editCard.selectedAB = "";
gEditCard.card =
(("arguments" in window) && (window.arguments.length > 0) &&
(window.arguments[0] instanceof Components.interfaces.nsIAbCard))
? window.arguments[0]
: Components.classes["@mozilla.org/addressbook/cardproperty;1"]
.createInstance(Components.interfaces.nsIAbCard);
gEditCard.titleProperty = "newCardTitle";
gEditCard.selectedAB = "";
if ("arguments" in window && window.arguments[0])
{
gEditCard.selectedAB = kPersonalAddressbookURI;
if ("selectedAB" in window.arguments[0]) {
// check if selected ab is a mailing list
var abURI = window.arguments[0].selectedAB;
@ -69,40 +66,27 @@ function OnLoadNewCard()
var directory = GetDirectoryFromURI(abURI);
if (directory.isMailList) {
var parentURI = GetParentDirectoryFromMailingListURI(abURI);
if (parentURI) {
editCard.selectedAB = parentURI;
}
else {
// it's a mailing list, but we failed to determine the parent directory
// use the personal addressbook
editCard.selectedAB = kPersonalAddressbookURI;
}
if (parentURI)
gEditCard.selectedAB = parentURI;
}
else if (!(directory.operations & directory.opWrite)) {
editCard.selectedAB = kPersonalAddressbookURI;
}
else {
editCard.selectedAB = window.arguments[0].selectedAB;
}
}
else {
editCard.selectedAB = kPersonalAddressbookURI;
else if (directory.operations & directory.opWrite)
gEditCard.selectedAB = window.arguments[0].selectedAB;
}
// we may have been given properties to pre-initialize the window with....
// we'll fill these in here...
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]) {
editCard.card.displayName = window.arguments[0].displayName;
gEditCard.card.displayName = window.arguments[0].displayName;
// if we've got a display name, don't generate
// a display name (and stomp on the existing display name)
// when the user types a first or last name
if (editCard.card.displayName.length)
editCard.generateDisplayName = false;
if (gEditCard.card.displayName.length)
gEditCard.generateDisplayName = false;
}
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])
gOkCallback = window.arguments[0].okCallback;
@ -111,11 +95,12 @@ function OnLoadNewCard()
// hide non vcard values
HideNonVcardFields();
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])
editCard.titleProperty = window.arguments[0].titleProperty;
gEditCard.titleProperty = window.arguments[0].titleProperty;
if ("hideABPicker" in window.arguments[0])
gHideABPicker = window.arguments[0].hideABPicker;
@ -123,7 +108,7 @@ function OnLoadNewCard()
// set popup with address book names
var abPopup = document.getElementById('abPopup');
abPopup.value = editCard.selectedAB || kPersonalAddressbookURI;
abPopup.value = gEditCard.selectedAB || kPersonalAddressbookURI;
if (gHideABPicker && abPopup) {
abPopup.hidden = true;
@ -131,19 +116,16 @@ function OnLoadNewCard()
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
// probably need to do the same in the addressing widget
// focus on first or last name based on the pref
var focus;
if (editCard.displayLastNameFirst)
focus = document.getElementById('LastName');
else
focus = document.getElementById('FirstName');
var focus = document.getElementById(gEditCard.displayLastNameFirst
? 'LastName' : 'FirstName');
if ( focus ) {
// XXX Using the setTimeout hack until bug 103197 is fixed
setTimeout( function(firstTextBox) { firstTextBox.focus(); }, 0, focus );
@ -158,7 +140,7 @@ function findCardIndex(directory)
var listCardsCount = directory.addressLists.Count();
for ( var i = 0; i < listCardsCount; i++ ) {
var card = directory.addressLists.QueryElementAt(i, Components.interfaces.nsIAbCard);
if (editCard.card.equals(card)) {
if (gEditCard.card.equals(card)) {
index = i;
break;
}
@ -172,12 +154,12 @@ function EditCardOKButton()
// See if this card is in any mailing list
// if so then we need to update the addresslists of those mailing lists
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
// in the parent directory if the card exists.
if (directory.isMailList) {
var parentURI = GetParentDirectoryFromMailingListURI(editCard.abURI);
var parentURI = GetParentDirectoryFromMailingListURI(gEditCard.abURI);
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++) {
// Update the addressLists item for this card
foundDirectories[i].directory.addressLists.
SetElementAt(foundDirectories[i].index, editCard.card);
SetElementAt(foundDirectories[i].index, gEditCard.card);
}
NotifySaveListeners();
@ -218,30 +200,31 @@ function OnLoadEditCard()
{
InitEditCard();
editCard.titleProperty = "editCardTitle";
gEditCard.titleProperty = "editCardTitle";
if (window.arguments && window.arguments[0])
{
if ( window.arguments[0].card )
editCard.card = window.arguments[0].card;
gEditCard.card = window.arguments[0].card;
if ( window.arguments[0].okCallback )
gOkCallback = window.arguments[0].okCallback;
if ( window.arguments[0].abURI )
editCard.abURI = window.arguments[0].abURI;
gEditCard.abURI = window.arguments[0].abURI;
}
// set global state variables
// if first or last name entered, disable generateDisplayName
if ( editCard.generateDisplayName && (editCard.card.firstName.length +
editCard.card.lastName.length +
editCard.card.displayName.length > 0) )
if (gEditCard.generateDisplayName &&
(gEditCard.card.firstName.length +
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
// if not disable all the fields
@ -280,7 +263,7 @@ function NotifySaveListeners()
if (gOnSaveListeners.length) {
// the save listeners might have tweaked the card
// 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();
gAddressBookBundle = document.getElementById("bundle_addressBook");
// create editCard object that contains global variables for editCard.js
editCard = new Object;
// Create gEditCard object that contains global variables for the current js
// 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 {
var displayLastNameFirst =
gPrefs.getComplexValue("mail.addr_book.displayName.lastnamefirst",
Components.interfaces.nsIPrefLocalizedString).data;
editCard.displayLastNameFirst = (displayLastNameFirst == "true");
editCard.generateDisplayName = gPrefs.getBoolPref("mail.addr_book.displayName.autoGeneration");
gEditCard.displayLastNameFirst = (displayLastNameFirst == "true");
gEditCard.generateDisplayName =
gPrefs.getBoolPref("mail.addr_book.displayName.autoGeneration");
}
catch (ex) {
dump("ex: failed to get pref" + ex + "\n");
@ -336,9 +321,9 @@ function NewCardOKButton()
{
if (gOkCallback)
{
SetCardValues(editCard.card, document);
SetCardValues(gEditCard.card, document);
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
}
@ -353,17 +338,17 @@ function NewCardOKButton()
return false; // don't close window
// -----
if ( editCard.card )
if (gEditCard.card)
{
SetCardValues(editCard.card, document);
SetCardValues(gEditCard.card, document);
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
// the card that got created.
var addedCard = directory.addCard(editCard.card);
editCard.card = addedCard;
var addedCard = directory.addCard(gEditCard.card);
gEditCard.card = addedCard;
NotifySaveListeners();
}
}
@ -518,7 +503,7 @@ function CleanUpWebPage(webPage)
function GenerateDisplayName()
{
if ( editCard.generateDisplayName )
if (gEditCard.generateDisplayName)
{
var displayName;
@ -527,10 +512,9 @@ function GenerateDisplayName()
var displayNameField = document.getElementById('DisplayName');
if (lastNameField.value && firstNameField.value) {
if ( editCard.displayLastNameFirst )
displayName = gAddressBookBundle.getFormattedString("lastFirstFormat",[ lastNameField.value, firstNameField.value ]);
else
displayName = gAddressBookBundle.getFormattedString("firstLastFormat",[ firstNameField.value, lastNameField.value ]);
displayName = (gEditCard.displayLastNameFirst)
? gAddressBookBundle.getFormattedString("lastFirstFormat", [ lastNameField.value, firstNameField.value ])
: gAddressBookBundle.getFormattedString("firstLastFormat", [ firstNameField.value, lastNameField.value ]);
}
else {
// one (or both) of these is empty, so this works.
@ -546,14 +530,14 @@ function GenerateDisplayName()
function DisplayNameChanged()
{
// turn off generateDisplayName if the user changes the display name
editCard.generateDisplayName = false;
gEditCard.generateDisplayName = false;
var displayName = document.getElementById('DisplayName').value;
SetCardDialogTitle(displayName);
SetCardDialogTitle(document.getElementById('DisplayName').value);
}
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);
}