Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <aura:component controller="OLM_Disclosure2_Controller"
- implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" >
- <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
- <aura:attribute name="wrapperDataRec" type="Object" />
- <aura:attribute name="recordId" type="Id" access="public" />
- <div class="slds-grid slds-gutters, slds-is-edited" style="margin-left:2px;">
- <lightning:datatable aura:id="conlistId"
- data="{!v.wrapperDataRec.contactData}"
- columns="{!v.oppCols}"
- keyField="Id"
- hideCheckboxColumn="false"
- showRowNumberColumn="true"
- onsave="{!c.handleSaveTable}"/>
- <!--selectedRows="{!v.selectedRows}"
- onsave="{!c.handleSaveTable}"-->
- </div>
- </aura:component>
- ({
- doInit : function(component,event,helper){
- component.set("v.oppCols", [
- { label: 'Name', fieldName: 'Name', type: 'text', editable: false},
- { label: 'Email', fieldName: 'Email', type: 'text', editable: true},
- { label: 'Country', fieldName: 'MailingCountry', type: 'text', editable: false},
- { label: 'State', fieldName: 'MailingState', type: 'text', editable: false}
- ]);
- var action = component.get("c.getOpptyData");
- action.setParams({"OpptyId" : component.get("v.recordId")});
- action.setCallback(this, function(response){
- var state = response.getState();
- if(state==="SUCCESS"){
- component.set("v.wrapperDataRec",response.getReturnValue());
- }
- else{
- console.log('Problem getting response state: ' + state);
- }
- });
- $A.enqueueAction(action);
- },
- handleSaveTable : function(component, event, helper) {
- var action = component.get("c.saveContact");
- var newCont = component.find("conlistId").get("v.data");
- action.setParams({"conList" : newCont});
- action.setCallback(this, function(response){
- });
- $A.enqueueAction(action);
- component.find("conlistId").set("v.draftValues", null);
- alert('Save working fine');
- })
- public class OLM_Disclosure2_Controller {
- @AuraEnabled
- public String email{get;set;}
- @AuraEnabled
- public static wrapperData getOpptyData(Id OpptyId){
- system.debug('OpptyId--->>>'+OpptyId);
- wrapperData wt = new wrapperData();
- Opportunity oppRec = [select Id,AccountId,RecordType__c,OLM_Brand_Type__c,RecordType.Name,
- OLM_Property_Country__c,OLM_Property_State__c from Opportunity where Id =:OpptyId];
- List<Contact> conList =[select Id,AccountId,Name,Email, MailingCountry, MailingState from Contact
- where AccountId =: oppRec.AccountId];
- wt.Rectype = oppRec.RecordType__c;
- if(oppRec.RecordType.Name=='OLM Opportunity – Contract Amendment(AMER)'){
- wt.rtype = false;
- }else{
- wt.rtype = true;
- }
- wt.brand = oppRec.OLM_Brand_Type__c;
- if(oppRec.RecordType.Name.contains('Franchised')){
- wt.btype = false;
- }else{
- wt.btype = true;
- }
- wt.country = oppRec.OLM_Property_Country__c;
- wt.state = oppRec.OLM_Property_State__c;
- wt.contactData = conList;
- wt.conID = conList[0].ID;
- System.debug('********Contacts'+wt.contactData);
- return wt;
- }
- public class wrapperData{
- @AuraEnabled
- public String Rectype{get;set;}
- @AuraEnabled
- public String brand{get;set;}
- @AuraEnabled
- public Boolean rtype{get;set;}
- @AuraEnabled
- public Boolean btype{get;set;}
- @AuraEnabled
- public String country{get;set;}
- @AuraEnabled
- public String state{get;set;}
- @AuraEnabled
- public ID conID{get;set;}
- @AuraEnabled
- public List<Contact> contactData{get;set;}
- public wrapperData(){
- contactData = new List<Contact>();
- }
- }
- @AuraEnabled
- public static void saveContact(List<Contact> conList)
- {
- System.debug('Updated Data: '+conList);
- database.update(conList);
- //Update conList;
- }
- }
Add Comment
Please, Sign In to add comment