Skip to content

Commit

Permalink
fix: File preview (#256)
Browse files Browse the repository at this point in the history
* fix: File preview

* feat: refactor to jQuery

---------

Co-authored-by: Tyler Matteson <[email protected]>
  • Loading branch information
MinHyeong-Lee and agritheory authored Jun 29, 2024
1 parent 9eda182 commit 061be4e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions check_run/public/js/custom/file_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ frappe.ui.form.Attachments.prototype.add_attachment = attachment => {
${frappe.utils.icon(attachment.is_private ? 'lock' : 'unlock', 'sm ml-0')}
</a>`

if (file_name.endsWith('.pdf')) {
if (file_name.toLowerCase().endsWith('.pdf')) {
icon += `<i class="fa fa-file-pdf-o" data-pdf-preview="${file_url}"></i>`
}

Expand All @@ -61,16 +61,24 @@ frappe.ui.form.Attachments.prototype.add_attachment = attachment => {
frappe.ui.pdfPreview(cur_frm, event.currentTarget.dataset.pdfPreview)
})

if (file_name.endsWith('.pdf')) {
frappe.ui.addFilePreviewWrapper()
if (file_name.toLowerCase().endsWith('.pdf')) {
frappe.ui.addFilePreviewWrapper(cur_frm)
}
}

frappe.ui.addFilePreviewWrapper = () => {
if ($('#pdf-preview-wrapper').length == 0) {
$('.page-body .page-wrapper').append(`<div id="pdf-preview-wrapper">
<button class="btn btn-secondary btn-default btn-sm" id='close-pdf-button'>Close PDF Preview</button>
</div>`)
frappe.ui.addFilePreviewWrapper = frm => {
$('#pdf-preview-wrapper').remove()
let target_div = $(`[id='page-${frm.doctype}']`)
if (target_div) {
let page_body = target_div.find('.page-body')
if (page_body) {
let page_wrapper = page_body.find('.page-wrapper')
if (page_wrapper) {
$(page_wrapper).append(`<div id="pdf-preview-wrapper">
<button class="btn btn-secondary btn-default btn-sm" id='close-pdf-button'>Close PDF Preview</button>
</div>`)
}
}
}
}

Expand Down

0 comments on commit 061be4e

Please sign in to comment.