platformservices_20_specific.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Contact service object based on com.nokia.device.contacts Interface
  3. */
  4. var contact = null;
  5. /*
  6. * Initializes contact service object
  7. */
  8. function initService(){
  9. try {
  10. contact = nokia.device.load("contacts");
  11. }catch(e){
  12. alert(e.toString());
  13. }
  14. }
  15. /*
  16. * Starts the device native contact editor
  17. */
  18. function startEditor(){
  19. try {
  20. contact.startEditor(startEditorCallBack, null, startEditorCallBackErr);
  21. }
  22. catch (e) {
  23. alert(e.toString());
  24. }
  25. }
  26. /*
  27. * Callback handler for startEditor
  28. */
  29. function startEditorCallBack(){
  30. //Do something
  31. }
  32. /*
  33. * Error Callback handler for startEditor
  34. */
  35. function startEditorCallBackErr(err){
  36. alert(err);
  37. }
  38. /*
  39. * Gets a list of contacts matching the pattern provided in contactFilter field
  40. */
  41. function listContacts(){
  42. var key = document.getElementById("contactFilter").value;
  43. try {
  44. contact.getContacts(getContactsCallBack, key, contact.SORT_ASCENDING, getContactsCallBackErr);
  45. }
  46. catch (e) {
  47. alert("listContacts: " + e.toString());
  48. }
  49. }
  50. /*
  51. * getContacts callback function that handles contact iterator and puts content to contactList container
  52. */
  53. function getContactsCallBack(outPut){
  54. var entry = null;
  55. 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>";
  56. try {
  57. while ((entry = outPut.next()) != null) {
  58. content += showContact(entry);
  59. }
  60. }
  61. catch (e) {
  62. alert("getContactsCallBack: " + e.toString());
  63. }
  64. content += "</table>";
  65. document.getElementById("contactList").innerHTML = content;
  66. }
  67. /*
  68. * Error Callback handler for getContacts
  69. */
  70. function getContactsCallBackErr(err){
  71. if(err.code == 101){ //data not found, no entries on given filter.
  72. 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>";
  73. }else{
  74. alert(err.toString());
  75. }
  76. }
  77. /*
  78. * Deletes contact by specified id
  79. * id - unique identifier of contact
  80. */
  81. function deleteContact(id){
  82. try {
  83. contact.deleteContacts(id);
  84. }
  85. catch (e) {
  86. alert(e.toString());
  87. }
  88. }
  89. /*
  90. * Adds a new contact based on the data in contact form
  91. */
  92. function addContact(){
  93. try {
  94. var contactEntry = prepareContactEntry();
  95. contact.addContact(contactEntry);
  96. }
  97. catch (e) {
  98. alert(e.toString());
  99. }
  100. }
  101. /*
  102. * Updates existing contact by specified id
  103. * id - unique identifier of contact
  104. */
  105. function updateContact(id){
  106. try {
  107. var contactUpdate = prepareContactEntry();
  108. contactUpdate.id = id;
  109. contact.updateContact(contactUpdate);
  110. }
  111. catch (e) {
  112. alert(e.toString());
  113. }
  114. }
  115. /*
  116. * Gets a contact by specified id
  117. * id - unique identifier of contact
  118. */
  119. function getContact(id){
  120. var result = null;
  121. try {
  122. result = contact.getContactInfo(id);
  123. }
  124. catch (e) {
  125. alert(e.toString());
  126. }
  127. return result;
  128. }