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.

This commit is contained in:
Josh Geenen 2008-09-21 16:19:37 +01:00
Родитель 76b777530f
Коммит d0b8b3d322
9 изменённых файлов: 55 добавлений и 72 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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();

Просмотреть файл

@ -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);

Просмотреть файл

@ -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();

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -8,7 +8,7 @@
"LastName" : "Last",
"NickName" : "Nickname",
"SecondEmail" : "secondemail@host.invalid",
"_AimScreenName" : "screenname",
"_AimScreenName" : "screenname",
"PreferMailFormat" : 2,
"LastModifiedDate" : 1213818826,
"WorkPhone" : "123-456-7890",

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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");