Bug 890507 - clean up mailnews/base/prefs/content/AccountManager.js::setFormElementValue function. r=mkmelin
authoraceman <acelists@atlas.sk>
Tue, 02 Aug 2016 22:56:06 +0200
changeset 26516 26b20089336b59dd89b893a5ba0b2460b8896472
parent 26515 5d476d6dfe087743a2b6abf1593ff3aa6deb1035
child 26517 c23005eea70868e2031e9e0a35c389cc3b00559c
push id353
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:39:40 +0000
reviewersmkmelin
bugs890507
Bug 890507 - clean up mailnews/base/prefs/content/AccountManager.js::setFormElementValue function. r=mkmelin
mailnews/base/prefs/content/AccountManager.js
mailnews/base/prefs/content/am-identity-edit.js
mailnews/base/prefs/content/am-identity-edit.xul
mailnews/base/prefs/content/am-main.xul
mailnews/base/prefs/content/am-offline.xul
mailnews/base/prefs/content/am-server.js
mailnews/base/prefs/content/am-server.xul
mailnews/base/prefs/content/am-serverwithnoidentities.xul
mailnews/base/prefs/content/amUtils.js
mailnews/extensions/newsblog/content/am-newsblog.xul
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -1322,107 +1322,104 @@ function restorePage(pageId, account)
   if ("onInit" in top.frames["contentFrame"])
     top.frames["contentFrame"].onInit(pageId, account.incomingServer.serverURI);
 
   // everything has succeeded, vervied by setting currentPageId
   currentPageId = pageId;
   currentAccount = account;
 }
 
