feat: refactor group title editing

add new titles
This commit is contained in:
Barış Soner Uşaklı
2024-02-25 13:51:58 -05:00
parent 646f0c588b
commit 112493fa30
4 changed files with 39 additions and 24 deletions

View File

@@ -46,7 +46,7 @@
"uploadRateLimitThreshold": 10,
"uploadRateLimitCooldown": 60,
"allowUserHomePage": 1,
"allowMultipleBadges": 0,
"allowMultipleBadges": 1,
"maximumFileSize": 2048,
"stripEXIFData": 1,
"orphanExpiryDays": 0,

View File

@@ -103,10 +103,10 @@
"nodebb-plugin-ntfy": "1.7.3",
"nodebb-plugin-spam-be-gone": "2.2.1",
"nodebb-rewards-essentials": "1.0.0",
"nodebb-theme-harmony": "1.2.27",
"nodebb-theme-harmony": "1.2.28",
"nodebb-theme-lavender": "7.1.7",
"nodebb-theme-peace": "2.2.0",
"nodebb-theme-persona": "13.3.8",
"nodebb-theme-peace": "2.2.1",
"nodebb-theme-persona": "13.3.9",
"nodebb-widget-essentials": "7.0.15",
"nodemailer": "6.9.10",
"nprogress": "0.2.0",

View File

@@ -155,6 +155,10 @@
"grouptitle": "Group Title",
"group-order-help": "Select a group and use the arrows to order titles",
"show-group-title": "Show group title",
"hide-group-title": "Hide group title",
"order-group-up": "Order group up",
"order-group-down": "Order group down",
"no-group-title": "No group title",
"select-skin": "Select a Skin",

View File

@@ -25,7 +25,7 @@ define('forum/account/edit', [
handleEmailConfirm();
updateSignature();
updateAboutMe();
handleGroupSort();
handleGroupControls();
if (!ajaxify.data.isSelf && ajaxify.data.canEdit) {
$(`a[href="${config.relative_path}/user/${ajaxify.data.userslug}/edit/email"]`).on('click', () => {
@@ -42,12 +42,15 @@ define('forum/account/edit', [
};
function updateProfile() {
function getGroupSelection() {
const els = $('[component="group/badge/list"] [component="group/badge/item"][data-selected="true"]');
return els.map((i, el) => $(el).attr('data-value')).get();
}
const userData = $('form[component="profile/edit/form"]').serializeObject();
userData.uid = ajaxify.data.uid;
userData.groupTitle = userData.groupTitle || '';
userData.groupTitle = JSON.stringify(
Array.isArray(userData.groupTitle) ? userData.groupTitle : [userData.groupTitle]
);
userData.groupTitle = JSON.stringify(getGroupSelection());
hooks.fire('action:profile.update', userData);
@@ -142,26 +145,34 @@ define('forum/account/edit', [
});
}
function handleGroupSort() {
function move(direction) {
const selected = $('#groupTitle').val();
if (!ajaxify.data.allowMultipleBadges || (Array.isArray(selected) && selected.length > 1)) {
return;
function handleGroupControls() {
const { allowMultipleBadges } = ajaxify.data;
$('[component="group/toggle/hide"]').on('click', function () {
const groupEl = $(this).parents('[component="group/badge/item"]');
groupEl.attr('data-selected', 'false');
$(this).addClass('hidden');
groupEl.find('[component="group/toggle/show"]').removeClass('hidden');
});
$('[component="group/toggle/show"]').on('click', function () {
if (!allowMultipleBadges) {
$('[component="group/badge/list"] [component="group/toggle/show"]').removeClass('hidden');
$('[component="group/badge/list"] [component="group/toggle/hide"]').addClass('hidden');
$('[component="group/badge/list"] [component="group/badge/item"]').attr('data-selected', 'false');
}
const el = $('#groupTitle').find(':selected');
if (el.length && el.val()) {
if (direction > 0) {
el.insertAfter(el.next());
} else if (el.prev().val()) {
el.insertBefore(el.prev());
}
}
}
const groupEl = $(this).parents('[component="group/badge/item"]');
groupEl.attr('data-selected', 'true');
$(this).addClass('hidden');
groupEl.find('[component="group/toggle/hide"]').removeClass('hidden');
});
$('[component="group/order/up"]').on('click', function () {
move(-1);
const el = $(this).parents('[component="group/badge/item"]');
el.insertBefore(el.prev());
});
$('[component="group/order/down"]').on('click', function () {
move(1);
const el = $(this).parents('[component="group/badge/item"]');
el.insertAfter(el.next());
});
}