-
${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" = "Перейти к своим документам";