-// gets the value of a widget
+/**
+ * Gets the value of a widget in current the account settings page,
+ * automatically setting the right property of it depending on element type.
+ *
+ * @param formElement  A XUL input element.
+ */
 function getFormElementValue(formElement) {
   try {
     var type = formElement.localName;
-    if (type=="checkbox") {
+    if (type == "checkbox") {
       if (formElement.getAttribute("reversed"))
         return !formElement.checked;
       return formElement.checked;
     }
     if (type == "textbox" &&
-        formElement.getAttribute("datatype") == "nsILocalFile") {
+        formElement.getAttribute("datatype") == "nsIFile") {
       if (formElement.value) {
-        var localfile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
+        let localfile = Components.classes["@mozilla.org/file/local;1"]
+                                  .createInstance(Components.interfaces.nsIFile);
 
         localfile.initWithPath(formElement.value);
         return localfile;
       }
       return null;
     }
     if ((type == "textbox") || ("value" in formElement)) {
       return formElement.value;
     }
     return null;
   }
   catch (ex) {
-    dump("getFormElementValue failed, ex="+ex+"\n");
+    Components.utils.reportError("getFormElementValue failed, ex=" + ex + "\n");
   }
   return null;
 }
 
-// sets the value of a widget
+/**
+ * Sets the value of a widget in current the account settings page,
+ * automatically setting the right property of it depending on element type.
+ *
+ * @param formElement  A XUL input element.
+ * @param value        The value to store in the element.
+ */
 function setFormElementValue(formElement, value) {
   var type = formElement.localName;
   if (type == "checkbox") {
-    if (value == undefined) {
-      if ("defaultChecked" in formElement && formElement.defaultChecked)
-        formElement.checked = formElement.defaultChecked;
-      else
-        formElement.checked = false;
+    if (value == null) {
+      formElement.checked = false;
     } else {
       if (formElement.getAttribute("reversed"))
         formElement.checked = !value;
       else
         formElement.checked = value;
     }
   }
-  else if (type == "radiogroup" || type =="menulist") {
-    if (value == undefined)
+  else if (type == "radiogroup" || type == "menulist") {
+    if (value == null)
       formElement.selectedIndex = 0;
     else
       formElement.value = value;
   }
-  // handle nsILocalFile
+  // handle nsIFile
   else if (type == "textbox" &&
-           formElement.getAttribute("datatype") == "nsILocalFile") {
+           formElement.getAttribute("datatype") == "nsIFile") {
     if (value) {
-      var localfile = value.QueryInterface(Components.interfaces.nsILocalFile);
+      let localfile = value.QueryInterface(Components.interfaces.nsIFile);
       try {
         formElement.value = localfile.path;
       } catch (ex) {
         dump("Still need to fix uninitialized nsIFile problem!\n");
       }
-
     } else {
-      if ("defaultValue" in formElement)
-        formElement.value = formElement.defaultValue;
-      else
-        formElement.value = "";
+      formElement.value = "";
     }
   }
   else if (type == "textbox") {
-    if (value == null || value == undefined) {
+    if (value == null)
       formElement.value = null;
-    } else {
+    else
       formElement.value = value;
-    }
   }
   else if (type == "label") {
-    if (value == null || value == undefined) {
-      formElement.value = "";
-    } else {
-      formElement.value = value;
-    }
+    formElement.value = value || "";
   }
-
   // let the form figure out what to do with it
   else {
-    if (value == undefined) {
-      if ("defaultValue" in formElement && formElement.defaultValue)
-        formElement.value = formElement.defaultValue;
-    }
+    if (value == null)
+      formElement.value = null;
     else
       formElement.value = value;
   }
 }
 
 //
 // conversion routines - get data associated
 // with a given pageId, serverId, etc
--- a/mailnews/base/prefs/content/am-identity-edit.js
+++ b/mailnews/base/prefs/content/am-identity-edit.js
@@ -191,17 +191,17 @@ function saveIdentitySettings(identity)
 
     var attachSignaturePath = document.getElementById('identity.signature').value;
     identity.signature = null; // this is important so we don't accidentally inherit the default
 
     if (attachSignaturePath)
     {
       // convert signature path back into a nsIFile
       var sfile = Components.classes["@mozilla.org/file/local;1"]
-                  .createInstance(Components.interfaces.nsILocalFile);
+                  .createInstance(Components.interfaces.nsIFile);
       sfile.initWithPath(attachSignaturePath);
       if (sfile.exists())
         identity.signature = sfile;
     }
   }
 }
 
 function saveCopiesAndFolderSettings(identity)
@@ -273,17 +273,17 @@ function GetSigFolder()
   try 
   {
     var account = parent.getCurrentAccount();
     var identity = account.defaultIdentity;
     var signatureFile = identity.signature;
 
     if (signatureFile) 
     {
-      signatureFile = signatureFile.QueryInterface( Components.interfaces.nsILocalFile );
+      signatureFile = signatureFile.QueryInterface(Components.interfaces.nsIFile);
       sigFolder = signatureFile.parent;
 
       if (!sigFolder.exists()) 
           sigFolder = null;
     }
   }
   catch (ex) {
       dump("failed to get signature folder..\n");
--- a/mailnews/base/prefs/content/am-identity-edit.xul
+++ b/mailnews/base/prefs/content/am-identity-edit.xul
@@ -84,17 +84,17 @@
 
         <hbox align="center">
           <checkbox id="identity.attachSignature" label="&signatureFile.label;" flex="1"
                     accesskey="&signatureFile.accesskey;"
                     oncommand="setupSignatureItems();"/>
         </hbox>
 
         <hbox align="center" class="indent">
-          <textbox id="identity.signature" datatype="nsILocalFile" flex="1" name="identity.signature"
+          <textbox id="identity.signature" datatype="nsIFile" flex="1" name="identity.signature"
                    aria-labelledby="identity.attachSignature"
                    observes="broadcaster_attachSignature" class="uri-element"/>
           <button class="push" name="browse" label="&choose.label;"
                   accesskey="&choose.accesskey;" 
                   oncommand="selectFile()"
                   observes="broadcaster_attachSignature"
                   id="identity.sigbrowsebutton"/>
         </hbox>
--- a/mailnews/base/prefs/content/am-main.xul
+++ b/mailnews/base/prefs/content/am-main.xul
@@ -86,17 +86,17 @@
         <checkbox wsm_persist="true" id="identity.attachSignature" label="&signatureFile.label;" flex="1"
                   accesskey="&signatureFile.accesskey;"
                   oncommand="setupSignatureItems();"
                   prefattribute="value"
                   prefstring="mail.identity.%identitykey%.attach_signature"/>
       </hbox>
 
       <hbox align="center" class="indent">
-        <textbox wsm_persist="true" id="identity.signature" datatype="nsILocalFile" flex="1" name="identity.signature"
+        <textbox wsm_persist="true" id="identity.signature" datatype="nsIFile" flex="1" name="identity.signature"
                  aria-labelledby="identity.attachSignature"
                  observes="broadcaster_attachSignature"
                  prefstring="mail.identity.%identitykey%.sig_file" class="uri-element"/>
         <button class="push" name="browse" label="&choose.label;"
                 accesskey="&choose.accesskey;" 
                 oncommand="selectFile()"
                 observes="broadcaster_attachSignature"
                 wsm_persist="true" id="identity.sigbrowsebutton"
--- a/mailnews/base/prefs/content/am-offline.xul
+++ b/mailnews/base/prefs/content/am-offline.xul
@@ -1,13 +1,10 @@
 <?xml version="1.0"?>
-
-<!--
-
- This Source Code Form is subject to the terms of the Mozilla Public
+<!-- 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/. -->
 
 <?xml-stylesheet href="chrome://messenger/skin/accountManage.css" type="text/css"?>
 
 <!DOCTYPE page SYSTEM "chrome://messenger/locale/am-offline.dtd">
 
 <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
@@ -52,21 +49,21 @@
     <groupbox id="diskspace.titlebox">
       <caption label="&diskspaceGroupTitle.label;" hidefor="movemail,pop3,none,rss"/>
 
     <description hidefor="pop3,nntp,movemail,none,rss">&doNotDownloadImap.label;</description>
     <description hidefor="pop3,imap,movemail,none,rss">&doNotDownloadNntp.label;</description>
     <description hidefor="imap,nntp,none,rss">&doNotDownloadPop3Movemail.label;</description>
 
     <!-- IMAP Autosync Preference -->
-    <radiogroup wsm_persist="true" hidefor="pop3,nntp,movemail,none,rss" id="autosyncSelect" class="indent">
-      <radio wsm_persist="true" id="useAutosync.AllMsg" value="0" accesskey="&allAutosync.accesskey;"
+    <radiogroup hidefor="pop3,nntp,movemail,none,rss" id="autosyncSelect" class="indent">
+      <radio id="useAutosync.AllMsg" value="0" accesskey="&allAutosync.accesskey;"
              label="&allAutosync.label;" oncommand="onAutosyncChange();"/>
       <hbox flex="1" align="center">
-        <radio wsm_persist="true" id="useAutosync.ByAge" accesskey="&ageAutosync.accesskey;" 
+        <radio id="useAutosync.ByAge" accesskey="&ageAutosync.accesskey;"
                value="1" label="&ageAutosyncBefore.label;" oncommand="onAutosyncChange();"/>
         <textbox id="autosyncValue" type="number" size="4" min="1"
                  class="autosync" onchange="onAutosyncChange();"
                  aria-labelledby="ageAutosyncBefore autosyncValue ageAutosyncMiddle autosyncInterval ageAutosyncAfter"/>
         <label id="ageAutosyncMiddle" control="autosyncValue" value="&ageAutosyncMiddle.label;"/>
         <menulist id="autosyncInterval" onselect="onAutosyncChange();">
           <menupopup>
             <menuitem label="&dayAgeInterval.label;" value="1"/>
@@ -114,48 +111,48 @@
     </hbox>
 
     <vbox align="start">
     <separator hidefor="none,rss"/>
     <label id="retentionDescription" hidefor="imap,pop3" class="desc" control="retention.keepMsg">&retentionCleanup.label;</label>
     <label id="retentionDescriptionImap" hidefor="movemail,pop3,nntp,none,rss" class="desc" control="retention.keepMsg">&retentionCleanupImap.label;</label>
     <label id="retentionDescriptionPop" hidefor="movemail,imap,nntp,none,rss" class="desc" control="retention.keepMsg">&retentionCleanupPop.label;</label>
 
-    <radiogroup wsm_persist="true" hidefor="" confirmfor="imap,pop3" id="retention.keepMsg" class="indent"
+    <radiogroup hidefor="" confirmfor="imap,pop3" id="retention.keepMsg" class="indent"
                 oncommand="warnServerRemove(this);">
-        <radio wsm_persist="true" id="retention.keepAllMsg" value="1" accesskey="&retentionKeepAll.accesskey;"
+        <radio id="retention.keepAllMsg" value="1" accesskey="&retentionKeepAll.accesskey;"
             label="&retentionKeepAll.label;" oncommand="onCheckKeepMsg();"/>
         <hbox flex="1" align="center">
-            <radio wsm_persist="true" id="retention.keepNewMsg" accesskey="&retentionKeepRecent.accesskey;" 
+            <radio id="retention.keepNewMsg" accesskey="&retentionKeepRecent.accesskey;"
                 value="3" label="&retentionKeepRecent.label;" oncommand="onCheckKeepMsg();"/>
-            <textbox wsm_persist="true" id="retention.keepNewMsgMin"
+            <textbox id="retention.keepNewMsgMin"
                      type="number" min="1" increment="10" size="4" value="2000"
                      aria-labelledby="retention.keepNewMsg retention.keepNewMsgMin newMsgLabel"/>
             <label value="&message.label;" control="retention.keepNewMsgMin" id="newMsgLabel"/>
         </hbox>
         <hbox flex="1" align="center">
-            <radio wsm_persist="true" id="retention.keepOldMsg" accesskey="&retentionKeepMsg.accesskey;"
+            <radio id="retention.keepOldMsg" accesskey="&retentionKeepMsg.accesskey;"
                 value="2" label="&retentionKeepMsg.label;" oncommand="onCheckKeepMsg();"/>
-            <textbox wsm_persist="true" id="retention.keepOldMsgMin"
+            <textbox id="retention.keepOldMsgMin"
                      type="number" min="1" size="4" value="30"
                      aria-labelledby="retention.keepOldMsg retention.keepOldMsgMin oldMsgLabel"/>
             <label value="&daysOld.label;" control="retention.keepOldMsgMin" id="oldMsgLabel"/>
         </hbox>
     </radiogroup>
 
     <hbox align="center" class="indent">
-      <checkbox id="retention.applyToFlagged" wsm_persist="true"
+      <checkbox id="retention.applyToFlagged"
                 label="&retentionApplyToFlagged.label;" hidefor=""
                 accesskey="&retentionApplyToFlagged.accesskey;"
                 checked="true"/>
     </hbox>
     <hbox align="center" class="indent" hidefor="movemail,pop3,imap,none,rss">
-        <checkbox wsm_persist="true" id="nntp.removeBody" accesskey="&nntpRemoveMsgBody.accesskey;"
+        <checkbox id="nntp.removeBody" accesskey="&nntpRemoveMsgBody.accesskey;"
                   label="&nntpRemoveMsgBody.label;" oncommand="onCheckItem('nntp.removeBodyMin','nntp.removeBody');"/>
-        <textbox wsm_persist="true" id="nntp.removeBodyMin" size="2" value="30"
+        <textbox id="nntp.removeBodyMin" size="2" value="30"
                  type="number" min="1"
                  aria-labelledby="nntp.removeBody nntp.removeBodyMin daysOldMsg"/>
         <label value="&daysOld.label;" control="nntp.removeBodyMin" id="daysOldMsg"/>
     </hbox>
     </vbox>
     </groupbox>
   </vbox>
 </page>
--- a/mailnews/base/prefs/content/am-server.js
+++ b/mailnews/base/prefs/content/am-server.js
@@ -273,31 +273,31 @@ function setupFixedUI()
     fixedElement.setAttribute("collapsed", "true");
     otherElement.removeAttribute("collapsed");
   }
 }
 
 function BrowseForNewsrc()
 {
   const nsIFilePicker = Components.interfaces.nsIFilePicker;
-  const nsILocalFile = Components.interfaces.nsILocalFile;
+  const nsIFile = Components.interfaces.nsIFile;
 
   var newsrcTextBox = document.getElementById("nntp.newsrcFilePath");
   var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
   fp.init(window,
           document.getElementById("browseForNewsrc").getAttribute("filepickertitle"),
           nsIFilePicker.modeSave);
 
   var currentNewsrcFile;
   try {
     currentNewsrcFile = Components.classes["@mozilla.org/file/local;1"]
-                                  .createInstance(nsILocalFile);
+                                  .createInstance(nsIFile);
     currentNewsrcFile.initWithPath(newsrcTextBox.value);
   } catch (e) {
-    dump("Failed to create nsILocalFile instance for the current newsrc file.\n");
+    dump("Failed to create nsIFile instance for the current newsrc file.\n");
   }
 
   if (currentNewsrcFile) {
     fp.displayDirectory = currentNewsrcFile.parent;
     fp.defaultString = currentNewsrcFile.leafName;
   }
 
   fp.appendFilters(nsIFilePicker.filterAll);
--- a/mailnews/base/prefs/content/am-server.xul
+++ b/mailnews/base/prefs/content/am-server.xul
@@ -352,19 +352,19 @@
               prefstring="mail.server.%serverkey%.always_authenticate"/>
 
   <!-- take out for now - bug 45079
       <hbox flex="1" hidefor="pop3,imap,movemail">
         <groupbox>
            <caption class="header" label="&abbreviate.label;"/>
 
            <radiogroup wsm_persist="true" id="nntp.abbreviate">
-             <radio wsm_persist="true" value="true"
+             <radio value="true"
                     label="&abbreviateOn.label;"/>
-             <radio wsm_persist="true" value="false"
+             <radio value="false"
                     label="&abbreviateOff.label;"/>
            </radiogroup>
         </groupbox>
       </hbox>
   -->
 
     </groupbox>
 
@@ -414,17 +414,17 @@
 
       <vbox hidefor="imap,pop3,movemail">
         <label value="&newsrcFilePath.label;" control="nntp.newsrcFilePath"/>
         <hbox align="center">
           <textbox readonly="true"
                    wsm_persist="true"
                    flex="1"
                    id="nntp.newsrcFilePath"
-                   datatype="nsILocalFile"
+                   datatype="nsIFile"
                    prefstring="mail.server.%serverkey%.newsrc.file"
                    class="uri-element"/>
           <button id="browseForNewsrc"
                   label="&browseNewsrc.label;"
                   filepickertitle="&newsrcPicker.label;"
                   accesskey="&browseNewsrc.accesskey;"
                   oncommand="BrowseForNewsrc();"/>
         </hbox>
@@ -434,17 +434,17 @@
 
       <vbox>
       <label value="&localPath.label;" control="server.localPath"/>
         <hbox align="center">
           <textbox readonly="true"
                    wsm_persist="true"
                    flex="1"
                    id="server.localPath"
-                   datatype="nsILocalFile"
+                   datatype="nsIFile"
                    prefstring="mail.server.%serverkey%.directory"
                    class="uri-element"/>
           <button id="browseForLocalFolder"
                   label="&browseFolder.label;"
                   filepickertitle="&localFolderPicker.label;"
                   accesskey="&browseFolder.accesskey;"
                   oncommand="BrowseForLocalFolders();"/>
         </hbox>
--- a/mailnews/base/prefs/content/am-serverwithnoidentities.xul
+++ b/mailnews/base/prefs/content/am-serverwithnoidentities.xul
@@ -63,15 +63,15 @@
         </menulist>
       </hbox>
     </vbox>
 
     <separator class="thin"/>
 
     <label value="&localPath.label;" control="server.localPath"/>
     <hbox align="center">
-      <textbox readonly="true" wsm_persist="true" flex="1" id="server.localPath" datatype="nsILocalFile"
+      <textbox readonly="true" wsm_persist="true" flex="1" id="server.localPath" datatype="nsIFile"
                prefstring="mail.server.%serverkey%.directory" class="uri-element"/>
       <button id="browseForLocalFolder" label="&browseFolder.label;" filepickertitle="&localFolderPicker.label;"
               accesskey="&browseFolder.accesskey;" oncommand="BrowseForLocalFolders()"/>
     </hbox>
   </groupbox>
 </page>
--- a/mailnews/base/prefs/content/amUtils.js
+++ b/mailnews/base/prefs/content/amUtils.js
@@ -6,29 +6,29 @@
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource:///modules/MailUtils.js");
 Components.utils.import("resource:///modules/iteratorUtils.jsm");
 
 function BrowseForLocalFolders()
 {
   const nsIFilePicker = Components.interfaces.nsIFilePicker;
-  const nsILocalFile = Components.interfaces.nsILocalFile;
+  const nsIFile = Components.interfaces.nsIFile;
 
   var currentFolderTextBox = document.getElementById("server.localPath");
   var fp = Components.classes["@mozilla.org/filepicker;1"]
                      .createInstance(nsIFilePicker);
 
   fp.init(window,
           document.getElementById("browseForLocalFolder")
                   .getAttribute("filepickertitle"),
           nsIFilePicker.modeGetFolder);
 
   var currentFolder = Components.classes["@mozilla.org/file/local;1"]
-                                .createInstance(nsILocalFile);
+                                .createInstance(nsIFile);
   currentFolder.initWithPath(currentFolderTextBox.value);
   fp.displayDirectory = currentFolder;
 
   if (fp.show() != nsIFilePicker.returnOK)
     return;
 
   // Retrieve the selected folder.
   let selectedFolder = fp.file;
--- a/mailnews/extensions/newsblog/content/am-newsblog.xul
+++ b/mailnews/extensions/newsblog/content/am-newsblog.xul
@@ -125,17 +125,17 @@
 
       <vbox>
         <label value="&localPath.label;" control="server.localPath"/>
         <hbox align="center">
           <textbox readonly="true"
                    wsm_persist="true"
                    flex="1"
                    id="server.localPath"
-                   datatype="nsILocalFile"
+                   datatype="nsIFile"
                    prefstring="mail.server.%serverkey%.directory"
                    class="uri-element"/>
           <button id="browseForLocalFolder"
                   label="&browseFolder.label;"
                   filepickertitle="&localFolderPicker.label;"
                   accesskey="&browseFolder.accesskey;"
                   oncommand="BrowseForLocalFolders();"/>
         </hbox>