From 0fb18e34f539c5f1ba4c15bf26fcb0c6f5475f71 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Mon, 27 Jan 2025 14:57:25 +0300 Subject: [PATCH] feat(docs): corct aud/img preview, hide report btn when doc is yours. --- Web/Models/Entities/Document.php | 10 ++++++ Web/Presenters/DocumentsPresenter.php | 2 +- Web/Presenters/templates/Documents/Page.xml | 10 ++++-- Web/static/css/main.css | 5 +++ Web/static/js/al_docs.js | 36 +++++++++++---------- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Web/Models/Entities/Document.php b/Web/Models/Entities/Document.php index 54d647d3..6f6bf369 100644 --- a/Web/Models/Entities/Document.php +++ b/Web/Models/Entities/Document.php @@ -166,6 +166,16 @@ class Document extends Media return in_array($this->getVKAPIType(), [3, 4]); } + function isBook(): bool + { + return in_array($this->getFileExtension(), ["pdf"]); + } + + function isAudio(): bool + { + return in_array($this->getVKAPIType(), [Document::VKAPI_TYPE_AUDIO]); + } + function isGif(): bool { return $this->getVKAPIType() == 3; diff --git a/Web/Presenters/DocumentsPresenter.php b/Web/Presenters/DocumentsPresenter.php index 92dd73b0..92521e20 100644 --- a/Web/Presenters/DocumentsPresenter.php +++ b/Web/Presenters/DocumentsPresenter.php @@ -139,7 +139,7 @@ final class DocumentsPresenter extends OpenVKPresenter } catch(\TypeError $e) { $this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax); } catch(ISE $e) { - $this->flashFail("err", tr("forbidden"), tr("error_file_preview"), null, $isAjax); + $this->flashFail("err", tr("forbidden"), "corrupted file", null, $isAjax); } catch(\ValueError $e) { $this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax); } catch(\ImagickException $e) { diff --git a/Web/Presenters/templates/Documents/Page.xml b/Web/Presenters/templates/Documents/Page.xml index b6640185..ca4fc78a 100644 --- a/Web/Presenters/templates/Documents/Page.xml +++ b/Web/Presenters/templates/Documents/Page.xml @@ -22,8 +22,12 @@
- {if $is_image} - doc image + {if $doc->isGif()} + doc image + {elseif $doc->isImage()} + doc image + {elseif $doc->isAudio()} + {else} @@ -63,7 +67,7 @@ {if isset($thisUser)} {_edit} - {_report} + {_report} {_add} {_remove} {/if} diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 49ac2ec5..323d3368 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -2718,6 +2718,11 @@ a.poll-retract-vote { user-select: none; } +.ovk-photo-view iframe { + width: 90vw; + height: 100vh; +} + .photo_com_title { font-weight: bold; padding-bottom: 16px; diff --git a/Web/static/js/al_docs.js b/Web/static/js/al_docs.js index 097b6688..28714be6 100644 --- a/Web/static/js/al_docs.js +++ b/Web/static/js/al_docs.js @@ -241,24 +241,26 @@ u(document).on('click', '.docMainItem #report_icon', (e) => { const item = target.closest('.docMainItem') const id = item.nodes[0].dataset.id.split("_") - MessageBox(tr("report_question"), ` + const msg = new CMessageBox({ + title: tr("report_question"), + unique_name: "report_doc", + body: ` ${tr("going_to_report_doc")}
${tr("report_question_text")} -

${tr("report_reason")}: `, [tr("confirm_m"), tr("cancel")], [(function() { - - res = document.querySelector("#uReportMsgInput").value; - xhr = new XMLHttpRequest(); - xhr.open("GET", "/report/" + id[1] + "?reason=" + res + "&type=doc", true); - xhr.onload = (function() { - if(xhr.responseText.indexOf("reason") === -1) - MessageBox(tr("error"), tr("error_sending_report"), ["OK"], [Function.noop]); - else - MessageBox(tr("action_successfully"), tr("will_be_watched"), ["OK"], [Function.noop]); - }); - xhr.send(null) - }), - - Function.noop]) +

${tr("report_reason")}: `, + buttons: [tr("confirm_m"), tr("cancel")], + callbacks: [(function() { + res = document.querySelector("#uReportMsgInput").value; + xhr = new XMLHttpRequest(); + xhr.open("GET", "/report/" + id[1] + "?reason=" + res + "&type=doc", true); + xhr.onload = (function() { + if(xhr.responseText.indexOf("reason") === -1) + MessageBox(tr("error"), tr("error_sending_report"), ["OK"], [Function.noop]); + else + MessageBox(tr("action_successfully"), tr("will_be_watched"), ["OK"], [Function.noop]); + }); + xhr.send(null) + }), Function.noop]}) }) u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", async (e) => { @@ -287,7 +289,7 @@ u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", asy const preview = body.querySelector('.photo-page-wrapper-photo') const details = body.querySelector('.ovk-photo-details') - u(preview.querySelector('img')).attr('id', 'ovk-photo-img') + u(preview.querySelector('.main_doc_block')).attr('id', 'ovk-photo-img') const photo_viewer = new CMessageBox({ title: '',