Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. <aura:component controller="AccountsController" implements="force:appHostable,flexipage:availableForAllPageTypes">
  2. <!-- PAGE HEADER -->
  3. <lightning:navigation aura:id="navigation"/>
  4. <aura:attribute name="recordId" type="String" />
  5.  
  6. <aura:attribute name="accounts" type="Account[]"/>
  7. <aura:attribute name="newAccount" type="Account"
  8. default="{ 'sobjectType': 'Account',
  9. 'Name': '',
  10. 'BillingStreet': '',
  11. 'BillingCity': '',
  12. 'BillingState': '',
  13. 'BillingCountry': '',
  14. 'BillingPostalCode': '' }"/>
  15. <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
  16. <!-- / PAGE HEADER -->
  17. <!-- NEW account FORM -->
  18. <lightning:layout>
  19. <lightning:layoutItem padding="around-small" size="6">
  20. <!-- CREATE NEW account -->
  21. <div aria-labelledby="newaccountform">
  22. <!-- BOXED AREA -->
  23. <fieldset class="slds-box slds-theme--default slds-container--small">
  24. <legend id="newaccountform" class="slds-text-heading--small
  25. slds-p-vertical--medium">
  26. Add Account and Primary Contact
  27. </legend>
  28.  
  29. <!-- CREATE NEW ACCOUNT FORM -->
  30. <form class="slds-form--stacked">
  31. <lightning:input aura:id="accountform" label="Account Name"
  32. name="accountname"
  33. value="{!v.newAccount.Name}"
  34. required="true"/>
  35. <lightning:input type="textarea" label="Billing Street"
  36. name="accountstreet"
  37. value="{!v.newAccount.BillingStreet}"
  38. required="true"/>
  39. <lightning:input type="string" label="Billing City"
  40. name="accountcity"
  41. value="{!v.newAccount.BillingCity}"
  42. required="true"/>
  43. <lightning:input type="string" label="Billing State"
  44. name="accountstate"
  45. value="{!v.newAccount.BillingState}"
  46. required="true"/>
  47. <lightning:input type="string" label="Billing Country"
  48. name="accountcountry"
  49. value="{!v.newAccount.BillingCountry}"
  50. required="true"/>
  51. <lightning:input type="string" label="Billing Zip/Postal Code"
  52. name="accountpostalcode"
  53. value="{!v.newAccount.BillingPostalCode}"
  54. required="true"/>
  55. <lightning:navigation aura:id="clickCreateAccount"/>
  56. <lightning:button label="Create Account"
  57. class="slds-m-top--medium"
  58. variant="brand"
  59. onclick="{!c.clickCreateAccount}"/>
  60. //other code
  61.  
  62. ({
  63. clickCreateAccount: function(component, event, helper) {
  64. var newAccount = component.get("v.newAccount");
  65. console.log("Create account: " + JSON.stringify(newAccount));
  66. helper.createAccount(component, newAccount);
  67. }
  68. })
  69.  
  70. ({
  71. createAccount: function(component, account) {
  72. var action = component.get("c.saveAccount");
  73. action.setParams({
  74. "account": account
  75. });
  76. action.setCallback(this, function(response){
  77. var state = response.getState();
  78. if (state === "SUCCESS") {
  79. var accounts = component.get("v.accounts");
  80. accounts.push(response.getReturnValue());
  81. component.set("v.accounts", accounts);
  82. }
  83.  
  84. });
  85. $A.enqueueAction(action);
  86.  
  87. var recordId = component.get("v.recordId");
  88. var navService = component.find("navService");
  89. var pageReference = {
  90. type: 'standard__recordPage',
  91. attributes: {
  92. recordId: recordId,
  93. objectApiName: 'Account',
  94. actionName: 'view'
  95. }
  96. };
  97. component.set("v.pageReference", pageReference);
  98. var defaultUrl = "#";
  99. navService.generateUrl(pageReference)
  100. .then($A.getCallback(function(url) {
  101. component.set("v.url", url ? url : defaultUrl);
  102. }), $A.getCallback(function(error) {
  103. component.set("v.url", defaultUrl);
  104. }));
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement