basic.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. addEvent("onload", init);
  2. addEvent("onresize", checkOrientation);
  3. var screenmode = 0;
  4. function init(){
  5. try {
  6. var myStyleTweaks = new StyleTweaker();
  7. myStyleTweaks.add("Series60/5.0", "styles/tweaks/S605th.css");
  8. myStyleTweaks.add("Series60/3.2", "styles/tweaks/S603rdFP2.css");
  9. myStyleTweaks.tweak();
  10. initService();
  11. listContacts();
  12. }
  13. catch (e) {
  14. alert(e.toString());
  15. }
  16. }
  17. function checkOrientation(){
  18. try {
  19. var width = parseInt(screen.width);
  20. var height = parseInt(screen.height);
  21. //var landscapeTweaker = new StyleTweaker();
  22. // Landscape tweaks for template styles not available in templates?
  23. //landscapeTweaker.add("Series60/5.0", "../resources/styles/tweaks/S605thLandscape.css");
  24. if (width > height) {
  25. // if already in landscape mode, return
  26. if (screenmode == 1)
  27. return;
  28. screenmode = 1;
  29. // landscapeTweaker.tweak();
  30. }
  31. else {
  32. // if already in portrait mode, return
  33. if (screenmode == 0)
  34. return;
  35. screenmode = 0;
  36. // landscapeTweaker.untweak();
  37. }
  38. }
  39. catch (e) {
  40. alert(e.toString());
  41. }
  42. }
  43. /*
  44. * Shows the content of selected tab.
  45. * tab - tab to be shown
  46. */
  47. function show(tab, tid){
  48. document.getElementById("nameGroup").style.display = "none";
  49. document.getElementById("a1").className = "";
  50. document.getElementById("telGroup").style.display = "none";
  51. document.getElementById("a2").className = "";
  52. document.getElementById("addressGroup").style.display = "none";
  53. document.getElementById("a3").className = "";
  54. document.getElementById("companyGroup").style.display = "none";
  55. document.getElementById("a4").className = "";
  56. document.getElementById(tab).style.display = "block";
  57. document.getElementById(tid).className = "selectedTab";
  58. }
  59. /*
  60. * Shows new contact form
  61. */
  62. function newContact(){
  63. document.contact.contactID.value = "";
  64. cleanForm();
  65. document.getElementById("header2").innerHTML = "New Contact";
  66. document.getElementById("contactListContainer").style.display = "none";
  67. show("nameGroup","a1");
  68. document.getElementById("singleContactContainer").style.display = "block";
  69. }
  70. /*
  71. * Shows selected contact in contact form
  72. * id - unique identifier of contact
  73. * Contact information is retrieved by getContact(id) function defined in platformservices_20_specific.js
  74. */
  75. function openContact(id){
  76. document.contact.contactID.value = id;
  77. var contactEntry = getContact(id);
  78. if (contactEntry != null) {
  79. preFillContactForm(contactEntry);
  80. var header = (contactEntry.name == null) ? "(unnamed)" : getValue(contactEntry.name.last) + " " + getValue(contactEntry.name.first);
  81. document.getElementById("header2").innerHTML = header;
  82. document.getElementById("contactListContainer").style.display = "none";
  83. show("nameGroup","a1");
  84. document.getElementById("singleContactContainer").style.display = "block";
  85. }
  86. else
  87. alert("Error retrieving contact info.");
  88. }
  89. /*
  90. * Shows list of contacts
  91. */
  92. function showContactList(){
  93. document.getElementById("contactListContainer").style.display = "block";
  94. document.getElementById("singleContactContainer").style.display = "none";
  95. }
  96. /*
  97. * Sets all contact checkboxes to specified status
  98. * checked - status to be set: true or false
  99. */
  100. function chALL(checked){
  101. var items = document.f1.ch;
  102. if(items==null) return;
  103. if(items.length){
  104. for (var i = 0; i < items.length; i++) {
  105. items[i].checked = checked;
  106. }
  107. }else
  108. items.checked = checked;
  109. }
  110. /*
  111. * Sets 'all' checkbox to 'checked' status if all contact checkboxes are checked
  112. */
  113. function checkMain(){
  114. var items = document.f1.ch;
  115. if(items==null) return;
  116. var checked = true;
  117. if (items.length) {
  118. for (var i = 0; i < items.length; i++) {
  119. checked = checked && items[i].checked;
  120. }
  121. }else
  122. checked = items.checked;
  123. document.f1.chAll.checked = checked;
  124. }
  125. /*
  126. * Deletes all selected contacts and refreshes contact list
  127. * deleteContact(id) is defined in platformservices_20_specific.js
  128. */
  129. function deleteContacts(){
  130. if (!confirm('Delete selected contact(s)?'))
  131. return;
  132. var contacts = document.f1.ch;
  133. if(contacts==null) return;
  134. if (contacts.length) {
  135. for (var i = 0; i < contacts.length; i++) {
  136. if (contacts[i].checked) {
  137. deleteContact(contacts[i].value);
  138. }
  139. }
  140. }else
  141. deleteContact(contacts.value);
  142. listContacts();
  143. }
  144. /*
  145. * Builds one row for contact list HTML table based on contact entry data.
  146. */
  147. function showContact(entry){
  148. var txt = "<tr>";
  149. try {
  150. txt += "<td width='5'><input type='checkbox' onclick='checkMain()' name='ch' value='" + entry.id + "'/></td>";
  151. if (entry.name != null)
  152. txt += "<td><a href=\"#\" onClick=\"openContact('" + entry.id + "');\">" + (entry.name.first == null ? "" : (entry.name.first + "&nbsp;")) + (entry.name.last == null ? "" : entry.name.last) + "</a></td>";
  153. else
  154. txt += "<td><a href=\"#\" onClick=\"openContact('" + entry.id + "');\">(unnamed)</a></td>";
  155. if (entry.tel != null)
  156. txt += "<td>" + (entry.tel.mobile == null ? "" : entry.tel.mobile) + "</td>";
  157. else
  158. txt += "<td></td>";
  159. }
  160. catch (e) {
  161. alert("showContact: " + e);
  162. }
  163. txt += "</tr>";
  164. return txt;
  165. }
  166. /*
  167. * Saves contact form data.
  168. * if contact id value is found existing contact is updated, new contact is created otherwise.
  169. * addContact() and updateContact(id) are defined in platformservices_20_specific.js
  170. */
  171. function saveContact(){
  172. var id = document.contact.contactID.value;
  173. if (id == "")
  174. addContact();
  175. else
  176. updateContact(id);
  177. document.getElementById("contactFilter").value = "";
  178. listContacts();
  179. showContactList();
  180. }
  181. /*
  182. * Creates new contact entry based on contact form data.
  183. * Contact schema:
  184. * {
  185. * name:{
  186. * last:'last name',
  187. * first: 'first name',
  188. * middle: 'middle name',
  189. * prefix: 'name prefix',
  190. * suffix: 'name suffix'
  191. * },
  192. * tel:{
  193. * land: 'landline number',
  194. * mobile: 'mobile number',
  195. * video: 'video number',
  196. * fax: 'fax number',
  197. * voip: 'voip number',
  198. * home:{
  199. * land: 'landline number',
  200. * mobile: 'mobile number',
  201. * video: 'video number',
  202. * fax: 'fax number',
  203. * voip: 'voip number'
  204. * },
  205. * work:{
  206. * land: 'landline number',
  207. * mobile: 'mobile number',
  208. * video: 'video number',
  209. * fax: 'fax number',
  210. * voip: 'voip number'
  211. * },
  212. * },
  213. * address: {
  214. * street: 'street address',
  215. * local: 'locality (e.g. city)',
  216. * region: 'region (e.g. state)',
  217. * code: 'postal code',
  218. * country: 'country',
  219. * email: 'email address',
  220. * url: 'web address',
  221. * home: {
  222. * street: 'street address',
  223. * local: 'locality (e.g. city)',
  224. * region: 'region (e.g. state)',
  225. * code: 'postal code',
  226. * country: 'country',
  227. * email: 'email address',
  228. * url: 'web address'
  229. * },
  230. * work: {
  231. * street: 'street address',
  232. * local: 'locality (e.g. city)',
  233. * region: 'region (e.g. state)',
  234. * code: 'postal code',
  235. * country: 'country',
  236. * email: 'email address',
  237. * url: 'web address'
  238. * }
  239. * },
  240. * company: {
  241. * name: 'company name',
  242. * title: 'job title'
  243. * },
  244. * id: {} // Applications must treat the ID object as opaque data.
  245. *
  246. * }
  247. */
  248. function prepareContactEntry(){
  249. var form = document.contact;
  250. var contactEntry = new Object();
  251. var contactName = new Object();
  252. var contactTel = new Object();
  253. var contactAddress = new Object();
  254. var contactCompany = new Object();
  255. contactEntry.name = contactName;
  256. contactEntry.tel = contactTel;
  257. contactEntry.address = contactAddress;
  258. contactEntry.company = contactCompany;
  259. contactName.last = form.lname.value;
  260. contactName.first = form.fname.value;
  261. contactName.middle = form.mname.value;
  262. contactName.prefix = form.pref.value;
  263. contactName.suffix = form.suf.value;
  264. contactTel.land = form.land.value;
  265. contactTel.mobile = form.mobile.value;
  266. contactTel.video = form.video.value;
  267. contactTel.fax = form.fax.value;
  268. //contactTel.voip = form.voip.value;//Not Supported on Nokia 5800 and 323 Devices
  269. contactAddress.street = form.street.value;
  270. contactAddress.local = form.city.value;
  271. contactAddress.region = form.region.value;
  272. contactAddress.code = form.pcode.value;
  273. contactAddress.country = form.country.value;
  274. contactAddress.email = form.email.value;
  275. contactAddress.url = form.url.value;
  276. contactCompany.name = form.cname.value;
  277. contactCompany.title = form.jtitle.value;
  278. return contactEntry;
  279. }
  280. /*
  281. * Fills contact form based on specified contactEntry object
  282. * Contact schema: see prepareContactEntry
  283. */
  284. function preFillContactForm(contactEntry){
  285. var form = document.contact;
  286. cleanForm();
  287. if (contactEntry.name != null) {
  288. form.lname.value = getValue(contactEntry.name.last);
  289. form.fname.value = getValue(contactEntry.name.first);
  290. form.mname.value = getValue(contactEntry.name.middle);
  291. form.pref.value = getValue(contactEntry.name.prefix);
  292. form.suf.value = getValue(contactEntry.name.suffix);
  293. }
  294. if (contactEntry.tel != null) {
  295. form.land.value = getValue(contactEntry.tel.land);
  296. form.mobile.value = getValue(contactEntry.tel.mobile);
  297. form.video.value = getValue(contactEntry.tel.video);
  298. form.fax.value = getValue(contactEntry.tel.fax);
  299. form.voip.value = getValue(contactEntry.tel.voip);
  300. }
  301. if (contactEntry.address != null) {
  302. form.street.value = getValue(contactEntry.address.street);
  303. form.city.value = getValue(contactEntry.address.local);
  304. form.region.value = getValue(contactEntry.address.region);
  305. form.pcode.value = getValue(contactEntry.address.code);
  306. form.country.value = getValue(contactEntry.address.country);
  307. form.email.value = getValue(contactEntry.address.email);
  308. form.url.value = getValue(contactEntry.address.url);
  309. }
  310. if (contactEntry.company != null) {
  311. form.cname.value = getValue(contactEntry.company.name);
  312. form.jtitle.value = getValue(contactEntry.company.title);
  313. }
  314. }
  315. /*
  316. * Returns value if it is not null, otherwise empty string is returned
  317. */
  318. function getValue(v){
  319. if (v == null)
  320. return "";
  321. return v;
  322. }
  323. /*
  324. * Empties all contact form member elements
  325. */
  326. function cleanForm(){
  327. document.contact.reset();
  328. }