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, "uploadRateLimitThreshold": 10,
"uploadRateLimitCooldown": 60, "uploadRateLimitCooldown": 60,
"allowUserHomePage": 1, "allowUserHomePage": 1,
"allowMultipleBadges": 0, "allowMultipleBadges": 1,
"maximumFileSize": 2048, "maximumFileSize": 2048,
"stripEXIFData": 1, "stripEXIFData": 1,
"orphanExpiryDays": 0, "orphanExpiryDays": 0,

View File

@@ -103,10 +103,10 @@
"nodebb-plugin-ntfy": "1.7.3", "nodebb-plugin-ntfy": "1.7.3",
"nodebb-plugin-spam-be-gone": "2.2.1", "nodebb-plugin-spam-be-gone": "2.2.1",
"nodebb-rewards-essentials": "1.0.0", "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-lavender": "7.1.7",
"nodebb-theme-peace": "2.2.0", "nodebb-theme-peace": "2.2.1",
"nodebb-theme-persona": "13.3.8", "nodebb-theme-persona": "13.3.9",
"nodebb-widget-essentials": "7.0.15", "nodebb-widget-essentials": "7.0.15",
"nodemailer": "6.9.10", "nodemailer": "6.9.10",
"nprogress": "0.2.0", "nprogress": "0.2.0",

View File

@@ -155,6 +155,10 @@
"grouptitle": "Group Title", "grouptitle": "Group Title",
"group-order-help": "Select a group and use the arrows to order titles", "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", "no-group-title": "No group title",
"select-skin": "Select a Skin", "select-skin": "Select a Skin",

View File

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