SHARE
TWEET

Untitled

a guest Jun 20th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Component markup
  2.  
  3. <aura:component controller="MBUCampaignTicketCtrl" implements="force:appHostable">
  4.     <aura:attribute name="index" type="Integer" default="0"/>
  5.     <aura:attribute name="parentId" type="String"/>
  6.     <aura:attribute name="caseId" type="String"/>
  7.     <aura:attribute name="campaigns" type="MBUCampaignTicketCtrl.CampaignWithLineItems[]"/>
  8.     <aura:attribute name="activeSections" type="List" />
  9.     <aura:attribute name="activeSectionsMessage" type="String" default="" />
  10.     <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
  11.  
  12.     <p>{! v.activeSectionsMessage }</p><br/>
  13.     <p><a onclick="{!c.handleExpandAll}">Expand All</a>&nbsp;|&nbsp;<a onclick="{!c.handleCollapseAll}">Collapse All </a></p>
  14.     <lightning:accordion allowMultipleSectionsOpen="true"
  15.                          onsectiontoggle="{! c.handleSectionToggle }"
  16.                          activeSectionName="{! v.activeSections }"
  17.                          >
  18.  
  19.         <aura:iteration items="{!v.campaigns}" var="campaignWrp" indexVar="index">
  20.             <lightning:accordionSection aura:id="accor" name="{!(index+1)+''}"
  21.                                         label="{!(index+1)+'. '+campaignWrp.campaign.Name}">
  22.                 <br/>
  23.                 <!--form class="slds-form-stacked"-->
  24.                 <div class="slds-grid slds-gutters slds-wrap slds-grid_align-space">
  25.                     <div class="slds-col slds-align_absolute-center form-group">
  26.                          <!--onclick="{!c.goToStoreDetail}"-->
  27.                         <span>
  28.                             <lightning:input aura:id="CampaignName" label="Campaign Name"
  29.                                              name="CampaignName" value="{!campaignWrp.campaign.Name}" />
  30.  
  31.                     <div class="slds-col slds-align_absolute-center form-group">
  32.                         <span>
  33.                             <lightning:button value="{!index}" label="New" onclick="{!c.appendNewCampaign}"
  34.                                               class="slds-button_brand"/>
  35.                             <lightning:button value="{!index}" label="Clone" onclick="{!c.cloneCampaign}"
  36.                                               class="slds-button_brand"/>
  37.                             <lightning:button value="{!index}" label="Delete" onclick="{!c.deleteCampaign}"
  38.                                               class="slds-button_neutral" disabled="{!v.campaigns.length == 1}"/>
  39.                         </span>
  40.                     </div>
  41.                 </div>
  42.                 <!--/form-->
  43.                 <br/>
  44.             </lightning:accordionSection>
  45.         </aura:iteration>
  46.     </lightning:accordion>
  47.  
  48. </aura:component>
  49.      
  50. JS Controller
  51.  
  52. ({
  53.     doInit : function(component, event, helper){
  54.         var campaigns = component.get("v.campaigns");
  55.         console.log(component.get("v.caseId"));
  56.         if(typeof(campaigns) !== "undefined" && !$A.util.isEmpty(campaigns)){
  57.             campaigns[0].campaign.Id = '';
  58.             campaigns[0].campaign.Name = "New Campaign";
  59.             component.set("v.campaigns", campaigns);
  60.  
  61.             component.set("v.activeSections", "1");
  62.             console.log(component.get("v.activeSections"));
  63.         }
  64.         console.log(campaigns[0].campaign);
  65.     },
  66.  
  67.     appendNewCampaign : function(component, event, helper){
  68.         helper.appendNewCampaign(component, event, helper);
  69.     },
  70.  
  71.     cloneCampaign : function(component, event, helper){
  72.         helper.cloneCampaign(component, event, helper);
  73.     },
  74.  
  75.     deleteCampaign : function(component, event, helper){
  76.         helper.deleteCampaign(component, event, helper);
  77.     },
  78.  
  79.  
  80.     handleExpandAll : function(component, event, helper){
  81.         var activeSections = component.get("v.activeSections");
  82.         activeSections = [];
  83.         var campaigns = component.get("v.campaigns");
  84.         if(typeof(campaigns) == "object"){
  85.             for(var i in campaigns){
  86.                 activeSections.push((parseInt(i)+1).toString());
  87.             }
  88.         }
  89.         component.set("v.activeSections", openSections);
  90.     },
  91.  
  92.     handleCollapseAll : function(component, event, helper){
  93.         var activeSections = component.get("v.activeSections");
  94.         console.log(activeSections);
  95.         activeSections = [];
  96.  
  97.         component.set("v.activeSections", activeSections);
  98.     },
  99.  
  100.     handleSectionToggle : function(component, event, helper){
  101.         var openSections = event.getParam("openSections");
  102.         console.log(openSections);
  103.         if(openSections.length === 0){
  104.             component.set("v.activeSectionsMessage", "All sections are closed");
  105.         }else{
  106.             component.set("v.activeSectionsMessage", "Open sections: " + openSections.join(', '));
  107.         }
  108.     }
  109. })
  110.      
  111. JS Helper
  112.  
  113.  
  114. ({
  115.     cloneObjectDeep : function (obj) {
  116.         var clone = {};
  117.         for(var i in obj) {
  118.             if(obj[i] != null &&  typeof(obj[i])=="object"){
  119.                 clone[i] = this.cloneObjectDeep(obj[i]);
  120.             }
  121.             else{
  122.                 clone[i] = obj[i];
  123.             }
  124.         }
  125.         console.log(clone);
  126.         return clone;
  127.     },
  128.     appendNewCampaign : function(component, event, helper){
  129.         var index = event.getSource().get("v.value");
  130.         var campaigns = component.get("v.campaigns");
  131.         var newElement = this.cloneObjectSh(campaigns[index]);
  132.         newElement.campaign = {};
  133.         newElement.caseCampaignLineItems = [{}];
  134.         newElement.campaign.Id = '';
  135.         newElement.campaign.Name = "New Campaign "+(index+1);
  136.         campaigns.splice(index+1, 0, newElement);
  137.         component.set("v.campaigns", campaigns);
  138.         var indx = parseInt(index)+2;
  139.         var activeSections = component.get("v.activeSections");
  140.         activeSections.push(indx.toString());
  141.         component.set("v.activeSections", activeSections);
  142.         console.log(activeSections);
  143.     },
  144.     cloneCampaign : function(component, event, helper){
  145.         var index = event.getSource().get("v.value");
  146.         var campaigns = component.get("v.campaigns");
  147.         var cloneElement = this.cloneObjectDeep(campaigns[index]);
  148.         cloneElement.campaign.Id = '';
  149.         campaigns.splice(index+1, 0, cloneElement);
  150.         component.set("v.campaigns",campaigns);
  151.  
  152.         var indx = parseInt(index)+2;
  153.         var activeSections = component.get("v.activeSections");
  154.         activeSections.push(indx.toString());
  155.         component.set("v.activeSections",activeSections);
  156.         console.log(activeSections);
  157.     },
  158.     deleteCampaign : function(component, event, helper){
  159.         var response = confirm("This Record will be deleted permanently. Do you Really want to Proceed?");
  160.         if(response){
  161.             var index = event.getSource().get("v.value");
  162.             var campaigns = component.get("v.campaigns");
  163.             console.log(index);
  164.             var deleteElement = campaigns[index];
  165.             if(deleteElement.Id == null){
  166.                 //campaigns.pop(deleteElement);
  167.                 campaigns.splice(index, 1);
  168.                 component.set("v.campaigns",campaigns);
  169.             }else{
  170.  
  171.             }
  172.         }else{
  173.             return;
  174.         }
  175.     }
  176. })
  177.      
  178. Apex Controller Wrapper
  179.  
  180.  
  181. public class CampaignWithLineItems{
  182.         @AuraEnabled
  183.         public Case_Campaign__c campaign {get;set;}
  184.         @AuraEnabled
  185.         public List<Case_Campaign_Line_Item__c> caseCampaignLineItems {get;set;}
  186.         @AuraEnabled
  187.         public String campaignFlag {get;set;}
  188.  
  189.         public CampaignWithLineItems(Case_Campaign__c campaign, List<Case_Campaign_Line_Item__c> caseCampaignLineItems, String campaignFlag){
  190.                 this.campaign = campaign;
  191.                 this.caseCampaignLineItems = caseCampaignLineItems;
  192.                 this.campaignFlag = campaignFlag;
  193.         }
  194.         public CampaignWithLineItems(){
  195.             this.campaign = new Case_Campaign__c();
  196.             this.caseCampaignLineItems = new List<Case_Campaign_Line_Item__c>{new Case_Campaign_Line_Item__c()};
  197.             this.campaignFlag = '';
  198.         }
  199.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top