From 0890a3204a58c5f1749b2482f2b5cad4b2ff2272 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Sat, 4 Dec 2021 23:59:21 +0300 Subject: [PATCH] AJAX: Adding group to the left menu does not require page reload --- Web/Presenters/templates/@layout.xml | 33 +++++++++---------- Web/Presenters/templates/User/Groups.xml | 8 +---- Web/static/css/style.css | 12 +++++++ Web/static/js/openvk.cls.js | 41 ++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 2a759469..b634a770 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -167,7 +167,7 @@ {var canAccessAdminPanel = $thisUser->getChandlerUser()->can("access")->model("admin")->whichBelongsTo(NULL)} {var canAccessHelpdesk = $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)} {var menuLinksAvaiable = sizeof(OPENVK_ROOT_CONF['openvk']['preferences']['menu']['links']) > 0} -
+ {if $canAccessAdminPanel} Админ-панель {/if} @@ -179,23 +179,22 @@ href="{$menuItem['url']}" target="_blank" class="link">{$menuItem["name"]} -
- {$club->getName()} - - - {php echo OPENVK_ROOT_CONF['openvk']['preferences']['adPoster']['caption']} - +
+ + {$club->getName()} + + {php echo OPENVK_ROOT_CONF['openvk']['preferences']['adPoster']['caption']} + +
{else} Поддержка Выйти diff --git a/Web/Presenters/templates/User/Groups.xml b/Web/Presenters/templates/User/Groups.xml index f8dc9154..9c2aa853 100644 --- a/Web/Presenters/templates/User/Groups.xml +++ b/Web/Presenters/templates/User/Groups.xml @@ -18,12 +18,6 @@ {/block} -{block actions} -
- Поиск групп -
-{/block} - {* BEGIN ELEMENTS DESCRIPTION *} {block tabs} @@ -62,7 +56,7 @@ {_actions}: - + {if $clubPinned} {_remove_from_left_menu} {else} diff --git a/Web/static/css/style.css b/Web/static/css/style.css index ed5be910..4c4e6606 100644 --- a/Web/static/css/style.css +++ b/Web/static/css/style.css @@ -145,6 +145,12 @@ a { right: 0; } +.navigation .group_link { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + .navigation_footer { padding: 0; } @@ -346,6 +352,12 @@ table { margin-bottom: 6px; } +.menu_divider { + height: 1px; + background: #CCC; + margin: 4px 0 2px; +} + .page_status { font-weight: normal; font-size: 11px; diff --git a/Web/static/js/openvk.cls.js b/Web/static/js/openvk.cls.js index 90178366..1e1cf6a0 100644 --- a/Web/static/js/openvk.cls.js +++ b/Web/static/js/openvk.cls.js @@ -85,6 +85,47 @@ document.addEventListener("DOMContentLoaded", function() { //BEGIN return e.preventDefault(); }); + u("#_pinGroup").on("click", async function(e) { + e.preventDefault(); + + let link = u(this).attr("href"); + let thisButton = u(this); + let groupName = u(this).attr("data-group-name"); + let groupId = u(this).attr("data-group-id"); + let list = u('#_groupListPinnedGroups'); + + let req = await ky(link); + if(req.ok == false) { + NewNotification(tr('error'), tr('error_1'), null); + } + + // Adding a divider if not already there + if(list.nodes[0].children.length == 0) { + list.nodes[0].append(u('').first()); + } + + // Changing the button name + if(thisButton.html().trim() == tr('remove_from_left_menu')) { + thisButton.html(tr('add_to_left_menu')); + for(let i = 0; i < list.nodes[0].children.length; i++) { + let element = list.nodes[0].children[i]; + if(element.pathname == '/club'+groupId) { + element.remove(); + } + } + }else{ + thisButton.html(tr('remove_from_left_menu')); + list.nodes[0].append(u('' + groupName + '').first()); + } + + // Adding the group to the left group list + if(list.nodes[0].children[0].className != "menu_divider" || list.nodes[0].children.length == 1) { + list.nodes[0].children[0].remove(); + } + + return false; + }); + }); //END ONREADY DECLS function repostPost(id, hash) {