home *** CD-ROM | disk | FTP | other *** search
Text File | 2006-01-06 | 36.3 KB | 1,087 lines |
- var PreSelectItem;
- var webmail=window.opener.webmail;
- var gUpdatingNow = false;
-
-
-
- function init(aEvent)
- {
- // if (aEvent.target != document)
- // return;
-
- fixElements();
- EnableRemove();
- }
-
- function uninit(aEvent)
- {
- if (aEvent.target != document)
- return;
- }
-
- function doCancel() {
- // window.close();
- //dump("\n**\nmanageEmailDialog.js, doCancel()\n**\n");
- removeInconsistentPrefs();
- try {
- webmail.fixMenus();
- webmail.fixCustomAccountMenus();
- } catch (ex) {
- webmail.debug("Problem with fixMenus():\n"+ex);
- }
- return true;
- }
-
- function doOK() {
- //dump("\n**\nmanageEmailDialog.js, doOk()\n**\n");
- 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);
-
-
- // Verify that there are no duplicate provider entries
- var item = null;
- var haveProv = new Array();
- for (item = listbox.getItemAtIndex(0);item;item = listbox.getNextItem(item,1))
- {
- var tempP = item.getAttribute("provider");
- if (tempP && tempP != "webmail:other")
- {
- if (haveProv[tempP])
- {
- alert("Unable to save two accounts for a single provider ("+tempP+")");
- return false;
- }
- haveProv[tempP] = true;
- }
- }
-
- // Save all preferences
- for (item = listbox.getItemAtIndex(0);item;item = listbox.getNextItem(item,1))
- {
- // only save valid webmail accounts
- if (isWebmailDataValid(item)) {
- saveWebmailValues(item);
- }
- }
-
- // 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) {
- //dump("\n**\nmanageEmailDialog.js, setFromPrefs(aItem, aAccountName, aPref)\n**\n");
- try {
- aItem.setAttribute(aPref,webmail.Prefs.getCharPref(aPref+"."+aAccountName));
- } catch(ex) {}
- }
-
- function setWebmailValues(aItem,aAccountName) {
- //dump("\n**\nmanageEmailDialog.js, setWebmailValues(aItem,aAccountName)\n**\n");
-
- 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.removeItemAt(listbox.getIndexOfItem(aItem));
- return;
- }
- //MERC CCOTE bug 203312
- // set temp variable
- aItem.setAttribute("origAccountName", aAccountName);
-
- 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 a master password is set on a mail account and user tries to open the dialog,
- // a prompt is displayed to enter master password. Cancelling the prompt used to
- // allow the dialog to open with no values for user and password, and some corresponding
- // exceptions thrown for bad list values. Now if user cancels prompt, dialog should not
- // open.
- try
- {
- webmail.debug('Found a passcard for this account, un/pw = '+pc.user+'/'+pc.password);
- var pcUser = pc.user;
- var pcPwd = pc.password;
-
- aItem.setAttribute("userid", pcUser);
- aItem.setAttribute("password", pcPwd);
- }
- catch (ex)
- {
- webmail.debug('\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) {
- //dump("\n**\nmanageEmailDialog.js, setPrefFromItem(aItem,aAccountName,aPref)\n**\n");
- webmail.Prefs.setCharPref(aPref+"."+aAccountName,aItem.getAttribute(aPref));
- }
-
- function saveWebmailValues(aItem) {
- //dump("\n**\nmanageEmailDialog.js, saveWebmailValues(aItem)\n**\n");
-
- ////MERC CCOTE bug 203312
- // Check if the original account name match curent account Name
- // If not clear the pref
- var accountName = aItem.getAttribute("origAccountName");
- if(accountName!= aItem.label){
-
- 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);
- }
- accountName = aItem.label;
- webmail.debug("saveWebmailValues() 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);
- }
- }
-
- // 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") {
-
- //MERC CCOTE bug fix 204414
- // Move the if code here to unable ok button when
- // Other is selected as a provider
- 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!!
- try {
- webmail.debug(' - removing old passcard with mKey=['+mKey+'] and username='+pc.user);
- var pcUser = pc.user;
- passwordManager.removeUser(domain, pcUser);
- } 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);
- }
-
- 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");
- }
- else
- { webmail.removeMenus(accountName);
- if (webmail.Prefs.prefHasUserValue("WriteURL."+accountName))
- webmail.Prefs.clearUserPref("WriteURL."+accountName);
- }
-
- if (aItem.getAttribute("AddressURL") != "")
- {
- setPrefFromItem(aItem,accountName,"AddressURL");
- }
- else
- {
- webmail.removeMenus(accountName);
- if (webmail.Prefs.prefHasUserValue("AddressURL."+accountName))
- webmail.Prefs.clearUserPref("AddressURL."+accountName);
- }
-
- setPrefFromItem(aItem,accountName,"dispSep");
- }
- }
- }
-
- // BLT #: 176412 BC (10/31/2005):
- // Modification. Script was incorrectly comparing accountName with listbox label.
- // The error was due to a substr(9) being applied to prefAccounts[i], thus making the two not equal for large names
-
- // 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()
- {
- //dump("\n**\nmanageEmailDialog.js, removeInconsistentPrefs()\n**\n");
- // Get all webmail accounts stored as prefs
-
- // BC: Getting the pref, and then comparing to listbox is not working.
- // If the user changes the webmail description, the listbox label changes as well, in realtime.(this could be wrong)
- // The problem is that the pref that stores the accountname is from the last-save, and doesn't have
- // our current changes (in realtime), so the comparison is never true.
- // Note: Still unsure why we lose the button if the match is false.
-
- 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
- // BC: 10/31/2005: The account name could be bigger than 9 characters, this borks the long description field compare.
- //accountName = prefAccounts[i].substr(9);
- accountName = document.getElementById("txtDescription").value;
- dump("**\nmanageEmailDialog.js, removeInconsistentPrefs(), accountName==" + accountName + "\n**\n");
-
- //accountName = prefAccounts[i];
-
- // Get all listbox webmail accounts
- foundMatch = false;
- item = listbox.getItemAtIndex(0);
- dump("**\nmanageEmailDialog.js, removeInconsistentPrefs(), item.label==" + item.label + "\n**\n");
- 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);
- }
- dump("**\nmanageEmailDialog.js, removeInconsistentPrefs(), foundMatch==" + foundMatch + "\n**\n");
- // 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)
- {
- //dump("\n**\nmanageEmailDialog.js, displaySeparately(accountName, aItem)\n**\n");
- // 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()
- {
- webmail.debug("fixElements()\n");
- //dump("\n**\nmanageEmailDialog.js, fixElements()\n**\n");
-
-
- // 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("txtDescription").setAttribute("isNew","true");
-
- //removeInvalidAccountsFromList();
- }
-
- function otherSelect() {
- //dump("\n**\nmanageEmailDialog.js, otherSelect()\n**\n");
- document.getElementById("otherDeck").selectedIndex=1;
-
- // MERC CCOTE bug fix 204414
- // check to see if the button is enable or unenable
- updateOkButton();
-
- }
-
- function selectFirstAccount() {
- //dump("\n**\nmanageEmailDialog.js, selectFirstAccount()\n**\n");
- webmail.debug("selectFirstAccount()\n");
-
- var listbox=document.getElementById("accountsListbox");
- var firstitem=listbox.getItemAtIndex(0);
- listbox.selectItem(firstitem);
- }
-
- function AccountSelect(){
- //dump("\n**\nmanageEmailDialog.js, AccountSelect()\n**\n");
-
- webmail.debug("AccountSelect() Called");
-
- var mylist=document.getElementById("accountsListbox");
-
- if (mylist.getRowCount()<1)
- return;
-
- var firstitem=mylist.getItemAtIndex(0);
- var myItem=mylist.selectedItem;
- var accountName;
- if (firstitem) webmail.debug("firstitem.provider = "+firstitem.getAttribute("provider"));
-
- if (!(myItem)) {
- //setTimeout("selectFirstAccount();",1);
- return;
- }
- gUpdatingNow = true;
- var newtext = myItem.label;
- document.getElementById("acctDesc").value = newtext+":";
- document.getElementById("txtDescription").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("txtDescription").setAttribute("isNew","false");
- webmail.debug("myItem.label (pre)="+myItem.label);
- if (myItem.hasAttribute("provider")){
- webmail.debug("setting provider to "+myItem.getAttribute("provider"));
- var tempitem = myproviders.getElementsByAttribute("id",myItem.getAttribute("provider"));
- if (tempitem && tempitem.length > 0) {
- webmail.debug("("+myItem.getAttribute("provider")+") is a valid provider");
- webmail.debug("Attempting to select provider # "+tempitem[0].id);
- 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="";
- }
- gUpdatingNow=false;
- changeDescription();
- PreSelectItem=myItem;
- }
-
- function setDispSep() {
- //dump("\n**\nmanageEmailDialog.js, setDispSep()\n**\n");
- document.getElementById("dispSep").checked = document.getElementById("dispSep2").checked;
- }
-
- function setDispSep2() {
- //dump("\n**\nmanageEmailDialog.js, setDispSep2()\n**\n");
- document.getElementById("dispSep2").checked = document.getElementById("dispSep").checked;
- }
-
- function changeDescription() {
- //dump("\n**\nmanageEmailDialog.js, changeDescription()\n**\n");
- var listbox=document.getElementById("accountsListbox");
- var firstitem=listbox.getItemAtIndex(0);
- if (firstitem) webmail.debug("in changeDescription: firstitem.provider = "+firstitem.getAttribute("provider"));
- var newtext=document.getElementById("txtDescription").value;
- document.getElementById("accountsListbox").selectedItem.label=newtext;
- document.getElementById("acctDesc").value=newtext+":";
- if (newtext == document.getElementById("webemailproviders").selectedItem.getAttribute("label")) {
- document.getElementById("txtDescription").setAttribute("isNew","true");
- } else {
- document.getElementById("txtDescription").setAttribute("isNew","false");
- }
- if (firstitem) webmail.debug("out changeDescription: firstitem.provider = "+firstitem.getAttribute("provider"));
- //removeInvalidAccountsFromList();
-
- }
-
- function changeUser() {
- //dump("\n**\nmanageEmailDialog.js, changeUser()\n**\n");
-
- webmail.debug("changeUser() Called");
-
- 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() {
- webmail.debug("updateOkButton() Called");
- //dump("\n**\nmanageEmailDialog.js, updateOkButton()\n**\n");
-
- if (gUpdatingNow) return;
- // MERC (rpaul) if no data is provided, disable ok button to prevent the userfrom storing an
- // an account
-
- var listbox=document.getElementById("accountsListbox");
-
- // Gets rid of exception when removing an account
- if (listbox.selectedIndex < 0 || listbox.getRowCount() < 1)
- return;
-
- var firstitem=listbox.getItemAtIndex(0);
- if (firstitem) webmail.debug("in updateOKButton: firstitem.provider = "+firstitem.getAttribute("provider"));
-
- 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;
-
- // CCote bug #141453
- // Before it used the selected item to enable or disable the OK button
- // The new behavior ask to check for all item in the list.
- // If one or more items are missing require fields the button is disable
- // until field is filled or user remove email acount
- var listbox=document.getElementById("accountsListbox");
- var item=listbox.getItemAtIndex(0);
- while (item) {
- if (!isWebmailDataValid(item)) {
- enableOk = false;
- }
-
- item = listbox.getNextItem(item,1);
- }
-
- document.getElementById('manageEmailDialog').getButton("accept").disabled=!enableOk;
- if (firstitem) webmail.debug("out updateOKButton: firstitem.provider = "+firstitem.getAttribute("provider"));
-
- return enableOk;
- }
-
- function changeprovider(aProvider) {
- //dump("\n**\nmanageEmailDialog.js, changeprovider(aProvider)\n**\n");
-
- webmail.debug("Changeprovider called with me.id=" + aProvider.id + ",me.label=" + aProvider.getAttribute("label"));
-
- if (PreSelectItem)
- webmail.debug("PreSelectItem.provider = "+PreSelectItem.getAttribute("provider"));
-
- 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("txtDescription").getAttribute("isNew");
- if (isNew && isNew=="true") {
- document.getElementById("txtDescription").value=aProvider.getAttribute("label");
- changeDescription();
- }
- if (PreSelectItem) webmail.debug("PreSelectItem.provider = "+PreSelectItem.getAttribute("provider"));
-
- // Fix for BLT 202383: User can save Webmail account with no information by switching
- // the provider for an existing account of type "Other" to another provider.
- updateOkButton();
-
- }
-
- function setDefault()
- {
- //dump("\n**\nmanageEmailDialog.js, setDefault()\n**\n");
- webmail.debug("setDefault() Called");
-
- var list=document.getElementById("accountsListbox");
- var item;
-
- // Set current item as default.
- 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) {
- //dump("\n**\nmanageEmailDialog.js, clearPref(aAccountName,aPref)\n**\n");
- try {
- if (webmail.Prefs.prefHasUserValue(aPref+"."+aAccountName))
- webmail.Prefs.clearUserPref(aPref+"."+aAccountName);
- } catch (ex) {
- webmail.debug("Error clearing pref ("+aPref+"): "+ex);
- }
- }
-
- function Remove() {
- //dump("\n**\nmanageEmailDialog.js, Remove()\n**\n");
- var list=document.getElementById("accountsListbox");
- var item=list.selectedItem;
- var index=list.selectedIndex;
- var removedDefault = false;
-
- webmail.debug("Remove item: "+item.label+"\n");
-
- // 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");
- removedDefault = true;
- }
- }
-
- 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();
- }
-
- // If the default account was removed, create a new one.
- if (removedDefault)
- {
- 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) {
- //dump("\n**\nmanageEmailDialog.js, AddAccount(aAccountName, setAsDefault)\n**\n");
-
- webmail.debug("AddAccount() Called");
-
- // 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("txtDescription="+document.getElementById("txtDescription").value);
- document.getElementById("txtDescription").setAttribute("isNew","true");
- EnableRemove();
- //document.getElementById('manageEmailDialog').getButton("accept").disabled=true;
- }
-
-
- function isWebmailDataValid(aItem) {
- //dump("\n**\nmanageEmailDialog.js, isWebmailDataValid(aItem)\n**\n");
-
- var isValid = false;
-
- webmail.debug("isWebmailDataValid() Called on "+aItem.label+" \n");
-
- // 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") == "")
- {
- isValid = false;
- } else {
- isValid = true;
- }
- } else {
- // check if the user entered a username and password
- var mUserId=aItem.getAttribute("userid");
- var mPassword=aItem.getAttribute("password");
- if (mUserId == "" || mPassword == "")
- {
- isValid = false;
- }
- else {
- isValid = true;
- }
- }
-
- return isValid;
- }
-
-
- /**
- * Enable the Remove button if there is an item in the list
- **/
- function EnableRemove()
- {
- //dump("\n**\nmanageEmailDialog.js, EnableRemove()\n**\n");
- webmail.debug("EnableRemove() Called");
-
- var removeBtn = document.getElementById("removeBtn");
- if (document.getElementById("accountsListbox").getRowCount() > 1)
- removeBtn.removeAttribute('disabled');
- else
- removeBtn.setAttribute('disabled', 'true');
- }
-
- /****
- * On opening the webmail dialog, make sure no useless/confusing default accounts are created.
- **/
- function removeInvalidAccountsFromList()
- {
- //dump("\n**\nmanageEmailDialog.js, removeInvalidAccountsFromList()\n**\n");
- var list = document.getElementById("accountsListbox");
- var item;
- var nRows = list.getRowCount();
-
- // If there is only one item, it doesn't matter if it is undefined.
- if (nRows < 2)
- return;
-
- for (var index=0; index<nRows; index++)
- {
- item = list.getItemAtIndex(index);
- if (!isWebmailDataValid(item) && item.label != "New Mail Account")
- {
-
-
- list.removeItemAt(index);
- nRows = list.getRowCount();
-
- }
- else
- {
- list.selectedItem = item;
- list.selectedIndex = index;
- }
- }
- }
-
-
-