Skip to content

Instantly share code, notes, and snippets.

@calvinnr7
Created June 27, 2016 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinnr7/27ac7a30a17a1ed9dfb9680c8e52055e to your computer and use it in GitHub Desktop.
Save calvinnr7/27ac7a30a17a1ed9dfb9680c8e52055e to your computer and use it in GitHub Desktop.
({
//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