You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/03/28 03:15:47 UTC
[1/17] wp7 commit: contact formatting issues
Updated Branches:
refs/heads/master ae0902f5c -> 012625df0
contact formatting issues
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/012625df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/012625df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/012625df
Branch: refs/heads/master
Commit: 012625df013eae396f9556efddb702e2f5455115
Parents: 358f8da
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Mar 27 18:10:06 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Mar 27 18:10:06 2012 -0700
----------------------------------------------------------------------
framework/Cordova/Commands/Contacts.cs | 62 ++++++++++++---
.../MobileSpecUnitTests/MobileSpecUnitTests.csproj | 1 -
tests/MobileSpecUnitTests/www/cordova-1.6.0.js | 44 ++++++++--
3 files changed, 84 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/012625df/framework/Cordova/Commands/Contacts.cs
----------------------------------------------------------------------
diff --git a/framework/Cordova/Commands/Contacts.cs b/framework/Cordova/Commands/Contacts.cs
index 07eaebd..1d260f2 100644
--- a/framework/Cordova/Commands/Contacts.cs
+++ b/framework/Cordova/Commands/Contacts.cs
@@ -189,6 +189,7 @@ namespace WP7CordovaClassLib.Cordova.Commands
JSONContact contact = JSON.JsonHelper.Deserialize<JSONContact>(jsonContact);
+
SaveContactTask contactTask = new SaveContactTask();
if (contact.nickname != null)
@@ -255,19 +256,26 @@ namespace WP7CordovaClassLib.Cordova.Commands
{
foreach (JSONContactField field in contact.emails)
{
- string fieldType = field.type.ToLower();
- if (fieldType == "work")
- {
- contactTask.WorkEmail = field.value;
- }
- else if (fieldType == "home" || fieldType == "personal")
+ if (field != null)
{
- contactTask.PersonalEmail = field.value;
- }
- else
- {
- contactTask.OtherEmail = field.value;
+ if (field.type != null)
+ {
+ string fieldType = field.type.ToLower();
+ if (fieldType == "work")
+ {
+ contactTask.WorkEmail = field.value;
+ }
+ else if (fieldType == "home" || fieldType == "personal")
+ {
+ contactTask.PersonalEmail = field.value;
+ }
+ }
+ else
+ {
+ contactTask.OtherEmail = field.value;
+ }
}
+
}
}
#endregion
@@ -482,14 +490,42 @@ namespace WP7CordovaClassLib.Cordova.Commands
return retVal.TrimEnd(',');
}
+ private string getFormattedJSONAddress(ContactAddress address, bool isPrefered)
+ {
+
+ string addressFormatString = "pref:{0}," + // bool
+ "type:'{1}'," +
+ "formatted:'{2}'," +
+ "streetAddress:'{3}'," +
+ "locality:'{4}'," +
+ "region:'{5}'," +
+ "postalCode:'{6}'," +
+ "country:'{7}'";
+
+ string jsonAddress = string.Format(addressFormatString,
+ isPrefered ? "true" : "false",
+ address.Kind.ToString(),
+ "formattedAddress",
+ address.PhysicalAddress.AddressLine1 + " " + address.PhysicalAddress.AddressLine2,
+ address.PhysicalAddress.City,
+ address.PhysicalAddress.StateProvince,
+ address.PhysicalAddress.PostalCode,
+ address.PhysicalAddress.CountryRegion);
+
+
+
+
+ return "{" + jsonAddress + "}";
+ }
+
private string FormatJSONAddresses(Contact con)
{
string retVal = "";
foreach (ContactAddress address in con.Addresses)
{
- retVal += "\"" + address.ToString() + "\",";
+ retVal += this.getFormattedJSONAddress(address, false) + ",";
}
- return retVal.TrimEnd(',');
+ return "[" + retVal.TrimEnd(',') + "]";
}
private string FormatJSONWebsites(Contact con)
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/012625df/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj b/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj
index da4b766..7312cc7 100644
--- a/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj
+++ b/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj
@@ -113,7 +113,6 @@
<Content Include="www\autotest\tests\storage.tests.js" />
<Content Include="www\autotest\tests\system.tests.js" />
<Content Include="www\cordova-1.6.0.js" />
- <Content Include="www\cordova.wp7.js" />
<Content Include="www\index.html">
<SubType>Designer</SubType>
</Content>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/012625df/tests/MobileSpecUnitTests/www/cordova-1.6.0.js
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/cordova-1.6.0.js b/tests/MobileSpecUnitTests/www/cordova-1.6.0.js
index 6abcf25..3d5ddfb 100644
--- a/tests/MobileSpecUnitTests/www/cordova-1.6.0.js
+++ b/tests/MobileSpecUnitTests/www/cordova-1.6.0.js
@@ -94,6 +94,7 @@ Cordova.exec = function(success, fail, service, action, args)
CordovaCommandResult = function(status,callbackId,args,cast)
{
+ console.log("CordovaCommandResult::" + status + ", " + callbackId + ", " + args);
if(status === "backbutton") {
Cordova.fireEvent(document,"backbutton");
@@ -110,15 +111,23 @@ CordovaCommandResult = function(status,callbackId,args,cast)
return "true";
}
- var safeStatus = parseInt(status);
- if(safeStatus === Cordova.callbackStatus.NO_RESULT ||
- safeStatus === Cordova.callbackStatus.OK) {
- Cordova.CallbackSuccess(callbackId,args,cast);
+ try
+ {
+ var safeStatus = parseInt(status);
+ if(safeStatus === Cordova.callbackStatus.NO_RESULT ||
+ safeStatus === Cordova.callbackStatus.OK) {
+ Cordova.CallbackSuccess(callbackId,args,cast);
+ }
+ else
+ {
+ Cordova.CallbackError(callbackId,args,cast);
+ }
}
- else
+ catch(ex)
{
- Cordova.CallbackError(callbackId,args,cast);
+ console.log("exception in CordovaCommandResult :: " + ex);
}
+
};
/**
@@ -1598,6 +1607,11 @@ Contacts.prototype.find = function(fields, successCB, errorCB, options) {
if (successCB === null) {
throw new TypeError("You must specify a success callback for the find command.");
}
+ console.log("Contacts.prototype.find :: fields=" + fields);
+ console.log("Contacts.prototype.find :: successCB=" + successCB);
+ console.log("Contacts.prototype.find :: errorCB=" + errorCB);
+ console.log("Contacts.prototype.find :: options=" + options);
+
if (fields === null || fields === "undefined" || fields.length === "undefined" || fields.length <= 0) {
if (typeof errorCB === "function")
{
@@ -1612,10 +1626,22 @@ Contacts.prototype.find = function(fields, successCB, errorCB, options) {
{
var onSuccess = function(res)
{
- setTimeout(function()
- {
+ console.log("contacts.search :: onSuccess" + res);
+ //setTimeout(function()
+ //{
successCB(res);
- },0);
+ //},0);
+ }
+ var onError = function(err)
+ {
+ console.log("contacts.search :: onError " + err);
+ if(errorCB)
+ {
+ //setTimeout(function()
+ //{
+ errorCB(err);
+ //},0);
+ }
}
Cordova.exec(onSuccess, errorCB, "Contacts", "search", {"fields":fields,"options":options});
}