From 49f82386702d83da1146462652d83d3fd043608c Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Sun, 12 Jan 2025 14:00:10 +0300 Subject: [PATCH] picker --- Web/Presenters/DocumentsPresenter.php | 24 ++ .../templates/Documents/ApiGetContext.xml | 9 + .../templates/components/attachment.xml | 4 +- .../templates/components/textArea.xml | 8 +- Web/static/css/main.css | 19 +- Web/static/js/al_docs.js | 244 ++++++++++++------ Web/static/js/al_wall.js | 5 +- locales/en.strings | 3 + locales/ru.strings | 3 + 9 files changed, 227 insertions(+), 92 deletions(-) create mode 100644 Web/Presenters/templates/Documents/ApiGetContext.xml diff --git a/Web/Presenters/DocumentsPresenter.php b/Web/Presenters/DocumentsPresenter.php index 6a8994f5..92dd73b0 100644 --- a/Web/Presenters/DocumentsPresenter.php +++ b/Web/Presenters/DocumentsPresenter.php @@ -34,6 +34,30 @@ final class DocumentsPresenter extends OpenVKPresenter $order = in_array($current_order, [0,1,2]) ? $current_order : 0; $tab = in_array($current_tab, [0,1,2,3,4,5,6,7,8]) ? $current_tab : 0; + $api_request = $this->queryParam("picker") == "1"; + if($api_request && $_SERVER["REQUEST_METHOD"] === "POST") { + $ctx_type = $this->postParam("context"); + $docs = NULL; + + switch($ctx_type) { + default: + case "list": + $docs = (new Documents)->getDocumentsByOwner($owner_id, (int)$order, (int)$tab); + break; + case "search": + $ctx_query = $this->postParam("ctx_query"); + $docs = (new Documents)->find($ctx_query); + break; + } + + $this->template->docs = $docs->page($page, OPENVK_DEFAULT_PER_PAGE); + $this->template->page = $page; + $this->template->count = $docs->size(); + $this->template->pagesCount = ceil($this->template->count / OPENVK_DEFAULT_PER_PAGE); + $this->template->_template = "Documents/ApiGetContext.xml"; + return; + } + $docs = (new Documents)->getDocumentsByOwner($owner_id, (int)$order, (int)$tab); $this->template->tabs = (new Documents)->getTypes($owner_id); $this->template->tags = (new Documents)->getTags($owner_id, (int)$tab); diff --git a/Web/Presenters/templates/Documents/ApiGetContext.xml b/Web/Presenters/templates/Documents/ApiGetContext.xml new file mode 100644 index 00000000..3098082f --- /dev/null +++ b/Web/Presenters/templates/Documents/ApiGetContext.xml @@ -0,0 +1,9 @@ + + + + +{foreach $docs as $doc} +
+ {include "components/doc.xml", doc => $doc, hideButtons => true} +
+{/foreach} diff --git a/Web/Presenters/templates/components/attachment.xml b/Web/Presenters/templates/components/attachment.xml index 2ceeed27..7ea8557b 100644 --- a/Web/Presenters/templates/components/attachment.xml +++ b/Web/Presenters/templates/components/attachment.xml @@ -67,8 +67,8 @@ {elseif $attachment instanceof \openvk\Web\Models\Entities\Document}
-
-
+
+
diff --git a/Web/Presenters/templates/components/textArea.xml b/Web/Presenters/templates/components/textArea.xml index 1e714d3e..f1e3d475 100644 --- a/Web/Presenters/templates/components/textArea.xml +++ b/Web/Presenters/templates/components/textArea.xml @@ -86,14 +86,14 @@ {_audio} + canBeModifiedBy($thisUser)}data-club="{$club->getRealId()}"{/if}> + + {_document} + {_note} - - - {_document} - {_graffiti} diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 1f5ff131..cb5e14f8 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -2711,6 +2711,10 @@ a.poll-retract-vote { justify-content: center; } +.ovk-photo-view .photo_viewer_wrapper.photo_viewer_wrapper_scrollable { + height: unset; +} + .ovk-photo-view #ovk-photo-img { max-width: 100%; max-height: 80vh; @@ -4107,7 +4111,7 @@ hr { border-bottom: unset !important; } -.docListViewItem:hover { +.docListViewItem:hover, .attachButton:hover { background: #f7f7f7; } @@ -4219,7 +4223,18 @@ hr { .attachments .docGalleryItem { display: block; - min-width: 200px; + min-width: 130px; + height: 150px; width: 50%; margin-bottom: 4px; } + +.attachButton { + width: 12%; + height: 55px; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + user-select: none; +} diff --git a/Web/static/js/al_docs.js b/Web/static/js/al_docs.js index d1099a77..7d3eb07b 100644 --- a/Web/static/js/al_docs.js +++ b/Web/static/js/al_docs.js @@ -304,112 +304,190 @@ u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", asy CMessageBox.toggleLoader() }) -u(document).on('click', '#__documentAttachment', async (e) => { +// ctx > "wall" and maybe "messages" in future +// source > "user" || "club" > source_id +async function __docAttachment(form, ctx = "wall", source = "user", source_id = 0) { const per_page = 10 - const form = u(e.target).closest('form') const msg = new CMessageBox({ title: tr('select_doc'), - body: ` -
-
-
-
-
- `, - buttons: [tr('close')], - callbacks: [Function.noop] + custom_template: u(` +
`), }) - msg.getNode().attr('style', 'width: 340px;') + msg.getNode().find(".ovk-photo-view").attr('style', 'width: 400px;') msg.getNode().find('.ovk-diag-body').attr('style', 'height:335px;padding:0px;') - - async function __recieveDocs(page) { - u('#gif_loader').remove() - u('#attachment_insert').append(`
`) - const insert_place = u('#attachment_insert .docsInsert') - let docs = null - - try { - docs = await window.OVKAPI.call('docs.get', {'owner_id': window.openvk.current_id, 'count': per_page, 'offset': per_page * page}) - } catch(e) { - u("#gif_loader").remove() - insert_place.html("Err") - return + docs_reciever = new class { + ctx = "my" + ctx_id = 0 + stat = { + page: 0, + pagesCount: 0, + count: 0, } - u("#gif_loader").remove() - const pages_count = Math.ceil(Number(docs.count) / per_page) + clean() { + this.stat = { + page: 0, + pagesCount: 0, + count: 0, + } - if(docs.count < 1) { - insert_place.append(tr('no_docs')) + u('#gif_loader').remove() } - docs.items.forEach(doc => { - is_attached = (form.find(`.upload-item[data-type='doc'][data-id='${doc.owner_id}_${doc.id}']`)).length > 0 - insert_place.append(` -
-
- ${is_attached ? tr("detach") : tr("attach")} + async page(page = 1, perPage = 10) { + u('#_attachment_insert').append(`
`) + + const fd = new FormData + fd.append("context", "list") + fd.append("hash", window.router.csrf) + const req = await fetch(`/docs${source == "club" ? source_id : ""}?picker=1&p=${page}`, { + method: "POST", + body: fd + }) + const res = await req.text() + const dom = new DOMParser + const pre = dom.parseFromString(res, "text/html") + const pagesCount = Number(pre.querySelector("input[name='pagesCount']").value) + const count = Number(pre.querySelector("input[name='count']").value) + if(count < 1) { + u('#_attachment_insert .docsInsert').append(` +
+   ${tr("no_documents")}.
+ `) + } + pre.querySelectorAll("._content").forEach(doc => { + const res = u(`${doc.outerHTML}`) + const id = res.attr("data-attachmentdata") + + res.find(".docMainItem").attr("style", "width: 85%;") + res.append(` +
+ ${this.isDocAttached(id) ? tr("detach") : tr("attach")}
- `) - }) + `) + u('#_attachment_insert .docsInsert').append(res) + }) - if(page < pages_count - 1) { - insert_place.append(` -
- ${tr('show_more')} -
`) + this.stat.page = page + this.stat.pagesCount = pagesCount + this.stat.count = count + u('#gif_loader').remove() + this.showMore() + } + + showMore() { + if(this.stat.page < this.stat.pagesCount) { + u('#_attachment_insert').append(` +
+ ${tr('show_more')} +
+ `) + } + } + + maxAttachmentsCheck() { + if(u(form).find(`.upload-item`).length > window.openvk.max_attachments) { + makeError(tr('too_many_attachments'), 'Red', 10000, 1) + return true + } + return false + } + + attach(dataset, button) { + if(this.isDocAttached(dataset.attachmentdata)) { + (form.find(`.upload-item[data-type='doc'][data-id='${dataset.attachmentdata}']`)).remove() + button.html(tr('attach')) + } else { + const _url = dataset.attachmentdata.split("_") + button.html(tr('detach')) + form.find('.post-vertical').append(` +
+
+
+ + + +
+
+
+
+
+
+ `) + } + } + + isDocAttached(attachmentdata) { + return (form.find(`.upload-item[data-type='doc'][data-id='${attachmentdata}']`)).length > 0 } } - // next page - u(".ovk-diag-body .attachment_selector").on("click", "#show_more", async (ev) => { - const target = u(ev.target).closest('#show_more') - target.addClass('lagged') - await __recieveDocs(Number(target.nodes[0].dataset.page)) - target.remove() + msg.getNode().find("#ovk-photo-close").on("click", function(e) { + msg.close() }) - - u(".ovk-diag-body .attachment_selector").on("click", "#__attach_doc", async (ev) => { - if(u(form).find(`.upload-item`).length > window.openvk.max_attachments) { - makeError(tr('too_many_attachments'), 'Red', 10000, 1) - return + msg.getNode().on("click", "#__attach_doc", async (ev) => { + if(docs_reciever.maxAttachmentsCheck() == true) { + return } const target = u(ev.target).closest('._content') const button = target.find('#__attach_doc') const dataset = target.nodes[0].dataset - const is_attached = (form.find(`.upload-item[data-type='doc'][data-id='${dataset.attachmentdata}']`)).length > 0 - if(is_attached) { - (form.find(`.upload-item[data-type='doc'][data-id='${dataset.attachmentdata}']`)).remove() - button.html(tr('attach')) - } else { - if(form.find(`.upload-item`).length + 1 > window.openvk.max_attachments) { - makeError(tr('too_many_attachments'), 'Red', 10000, 1) - return - } - - button.html(tr('detach')) - form.find('.post-vertical').append(` -
-
-
- - - -
-
-
-
-
-
- `) - } + docs_reciever.attach(dataset, button) + }) + msg.getNode().on("click", "#show_more", async (ev) => { + const target = u(ev.target).closest('#show_more') + target.addClass('lagged') + await docs_reciever.page(docs_reciever.stat.page + 1) + target.remove() + }) + msg.getNode().on("click", "#_doc_picker_go_to_my", async (e) => { + msg.close() + await __docAttachment(form, "wall") }) - __recieveDocs(0) + await docs_reciever.page(docs_reciever.stat.page + 1) +} +u(document).on('click', '#__documentAttachment', async (e) => { + const form = u(e.target).closest('form') + const targ = u(e.target).closest("#__documentAttachment") + let entity_source = "user" + let entity_id = 0 + if(targ.attr('data-club') != null) { + entity_source = "club" + entity_id = Number(targ.attr('data-club')) + } + + await __docAttachment(form, "wall", entity_source, entity_id) }) diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index c04f1932..f4b2b438 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -1039,7 +1039,10 @@ u(document).on("click", "#editPost", async (e) => { // horizontal attachments api_post.attachments.forEach(att => { const type = att.type - const aid = att[type].owner_id + '_' + att[type].id + let aid = att[type].owner_id + '_' + att[type].id + if(att[type] && att[type].access_key) { + aid += "_" + att[type].access_key + } if(type == 'video' || type == 'photo') { let preview = '' diff --git a/locales/en.strings b/locales/en.strings index 7fbc42cd..aa30bd5a 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -2381,3 +2381,6 @@ "documents_sort_add" = "By date"; "documents_sort_alphabet" = "A-Z"; "documents_sort_size" = "By size"; +"select_doc" = "Attach document"; +"no_documents" = "No documents found"; +"go_to_my_documents" = "Go to own documents"; diff --git a/locales/ru.strings b/locales/ru.strings index ac6ad5f6..1a2dafed 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -2276,3 +2276,6 @@ "documents_sort_add" = "По дате добавления"; "documents_sort_alphabet" = "A-Z/А-Я"; "documents_sort_size" = "По размеру"; +"select_doc" = "Выбор документа"; +"no_documents" = "Документов нет"; +"go_to_my_documents" = "Перейти к своим документам";