Bug 733535 - fix 'cards[i] is null' by making GetSelectedAbCards only return non-null cards. r=mconley, a=mkmelin landing on CLOSED TREE for seamonkey
This commit is contained in:
Родитель
59a0bea758
Коммит
fea357b482
|
@ -1,3 +1,5 @@
|
|||
/* -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 ; js-indent-level: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
@ -384,26 +386,28 @@ function GetSelectedAddressesFromDirTree()
|
|||
return addresses;
|
||||
}
|
||||
|
||||
// Generate a comma separated list of addresses from a given
|
||||
// set of cards.
|
||||
// Generate a comma separated list of addresses from a given set of
|
||||
// cards.
|
||||
function GetAddressesForCards(cards)
|
||||
{
|
||||
var addresses = "";
|
||||
|
||||
if (!cards)
|
||||
if (!cards) {
|
||||
Components.utils.reportError("GetAddressesForCards: |cards| is null.");
|
||||
return addresses;
|
||||
}
|
||||
|
||||
var count = cards.length;
|
||||
if (count > 0)
|
||||
addresses += GenerateAddressFromCard(cards[0]);
|
||||
|
||||
for (var i = 1; i < count; i++) {
|
||||
var generatedAddress = GenerateAddressFromCard(cards[i]);
|
||||
// We do not handle the case where there is one or more null-ish
|
||||
// element in the Array. Always non-null element is pushed into
|
||||
// cards[] array.
|
||||
|
||||
if (generatedAddress)
|
||||
addresses += "," + generatedAddress;
|
||||
}
|
||||
return addresses;
|
||||
let generatedAddresses = cards.map(GenerateAddressFromCard)
|
||||
.filter(function(aAddress) {
|
||||
return aAddress;
|
||||
});
|
||||
return generatedAddresses.join(',');
|
||||
}
|
||||
|
||||
function SelectFirstAddressBook()
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 ; js-indent-level: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
@ -41,7 +43,7 @@ function addSelectedAddresses(recipientType)
|
|||
var count = cards.length;
|
||||
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
// turn each card into a properly formatted address
|
||||
var address = GenerateAddressFromCard(cards[i]);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 ; js-indent-level: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
@ -289,8 +291,15 @@ function UpdateCardView()
|
|||
{
|
||||
var cards = GetSelectedAbCards();
|
||||
|
||||
if (!cards) {
|
||||
ClearCardViewPane();
|
||||
return;
|
||||
}
|
||||
|
||||
// display the selected card, if exactly one card is selected.
|
||||
// either no cards, or more than one card is selected, clear the pane.
|
||||
// We do not need to check cards[0] any more since GetSelectedAbCards() only
|
||||
// push non-null entity to the list.
|
||||
if (cards.length == 1)
|
||||
OnClickedCard(cards[0])
|
||||
else
|
||||
|
@ -455,7 +464,7 @@ function SetStatusText(total)
|
|||
gStatusText.setAttribute("label", statusText);
|
||||
}
|
||||
catch(ex) {
|
||||
dump("failed to set status text: " + ex + "\n");
|
||||
Components.utils.reportError("ERROR: failed to set status text: " + ex );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -533,7 +542,7 @@ function SwitchPaneFocus(event)
|
|||
dirTree.focus();
|
||||
else if (focusedElement != cardViewBox && !IsCardViewAndAbResultsPaneSplitterCollapsed())
|
||||
{
|
||||
if(cardViewBoxEmail1)
|
||||
if (cardViewBoxEmail1)
|
||||
cardViewBoxEmail1.focus();
|
||||
else
|
||||
cardViewBox.focus();
|
||||
|
@ -547,7 +556,7 @@ function SwitchPaneFocus(event)
|
|||
gAbResultsTree.focus();
|
||||
else if (focusedElement == gAbResultsTree && !IsCardViewAndAbResultsPaneSplitterCollapsed())
|
||||
{
|
||||
if(cardViewBoxEmail1)
|
||||
if (cardViewBoxEmail1)
|
||||
cardViewBoxEmail1.focus();
|
||||
else
|
||||
cardViewBox.focus();
|
||||
|
@ -572,10 +581,10 @@ function WhichPaneHasFocus()
|
|||
{
|
||||
var nodeId = currentNode.getAttribute('id');
|
||||
|
||||
if(currentNode == gAbResultsTree ||
|
||||
currentNode == cardViewBox ||
|
||||
currentNode == searchBox ||
|
||||
currentNode == dirTree)
|
||||
if (currentNode == gAbResultsTree ||
|
||||
currentNode == cardViewBox ||
|
||||
currentNode == searchBox ||
|
||||
currentNode == dirTree)
|
||||
return currentNode;
|
||||
|
||||
currentNode = currentNode.parentNode;
|
||||
|
@ -643,15 +652,24 @@ function AbIMSelected()
|
|||
{
|
||||
let cards = GetSelectedAbCards();
|
||||
|
||||
if (!cards) {
|
||||
Components.utils.reportError("ERROR: AbIMSelected: |cards| is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (cards.length != 1) {
|
||||
Components.utils.reportError("AbIMSelected should only be called when 1"
|
||||
+ " card is selected. There are " + cards.length
|
||||
+ " cards selected.");
|
||||
Components.utils.reportError("AbIMSelected should only be called when 1" +
|
||||
" card is selected. There are " +
|
||||
cards.length + " cards selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
let card = cards[0];
|
||||
|
||||
if (!card) {
|
||||
Components.utils.reportError("AbIMSelected: one card was selected, but its only member was null.");
|
||||
return;
|
||||
}
|
||||
// We want to open a conversation with the first online username that we can
|
||||
// find. Failing that, we'll take the first offline (but still chat-able)
|
||||
// username we can find.
|
||||
|
@ -771,6 +789,8 @@ let abResultsController = {
|
|||
return false;
|
||||
|
||||
let selectedCard = selected[0];
|
||||
if (!selectedCard)
|
||||
return false;
|
||||
|
||||
let isIMContact = kChatProperties.some(function(aProperty) {
|
||||
let contactName = selectedCard.getProperty(aProperty, "");
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 ; js-indent-level: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
@ -13,7 +15,7 @@
|
|||
* Is called when a card is to be edited, with the card as the parameter.
|
||||
*
|
||||
* The following function is only required if ResultsPaneController is used:
|
||||
*
|
||||
*
|
||||
* goSetMenuValue()
|
||||
* Core function in globalOverlay.js
|
||||
*/
|
||||
|
@ -111,21 +113,24 @@ function GetNumSelectedCards()
|
|||
function GetSelectedCardTypes()
|
||||
{
|
||||
var cards = GetSelectedAbCards();
|
||||
if (!cards)
|
||||
if (!cards) {
|
||||
Components.utils.reportError("ERROR: GetSelectedCardTypes: |cards| is null.");
|
||||
return kNothingSelected; // no view
|
||||
|
||||
}
|
||||
var count = cards.length;
|
||||
if (count == 0)
|
||||
return kNothingSelected; // nothing selected
|
||||
|
||||
var mailingListCnt = 0;
|
||||
var cardCnt = 0;
|
||||
for (var i = 0; i < count; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
// We can assume no values from GetSelectedAbCards will be null.
|
||||
if (cards[i].isMailList)
|
||||
mailingListCnt++;
|
||||
else
|
||||
cardCnt++;
|
||||
}
|
||||
|
||||
return (mailingListCnt == 0) ? kCardsOnly :
|
||||
(cardCnt > 0) ? kListsAndCards :
|
||||
(mailingListCnt == 1) ? kSingleListOnly :
|
||||
|
@ -157,6 +162,11 @@ function GetSelectedCard()
|
|||
return (index == -1) ? null : gAbView.getCardFromRow(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a (possibly empty) list of cards
|
||||
*
|
||||
* It pushes only non-null/empty element, if any, into the returned list.
|
||||
*/
|
||||
function GetSelectedAbCards()
|
||||
{
|
||||
var abView = gAbView;
|
||||
|
@ -165,26 +175,32 @@ function GetSelectedAbCards()
|
|||
// then use the ab view from sidebar (gCurFrame is from sidebarOverlay.js)
|
||||
if (document.getElementById("sidebar-box")) {
|
||||
const abPanelUrl =
|
||||
"chrome://messenger/content/addressbook/addressbook-panel.xul";
|
||||
if (gCurFrame &&
|
||||
"chrome://messenger/content/addressbook/addressbook-panel.xul";
|
||||
if (gCurFrame &&
|
||||
gCurFrame.getAttribute("src") == abPanelUrl &&
|
||||
document.commandDispatcher.focusedWindow == gCurFrame.contentDocument.defaultView)
|
||||
abView = gCurFrame.contentDocument.defaultView.gAbView;
|
||||
}
|
||||
|
||||
if (!abView)
|
||||
return null;
|
||||
return [];
|
||||
|
||||
var cards = new Array(abView.selection.count);
|
||||
var i, j;
|
||||
let cards = [];
|
||||
var count = abView.selection.getRangeCount();
|
||||
var current = 0;
|
||||
for (i = 0; i < count; ++i) {
|
||||
var start = new Object;
|
||||
var end = new Object;
|
||||
abView.selection.getRangeAt(i,start,end);
|
||||
for (j = start.value; j <= end.value; ++j)
|
||||
cards[current++] = abView.getCardFromRow(j);
|
||||
for (let i = 0; i < count; ++i) {
|
||||
let start = {};
|
||||
let end = {};
|
||||
|
||||
abView.selection.getRangeAt(i, start, end);
|
||||
|
||||
for (let j = start.value; j <= end.value; ++j) {
|
||||
// avoid inserting null element into the list. GetRangeAt() may be buggy.
|
||||
let tmp = abView.getCardFromRow(j);
|
||||
if (tmp) {
|
||||
cards.push(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
@ -200,13 +216,12 @@ function GetSelectedRows()
|
|||
if (!gAbView)
|
||||
return selectedRows;
|
||||
|
||||
var i, j;
|
||||
var rangeCount = gAbView.selection.getRangeCount();
|
||||
for (i = 0; i < rangeCount; ++i) {
|
||||
for (let i = 0; i < rangeCount; ++i) {
|
||||
var start = new Object;
|
||||
var end = new Object;
|
||||
gAbView.selection.getRangeAt(i, start, end);
|
||||
for (j = start.value;j <= end.value; ++j) {
|
||||
for (let j = start.value;j <= end.value; ++j) {
|
||||
if (selectedRows)
|
||||
selectedRows += ",";
|
||||
selectedRows += j;
|
||||
|
|
Загрузка…
Ссылка в новой задаче