Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.5 kB
1
Indexable
Never
import { LightningElement,track,wire,api } from 'lwc';
import { getObjectInfos, getObjectInfo } from 'lightning/uiObjectInfoApi';
import TEMPLATEOBJ from '@salesforce/schema/Product_Configuration_Template__c';

import closeCLabel from '@salesforce/label/c.ProductConfiguration_Close';

import getAvailableTemplates from '@salesforce/apex/ProductConfigurationController.getAvailableTemplates';

export default class TemplateAdder extends LightningElement {

    @api prodid;
    @api oppid;
    @track itemsforcurrentview;
    @track columns;
    @track isLoaded = true;

    closeLabel = closeCLabel;

    @wire(getObjectInfos, {  objectApiNames: [TEMPLATEOBJ] })
    oppInfo({ data, error }) {
        if (data){
            this.columns = this.fillColumns(data);
        }
    }

    connectedCallback(){
        getAvailableTemplates({
            opportunityId: this.oppid,
            productId: this.prodid
        })
        .then((result) => {
            console.log(JSON.stringify(result));
            this.itemsforcurrentview = result;
        });
    }

    fillColumns(data){
        var newcolumns = [];
        var templateObj = data.results[0];
        
        this.nameColumn = templateObj.result.fields.Name.apiName;

        console.log(templateObj.result.fields.Name.apiName);
        
        newcolumns.push({ 
            label: templateObj.result.fields.Name.label, 
            fieldName: templateObj.result.fields.Name.apiName,
            hideDefaultActions: true 
        });
        
        newcolumns.push({ 
            type: "button", 
            label: 'Select', 
            initialWidth: 150, 
            typeAttributes: {
                label: 'Select',
                name: 'Select',
                title: 'Select',
                disabled: false,
                value: 'Select',
                variant:'Brand'
            } 
        });
    
        return newcolumns;
    }

    callRowAction(event) {
        const recId = event.detail.row.Id;
        const actionName = event.detail.action.name;

        this.dispatchEvent(new CustomEvent('selecttemplate', {
            detail: {
                templateId: recId
            }
        }));

    }

    closeModal(){
        this.dispatchEvent(new CustomEvent('closemodal', {
            detail: {
                message: 'Close modal'
            }
        }));
    }
}
Leave a Comment