104 lines
3.1 KiB
JavaScript
104 lines
3.1 KiB
JavaScript
import { LightningElement, wire, api, track } from "lwc";
|
|
import { refreshApex } from "@salesforce/apex";
|
|
import { ShowToastEvent } from "lightning/platformShowToastEvent";
|
|
import updateFileDescription from '@salesforce/apex/FileDescrip.updateFileDescription';
|
|
import getFileVersions from "@salesforce/apex/FileController.getVersionFiles";
|
|
|
|
export default class PreviewFileThumbnails extends LightningElement {
|
|
isDisable=true;
|
|
@track descrip="";
|
|
@track addDes="";
|
|
loaded = false;
|
|
@track fileList;
|
|
@api recordId;
|
|
@track files = [];
|
|
get acceptedFormats() {
|
|
return [".pdf", ".png", ".jpg", ".jpeg"];
|
|
}
|
|
|
|
@wire(getFileVersions, { recordId: "$recordId" })
|
|
fileResponse(value) {
|
|
this.wiredActivities = value;
|
|
const { data, error } = value;
|
|
this.fileList = "";
|
|
this.files = [];
|
|
if (data) {
|
|
this.fileList = data;
|
|
for (let i = 0; i < this.fileList.length; i++) {
|
|
let file = {
|
|
Id: this.fileList[i].Id,
|
|
Title: this.fileList[i].Title,
|
|
Extension: this.fileList[i].FileExtension,
|
|
ContentDocumentId: this.fileList[i].ContentDocumentId,
|
|
ContentDocument: this.fileList[i].ContentDocument,
|
|
CreatedDate: this.fileList[i].CreatedDate,
|
|
thumbnailFileCard:
|
|
"/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=" +
|
|
this.fileList[i].Id +
|
|
"&operationContext=CHATTER&contentId=" +
|
|
this.fileList[i].ContentDocumentId,
|
|
downloadUrl:
|
|
"/sfc/servlet.shepherd/document/download/" +
|
|
this.fileList[i].ContentDocumentId
|
|
};
|
|
this.files.push(file);
|
|
}
|
|
this.loaded = true;
|
|
} else if (error) {
|
|
this.dispatchEvent(
|
|
new ShowToastEvent({
|
|
title: "Error loading Files",
|
|
message: error.body.message,
|
|
variant: "error"
|
|
})
|
|
);
|
|
}
|
|
}
|
|
handleUploadFinished(event) {
|
|
const uploadedFiles = event.detail.files;
|
|
refreshApex(this.wiredActivities);
|
|
this.dispatchEvent(
|
|
new ShowToastEvent({
|
|
title: "Success!",
|
|
message: uploadedFiles.length + " Files Uploaded Successfully.",
|
|
variant: "success"
|
|
})
|
|
);
|
|
|
|
}
|
|
addnotes(event){
|
|
this.descrip=event.target.value;
|
|
console.log("@@@@text:"+this.descrip);
|
|
if(this.descrip==""){
|
|
this.isDisable=true;
|
|
}
|
|
else{
|
|
this.isDisable=false;
|
|
}
|
|
}
|
|
add() {
|
|
this.addDes = this.descrip;
|
|
console.log('add des:', this.addDes);
|
|
console.log('RecordId', this.recordId);
|
|
updateFileDescription({ recordId: this.recordId, description:this.addDes })
|
|
.then(result => {
|
|
const event = new ShowToastEvent({
|
|
title: 'INSERTED',
|
|
message: 'SUCCESS',
|
|
variant: 'success'
|
|
});
|
|
this.dispatchEvent(event);
|
|
})
|
|
.catch(error => {
|
|
console.log(error);
|
|
const event = new ShowToastEvent({
|
|
title: 'error',
|
|
message: 'Failed',
|
|
variant: 'error'
|
|
});
|
|
this.dispatchEvent(event);
|
|
});
|
|
}
|
|
|
|
|
|
} |