home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2005 December
/
PCWorld_2005-12_cd.bin
/
komunikace
/
netscape
/
nsb-install-8-0.exe
/
chrome
/
browser.jar
/
content
/
browser
/
manageEmailDialog.js
< prev
next >
Wrap
Text File
|
2005-09-26
|
29KB
|
848 lines
var PreSelectItem;
var webmail=window.opener.webmail;
function init(aEvent)
{
// if (aEvent.target != document)
// return;
fixElements();
EnableRemove();
}
function uninit(aEvent)
{
if (aEvent.target != document)
return;
}
function doCancel() {
// window.close();
removeInconsistentPrefs();
try {
webmail.fixMenus();
webmail.fixCustomAccountMenus();
} catch (ex) {
webmail.debug("Problem with fixMenus():\n"+ex);
}
return true;
}
function doOK() {
var listbox=document.getElementById("accountsListbox");
var myproviders=document.getElementById("webemailproviders");
// Set values for current item
var curItem = listbox.selectedItem;
curItem.setAttribute("provider",myproviders.selectedItem.id);
curItem.setAttribute("userid",document.getElementById("userid").value);
curItem.setAttribute("password",document.getElementById("password").value);
curItem.setAttribute("dispSep",document.getElementById("dispSep").checked);
curItem.setAttribute("autolog",document.getElementById("autolog").checked);
curItem.setAttribute("checkUpdates",document.getElementById("checkUpdates").checked);
curItem.setAttribute("emailfreq",document.getElementById("emailfreq").selectedItem.value);
curItem.setAttribute("notification",document.getElementById("notification").selectedItem.value);
curItem.setAttribute("otherDeck",document.getElementById("otherDeck").selectedIndex);
curItem.setAttribute("InboxURL",document.getElementById("InboxURL").value);
curItem.setAttribute("WriteURL",document.getElementById("WriteURL").value);
curItem.setAttribute("AddressURL",document.getElementById("AddressURL").value);
// Save all preferences
var item=listbox.getItemAtIndex(0);
while (item) {
// only save valid webmail accounts
if (isWebmailDataValid(item)) {
saveWebmailValues(item);
}
item = listbox.getNextItem(item,1);
}
// MERC - JCH: Remove any webmail prefs inconsistent with listbox values.
// And do it before menus are changed.
removeInconsistentPrefs();
try {
webmail.fixMenus();
webmail.fixCustomAccountMenus();
} catch (ex) {
webmail.debug("Problem with fixMenus():\n"+ex);
}
// window.close();
return true;
}
function setFromPrefs(aItem, aAccountName, aPref) {
try {
aItem.setAttribute(aPref,webmail.Prefs.getCharPref(aPref+"."+aAccountName));
} catch(ex) {}
}
function setWebmailValues(aItem,aAccountName) {
webmail.debug('setWebmailValues(..., '+aAccountName+')');
setFromPrefs(aItem,aAccountName,"provider");
var myProvider=aItem.getAttribute("provider");
if (!myProvider || myProvider == "") {
webmail.debug("provider is null, removing "+aAccountName);
var listbox=document.getElementById("accountsListbox");
listbox.removeItemAtIndex(listbox.getIndexOfItem(aItem));
return;
}
if (myProvider && myProvider == "webmail:other") {
aItem.setAttribute("otherDeck",1);
} else {
aItem.setAttribute("otherDeck",0);
}
//var fHost={ value: "" }
//var fUser={ value: "" }
//var fPassword={ value: "" }
var mKey="webmail:"+aAccountName;
var service = webmail.getServiceById(myProvider);
// MERC - JCH: Make sure service is defined. Defined services are found in webmail.rdf
if (service) {
var domain = service.passcarddomain;
var pc = window.opener.GetWebmailPasscard(domain, mKey);
if (pc) {
webmail.debug('Found a passcard for this account, un/pw = '+pc.user+'/'+pc.password);
aItem.setAttribute("userid", pc.user);
aItem.setAttribute("password", pc.password);
} else {
dump('\n\nWEBMAIL ERROR: Did not find passcard for mKey = '+mKey+'\n');
}
}
setFromPrefs(aItem,aAccountName,"dispSep");
setFromPrefs(aItem,aAccountName,"autolog");
setFromPrefs(aItem,aAccountName,"checkUpdates");
setFromPrefs(aItem,aAccountName,"emailfreq");
setFromPrefs(aItem,aAccountName,"notification");
setFromPrefs(aItem,aAccountName,"InboxURL");
setFromPrefs(aItem,aAccountName,"WriteURL");
setFromPrefs(aItem,aAccountName,"AddressURL");
}
function setPrefFromItem(aItem,aAccountName,aPref) {
webmail.Prefs.setCharPref(aPref+"."+aAccountName,aItem.getAttribute(aPref));
}
function saveWebmailValues(aItem) {
var accountName = aItem.label;
webmail.debug("saving " + accountName);
webmail.debug("\tstyle: " + aItem.getAttribute("style"));
if (aItem.getAttribute("style") == "font-weight: bold;") {
webmail.debug("attempting to set default to: "+accountName);
try {
webmail.Prefs.setCharPref("default",accountName);
} catch (ex) {
webmail.debug("set default failed:\n"+ex);
}
}
var mUserId=aItem.getAttribute("userid");
var mPassword=aItem.getAttribute("password");
if (mUserId.length > 0 && mPassword.length > 0) {
var mKey="webmail:"+accountName;
var fHost={ value: "" }
var fUser={ value: "" }
var fPassword={ value: "" }
var passwordManagerInternal = Components.classes["@mozilla.org/passwordmanager;1"].getService(Components.interfaces.nsIPasswordManagerInternal);
var passwordManager = Components.classes["@mozilla.org/passwordmanager;1"].getService(Components.interfaces.nsIPasswordManager);
var provider = aItem.getAttribute('provider');
webmail.debug('using provider: '+provider);
var service = webmail.getServiceById(provider);
var domain = service.passcarddomain;
var pc = window.opener.GetWebmailPasscard(domain, mKey);
if (pc) {
// There is an existing passcard, so toast it!!
webmail.debug(' - removing old passcard with mKey=['+mKey+'] and username='+pc.user);
try {
passwordManager.removeUser(domain, pc.user);
} catch (ex) {
}
}
var username = (service.passcardusername) ? service.passcardusername : 'userid';
var password = (service.passcardpassword) ? service.passcardpassword : 'password';
dump('\n\n\nAbout to save webmail passcard.\n');
dump(' - domain: '+domain+'\n');
dump(' - username: '+username+'\n');
dump(' - password: '+password+'\n');
dump("++++ JMC: addUserFull with domain: " + domain + ", mUserId : " + mUserId + ", mPassword: " + mPassword + ", mKey : " + mKey + "\t\t");
passwordManagerInternal.addUserFull(domain, mUserId, mPassword, username, password, mKey);
}
// MERC - JCH: Remove both built-in accounts and custom accounts
// if 'dispSep' unchecked.
if (aItem.getAttribute("dispSep") == "false") {
webmail.debug("attempting to remove menus");
webmail.removeMenus(aItem.getAttribute("origName"));
}
var myProvider=aItem.getAttribute("provider");
if (myProvider && myProvider != "webmail:other") {
setPrefFromItem(aItem,accountName,"provider");
setPrefFromItem(aItem,accountName,"dispSep");
setPrefFromItem(aItem,accountName,"autolog");
if (aItem.getAttribute("autolog") == 'true') {
webmail.setAutoLoginPref(accountName, service, true);
} else if (service) {
webmail.setAutoLoginPref(accountName, service, false);
}
setPrefFromItem(aItem,accountName,"checkUpdates");
setPrefFromItem(aItem,accountName,"emailfreq");
setPrefFromItem(aItem,accountName,"notification");
} else {
if (myProvider) {
setPrefFromItem(aItem,accountName,"provider");
setPrefFromItem(aItem,accountName,"InboxURL");
if (aItem.getAttribute("WriteURL") != "") {
setPrefFromItem(aItem,accountName,"WriteURL");
}
if (aItem.getAttribute("AddressURL") != "") {
setPrefFromItem(aItem,accountName,"AddressURL");
}
setPrefFromItem(aItem,accountName,"dispSep");
}
}
}
// MERC - JCH: Removes all webmail accounts in the prefs that are not in the listbox.
// This is to make sure the two are properly synced.
function removeInconsistentPrefs()
{
// Get all webmail accounts stored as prefs
var count = {value:0};
var prefAccounts = webmail.Prefs.getChildList("provider.", count);
// Define listbox vars
var listbox = document.getElementById("accountsListbox");
var item;
// For each webmail account in the prefs, check if it is among the listbox accounts.
// If it is not, delete it, otherwise do nothing.
var accountName;
var foundMatch;
for (var i=0; i<prefAccounts.length; i++)
{
// Get webmail account name from prefs
accountName = prefAccounts[i].substr(9);
// Get all listbox webmail accounts
foundMatch = false;
item = listbox.getItemAtIndex(0);
while (item)
{
if (item.label == accountName)
{
foundMatch = true;
// CDC hack - see if this should be added to toolbar currentset
/*
try {
if (item.hasAttribute('dispSep') &&
(item.getAttribute('dispSep')=='true'))
{
displaySeparately(accountName, item);
}
} catch (ex) { }
*/
break;
}
item = listbox.getNextItem(item,1);
}
// Pref account is not among the listbox accounts, so delete it
if (!foundMatch)
{
clearPref(accountName,"provider");
clearPref(accountName,"dispSep");
clearPref(accountName,"autolog");
clearPref(accountName,"checkUpdates");
clearPref(accountName,"emailfreq");
clearPref(accountName,"notification");
clearPref(accountName,"InboxURL");
clearPref(accountName,"WriteURL");
clearPref(accountName,"AddressURL");
webmail.removeMenus(accountName);
}
}
}
function displaySeparately(accountName, aItem)
{
// First find the webmail-button
var webmailBtn = window.opener.document.getElementById('webmail-button');
// Determine if this button is already displayed on a toolbar
var newId = 'webmail-toolbaritem-'+accountName;
dump('displaySeparately(): '+newId+'\n');
var toolbars = window.opener.document.getElementsByTagName('toolbar');
for (var i = 0; i < toolbars.length; i++) {
var toolbar = toolbars.item(i);
var currentSet = toolbar.currentSet.split(',');
for (var j = 0; j < currentSet.length; j++) {
if (currentSet[j] == newId) return;
}
}
toolbars = window.opener.document.getElementsByTagName('multibartray');
for (var i = 0; i < toolbars.length; i++) {
var toolbar = toolbars.item(i);
var currentSet = toolbar.currentSet.split(',');
for (var j = 0; j < currentSet.length; j++) {
if (currentSet[j] == newId) return;
}
}
dump(' - find toolbar\n');
// Find the toolbar that contains it
var toolbar = webmailBtn.parentNode;
while ((toolbar) &&
(toolbar.localName != 'toolbar') &&
(toolbar.localName != 'multibartray'))
{
toolbar = toolbar.parentNode;
}
if (!toolbar) {
throw "No toolbar found for webmail-button";
}
dump(' - add item\n');
// Add this new item to the currentSet for the toolbar
var currentSet = toolbar.currentSet.split(',');
var found = false;
for (var i = 0; i < currentSet.length; i++) {
if (currentSet[i] == 'webmail-button') {
currentSet[i] = 'webmail-button,'+newId;
found = true;
break;
}
}
if (!found) {
dump(' - adding item to END of toolbar\n');
var lastItem = currentSet[currentSet.length];
currentSet[currentSet.length] = lastItem+','+newId;
}
var newCurrentSet = currentSet.join(',');
dump(' ------ setting currentSetAtLoadTime to:'+newCurrentSet+'\n');
toolbar.currentSetAtLoadTime = newCurrentSet;
//toolbar.setAttribute('currentset', newCurrentSet);
dump(' -- NEW currentSetAtLoadTime = '+toolbar.currentSetAtLoadTime+'\n');
}
function fixElements()
{
// fix the providers dropdown box
var list=document.getElementById("webemailproviders");
var services=webmail.services;
var items=list.firstChild.childNodes;
var i;
for (i=0;i<services.length;i++){
list.insertItemAt(i,services[i].name,"");
items=list.firstChild.childNodes;
items[items.length-2].id=services[i].id;
items[items.length-2].setAttribute("oncommand","changeprovider(this);");
items[items.length-2].setAttribute("notify",services[i].notify);
items[items.length-2].setAttribute("username",services[i].username + ":");
}
list.selectedIndex=0;
// fix the listbox of defined webmail accounts
var listbox = document.getElementById("accountsListbox");
var citem;
var defaultWebmail;
if (webmail.Prefs.prefHasUserValue("default") &&
(webmail.Prefs.getPrefType("default") == webmail.Prefs.PREF_STRING))
{
defaultWebmail = webmail.Prefs.getCharPref("default");
webmail.debug("Default Webmail account="+defaultWebmail);
if (defaultWebmail != "") {
citem = listbox.getItemAtIndex(0);
citem.label = defaultWebmail;
citem.setAttribute("origName",defaultWebmail);
setWebmailValues(citem,defaultWebmail);
}
}
else
{
webmail.debug("No Default Webmail account set\n");
}
var firstitem=listbox.getItemAtIndex(0);
firstitem.setAttribute("style","font-weight:bold");
var childcount=Object();
try {
var myprefs=webmail.Prefs.getChildList("provider.",childcount);
myprefs.sort();
var i;
var newitem;
var accountName;
for (i=0; i<myprefs.length; i++){
accountName = myprefs[i].substr(9);
webmail.debug("found account: "+accountName);
var temp=null;
var doesExist = webmail.Prefs.getPrefType(myprefs[i]);
if (doesExist==webmail.Prefs.PREF_STRING && webmail.Prefs.prefHasUserValue(myprefs[i])) {
webmail.debug("attempting to getCharPref("+myprefs[i]+")");
temp = webmail.Prefs.getCharPref(myprefs[i]);
}
if (!temp || temp == "") {
webmail.debug("rejected as no provider");
continue;
}
//append an item to the list
if (accountName == defaultWebmail) {
webmail.debug("rejected as is default");
continue;
}
newitem = listbox.appendItem(accountName,"");
webmail.debug("added list item for "+accountName);
//set the information for the list item
newitem.setAttribute("origName",accountName);
setWebmailValues(newitem,accountName);
}
} catch (ex) {
webmail.debug("Error getting additional acocunts "+ex);
}
// deal with passed arguments
if (window.arguments && window.arguments.length > 0) {
webmail.debug("manageEmailDialog has arguments");
for (var i =0;i<window.arguments.length;i++){
webmail.debug("arguments["+i+"]="+window.arguments[i]);
}
if (window.arguments[0] == "_new") {
var list=document.getElementById("webemailproviders");
var tempitem=list.getElementsByAttribute("id","webmail:feed:netscape");
// var allchildren = list.firstChild.childNodes;
// webmail.debug("tempitem length="+tempitem.length+" listlength="+allchildren.length);
// for(var i=0;i<allchildren.length;i++) {
// webmail.debug("list["+i+"]="+allchildren[i].getAttribute("label")+", id="+allchildren[i].id);
// }
// MERC (RP) for aolblt bug #126325 adding a new account should default
// to saying "New Email Account" instead of "Netscape Mail"
//AddAccount(tempitem[0].getAttribute("label"));
var listbox=document.getElementById("accountsListbox");
// check to see if the first element is invalid, this is for the startup case
var item = listbox.getItemAtIndex(0);
if (!isWebmailDataValid(item)) {
// if the first item in the listbox is invalid, then create a new account
// but make the new account the default account
AddAccount("New Mail Account", true);
} else {
AddAccount("New Mail Account", false);
}
} else {
var found=false;
citem=listbox.getItemAtIndex(0);
while (citem) {
if (citem.label == window.arguments[0]) {
listbox.selectItem(citem);
found=true;
}
citem=listbox.getNextItem(citem,1);
}
if (!found) {
AddAccount(window.arguments[0], false);
}
}
}
if (!listbox.selectedItem) {
listbox.selectItem(firstitem);
}
document.getElementById("description").setAttribute("isNew","true");
}
function otherSelect() {
document.getElementById("otherDeck").selectedIndex=1;
}
function selectFirstAccount() {
var listbox=document.getElementById("accountsListbox");
var firstitem=listbox.getItemAtIndex(0);
listbox.selectItem(firstitem);
}
function AccountSelect(){
webmail.debug("AccountSelect() Called");
var mylist=document.getElementById("accountsListbox");
var myItem=mylist.selectedItem;
var accountName;
if (!(myItem)) {
//setTimeout("selectFirstAccount();",1);
return;
}
var newtext = myItem.label;
document.getElementById("acctDesc").value = newtext+":";
document.getElementById("description").value = newtext;
accountName = newtext;
// Save the current information to previously selected element
var myproviders = document.getElementById("webemailproviders");
if (PreSelectItem && PreSelectItem !== myItem) {
try {
mylist.getIndexOfItem(PreSelectItem);
webmail.debug("Previously selected item exists, continuing to set values");
PreSelectItem.setAttribute("provider",myproviders.selectedItem.id);
PreSelectItem.setAttribute("userid",document.getElementById("userid").value);
PreSelectItem.setAttribute("password",document.getElementById("password").value);
PreSelectItem.setAttribute("dispSep",document.getElementById("dispSep").checked);
PreSelectItem.setAttribute("dispSep2",document.getElementById("dispSep").checked);
PreSelectItem.setAttribute("autolog",document.getElementById("autolog").checked);
PreSelectItem.setAttribute("checkUpdates",document.getElementById("checkUpdates").checked);
PreSelectItem.setAttribute("emailfreq",document.getElementById("emailfreq").selectedItem.value);
PreSelectItem.setAttribute("notification",document.getElementById("notification").selectedItem.value);
PreSelectItem.setAttribute("otherDeck",document.getElementById("otherDeck").selectedIndex);
PreSelectItem.setAttribute("InboxURL",document.getElementById("InboxURL").value);
PreSelectItem.setAttribute("WriteURL",document.getElementById("WriteURL").value);
PreSelectItem.setAttribute("AddressURL",document.getElementById("AddressURL").value);
} catch(ex) {
webmail.debug("Previously selected item does not exist!!!");
}
}
// Load the information from the currently selected element
document.getElementById("description").setAttribute("isNew","false");
webmail.debug("myItem.label (pre)="+myItem.label);
if (myItem.hasAttribute("provider")){
var tempitem = myproviders.getElementsByAttribute("id",myItem.getAttribute("provider"));
if (tempitem && tempitem.length > 0) {
webmail.debug("("+myItem.getAttribute("provider")+") is a valid provider");
myproviders.selectedItem = tempitem[0];
changeprovider(tempitem[0]);
} else {
// provider is not valid -- Select first item on list
webmail.debug("Invalid Provider: attempting to select netscape");
tempitem=myproviders.getElementsByAttribute("id","webmail:feed:netscape");
myproviders.selectedItem = tempitem[0];
changeprovider(tempitem[0]);
}
webmail.debug("myItem.label (post)="+myItem.label);
webmail.debug("un/pw: "+myItem.getAttribute("userid")+'/'+myItem.getAttribute("password"));
document.getElementById("userid").value = myItem.getAttribute("userid");
document.getElementById("password").value = myItem.getAttribute("password");
document.getElementById("autolog").checked = myItem.getAttribute("autolog")=="true";
if (myItem.getAttribute("userid") && myItem.getAttribute("password")) {
document.getElementById("autolog").disabled=false;
}
document.getElementById("checkUpdates").checked = myItem.getAttribute("checkUpdates")=="true";
document.getElementById("dispSep").checked = myItem.getAttribute("dispSep")=="true";
document.getElementById("dispSep2").checked = myItem.getAttribute("dispSep")=="true";
tempitem = document.getElementById("emailfreq").getElementsByAttribute("value",myItem.getAttribute("emailfreq"));
if (tempitem && tempitem.length > 0) {
document.getElementById("emailfreq").selectedItem = tempitem[0];
} else {
document.getElementById("emailfreq").selectedIndex = 2;
}
tempitem = document.getElementById("notification").getElementsByAttribute("value",myItem.getAttribute("notification"));
if (tempitem && tempitem.length > 0) {
document.getElementById("notification").selectedItem = tempitem[0];
}
document.getElementById("otherDeck").selectedIndex = myItem.getAttribute("otherDeck");
document.getElementById("InboxURL").value = myItem.getAttribute("InboxURL");
document.getElementById("WriteURL").value = myItem.getAttribute("WriteURL");
document.getElementById("AddressURL").value = myItem.getAttribute("AddressURL");
} else {
// Put in the defaults if there is no data
myproviders.selectedIndex=0;
changeprovider(myproviders.firstChild.childNodes[0]);
document.getElementById("userid").value="";
document.getElementById("password").value="";
document.getElementById("autolog").disabled=true;
document.getElementById("autolog").checked=false;
document.getElementById("checkUpdates").checked=false;
document.getElementById("dispSep").checked=false;
document.getElementById("dispSep2").checked=false;
document.getElementById("emailfreq").selectedIndex=2;
document.getElementById("notification").selectedIndex=0;
document.getElementById("InboxURL").value="";
document.getElementById("WriteURL").value="";
document.getElementById("AddressURL").value="";
}
changeDescription();
PreSelectItem=myItem;
}
function setDispSep() {
document.getElementById("dispSep").checked = document.getElementById("dispSep2").checked;
}
function setDispSep2() {
document.getElementById("dispSep2").checked = document.getElementById("dispSep").checked;
}
function changeDescription() {
var newtext=document.getElementById("description").value;
document.getElementById("accountsListbox").selectedItem.label=newtext;
document.getElementById("acctDesc").value=newtext+":";
if (newtext == document.getElementById("webemailproviders").selectedItem.getAttribute("label")) {
document.getElementById("description").setAttribute("isNew","true");
} else {
document.getElementById("description").setAttribute("isNew","false");
}
}
function changeUser() {
if (document.getElementById("userid").textLength > 0 &&
document.getElementById("password").textLength > 0)
{
document.getElementById("autolog").disabled=false;
} else {
document.getElementById("autolog").disabled=true;
document.getElementById("autolog").checked=false;
}
}
function updateOkButton() {
// MERC (rpaul) if no data is provided, disable ok button to prevent the userfrom storing an
// an account
var listbox=document.getElementById("accountsListbox");
// MERC - JCH: Gets rid of exception when removing an account
if (listbox.selectedIndex < 0)
return;
var myproviders=document.getElementById("webemailproviders");
// Set values for current item
var curItem = listbox.selectedItem;
curItem.setAttribute("provider",myproviders.selectedItem.id);
curItem.setAttribute("userid",document.getElementById("userid").value);
curItem.setAttribute("password",document.getElementById("password").value);
if (myproviders.selectedItem.id == "webmail:other") {
curItem.setAttribute("InboxURL", document.getElementById("InboxURL").value);
curItem.setAttribute("WriteURL", document.getElementById("WriteURL").value);
curItem.setAttribute("AddressURL", document.getElementById("AddressURL").value);
}
var enableOk = true;
var item = new Array();
item=listbox.selectedItems;
// if the current item in the listbox is invalid, then disable it
if (!isWebmailDataValid(item[0])) {
enableOk = false;
}
document.getElementById('manageEmailDialog').getButton("accept").disabled=!enableOk;
return enableOk;
}
function changeprovider(aProvider) {
webmail.debug("Changeprovider called with me.id=" + aProvider.id + ",me.label=" + aProvider.getAttribute("label"));
document.getElementById("uname").value = aProvider.getAttribute("username");
var notify=aProvider.getAttribute("notify");
var allnotify;
var i;
webmail.debug("notify="+notify);
document.getElementById("otherDeck").selectedIndex=0;
allnotify=document.getElementsByAttribute("notifyonly","true");
if (notify == "_none"){
for (i=0;i<allnotify.length;i++){
allnotify[i].disabled=true;
}
document.getElementById("checkUpdates").setAttribute("checked",false);
} else {
for (i=0;i<allnotify.length;i++){
allnotify[i].disabled=false;
}
}
var isNew=document.getElementById("description").getAttribute("isNew");
if (isNew && isNew=="true") {
document.getElementById("description").value=aProvider.getAttribute("label");
changeDescription();
}
}
function setDefault()
{
var list=document.getElementById("accountsListbox");
var item;
item=list.getItemAtIndex(0);
while(item){
if (item.current){
if (isWebmailDataValid(item)) {
item.setAttribute("style","font-weight:bold");
webmail.Prefs.setCharPref("default", item.label);
} else {
item.removeAttribute("style");
}
} else {
item.setAttribute("style","");
}
item =list.getNextItem(item,1);
}
list.focus();
}
function clearPref(aAccountName,aPref) {
try {
if (webmail.Prefs.prefHasUserValue(aPref+"."+aAccountName))
webmail.Prefs.clearUserPref(aPref+"."+aAccountName);
} catch (ex) {
webmail.debug("Error clearing pref ("+aPref+"): "+ex);
}
}
function Remove() {
var list=document.getElementById("accountsListbox");
var item=list.selectedItem;
var index=list.selectedIndex;
// Confirm removal with user
var promptName;
var origName = item.getAttribute("origName");
if (!origName || origName == item.label) {
promptName = item.label;
} else {
promptName = item.label + " (was " + origName + ")";
}
if (confirm("Do you really want to remove "+promptName+" and all associated preferences?")) {
clearPref(origName,"provider");
clearPref(origName,"dispSep");
clearPref(origName,"autolog");
clearPref(origName,"checkUpdates");
clearPref(origName,"emailfreq");
clearPref(origName,"notification");
clearPref(origName,"InboxURL");
clearPref(origName,"WriteURL");
clearPref(origName,"AddressURL");
// If the removed account is the default, remove the default pref value.
if (webmail.Prefs.prefHasUserValue("default")) {
if (webmail.Prefs.getCharPref("default") == item.label) {
webmail.Prefs.clearUserPref("default");
}
}
webmail.removeMenus(origName);
// TODO Remove the passcard reference (if it exists) - not sure I really want to do
// this. The user may change their mind. - MSD
// Remove item from the list
list.removeItemAt(index);
// If there are no items, insert a new item that is Netscape Mail
if (list.getRowCount() < 1) {
var myproviders=document.getElementById("webemailproviders");
var tempitem=myproviders.getElementsByAttribute("id","webmail:feed:netscape");
AddAccount("New Mail Account", true);
// The new account is not valid so disable OK button.
document.getElementById('manageEmailDialog').getButton("accept").disabled = true;
//list.focus();
//return;
} else {
// select another item
if (index > list.getRowCount() - 1) {
list.selectedIndex = list.getRowCount() - 1;
} else {
list.selectedIndex=index;
}
updateOkButton();
}
// Always check if next item can be made default.
setDefault();
}
list.focus();
EnableRemove();
}
/*****
* AddAccount
* var aAccountName - the name of the account to add
* var setAsDefault - boolean that determines whether the new account is set to default
*/
function AddAccount(aAccountName, setAsDefault) {
// Add an entry to the listbox
var listbox=document.getElementById("accountsListbox");
var newItem=listbox.appendItem(aAccountName,"");
// Select the new entry
// MERC (rpaul) for BLT bug # 128289 before adding new account make sure the list item is visible
// so it is selectable
listbox.focus();
listbox.ensureIndexIsVisible(listbox.getRowCount()-1);
listbox.selectedIndex = listbox.getRowCount()-1;
if (setAsDefault == true) {
newItem.setAttribute("style","font-weight:bold");
var firstItem = listbox. getItemAtIndex(0);
firstItem.removeAttribute("style");
}
webmail.debug("description="+document.getElementById("description").value);
document.getElementById("description").setAttribute("isNew","true");
EnableRemove();
//document.getElementById('manageEmailDialog').getButton("accept").disabled=true;
}
function isWebmailDataValid(aItem) {
// must enter a description
if (aItem.label == "") return false;
// validation of custom accounts have differnet rules
// check if the user has entered a valid inbox, write email url and addressbook
if (aItem.getAttribute("provider")=="webmail:other") {
// MERC - JCH: Insist on only the inbox url rather
// than inbox url, address box url and write url.
if (aItem.getAttribute("InboxURL") == "")
{
return false;
} else {
return true;
}
} else {
// check if the user entered a username and password
var mUserId=aItem.getAttribute("userid");
var mPassword=aItem.getAttribute("password");
if (mUserId == "" || mPassword == "") {
return false;
}
else {
return true;
}
}
}
/**
* Enable the Remove button if there is an item in the list
**/
function EnableRemove()
{
var removeBtn = document.getElementById("removeBtn");
if (document.getElementById("accountsListbox").getRowCount() > 0)
removeBtn.removeAttribute('disabled');
else
removeBtn.setAttribute('disabled', 'true');
}