Update to code that creates the display name as the first and last names are entered in the edit card dialog

This commit is contained in:
hangas%netscape.com 1999-07-15 02:27:53 +00:00
Родитель b74c420bfb
Коммит dfc7233f2b
2 изменённых файлов: 106 добавлений и 84 удалений

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

@ -1,40 +1,73 @@
var card;
var newCard = -1;
var okCallback;
var abURI;
var editCard;
var editCardTitlePrefix = "Card for ";
function OnLoadNewCard()
{
top.card = newCard;
top.okCallback = 0;
InitEditCard();
editCard.card = 0;
editCard.okCallback = 0;
editCard.generateDisplayName = true;
if (window.arguments && window.arguments[0])
{
if ( window.arguments[0].abURI )
top.abURI = window.arguments[0].abURI;
editCard.abURI = window.arguments[0].abURI;
}
}
function OnLoadEditCard()
{
InitEditCard();
// look in arguments[0] for card
if (window.arguments && window.arguments[0])
{
if ( window.arguments[0].card )
top.card = window.arguments[0].card;
editCard.card = window.arguments[0].card;
if ( window.arguments[0].okCallback )
top.okCallback = window.arguments[0].okCallback;
editCard.okCallback = window.arguments[0].okCallback;
if ( window.arguments[0].abURI )
top.abURI = window.arguments[0].abURI;
editCard.abURI = window.arguments[0].abURI;
}
GetCardValues(top.card, frames["editcard"].document);
// set global state variables
// if first or last name entered, disable generateDisplayName
editCard.generateDisplayName = (editCard.card.FirstName.length +
editCard.card.LastName.length +
editCard.card.DisplayName.length == 0)
GetCardValues(editCard.card, frames["editcard"].document);
//top.window.setAttribute('title', editCardTitlePrefix + top.card.DisplayName);
//top.window.setAttribute('title', editCardTitlePrefix + editCard.card.DisplayName);
}
function InitEditCard()
{
// create editCard object that contains global variables for editCard.js
editCard = new Object;
// get pointer to nsIPref object
var prefs = Components.classes["component://netscape/preferences"];
if ( prefs )
{
prefs = prefs.getService();
if ( prefs )
{
prefs = prefs.QueryInterface(Components.interfaces.nsIPref);
editCard.prefs = prefs;
}
}
// get specific prefs that editCard will need
if ( prefs )
{
editCard.displayLastNameFirst = prefs.GetBoolPref("mail.addr_book.lastnamefirst");
editCard.displayLastNameFirst = true;//this is a test XXXXXXXXXXX this is only a test
}
}
function NewCardOKButton()
{
@ -46,7 +79,7 @@ function NewCardOKButton()
{
SetCardValues(cardproperty, frames["editcard"].document);
cardproperty.AddCardToDatabase();// Candice pass top.abURI this is the var containing GetResultTreeDirectory()
cardproperty.AddCardToDatabase();// Candice pass editCard.abURI this is the var containing GetResultTreeDirectory()
}
top.window.close();
@ -55,13 +88,13 @@ function NewCardOKButton()
function EditCardOKButton()
{
SetCardValues(top.card, frames["editcard"].document);
SetCardValues(editCard.card, frames["editcard"].document);
top.card.EditCardToDatabase();// Candice pass top.abURI this is the var containing GetResultTreeDirectory()
editCard.card.EditCardToDatabase();// Candice pass editCard.abURI this is the var containing GetResultTreeDirectory()
// callback to allow caller to update
if ( top.okCallback )
top.okCallback();
if ( editCard.okCallback )
editCard.okCallback();
top.window.close();
}
@ -173,3 +206,47 @@ function EditCardCancelButton()
top.window.close();
}
function GenerateDisplayName()
{
if ( editCard.generateDisplayName )
{
var doc = frames["editcard"].document;
var firstNameField = doc.getElementById('FirstName');
var lastNameField = doc.getElementById('LastName');
var displayNameField = doc.getElementById('DisplayName');
/* todo: i18N work todo here */
/* this used to be XP_GetString(MK_ADDR_FIRST_LAST_SEP) */
/* todo: mscott says there was a pref in 4.5 that would */
/* cause GenerateDisplayName() to do nothing. */
/* the i18N people need it. */
/* find the pref and heed it. */
/* trying to be smart about no using the first last sep */
/* if first or last is missing */
/* todo: is this i18N safe? */
var separator = "";
if ( lastNameField.value && firstNameField.value )
{
if ( editCard.displayLastNameFirst )
separator = ", ";
else
separator = " ";
}
if ( editCard.displayLastNameFirst )
displayNameField.value = lastNameField.value + separator + firstNameField.value;
else
displayNameField.value = firstNameField.value + separator + lastNameField.value;
}
}
function DisplayNameChanged()
{
// turn off generateDisplayName if the user changes the display name
editCard.generateDisplayName = false;
}

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

