The index.html
file containing JavaScript that makes use of the
Contact Database API functionality is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | <!DOCTYPE html> <html manifest= "cache.mf" > <head> <script type= "text/javascript" > var now = new Date(); var nowUtc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()); var dateStampGlobalVariable = nowUtc.toJSON().toString(); function printText(str) { var d = document.getElementById( "results" ); d.appendChild(document.createTextNode(str)); d.appendChild(document.createElement( 'br' )); d.scrollTop = d.scrollHeight; } ; function clearOutput() { var d = document.getElementById( "results" ); d.innerHTML = "" ; } ; function saveContact() { var newContact = { //id, readOnly: true , //lastUpdated, read-only name: [ "name" ], honorificPrefix: [ "honorificPrefix" ], givenName: [ "givenName" ], additionalName: [ "additionalName" ], // {String[]} Only first item is supported on Android/iOS. familyName: [ "familyName" ], // {String[]} Only first item is supported on Android/iOS. honorificSuffix: [ "honorificSuffix" ], // {String[]} Only first item is supported on Android/iOS. nickname: [ "nickname" ], // {String[]} Only first item is supported on Android/iOS. email: [ {value: 'email1@gmail.com' , type: "work" }, {value: 'email2@gmail.com' , type: "home" } ], // {ContactField[]} //photo, // {String[]} Data URI, only first item is supported on Android/iOS. // On iOS thumbnails are returned for performance reasons. url: [ {value: 'http/google.com' , type: "work" }, {value: 'http://onet.pl' , type: "home" } ], // {ContactField[]} //categories, // {String[]} Not Supported adr: [ {type: "work" , streetAddress: "streetAddress" , postalCode: "11-222" }, {type: "home" , streetAddress: "streetAddress2" , postalCode: "11-333" } ], // {ContactAddress[]} tel: [ {type: "work" , value: "123456789" }, {type: "home" , value: "987654321" } ], // {ContactTelField[]} Carrier name is not supported on iOS. org: [ "Organization" ], // {String[]} Only first item is supported on Android/iOS. jobTitle: [ "jobTitle" ], // {String[]} Only first item is supported on Android/iOS. bday: dateStampGlobalVariable, note: [ "Lorem ipsum dolor sit amet, consectetur adipiscing elit." ], // {String[]} Only first item is supported on iOS. //impp, // {ContactField[]} Not supported. anniversary: dateStampGlobalVariable // {Date} //sex, // {String} Not supported (no corresponding native field). //genderIdentity, // {String} Not supported (no corresponding native field). }; var callbacks = { onSuccess: function (contact) { printText( "save onSuccess called!" ); printText(JSON.stringify(contact)); }, onFailure: function (err) { printText( "save onFailure called!" ); printText(err.code); printText(err.description); } }; var contacts = launchbox.Contacts; contacts.save(newContact, callbacks); } ; function findContact(){ var options = { filterValue: "jobTitle" , filterOp: "is" , filterBy: [ "jobTitle" ], sortBy: "givenName" , sortOrder: "ascending" , filterLimit: 100 }; var callbacks = { onSuccess: function (contact) { printText( "find onSuccess called!" ); printText(JSON.stringify(contact)); }, onFailure: function () { printText( "find onFailure called!" ); } }; var contacts = launchbox.Contacts; contacts.find(options, callbacks); }; function removeContact(){ var options = { filterValue: "jobTitle" , filterOp: "is" , filterBy: [ "jobTitle" ], sortBy: "givenName" , sortOrder: "ascending" , filterLimit: 100 }; var removeCallbacks = { onSuccess: function (contact) { printText( "remove onSuccess called!" ); printText(JSON.stringify(contact)); }, onFailure: function () { printText( "remove onFailure called!" ); } }; var findCallbacks = { onSuccess: function (contact) { printText( "find onSuccess called!" ); printText(JSON.stringify(contact)); window.launchbox.Contacts.remove(contacts[0], removeCallbacks); }, onFailure: function () { printText( "find onFailure called!" ); } }; var contacts = launchbox.Contacts; contacts.find(options, findCallbacks); } </script> </head> <body> <input type= "button" onclick= "clearOutput();" value= "Clear output" > <hr/> <p>Contacts Launchbox API</p> <input type= "button" onclick= "saveContact();" value= "save Contact" > <input type= "button" onclick= "findContact();" value= "find Contact" > <input type= "button" onclick= "removeContact();" value= "remove Contact" > <hr/> <div id= "results" ></div> </body> </html> |
The contents of the cache manifest file called manifest.appcache
for
this application are listed below:
1 2 3 4 5 6 7 | CACHE MANIFEST CACHE: index.html NETWORK: * |