From d0b8b3d3228b13060c57cc332a0b10d13cf08a05 Mon Sep 17 00:00:00 2001 From: Josh Geenen Date: Sun, 21 Sep 2008 16:19:37 +0100 Subject: [PATCH] Bug 455797 - "birthday picker doesn't let me enter certain dates, resets day and year", also allow LDAP and LDIF import/export to work correctly. r=Standard8,sr=Neil. a=KaiRo for SM2a1. --- .../addrbook/content/abCardOverlay.js | 43 ++++++++----------- .../addrbook/content/abCardViewOverlay.js | 4 +- .../resources/content/abCardOverlay.js | 43 ++++++++----------- .../resources/content/abCardViewOverlay.js | 4 +- mailnews/import/test/resources/AB_README | 10 ++--- .../import/test/resources/addressbook.json | 2 +- .../resources/basic_ldif_addressbook.ldif | 2 + .../import/test/resources/import_helper.js | 17 +++----- mailnews/mailnews.js | 2 + 9 files changed, 55 insertions(+), 72 deletions(-) diff --git a/mail/components/addrbook/content/abCardOverlay.js b/mail/components/addrbook/content/abCardOverlay.js index 56102c08fd..b6598ae6b3 100644 --- a/mail/components/addrbook/content/abCardOverlay.js +++ b/mail/components/addrbook/content/abCardOverlay.js @@ -407,24 +407,24 @@ function GetCardValues(cardproperty, doc) // get the month of the year (1 - 12) var month = cardproperty.getProperty("BirthMonth", null); - // set the datepicker's month and prepend a zero if necessary - if (month) { - birthday.month = parseInt(month) - 1; - if (month.length < 2) - month = "0" + month; - } - birthday.monthField.value = month; + if (month > 0 && month < 13) + birthday.month = month - 1; + else + birthday.monthField.value = null; // get the date of the month (1 - 31) var date = cardproperty.getProperty("BirthDay", null); - birthday.dateField.value = date; + if (date > 0 && date < 32) + birthday.date = date; + else + birthday.dateField.value = null; // get the year var year = cardproperty.getProperty("BirthYear", null); var birthYear = doc.getElementById("BirthYear"); // set the year in the datepicker to the stored year // if the year isn't present, default to 2000 (a leap year) - birthday.year = year ? year : kDefaultYear; + birthday.year = year && year < 10000 && year > 0 ? year : kDefaultYear; birthYear.value = year; // get the current age @@ -484,19 +484,10 @@ function CheckAndSetCardValues(cardproperty, doc, check) var birthDay = birthdayElem.dateField.value; var birthYear = doc.getElementById("BirthYear").value; - // set or delete the birth day, month, and year properties, if necessary - if (birthDay) - cardproperty.setProperty("BirthDay", birthDay); - else if(cardproperty.getProperty("BirthDay", null)) - cardproperty.deleteProperty("BirthDay"); - if (birthMonth) - cardproperty.setProperty("BirthMonth", birthMonth); - else if(cardproperty.getProperty("BirthMonth", null)) - cardproperty.deleteProperty("BirthMonth"); - if (birthYear) - cardproperty.setProperty("BirthYear", birthYear); - else if(cardproperty.getProperty("BirthYear", null)) - cardproperty.deleteProperty("BirthYear"); + // set the birth day, month, and year properties + cardproperty.setProperty("BirthDay", birthDay); + cardproperty.setProperty("BirthMonth", birthMonth); + cardproperty.setProperty("BirthYear", birthYear); var popup = document.getElementById("PreferMailFormatPopup"); if (popup) @@ -783,18 +774,18 @@ function modifyDatepicker(aDatepicker) { this._dateValue.setDate(0); this._updateUI(this.dateField, this.date); var date = this._dateValue.getDate(); - this.dateField.value = date < 10 ? "0" + date : date; + this.dateField.value = date < 10 && this.dateLeadingZero ? "0" + date : date; var month = this._dateValue.getMonth() + 1; - this.monthField.value = month < 10 ? "0" + month : month; + this.monthField.value = month < 10 && this.monthLeadingZero ? "0" + month : month; } // update the date if the value isn't null else if (aField == this.dateField && aValue != null) { this._dateValue.setDate(aValue); this._updateUI(this.dateField, this.date); var date = this._dateValue.getDate(); - this.dateField.value = date < 10 ? "0" + date : date; + this.dateField.value = date < 10 && this.dateLeadingZero ? "0" + date : date; var month = this._dateValue.getMonth() + 1; - this.monthField.value = month < 10 ? "0" + month : month; + this.monthField.value = month < 10 && this.monthLeadingZero ? "0" + month : month; } this.setAttribute("value", this.value); diff --git a/mail/components/addrbook/content/abCardViewOverlay.js b/mail/components/addrbook/content/abCardViewOverlay.js index b54d95ebd1..38d4a4a977 100644 --- a/mail/components/addrbook/content/abCardViewOverlay.js +++ b/mail/components/addrbook/content/abCardViewOverlay.js @@ -318,8 +318,8 @@ function DisplayCardViewPane(realCard) var month = card.getProperty("BirthMonth", null); var year = card.getProperty("BirthYear", null); var dateStr; - if (day || month) { - var date = (new Date(year, parseInt(month) - 1, day)); + if (day > 0 && day < 32 && month > 0 && month < 13) { + var date = new Date(year, month - 1, day); // if the year exists, just use Date.toLocaleString if (year) dateStr = date.toLocaleDateString(); diff --git a/mailnews/addrbook/resources/content/abCardOverlay.js b/mailnews/addrbook/resources/content/abCardOverlay.js index 22a9bac069..0cc47c82ed 100644 --- a/mailnews/addrbook/resources/content/abCardOverlay.js +++ b/mailnews/addrbook/resources/content/abCardOverlay.js @@ -405,24 +405,24 @@ function GetCardValues(cardproperty, doc) // get the month of the year (1 - 12) var month = cardproperty.getProperty("BirthMonth", null); - // set the datepicker's month and prepend a zero if necessary - if (month) { - birthday.month = parseInt(month) - 1; - if (month.length < 2) - month = "0" + month; - } - birthday.monthField.value = month; + if (month > 0 && month < 13) + birthday.month = month - 1; + else + birthday.monthField.value = null; // get the date of the month (1 - 31) var date = cardproperty.getProperty("BirthDay", null); - birthday.dateField.value = date; + if (date > 0 && date < 32) + birthday.date = date; + else + birthday.dateField.value = null; // get the year var year = cardproperty.getProperty("BirthYear", null); var birthYear = doc.getElementById("BirthYear"); // set the year in the datepicker to the stored year // if the year isn't present, default to 2000 (a leap year) - birthday.year = year ? year : kDefaultYear; + birthday.year = year && year < 10000 && year > 0 ? year : kDefaultYear; birthYear.value = year; // get the current age @@ -481,19 +481,10 @@ function CheckAndSetCardValues(cardproperty, doc, check) var birthDay = birthdayElem.dateField.value; var birthYear = doc.getElementById("BirthYear").value; - // set or delete the birth day, month, and year properties, if necessary - if (birthDay) - cardproperty.setProperty("BirthDay", birthDay); - else if(cardproperty.getProperty("BirthDay", null)) - cardproperty.deleteProperty("BirthDay"); - if (birthMonth) - cardproperty.setProperty("BirthMonth", birthMonth); - else if(cardproperty.getProperty("BirthMonth", null)) - cardproperty.deleteProperty("BirthMonth"); - if (birthYear) - cardproperty.setProperty("BirthYear", birthYear); - else if(cardproperty.getProperty("BirthYear", null)) - cardproperty.deleteProperty("BirthYear"); + // set the birth day, month, and year properties + cardproperty.setProperty("BirthDay", birthDay); + cardproperty.setProperty("BirthMonth", birthMonth); + cardproperty.setProperty("BirthYear", birthYear); var popup = document.getElementById("PreferMailFormatPopup"); if (popup) @@ -780,18 +771,18 @@ function modifyDatepicker(aDatepicker) { this._dateValue.setDate(0); this._updateUI(this.dateField, this.date); var date = this._dateValue.getDate(); - this.dateField.value = date < 10 ? "0" + date : date; + this.dateField.value = date < 10 && this.dateLeadingZero ? "0" + date : date; var month = this._dateValue.getMonth() + 1; - this.monthField.value = month < 10 ? "0" + month : month; + this.monthField.value = month < 10 && this.monthLeadingZero ? "0" + month : month; } // update the date if the value isn't null else if (aField == this.dateField && aValue != null) { this._dateValue.setDate(aValue); this._updateUI(this.dateField, this.date); var date = this._dateValue.getDate(); - this.dateField.value = date < 10 ? "0" + date : date; + this.dateField.value = date < 10 && this.dateLeadingZero ? "0" + date : date; var month = this._dateValue.getMonth() + 1; - this.monthField.value = month < 10 ? "0" + month : month; + this.monthField.value = month < 10 && this.monthLeadingZero ? "0" + month : month; } this.setAttribute("value", this.value); diff --git a/mailnews/addrbook/resources/content/abCardViewOverlay.js b/mailnews/addrbook/resources/content/abCardViewOverlay.js index e5c9487456..1debd405ea 100644 --- a/mailnews/addrbook/resources/content/abCardViewOverlay.js +++ b/mailnews/addrbook/resources/content/abCardViewOverlay.js @@ -300,8 +300,8 @@ function DisplayCardViewPane(realCard) var month = card.getProperty("BirthMonth", null); var year = card.getProperty("BirthYear", null); var dateStr; - if (day || month) { - var date = (new Date(year, parseInt(month) - 1, day)); + if (day > 0 && day < 32 && month > 0 && month < 13) { + var date = new Date(year, month - 1, day); // if the year exists, just use Date.toLocaleString if (year) dateStr = date.toLocaleDateString(); diff --git a/mailnews/import/test/resources/AB_README b/mailnews/import/test/resources/AB_README index 206c24e0c0..1f79b70e53 100644 --- a/mailnews/import/test/resources/AB_README +++ b/mailnews/import/test/resources/AB_README @@ -23,17 +23,17 @@ You will also need to give the AbImportHelper constructor two additional parameters: the name the imported address book will have (the filename without the extension) and the name you chose for the JSON object. -Here is a sample unit test that doesn't check the results: +Here is a sample LDIF unit test that doesn't check the results: function run_test() { var file = do_get_file("../mailnews/import/test/resources/basic_ldif_addressbook.ldif"); - new AbImportHelper(file, "ldif").beginImport(); + new AbImportHelper(file, "LDIF").beginImport(); } -Here is a sample unit test that checks the results: +Here is a sample CSV unit test that checks the results: function run_test() { - var file = do_get_file("../mailnews/import/test/resources/basic_ldif_addressbook.ldif"); - new AbImportHelper(file, "ldif", "basic_ldif_addressbook", + var file = do_get_file("../mailnews/import/test/resources/basic_csv_addressbook.csv"); + new AbImportHelper(file, "CSV", "basic_csv_addressbook", "basic_addressbook").beginImport(); } diff --git a/mailnews/import/test/resources/addressbook.json b/mailnews/import/test/resources/addressbook.json index 3f7dc8e8e3..ea0910467b 100644 --- a/mailnews/import/test/resources/addressbook.json +++ b/mailnews/import/test/resources/addressbook.json @@ -8,7 +8,7 @@ "LastName" : "Last", "NickName" : "Nickname", "SecondEmail" : "secondemail@host.invalid", - "_AimScreenName" : "screenname", + "_AimScreenName" : "screenname", "PreferMailFormat" : 2, "LastModifiedDate" : 1213818826, "WorkPhone" : "123-456-7890", diff --git a/mailnews/import/test/resources/basic_ldif_addressbook.ldif b/mailnews/import/test/resources/basic_ldif_addressbook.ldif index f22a1cf18c..cf8ebab355 100644 --- a/mailnews/import/test/resources/basic_ldif_addressbook.ldif +++ b/mailnews/import/test/resources/basic_ldif_addressbook.ldif @@ -36,6 +36,8 @@ o: Organization Name mozillaWorkUrl: http://127.0.0.1 mozillaHomeUrl: http://localhost birthyear: 1900 +birthmonth: 1 +birthday: 2 mozillaCustom1: Custom Field 1 mozillaCustom2: Custom Field 2 mozillaCustom3: Custom Field 3 diff --git a/mailnews/import/test/resources/import_helper.js b/mailnews/import/test/resources/import_helper.js index c21f06aeda..ef4f49488a 100644 --- a/mailnews/import/test/resources/import_helper.js +++ b/mailnews/import/test/resources/import_helper.js @@ -20,14 +20,13 @@ var gAbImportHelper; */ function AbImportHelper(aFile, aType, aAbName, aJsonName) { - helper = null; + gAbImportHelper = null; this.mFile = aFile; // checked in the beginImport method this.mAbName = aAbName; /* Attribute notes: The attributes listed in the declaration below are - * supported by all three text export/import types. AimScreenName & - * PreferMailFormat are only supported by LDIF, and BirthMonth and BirthDay - * are only supported by CSV and tab-delimited exports/imports. + * supported by all three text export/import types. AimScreenName and + * PreferMailFormat are only supported by LDIF. * The following are not supported: anniversaryYear, anniversaryMonth, * anniversaryDay, popularityIndex, isMailList, mailListURI, lastModifiedDate, * and allowRemoteContent @@ -38,8 +37,8 @@ function AbImportHelper(aFile, aType, aAbName, aJsonName) "CellularNumber", "HomeAddress", "HomeAddress2", "HomeCity", "HomeState", "HomeZipCode", "HomeCountry", "WorkAddress", "WorkAddress2", "WorkCity", "WorkState", "WorkZipCode", "WorkCountry", "JobTitle", "Department", - "Company", "BirthYear", "WebPage1", "WebPage2", "Custom1", "Custom2", - "Custom3", "Custom4", "Notes"]; + "Company", "BirthYear", "BirthMonth", "BirthDay", "WebPage1", "WebPage2", + "Custom1", "Custom2", "Custom3", "Custom4", "Notes"]; // get the extra attributes supported for the given type of import if (aType == "LDIF") { @@ -50,9 +49,7 @@ function AbImportHelper(aFile, aType, aAbName, aJsonName) } else if (aType == "CSV" || aType == "TAB") { - // CSV or TAB: add BirthMonth and BirthDay - this.mSupportedAttributes = supportedAttributes.concat(["BirthMonth", - "BirthDay"]); + this.mSupportedAttributes = supportedAttributes; this.mLdif = false; } else @@ -232,7 +229,7 @@ AbImportHelper.prototype = { for (var i in aJsonCard) if (this.mSupportedAttributes.indexOf(i) >= 0) - do_check_eq(aJsonCard[i], aCard.getProperty(i, "BAD")); + do_check_eq(aJsonCard[i], aCard.getProperty(i, "BAD")); }, /** * AbImportHelper.getJsonCards diff --git a/mailnews/mailnews.js b/mailnews/mailnews.js index b1f8e19dd1..474212bc78 100644 --- a/mailnews/mailnews.js +++ b/mailnews/mailnews.js @@ -365,6 +365,8 @@ pref("ldap_2.servers.default.attrmap._AimScreenName", "nsAIMid,nscpaimscreenname pref("ldap_2.servers.default.attrmap.WebPage1", "mozillaWorkUrl,workurl"); pref("ldap_2.servers.default.attrmap.WebPage2", "mozillaHomeUrl,homeurl"); pref("ldap_2.servers.default.attrmap.BirthYear", "birthyear"); +pref("ldap_2.servers.default.attrmap.BirthMonth", "birthmonth"); +pref("ldap_2.servers.default.attrmap.BirthDay", "birthday"); pref("ldap_2.servers.default.attrmap.Custom1", "mozillaCustom1,custom1"); pref("ldap_2.servers.default.attrmap.Custom2", "mozillaCustom2,custom2"); pref("ldap_2.servers.default.attrmap.Custom3", "mozillaCustom3,custom3");