Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <aura:component controller="AccountsController" implements="force:appHostable,flexipage:availableForAllPageTypes">
- <!-- PAGE HEADER -->
- <lightning:navigation aura:id="navigation"/>
- <aura:attribute name="recordId" type="String" />
- <aura:attribute name="accounts" type="Account[]"/>
- <aura:attribute name="newAccount" type="Account"
- default="{ 'sobjectType': 'Account',
- 'Name': '',
- 'BillingStreet': '',
- 'BillingCity': '',
- 'BillingState': '',
- 'BillingCountry': '',
- 'BillingPostalCode': '' }"/>
- <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
- <!-- / PAGE HEADER -->
- <!-- NEW account FORM -->
- <lightning:layout>
- <lightning:layoutItem padding="around-small" size="6">
- <!-- CREATE NEW account -->
- <div aria-labelledby="newaccountform">
- <!-- BOXED AREA -->
- <fieldset class="slds-box slds-theme--default slds-container--small">
- <legend id="newaccountform" class="slds-text-heading--small
- slds-p-vertical--medium">
- Add Account and Primary Contact
- </legend>
- <!-- CREATE NEW ACCOUNT FORM -->
- <form class="slds-form--stacked">
- <lightning:input aura:id="accountform" label="Account Name"
- name="accountname"
- value="{!v.newAccount.Name}"
- required="true"/>
- <lightning:input type="textarea" label="Billing Street"
- name="accountstreet"
- value="{!v.newAccount.BillingStreet}"
- required="true"/>
- <lightning:input type="string" label="Billing City"
- name="accountcity"
- value="{!v.newAccount.BillingCity}"
- required="true"/>
- <lightning:input type="string" label="Billing State"
- name="accountstate"
- value="{!v.newAccount.BillingState}"
- required="true"/>
- <lightning:input type="string" label="Billing Country"
- name="accountcountry"
- value="{!v.newAccount.BillingCountry}"
- required="true"/>
- <lightning:input type="string" label="Billing Zip/Postal Code"
- name="accountpostalcode"
- value="{!v.newAccount.BillingPostalCode}"
- required="true"/>
- <lightning:navigation aura:id="clickCreateAccount"/>
- <lightning:button label="Create Account"
- class="slds-m-top--medium"
- variant="brand"
- onclick="{!c.clickCreateAccount}"/>
- //other code
- ({
- clickCreateAccount: function(component, event, helper) {
- var newAccount = component.get("v.newAccount");
- console.log("Create account: " + JSON.stringify(newAccount));
- helper.createAccount(component, newAccount);
- }
- })
- ({
- createAccount: function(component, account) {
- var action = component.get("c.saveAccount");
- action.setParams({
- "account": account
- });
- action.setCallback(this, function(response){
- var state = response.getState();
- if (state === "SUCCESS") {
- var accounts = component.get("v.accounts");
- accounts.push(response.getReturnValue());
- component.set("v.accounts", accounts);
- }
- });
- $A.enqueueAction(action);
- var recordId = component.get("v.recordId");
- var navService = component.find("navService");
- var pageReference = {
- type: 'standard__recordPage',
- attributes: {
- recordId: recordId,
- objectApiName: 'Account',
- actionName: 'view'
- }
- };
- component.set("v.pageReference", pageReference);
- var defaultUrl = "#";
- navService.generateUrl(pageReference)
- .then($A.getCallback(function(url) {
- component.set("v.url", url ? url : defaultUrl);
- }), $A.getCallback(function(error) {
- component.set("v.url", defaultUrl);
- }));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement