Modifications to lightning component
This commit is contained in:
1 parent
2622f14385
commit
21df2d0bd2
16 files changed
+363
-7
No files matched your search
@@ -1,3 +1,122 @@
|
||||
import { LightningElement } from 'lwc';
|
||||
import { LightningElement, api, wire, track } from 'lwc';
|
||||
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
|
||||
import { getRecord } from 'lightning/uiRecordApi';
|
||||
import OPPORTUNITY_OBJECT from '@salesforce/schema/Opportunity';
|
||||
import ObtainCloneOpportunityFields from '@salesforce/apex/OpportunityCloneService.ObtainCloneOpportunityFields';
|
||||
import ObtainChildRelationships from '@salesforce/apex/OpportunityCloneService.ObtainOpporunityChildRelationships';
|
||||
import CloneOpportunityWithChildren from '@salesforce/apex/OpportunityCloneService.CloneOpportunityWithChildren';
|
||||
|
||||
export default class OpportunityCustomClone extends LightningElement {}
|
||||
export default class OpportunityCustomClone extends LightningElement {
|
||||
@api recordId;
|
||||
|
||||
formObjectApiName;
|
||||
displayedFields;
|
||||
requiredFieldMap;
|
||||
opportunityFields;
|
||||
childRelationshipList;
|
||||
recordInfo;
|
||||
childRelationshipDisplayList = [];
|
||||
@track childRelationshipSelectionList = [];
|
||||
|
||||
@wire(getRecord,{recordId:'$recordId',layoutTypes:['Full'],modes:['Edit']})
|
||||
processRecordInfo({err, data}) {
|
||||
if(err) {
|
||||
window.console.error('There was a problem obtaining Opportunity Record Data');
|
||||
window.console.error(err);
|
||||
}
|
||||
|
||||
if(data) {
|
||||
//window.console.log('Original Data: %s',JSON.stringify(data,null,"\t"));
|
||||
this.recordInfo = data.fields;
|
||||
}
|
||||
}
|
||||
|
||||
@wire(ObtainChildRelationships)
|
||||
processChildRelationships({error, data}) {
|
||||
if(error) {
|
||||
window.console.log('There is an error obtaining Cild Relationships');
|
||||
window.console.error(error);
|
||||
}
|
||||
|
||||
if(data) {
|
||||
var childRelationshipPicklistArray = [];
|
||||
Object.keys(data).forEach(childItem => {
|
||||
childRelationshipPicklistArray.push({'label':data[childItem],'value':childItem});
|
||||
})
|
||||
this.childRelationshipDisplayList = childRelationshipPicklistArray;
|
||||
}
|
||||
}
|
||||
|
||||
@wire(ObtainCloneOpportunityFields,{fieldsetName:'ClonedFields'})
|
||||
processFieldsetInfo({error, data}) {
|
||||
if(error){
|
||||
window.console.error('There is an error obtaining ClonedFields fieldset');
|
||||
window.console.error(error);
|
||||
}
|
||||
if(data){
|
||||
this.displayedFields = Object.keys(data);
|
||||
this.requiredFieldMap = data;
|
||||
}
|
||||
}
|
||||
|
||||
@wire(getObjectInfo,{ objectApiName: OPPORTUNITY_OBJECT })
|
||||
processOpportunityObjectInfo({error, data}) {
|
||||
if(error){
|
||||
window.console.error('There is an error obtaining fields');
|
||||
}
|
||||
if(data){
|
||||
this.formObjectApiName = OPPORTUNITY_OBJECT.objectApiName;
|
||||
this.opportunityFields = data.fields;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description Handler that executes on selection of child Relationship
|
||||
*/
|
||||
handleChildRelationshipSelection(evt){
|
||||
//find the item that was selected from the distplay list
|
||||
var selectedItem = evt.target.value;
|
||||
let fullSelectedList = this.childRelationshipSelectionList;
|
||||
let displayList = this.childRelationshipDisplayList;
|
||||
let chosenObj = displayList.find( element => element.value === selectedItem);
|
||||
let alreadySelected = fullSelectedList.findIndex(element => element.value === selectedItem);
|
||||
window.console.log('Already Selected Value: %s',alreadySelected);
|
||||
if(chosenObj && alreadySelected < 0){
|
||||
fullSelectedList.push(chosenObj);
|
||||
}
|
||||
this.childRelationshipSelectionList = fullSelectedList;
|
||||
window.console.log('Full Selected List: %s',JSON.stringify(this.childRelationshipSelectionList,null,"\t"));
|
||||
}
|
||||
|
||||
handleChildSelectionRemoval(evt){
|
||||
window.console.log('Item Clicked: %s',evt.detail.index);
|
||||
let fullSelectedList = this.childRelationshipSelectionList;
|
||||
let removedItem = fullSelectedList.splice(evt.detail.index,1);
|
||||
this.childRelationshipSelectionList = fullSelectedList;
|
||||
}
|
||||
/**
|
||||
* @description This will override the submission
|
||||
* @param {*} evt
|
||||
*/
|
||||
handleSubmit(evt){
|
||||
evt.preventDefault();
|
||||
var fields = evt.detail.fields;
|
||||
window.console.log('Fields Submitted: %s',JSON.stringify(fields,null,"\t"));
|
||||
}
|
||||
|
||||
get formFields(){
|
||||
var formFieldsToReturn = [];
|
||||
var fieldRequirementMap = this.requiredFieldMap;
|
||||
if(this.opportunityFields && this.displayedFields && this.recordInfo) {
|
||||
window.console.log('fieldInfo %s: ', JSON.stringify(this.recordInfo,null,"\t"));
|
||||
this.displayedFields.forEach(fieldName => {
|
||||
let fieldItem = fieldRequirementMap[fieldName];
|
||||
let fieldDisplay = JSON.parse(JSON.stringify(this.opportunityFields[fieldName]));
|
||||
if(!fieldItem){
|
||||
fieldDisplay.value = this.recordInfo[fieldName].value;
|
||||
}
|
||||
formFieldsToReturn.push(fieldDisplay);
|
||||
});
|
||||
}
|
||||
return formFieldsToReturn;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user