From 1d7452f4e73cbf59bd9780e4e8db19d28383e71e Mon Sep 17 00:00:00 2001 From: "cavin%netscape.com" Date: Wed, 19 Mar 2003 21:32:48 +0000 Subject: [PATCH] Fix for 197773. Prompt users for deleting mailing lists from the results pane. r/sr=sspitzer. --- .../addrbook/resources/content/abCommon.js | 59 ++++++++++++++++++- .../locale/en-US/addressBook.properties | 2 + 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/mailnews/addrbook/resources/content/abCommon.js b/mailnews/addrbook/resources/content/abCommon.js index e730e0155d1..2b4ef1598c2 100644 --- a/mailnews/addrbook/resources/content/abCommon.js +++ b/mailnews/addrbook/resources/content/abCommon.js @@ -53,6 +53,13 @@ const kDefaultDescending = "descending"; const kPersonalAddressbookURI = "moz-abmdbdirectory://abook.mab"; const kCollectedAddressbookURI = "moz-abmdbdirectory://history.mab"; +// List/card selections in the results pane. +const kNothingSelected = 0; +const kListsAndCards = 1; +const kMultipleListsOnly = 2; +const kSingleListOnly = 3; +const kCardsOnly = 4; + // Controller object for Results Pane var ResultsPaneController = { @@ -310,10 +317,58 @@ function SetupAbCommandUpdateHandlers() gAbResultsTree.controllers.appendController(ResultsPaneController); } +function GetSelectedCardTypes() +{ + var cards = GetSelectedAbCards(); + if (!cards) + return kNothingSelected; // no view + + var count = cards.length; + if (!count) + return kNothingSelected; // nothing selected + + var mailingListCnt = 0; + var cardCnt = 0; + for (var i = 0; i < count; i++) { + if (cards[i].isMailList) + mailingListCnt++; + else + cardCnt++; + } + if (mailingListCnt && cardCnt) + return kListsAndCards; // lists and cards selected + else if (mailingListCnt && !cardCnt) { + if (mailingListCnt > 1) + return kMultipleListsOnly; // only multiple mailing lists selected + else + return kSingleListOnly; // only single mailing list + } + else if (!mailingListCnt && cardCnt) + return kCardsOnly; // only card(s) selected +} + function AbDelete() { - if (gAbView) - gAbView.deleteSelectedCards(); + var types = GetSelectedCardTypes(); + if (types == kNothingSelected) + return; + + var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); + // If at least one mailing list is selected then prompt users for deletion. + if (types != kCardsOnly) + { + var confirmDeleteMessage; + if (types == kListsAndCards) + confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteListsAndCards"); + else if (types == kMultipleListsOnly) + confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteMailingLists"); + else + confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteMailingList"); + if (!promptService.confirm(window, null, confirmDeleteMessage)) + return; + } + + gAbView.deleteSelectedCards(); } function AbNewCard(abListItem) diff --git a/mailnews/addrbook/resources/locale/en-US/addressBook.properties b/mailnews/addrbook/resources/locale/en-US/addressBook.properties index 000ab002e76..782f8062776 100644 --- a/mailnews/addrbook/resources/locale/en-US/addressBook.properties +++ b/mailnews/addrbook/resources/locale/en-US/addressBook.properties @@ -38,6 +38,8 @@ cannotDeleteTitle=Delete Failed cannotDeleteMessage=You are not allowed to delete the Personal or Collected Addresses address books. confirmDeleteAddressbook=Are you sure you want to delete the selected address book? confirmDeleteMailingList=Are you sure you want to delete the selected mailing list? +confirmDeleteListsAndCards=Are you sure you want to delete the selected cards and mailing lists? +confirmDeleteMailingLists=Are you sure you want to delete the selected mailing lists? propertyPrimaryEmail=Email propertyListName=List Name