Advertisement
Guest User

Untitled

a guest
May 17th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. var currentIndex = 0;
  2. readRecords("Contacts", {}, function(records){
  3. function showCurrentContact(){
  4. setImageURL("contactImage", records[currentIndex].pic);
  5. setText("contactInfo", "Name: " + records[currentIndex].name + "\n Phone #: " + records[currentIndex].number + "\n D.o.b: " + records[currentIndex].dob);
  6. }
  7. showCurrentContact();
  8. currentIndex = 1;
  9. showCurrentContact();
  10. currentIndex = 0;
  11. showCurrentContact();
  12. onEvent("viewContactsScreen", "keydown", function(event) {
  13. if(event.key == "Left"){
  14. currentIndex--;
  15. currentIndex = wrap(currentIndex, 0, records.length-1);
  16. showCurrentContact();
  17. } else if (event.key == "Right"){
  18. currentIndex++;
  19. currentIndex = wrap(currentIndex, 0, records.length-1);
  20. showCurrentContact();
  21. }
  22. });
  23. onEvent("saveContactBtn", "click", function() {
  24. updateRecord("Contacts", {}, function(update){
  25. var updateNum = update.length;
  26. (update[updateNum]).name = getText("nameInput");
  27. (update[updateNum]).dob = getText("birthdayInput");
  28. (update[updateNum]).number = getText("phoneInput");
  29. (update[updateNum]).pic = getText("URLinput");
  30. });
  31. });
  32. });
  33.  
  34. onEvent("addContactBtn", "click", function(event) {
  35. setScreen("addContactsScreen");
  36. });
  37.  
  38. onEvent("backBtn", "click", function(event) {
  39. setScreen("viewContactsScreen");
  40. });
  41.  
  42. onEvent("addContactsScreen", "click", function() {
  43. setImageURL("previewImage", getText("URLinput"));
  44. });
  45.  
  46. function wrap(val, low, high){
  47. var output;
  48. if(val < low){
  49. output = high;
  50. } else if (val > high){
  51. output = low;
  52. } else {
  53. output = val;
  54. }
  55. return output;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement