You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2012/05/11 17:21:25 UTC

[1/3] bada-wac commit: updating sample code

Updated Branches:
  refs/heads/master 4de730309 -> c4f7a099f


updating sample code


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/commit/c4f7a099
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/tree/c4f7a099
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/diff/c4f7a099

Branch: refs/heads/master
Commit: c4f7a099f8a1ee38f4f7171588167cfd30bccb55
Parents: fa5648e
Author: Anis Kadri <an...@gmail.com>
Authored: Fri May 11 08:18:43 2012 -0700
Committer: Anis Kadri <an...@gmail.com>
Committed: Fri May 11 08:18:43 2012 -0700

----------------------------------------------------------------------
 Res/js/sample.js |   93 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 93 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/blob/c4f7a099/Res/js/sample.js
----------------------------------------------------------------------
diff --git a/Res/js/sample.js b/Res/js/sample.js
index 1a6c0e8..5a1fd23 100644
--- a/Res/js/sample.js
+++ b/Res/js/sample.js
@@ -308,4 +308,97 @@ function captureVideo() {
 		console.log(error);
 	};
 	navigator.device.capture.captureVideo(success, fail);
+}
+
+function createContact() {
+	function onSuccess(contact) {
+	    alert("Save Success "+JSON.stringify(contact));
+	};
+
+	function onError(contactError) {
+	    alert("Error = " + contactError.code);
+	};
+
+	// create a new contact object
+	var contact = navigator.contacts.create();
+	contact.displayName = "Plumber";
+	contact.nickname = "Plumber";       //specify both to support all devices
+
+	// populate some fields
+	var name = new ContactName();
+	name.givenName = "Jackson";
+	name.familyName = "Doe";
+	contact.name = name;
+
+	// save to device
+	contact.save(onSuccess,onError);
+}
+
+function findContact() {	
+	function onSuccess(contacts) {
+		alert(JSON.stringify(contacts));
+	    alert('Found ' + contacts.length + ' contacts.');
+	};
+
+	function onError(contactError) {
+	    alert('onError!');
+	};
+
+	var options = new ContactFindOptions();
+	options.filter="Jane"; 
+	var fields = ["displayName", "name"];
+	navigator.contacts.find(fields, onSuccess, onError, options);
+
+}
+
+function updateContact() {
+	function onSuccess(contact) {
+	    alert("Save Success "+JSON.stringify(contact));
+	};
+
+	function onError(contactError) {
+	    alert("Error = " + contactError.code);
+	};
+
+	// create a new contact object
+	var contact = navigator.contacts.create();
+	contact.displayName = "Plumber";
+	contact.nickname = "Plumber";       //specify both to support all devices
+
+	// populate some fields
+	var name = new ContactName();
+	name.givenName = "Jane";
+	name.familyName = "Doe";
+	contact.name = name;
+
+	// save to device
+	contact.save(onSuccess,onError);
+	
+	// update
+	name.givenName = "John";
+	contact.name = name;
+	contact.save(onSuccess,onError);
+}
+
+function removeContact() {
+	function onSuccess(contacts) {
+		var i, j;
+		var success = function(c) {
+			alert('contact removed!');
+		};
+		var error = function(c) {
+			alert('error removing');
+		};
+		for(i = 0, j = contacts.length ; i < j ; i++) {
+			contacts[i].remove(success, error);
+		}
+	};
+
+	function onError(contactError) {
+	    alert('onError!');
+	};
+	var options = new ContactFindOptions();
+	options.filter="Doe"; 
+	var fields = ["displayName", "name"];
+	navigator.contacts.find(fields, onSuccess, onError, options);	
 }
\ No newline at end of file