From be85edf4c283e4d701c8ea04e58a101e99f9d5ab Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Sun, 6 Aug 2023 22:36:09 +0300 Subject: [PATCH] Update loaders and add avtopodgruzka postov --- Web/Presenters/templates/Group/Suggested.xml | 23 +++++----- Web/static/css/main.css | 5 +++ Web/static/js/al_wall.js | 44 +++++++++++++++++++- locales/en.strings | 2 + locales/ru.strings | 2 + 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/Web/Presenters/templates/Group/Suggested.xml b/Web/Presenters/templates/Group/Suggested.xml index 93ec7025..b3e4ad20 100644 --- a/Web/Presenters/templates/Group/Suggested.xml +++ b/Web/Presenters/templates/Group/Suggested.xml @@ -12,15 +12,18 @@ {include "../components/error.xml", title => "", description => $type == "my" ? tr("no_suggested_posts_by_you") : tr("no_suggested_posts_by_people")} {else}

{if $type == "my"}{tr("suggested_posts_in_group_by_you", $count)}{else}{tr("suggested_posts_in_group", $count)}{/if}

- {foreach $posts as $post} - {include "../components/post/microblogpost.xml", post => $post, commentSection => false, suggestion => true, forceNoCommentsLink => true, forceNoPinLink => true, forceNoLike => true, forceNoShareLink => true} - {/foreach} +
+ {foreach $posts as $post} + {include "../components/post/microblogpost.xml", post => $post, commentSection => false, suggestion => true, forceNoCommentsLink => true, forceNoPinLink => true, forceNoLike => true, forceNoShareLink => true} + {/foreach} + + {include "../components/paginator.xml", conf => (object) [ + "page" => $page, + "count" => $count, + "amount" => sizeof($posts), + "perPage" => OPENVK_DEFAULT_PER_PAGE, + "atBottom" => true, + ]} +
{/if} - {include "../components/paginator.xml", conf => (object) [ - "page" => $page, - "count" => $count, - "amount" => sizeof($posts), - "perPage" => OPENVK_DEFAULT_PER_PAGE, - "atBottom" => true, - ]} {/block} diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 618f9de1..b1fad4f0 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -2714,3 +2714,8 @@ body.article .floating_sidebar, body.article .page_content { .suggestionControls { text-align: center; } + +.button.loaded { + background: #595959 url("/assets/packages/static/openvk/img/loading_mini.gif") no-repeat 50% 50%; + padding: 16px 40px 6px 4px; +} diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index b25337fd..f4f543f8 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -277,6 +277,9 @@ $(document).on("click", "#publish_post", async (e) => { let post; try { + e.currentTarget.classList.add("loaded") + e.currentTarget.setAttribute("value", "") + e.currentTarget.setAttribute("id", "") post = await API.Wall.acceptPost(id, document.getElementById("signatr").checked, document.getElementById("pooblish").value) } catch(ex) { switch(ex.code) { @@ -297,12 +300,19 @@ $(document).on("click", "#publish_post", async (e) => { break; } + e.currentTarget.setAttribute("value", tr("publish_suggested")) + e.currentTarget.classList.remove("loaded") + e.currentTarget.setAttribute("id", "publish_post") return 0; } NewNotification(tr("suggestion_succefully_published"), tr("suggestion_press_to_go"), null, () => {window.location.assign("/wall" + post.id)}); document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post.new_count) e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" + + if(document.querySelectorAll(".post.post-divider").length < 1 && post.new_count > 0) { + loadMoreSuggestedPosts() + } }), Function.noop]); document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML.replace(/(<([^>]+)>)/gi, '') @@ -314,7 +324,9 @@ $(document).on("click", "#decline_post", async (e) => { let post; try { - e.currentTarget.parentNode.parentNode.insertAdjacentHTML("afterbegin", ``) + e.currentTarget.classList.add("loaded") + e.currentTarget.setAttribute("value", "") + e.currentTarget.setAttribute("id", "") post = await API.Wall.declinePost(id) } catch(ex) { switch(ex.code) { @@ -335,6 +347,9 @@ $(document).on("click", "#decline_post", async (e) => { break; } + e.currentTarget.setAttribute("value", tr("decline_suggested")) + e.currentTarget.setAttribute("id", "decline_post") + e.currentTarget.classList.remove("loaded") return 0; } finally { u("#deleteMe").remove() @@ -343,4 +358,31 @@ $(document).on("click", "#decline_post", async (e) => { NewNotification(tr("suggestion_succefully_declined"), "", null); e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post) + + if(document.querySelectorAll(".post.post-divider").length < 1 && post > 0) { + loadMoreSuggestedPosts() + } }) + +function loadMoreSuggestedPosts() +{ + let xhr = new XMLHttpRequest + xhr.open("GET", location.href) + + xhr.onloadstart = () => { + document.getElementById("postz").innerHTML = `` + } + + xhr.onload = () => { + let parser = new DOMParser() + let body = parser.parseFromString(xhr.responseText, "text/html").getElementById("postz") + + document.getElementById("postz").innerHTML = body.innerHTML + } + + xhr.onerror = () => { + document.getElementById("postz").innerHTML = tr("error_loading_suggest") + } + + xhr.send() +} diff --git a/locales/en.strings b/locales/en.strings index 55290b2a..2d245a98 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -326,6 +326,8 @@ "publish_suggested" = "Accept"; "decline_suggested" = "Decline"; +"error_loading_suggest" = "Error when loading new posts"; + "publishing_suggested_post" = "Publishing suggested post"; "suggested_posts_in_group_zero" = "You've looked at all the suggested posts, congratulations!"; "suggested_posts_in_group_one" = "This group has one suggested post"; diff --git a/locales/ru.strings b/locales/ru.strings index ae98c60f..5b033e7c 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -310,6 +310,8 @@ "publish_suggested" = "Опубликовать запись"; "decline_suggested" = "Отклонить"; +"error_loading_suggest" = "Не удалось подгрузить новые посты"; + "publishing_suggested_post" = "Публикация предложенной записи"; "suggested_posts_in_group_zero" = "Вы посмотрели всю предложку, поздравляю!"; "suggested_posts_in_group_one" = "В эту группу предложили одну запись";