123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- /*
- * Contact service object based on com.nokia.device.contacts Interface
- */
- var contact = null;
- /*
- * Initializes contact service object
- */
- function initService(){
- try {
- contact = nokia.device.load("contacts");
- }catch(e){
- alert(e.toString());
- }
- }
- /*
- * Starts the device native contact editor
- */
- function startEditor(){
- try {
- contact.startEditor(startEditorCallBack, null, startEditorCallBackErr);
- }
- catch (e) {
- alert(e.toString());
- }
- }
- /*
- * Callback handler for startEditor
- */
- function startEditorCallBack(){
- //Do something
- }
- /*
- * Error Callback handler for startEditor
- */
- function startEditorCallBackErr(err){
- alert(err);
- }
- /*
- * Gets a list of contacts matching the pattern provided in contactFilter field
- */
- function listContacts(){
- var key = document.getElementById("contactFilter").value;
-
- try {
- contact.getContacts(getContactsCallBack, key, contact.SORT_ASCENDING, getContactsCallBackErr);
- }
- catch (e) {
- alert("listContacts: " + e.toString());
- }
- }
- /*
- * getContacts callback function that handles contact iterator and puts content to contactList container
- */
- function getContactsCallBack(outPut){
- var entry = null;
- var content = "<table border='0' width='100%'><tr><th width='5'><input type='checkbox' name='chAll' onClick='chALL(this.checked)'/></th><th colspan='2'><ul class='button-rounded'><li><a href='#' onclick='deleteContacts();'>Delete selected</a></li></th></tr>";
- try {
- while ((entry = outPut.next()) != null) {
- content += showContact(entry);
- }
- }
- catch (e) {
- alert("getContactsCallBack: " + e.toString());
- }
- content += "</table>";
- document.getElementById("contactList").innerHTML = content;
- }
- /*
- * Error Callback handler for getContacts
- */
- function getContactsCallBackErr(err){
-
- if(err.code == 101){ //data not found, no entries on given filter.
- document.getElementById("contactList").innerHTML = "<table border='0' width='100%'><tr><th width='5'><input type='checkbox' name='chAll'/></th><th colspan='2'><ul class='button-rounded'><li><a href='#'>Delete selected</a></li></th></tr></table><p>No Contacts</p>";
- }else{
- alert(err.toString());
- }
- }
- /*
- * Deletes contact by specified id
- * id - unique identifier of contact
- */
- function deleteContact(id){
- try {
- contact.deleteContacts(id);
- }
- catch (e) {
- alert(e.toString());
- }
- }
- /*
- * Adds a new contact based on the data in contact form
- */
- function addContact(){
- try {
- var contactEntry = prepareContactEntry();
- contact.addContact(contactEntry);
- }
- catch (e) {
- alert(e.toString());
- }
- }
- /*
- * Updates existing contact by specified id
- * id - unique identifier of contact
- */
- function updateContact(id){
- try {
- var contactUpdate = prepareContactEntry();
- contactUpdate.id = id;
- contact.updateContact(contactUpdate);
- }
- catch (e) {
- alert(e.toString());
- }
- }
- /*
- * Gets a contact by specified id
- * id - unique identifier of contact
- */
- function getContact(id){
- var result = null;
- try {
- result = contact.getContactInfo(id);
- }
- catch (e) {
- alert(e.toString());
- }
- return result;
- }
|