abcardoverlay.js
来自「现在很火的邮件客户端软件thunderbird的源码」· JavaScript 代码 · 共 597 行 · 第 1/2 页
JS
597 行
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */# ***** BEGIN LICENSE BLOCK *****# Version: MPL 1.1/GPL 2.0/LGPL 2.1## The contents of this file are subject to the Mozilla Public License Version# 1.1 (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at# http://www.mozilla.org/MPL/## Software distributed under the License is distributed on an "AS IS" basis,# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License# for the specific language governing rights and limitations under the# License.## The Original Code is mozilla.org code.## The Initial Developer of the Original Code is# Netscape Communications Corporation.# Portions created by the Initial Developer are Copyright (C) 1998# the Initial Developer. All Rights Reserved.## Contributor(s):# Seth Spitzer <sspitzer@netscape.com>## Alternatively, the contents of this file may be used under the terms of# either the GNU General Public License Version 2 or later (the "GPL"), or# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),# in which case the provisions of the GPL or the LGPL are applicable instead# of those above. If you wish to allow use of your version of this file only# under the terms of either the GPL or the LGPL, and not to allow others to# use your version of this file under the terms of the MPL, indicate your# decision by deleting the provisions above and replace them with the notice# and other provisions required by the GPL or the LGPL. If you do not delete# the provisions above, a recipient may use your version of this file under# the terms of any one of the MPL, the GPL or the LGPL.## ***** END LICENSE BLOCK *****const kNonVcardFields = ["nickNameContainer", "secondaryEmailContainer", "screenNameContainer", "homeAddressGroup", "customFields", "allowRemoteContent"];const kPhoneticFields = ["PhoneticLastName", "PhoneticLabel1", "PhoneticSpacer1", "PhoneticFirstName", "PhoneticLabel2", "PhoneticSpacer2"];// Item is |[dialogField, cardProperty]|.const kVcardFields = [ // Contact > Name ["FirstName", "firstName"], ["LastName", "lastName"], ["DisplayName", "displayName"], ["NickName", "nickName"], // Contact > Internet ["PrimaryEmail", "primaryEmail"], ["SecondEmail", "secondEmail"], ["ScreenName", "aimScreenName"], // NB: AIM. // Contact > Phones ["WorkPhone", "workPhone"], ["HomePhone", "homePhone"], ["FaxNumber", "faxNumber"], ["PagerNumber", "pagerNumber"], ["CellularNumber", "cellularNumber"], // Address > Home ["HomeAddress", "homeAddress"], ["HomeAddress2", "homeAddress2"], ["HomeCity", "homeCity"], ["HomeState", "homeState"], ["HomeZipCode", "homeZipCode"], ["HomeCountry", "homeCountry"], ["WebPage2", "webPage2"], // Address > Work ["JobTitle", "jobTitle"], ["Department", "department"], ["Company", "company"], ["WorkAddress", "workAddress"], ["WorkAddress2", "workAddress2"], ["WorkCity", "workCity"], ["WorkState", "workState"], ["WorkZipCode", "workZipCode"], ["WorkCountry", "workCountry"], ["WebPage1", "webPage1"], // Other > (custom) ["Custom1", "custom1"], ["Custom2", "custom2"], ["Custom3", "custom3"], ["Custom4", "custom4"], // Other > Notes ["Notes", "notes"]];var gEditCard;var gOnSaveListeners = new Array();var gOkCallback = null;var gAddressBookBundle;var gHideABPicker = false;function OnLoadNewCard(){ InitEditCard(); 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; var directory = GetDirectoryFromURI(abURI); if (directory.isMailList) { var parentURI = GetParentDirectoryFromMailingListURI(abURI); if (parentURI) gEditCard.selectedAB = parentURI; } 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]) gEditCard.card.primaryEmail = window.arguments[0].primaryEmail; if ("displayName" in window.arguments[0]) { 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 (gEditCard.card.displayName.length) gEditCard.generateDisplayName = false; } if ("aimScreenName" in window.arguments[0]) gEditCard.card.aimScreenName = window.arguments[0].aimScreenName; if ("allowRemoteContent" in window.arguments[0]) { gEditCard.card.allowRemoteContent = window.arguments[0].allowRemoteContent; window.arguments[0].allowRemoteContent = false; } if ("okCallback" in window.arguments[0]) gOkCallback = window.arguments[0].okCallback; if ("escapedVCardStr" in window.arguments[0]) { // hide non vcard values HideNonVcardFields(); gEditCard.card = Components.classes["@mozilla.org/addressbook;1"] .createInstance(Components.interfaces.nsIAddressBook) .escapedVCardToAbCard(window.arguments[0].escapedVCardStr); } if ("titleProperty" in window.arguments[0]) gEditCard.titleProperty = window.arguments[0].titleProperty; if ("hideABPicker" in window.arguments[0]) gHideABPicker = window.arguments[0].hideABPicker; } // set popup with address book names var abPopup = document.getElementById('abPopup'); abPopup.value = gEditCard.selectedAB || kPersonalAddressbookURI; if (gHideABPicker && abPopup) { abPopup.hidden = true; document.getElementById("abPopupLabel").hidden = true; } SetCardDialogTitle(gEditCard.card.displayName); 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 = 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 ); } moveToAlertPosition();}// @Returns The index in addressLists for the card that is being saved;// or |-1| if the card is not found.function findCardIndex(directory){ var i = directory.addressLists.Count(); while (i-- > 0) { var card = directory.addressLists.QueryElementAt(i, Components.interfaces.nsIAbCard); if (gEditCard.card.equals(card)) break; } return i;}function EditCardOKButton(){ if (!CheckCardRequiredDataPresence(document)) return false; // don't close window // 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(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(gEditCard.abURI); directory = GetDirectoryFromURI(parentURI); } var listDirectoriesCount = directory.addressLists.Count(); var foundDirectories = new Array(); var foundDirectoriesCount = 0; var i; // create a list of mailing lists and the index where the card is at. for ( i=0; i < listDirectoriesCount; i++ ) { var subdirectory = directory.addressLists.QueryElementAt(i, Components.interfaces.nsIAbDirectory); index = findCardIndex(subdirectory); if (index > -1) { foundDirectories[foundDirectoriesCount] = {directory:subdirectory, index:index}; foundDirectoriesCount++; } } CheckAndSetCardValues(gEditCard.card, document, false); 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, gEditCard.card); } NotifySaveListeners(); // callback to allow caller to update if (gOkCallback) gOkCallback(); return true; // close the window}function OnLoadEditCard(){ InitEditCard(); gEditCard.titleProperty = "editCardTitle"; if (window.arguments && window.arguments[0]) { if ( 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 ) gEditCard.abURI = window.arguments[0].abURI; } // set global state variables // if first or last name entered, disable generateDisplayName if (gEditCard.generateDisplayName && (gEditCard.card.firstName.length + gEditCard.card.lastName.length + gEditCard.card.displayName.length > 0)) { gEditCard.generateDisplayName = false; } GetCardValues(gEditCard.card, document); SetCardDialogTitle(gEditCard.card.displayName); // check if selectedAB is a writeable // if not disable all the fields if ("arguments" in window && window.arguments[0]) { if ("abURI" in window.arguments[0]) { var abURI = window.arguments[0].abURI; var directory = GetDirectoryFromURI(abURI); if (!(directory.operations & directory.opWrite)) { // Set all the editable vcard fields to read only for (var i = kVcardFields.length; i-- > 0; ) document.getElementById(kVcardFields[i][0]).readOnly = true;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?