Bug 824150 - Code cleanup in /mail/ and /mailnews/: Use new String methods like startsWith, endsWith, contains, remaining Services.jsm switches and querySelector use instead of NodeList calls: import. r=mbanner
--- a/mailnews/import/content/importDialog.js
+++ b/mailnews/import/content/importDialog.js
@@ -61,17 +61,17 @@ function OnLoadImportDialog()
function SetUpImportType()
{
// set dialog title
document.getElementById("importFields").value = importType;
// Mac migration not working right now, so disable it
- if (navigator.platform.match("^Mac"))
+ if (navigator.platform.startsWith("Mac"))
{
document.getElementById("allRadio").setAttribute("disabled", "true");
if (importType == "all")
document.getElementById("importFields").value = "addressbook";
}
let descriptionDeck = document.getElementById("selectDescriptionDeck");
descriptionDeck.setAttribute("selectedIndex", "0");
@@ -414,17 +414,17 @@ function ListFeedAccounts() {
}, this);
if (index)
// If there is an existing feed account, select the first one.
body.selectedIndex = 1;
}
function ContinueImport( info) {
- var isMail = info.importType == 'mail' ? true : false;
+ var isMail = info.importType == 'mail';
var clear = true;
var deck;
var pcnt;
if (info.importInterface) {
if (!info.importInterface.ContinueImport()) {
info.importSuccess = false;
clearInterval( info.intervalState);
@@ -547,17 +547,17 @@ function ShowImportResultsRaw(title, res
nextButton.removeAttribute("disabled");
var cancelButton = document.getElementById("cancel");
cancelButton.setAttribute("disabled", "true");
var backButton = document.getElementById("back");
backButton.setAttribute("disabled", "true");
// If the Local Folder is not existed, create it after successfully
// import "mail" and "settings"
- var checkLocalFolder = (top.progressInfo.importType == 'mail' || top.progressInfo.importType == 'settings') ? true : false;
+ var checkLocalFolder = (top.progressInfo.importType == 'mail' || top.progressInfo.importType == 'settings');
if (good && checkLocalFolder && !top.progressInfo.localFolderExists) {
var am = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
if (am)
am.createLocalMailAccount();
}
}
function attachStrings(aNode, aString)
--- a/mailnews/import/test/unit/resources/import_helper.js
+++ b/mailnews/import/test/unit/resources/import_helper.js
@@ -102,20 +102,16 @@ GenericImportHelper.prototype =
* GenericImportHelper.checkResults
* Checks the results of the import.
* Child class should implement this method.
*/
checkResults: function() {
}
};
-function endsWith(string, suffix) {
- return string.indexOf(suffix, string.length - suffix.length) != -1;
-}
-
/**
* AbImportHelper
* A helper for Address Book imports. To use, supply at least the file and type.
* If you would like the results checked, add a new array in the addressbook
* JSON file in the resources folder and supply aAbName and aJsonName.
* See AB_README for more information.
*
* @param aFile An instance of nsIAbFile to import.
@@ -148,23 +144,23 @@ function AbImportHelper(aFile, aModuleSe
"SecondEmail", "WorkPhone", "HomePhone", "FaxNumber", "PagerNumber",
"CellularNumber", "HomeAddress", "HomeAddress2", "HomeCity", "HomeState",
"HomeZipCode", "HomeCountry", "WorkAddress", "WorkAddress2", "WorkCity",
"WorkState", "WorkZipCode", "WorkCountry", "JobTitle", "Department",
"Company", "BirthYear", "BirthMonth", "BirthDay", "WebPage1", "WebPage2",
"Custom1", "Custom2", "Custom3", "Custom4", "Notes", "_AimScreenName"];
// get the extra attributes supported for the given type of import
- if (endsWith(this.mFile.leafName.toLowerCase(), ".ldif")) {
+ if (this.mFile.leafName.toLowerCase().endsWith(".ldif")) {
// LDIF: add PreferMailFormat
this.mSupportedAttributes = supportedAttributes.concat(["PreferMailFormat"]);
- } else if (endsWith(this.mFile.leafName.toLowerCase(), ".csv")) {
+ } else if (this.mFile.leafName.toLowerCase().endsWith(".csv")) {
this.mSupportedAttributes = supportedAttributes;
this.setFieldMap(this.getDefaultFieldMap(true));
- } else if (endsWith(this.mFile.leafName.toLowerCase(), ".vcf")) {
+ } else if (this.mFile.leafName.toLowerCase().endsWith(".vcf")) {
this.mSupportedAttributes = supportedAttributes;
};
// get the "cards" from the JSON file, if necessary
if (aJsonName)
this.mJsonCards = this.getJsonCards(aJsonName);
}