({ | |
//Fetch the asteroids from the Apex controller | |
getAsteroidList: function(component) { | |
var action = component.get("c.getAsteroids"); | |
var fromDateInput = component.find("fromDate"); | |
var fromDateValue = fromDateInput.get("v.value"); | |
var toDateInput = component.find("toDate"); | |
var toDateValue = toDateInput.get("v.value"); | |
//Set the default dates if first time load. | |
if(!fromDateValue || !toDateValue) | |
{ | |
var today = new Date(); | |
component.set('v.fromDate', today.getFullYear() + "-" + (today.getMonth()+1) + "-" + today.getDate()); | |
component.set('v.toDate', today.getFullYear() + "-" + (today.getMonth()+1) + "-" + (today.getDate() + 2)); | |
} | |
//alert('fromDateValue is ' + fromDateValue + ':' + 'toDateValue is ' + toDateValue); | |
action.setParams({ | |
"toDate" : toDateValue, | |
"fromDate" : fromDateValue | |
}); | |
//Set up the callback | |
var self = this; | |
//alert('Am here'); | |
action.setCallback(this, function(actionResult) { | |
if(actionResult.getState()==='SUCCESS') | |
{ | |
component.set("v.asteroids", actionResult.getReturnValue()); | |
} | |
else if(actionResult.getState()==='ERROR') | |
{ | |
var errors = action.getError(); | |
if (errors) { | |
if (errors[0] && errors[0].message) { | |
// System Error | |
component.set("v.message", errors[0].message); | |
} | |
} | |
} | |
//var obj1 = actionResult.getReturnValue(); | |
//for(var property in obj1) { | |
//console.log(property + "=" + obj1[property]); | |
//} | |
}); | |
$A.enqueueAction(action); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment