Guest User

Untitled

a guest
Jul 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. <aura:component controller="OLM_Disclosure2_Controller"
  2. implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" >
  3. <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
  4. <aura:attribute name="wrapperDataRec" type="Object" />
  5. <aura:attribute name="recordId" type="Id" access="public" />
  6.  
  7. <div class="slds-grid slds-gutters, slds-is-edited" style="margin-left:2px;">
  8. <lightning:datatable aura:id="conlistId"
  9. data="{!v.wrapperDataRec.contactData}"
  10. columns="{!v.oppCols}"
  11. keyField="Id"
  12. hideCheckboxColumn="false"
  13. showRowNumberColumn="true"
  14. onsave="{!c.handleSaveTable}"/>
  15. <!--selectedRows="{!v.selectedRows}"
  16. onsave="{!c.handleSaveTable}"-->
  17. </div>
  18. </aura:component>
  19.  
  20. ({
  21. doInit : function(component,event,helper){
  22. component.set("v.oppCols", [
  23. { label: 'Name', fieldName: 'Name', type: 'text', editable: false},
  24. { label: 'Email', fieldName: 'Email', type: 'text', editable: true},
  25. { label: 'Country', fieldName: 'MailingCountry', type: 'text', editable: false},
  26. { label: 'State', fieldName: 'MailingState', type: 'text', editable: false}
  27. ]);
  28.  
  29. var action = component.get("c.getOpptyData");
  30. action.setParams({"OpptyId" : component.get("v.recordId")});
  31. action.setCallback(this, function(response){
  32. var state = response.getState();
  33. if(state==="SUCCESS"){
  34. component.set("v.wrapperDataRec",response.getReturnValue());
  35. }
  36. else{
  37. console.log('Problem getting response state: ' + state);
  38. }
  39. });
  40. $A.enqueueAction(action);
  41. },
  42. handleSaveTable : function(component, event, helper) {
  43. var action = component.get("c.saveContact");
  44. var newCont = component.find("conlistId").get("v.data");
  45. action.setParams({"conList" : newCont});
  46. action.setCallback(this, function(response){
  47. });
  48. $A.enqueueAction(action);
  49. component.find("conlistId").set("v.draftValues", null);
  50. alert('Save working fine');
  51. })
  52.  
  53. public class OLM_Disclosure2_Controller {
  54. @AuraEnabled
  55. public String email{get;set;}
  56. @AuraEnabled
  57. public static wrapperData getOpptyData(Id OpptyId){
  58. system.debug('OpptyId--->>>'+OpptyId);
  59. wrapperData wt = new wrapperData();
  60. Opportunity oppRec = [select Id,AccountId,RecordType__c,OLM_Brand_Type__c,RecordType.Name,
  61. OLM_Property_Country__c,OLM_Property_State__c from Opportunity where Id =:OpptyId];
  62. List<Contact> conList =[select Id,AccountId,Name,Email, MailingCountry, MailingState from Contact
  63. where AccountId =: oppRec.AccountId];
  64. wt.Rectype = oppRec.RecordType__c;
  65. if(oppRec.RecordType.Name=='OLM Opportunity – Contract Amendment(AMER)'){
  66. wt.rtype = false;
  67. }else{
  68. wt.rtype = true;
  69. }
  70. wt.brand = oppRec.OLM_Brand_Type__c;
  71. if(oppRec.RecordType.Name.contains('Franchised')){
  72. wt.btype = false;
  73. }else{
  74. wt.btype = true;
  75. }
  76. wt.country = oppRec.OLM_Property_Country__c;
  77. wt.state = oppRec.OLM_Property_State__c;
  78. wt.contactData = conList;
  79. wt.conID = conList[0].ID;
  80. System.debug('********Contacts'+wt.contactData);
  81. return wt;
  82. }
  83.  
  84. public class wrapperData{
  85. @AuraEnabled
  86. public String Rectype{get;set;}
  87. @AuraEnabled
  88. public String brand{get;set;}
  89. @AuraEnabled
  90. public Boolean rtype{get;set;}
  91. @AuraEnabled
  92. public Boolean btype{get;set;}
  93. @AuraEnabled
  94. public String country{get;set;}
  95. @AuraEnabled
  96. public String state{get;set;}
  97. @AuraEnabled
  98. public ID conID{get;set;}
  99. @AuraEnabled
  100. public List<Contact> contactData{get;set;}
  101. public wrapperData(){
  102. contactData = new List<Contact>();
  103. }
  104. }
  105.  
  106. @AuraEnabled
  107. public static void saveContact(List<Contact> conList)
  108. {
  109. System.debug('Updated Data: '+conList);
  110. database.update(conList);
  111. //Update conList;
  112. }
  113. }
Add Comment
Please, Sign In to add comment