@ -5,32 +5,32 @@
<!DOCTYPE window
[
<!-- Labels -->
<!ENTITY Name.tab "Name">
<!ENTITY Name.box "Name">
<!ENTITY Name.tab "Name">
<!ENTITY Name.box "Name">
<!ENTITY FirstName.label "First:">
<!ENTITY LastName.label "Last:">
<!ENTITY DisplayName.label "Display:">
<!ENTITY NickName.label "Nickname:">
<!ENTITY Internet.box "Internet">
<!ENTITY Internet.box "Internet">
<!ENTITY PrimaryEmail.label "* Primary email:">
<!ENTITY SecondEmail.label "Secondary email:">
<!ENTITY SendPlainText.label "Send email as plain text (no html)">
<!ENTITY Phones.box "Phones">
<!ENTITY Phones.box "Phones">
<!ENTITY WorkPhone.label "Work:">
<!ENTITY HomePhone.label "Home:">
<!ENTITY FaxNumber.label "Fax:">
<!ENTITY PagerNumber.label "Pager:">
<!ENTITY CellularNumber.label "Cellular:">
<!ENTITY Address.tab "Address">
<!ENTITY Home.box "Home">
<!ENTITY Address.tab "Address">
<!ENTITY Home.box "Home">
<!ENTITY HomeAddress.label "Address:">
<!ENTITY HomeAddress2.label "">
<!ENTITY HomeCity.label "City:">
<!ENTITY HomeState.label "State:">
<!ENTITY HomeZipCode.label "Zip:">
<!ENTITY HomeCountry.label "Country:">
<!ENTITY Work.box "Work">
<!ENTITY Work.box "Work">
<!ENTITY JobTitle.label "Title:">
<!ENTITY Department.label "Department:">
<!ENTITY Company.label "Company:">
@ -43,12 +43,12 @@
<!ENTITY Web.box "Web">
<!ENTITY WebPage1.label "Page:">
<!ENTITY Other.tab "Other">
<!ENTITY Other.tab "Other">
<!ENTITY Custom1.label "Custom 1:">
<!ENTITY Custom2.label "Custom 2:">
<!ENTITY Custom3.label "Custom 3:">
<!ENTITY Custom4.label "Custom 4:">
<!ENTITY Notes.box "Notes">
<!ENTITY Notes.box "Notes">
]>
<window xmlns:html="http://www.w3.org/TR/REC-html40"
@ -56,61 +56,6 @@
style="height:100%; width:100%; border:none"
align="vertical">
<html:script language="JavaScript">
var pref;
var prefInitialized = false;
var lastFirst = false;
function GenerateDisplayName()
{
/* see AB_GenerateDisplayName in http://lxr.mcom.com/nova/source/ns/lib/libaddr/abglue.cpp for the proper logic */
var firstNameField = document.getElementById('FirstName');
var lastNameField = document.getElementById('LastName');
var displayNameField = document.getElementById('DisplayName');
/* todo: i18N work todo here */
/* this used to be XP_GetString(MK_ADDR_FIRST_LAST_SEP) */
var firstLastSep = " ";
if (!prefInitialized) {
pref = Components.classes['component://netscape/preferences'];
if (pref) {
pref = pref.getService();
}
if (pref) {
pref = pref.QueryInterface(Components.interfaces.nsIPref);
}
if (pref) {
lastFirst = pref.GetBoolPref("mail.addr_book.lastnamefirst");
}
prefInitialized = true;
}
/* todo: mscott says there was a pref in 4.5 that would */
/* cause GenerateDisplayName() to do nothing. */
/* the i18N people need it. */
/* find the pref and heed it. */
/* trying to be smart about no using the first last sep */
/* if first or last is missing */
/* todo: is this i18N safe? */
if ((lastNameField.value == "") || (firstNameField.value == "")) {
firstLastSep = "";
}
if (lastFirst) {
displayNameField.value = lastNameField.value + firstLastSep + firstNameField.value;
}
else {
displayNameField.value = firstNameField.value + firstLastSep + lastNameField.value;
}
}
</html:script>
<tabcontrol align="vertical" style="margin:5px">
<tabbox align="horizontal">
<tab>&Name.tab;</tab>
@ -132,17 +77,17 @@ function GenerateDisplayName()
<box align="horizontal" flex="100%">
<spring flex="100%"/>
<html:label for="FirstName">&FirstName.label;</html:label>
<html:input type="text" id="FirstName" class="CardEdit" onkeyup="GenerateDisplayName();" />
<html:input type="text" id="FirstName" class="CardEdit" onkeypress="top.GenerateDisplayName()" />
</box>
<box align="horizontal">
<spring flex="100%"/>
<html:label for="LastName">&LastName.label;</html:label>
<html:input id="LastName" type="text" class="CardEdit" onkeyup="GenerateDisplayName();"/>
<html:input id="LastName" type="text" class="CardEdit" onkeypress="top.GenerateDisplayName()"/>
</box>
<box align="horizontal">
<spring flex="100%"/>
<html:label for="DisplayName">&DisplayName.label;</html:label>
<html:input id="DisplayName" type="text" class="CardEdit"/>
<html:input id="DisplayName" type="text" class="CardEdit" onkeypress="top.DisplayNameChanged()"/>
</box>
<box align="horizontal">
<spring flex="100%"/>