Last active
June 26, 2018 00:16
-
-
Save kiran-machhewar/40d90fa6b8286f86c51939bd02a8f3e8 to your computer and use it in GitHub Desktop.
Lightning Component Template - This can be used as a boiler plate code for lightning component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,flexipage:availableForAllPageTypes" | |
controller="<CONTROLLER_NAME>" access="global"> | |
<aura:attribute name="recordId" type="Id" /> | |
<aura:attribute name="showSpinner" type="Boolean" default="false" /> | |
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/> | |
<!-- Spinner component --> | |
<aura:if isTrue="{!v.showSpinner}"> | |
<lightning:spinner variant="brand" size="large" aura:id="mySpinner"/> | |
</aura:if> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component, event, helper) { | |
// Create the action | |
var action = component.get("c.<CONTROLLER_METHOD_NAME>"); | |
action.setParams({ | |
caseId : component.get("v.<PUT_PARAM_NAME>") | |
}); | |
component.set("v.showSpinner","true"); | |
// Add callback behavior for when response is received | |
action.setCallback(this, function(response) { | |
component.set("v.showSpinner","false"); | |
var state = response.getState(); | |
var toastEvent = $A.get("e.force:showToast"); | |
if (component.isValid() && state === "SUCCESS" ) { | |
var result = response.getReturnValue(); | |
//<LOGIC_GOES_HERE> | |
toastEvent.setParams({ | |
"title": "Success!", | |
"type": "success", | |
"message": "<SUCCESS_MESSAGE_GOES_HERE>" | |
}); | |
} | |
else { | |
console.log("Failed with state: " + state); | |
toastEvent.setParams({ | |
"title": "Error!", | |
"type": "error", | |
"message": "Error "+response.getError()[0].message | |
}); | |
} | |
toastEvent.fire(); | |
}); | |
// Send action off to be executed | |
$A.enqueueAction(action); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment