Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

ACS - If custom object is created, update field

$
0
0

I three button states and each is a different parameter for my custom object "Out" field. "No" should be the automatically selected state on launch and should create the custom object and "maybe" and "yes" should update the objects field parameters. The problem I am running into is figuring out how to create the id for the custom object so I can update the field parameters and creating an if/else function where the created object in the "no" state is updated when selected again, as opposed to creating another custom object.

Here is my code:

var toggledButton;
var toggleButton = function (e) {
    if (e.source.isToggled === false) {
        // reset previous button to off
        toggledButton.setBackgroundImage(toggledButton.imageOff);
        toggledButton.isToggled = false;
        // set new button to on
        e.source.setBackgroundImage(e.source.imageOn);
        e.source.isToggled = true;
 
        // cache current button as previous button
        toggledButton = e.source;
    }
    switch (e.source.id) {
    case 1:
 
    Cloud.Objects.create({
          classname : 'personOut',
          fields : {
            out: 'No'
          }
        }, function(e) {
          if(e.success) {
            var going = e.personOut[0];
            alert("created" + 'id:' + going.id + 'out:' + out.going);
          } else {
            alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
          }
        }); 
 
        break;
 
        case 2: 
 
        var goingOut = e.goingOutTonight[0];
 
        Cloud.Objects.update({
          classname : 'personOut',
          id: going.id,
          fields : {
            out: 'Maybe'
          }
        }, function(e) {
          if(e.success) {
 
            alert("Updated");
          } else {
            alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
          }
        }); 
 
        break;
 
        case 3:
 
        Cloud.Objects.update({
          classname : 'personOut',
          id: going.id,
          fields : {
           out: 'Yes'
          }
        }, function(e) {
          if(e.success) {
            alert("Updated");
          } else {
            alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
          }
        }); 
 
    }
 
};
 
 
var outNo = Ti.UI.createButton({
    title: 'No',
    isToggled: true,
    status: '/images/statusNo.png',
    width:55,
    height:30,
    right: 110,
    id: 1
});
 
var outMaybe = Ti.UI.createButton({
    title: 'Maybe',
    isToggled: true,
    status: '/images/statusNo.png',
    width:55,
    height:30,
    right: 110,
    id: 2
});
 
var outNo = Ti.UI.createButton({
    title: 'No',
    isToggled: true,
    status: '/images/statusNo.png',
    width:55,
    height:30,
    right: 110,
    id: 3
});
 
 
outNo.addEventListener('click', toggleButton);
outMaybe.addEventListener('click', toggleButton);
outYes.addEventListener('click', toggleButton);
toggledButton = outNo; // set to on button

Viewing all articles
Browse latest Browse all 8068


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>