Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var currentIndex = 0;
- readRecords("Contacts", {}, function(records){
- function showCurrentContact(){
- setImageURL("contactImage", records[currentIndex].pic);
- setText("contactInfo", "Name: " + records[currentIndex].name + "\n Phone #: " + records[currentIndex].number + "\n D.o.b: " + records[currentIndex].dob);
- }
- showCurrentContact();
- currentIndex = 1;
- showCurrentContact();
- currentIndex = 0;
- showCurrentContact();
- onEvent("viewContactsScreen", "keydown", function(event) {
- if(event.key == "Left"){
- currentIndex--;
- currentIndex = wrap(currentIndex, 0, records.length-1);
- showCurrentContact();
- } else if (event.key == "Right"){
- currentIndex++;
- currentIndex = wrap(currentIndex, 0, records.length-1);
- showCurrentContact();
- }
- });
- onEvent("saveContactBtn", "click", function() {
- updateRecord("Contacts", {}, function(update){
- var updateNum = update.length;
- (update[updateNum]).name = getText("nameInput");
- (update[updateNum]).dob = getText("birthdayInput");
- (update[updateNum]).number = getText("phoneInput");
- (update[updateNum]).pic = getText("URLinput");
- });
- });
- });
- onEvent("addContactBtn", "click", function(event) {
- setScreen("addContactsScreen");
- });
- onEvent("backBtn", "click", function(event) {
- setScreen("viewContactsScreen");
- });
- onEvent("addContactsScreen", "click", function() {
- setImageURL("previewImage", getText("URLinput"));
- });
- function wrap(val, low, high){
- var output;
- if(val < low){
- output = high;
- } else if (val > high){
- output = low;
- } else {
- output = val;
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement