From 7162051905f07495caf1eecbaba4516298085b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 13 Aug 2019 16:13:39 -0400 Subject: [PATCH] fix: #7791 --- public/language/en-GB/user.json | 1 + public/src/client/account/edit.js | 23 +++++++++++++++++++++++ src/controllers/accounts/edit.js | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/public/language/en-GB/user.json b/public/language/en-GB/user.json index 571c9fc1bd..5dc59cd59c 100644 --- a/public/language/en-GB/user.json +++ b/public/language/en-GB/user.json @@ -137,6 +137,7 @@ "follow_topics_you_create": "Watch topics you create", "grouptitle": "Group Title", + "group-order-help": "Select a group and use the arrows to order titles", "no-group-title": "No group title", "select-skin": "Select a Skin", diff --git a/public/src/client/account/edit.js b/public/src/client/account/edit.js index e0ecdf248a..ccc293f03b 100644 --- a/public/src/client/account/edit.js +++ b/public/src/client/account/edit.js @@ -23,6 +23,7 @@ define('forum/account/edit', ['forum/account/header', 'translator', 'components' handleEmailConfirm(); updateSignature(); updateAboutMe(); + handleGroupSort(); }; function updateProfile() { @@ -329,6 +330,28 @@ define('forum/account/edit', ['forum/account/header', 'translator', 'components' }); } + function handleGroupSort() { + function move(direction) { + var selected = $('#groupTitle').val(); + if (!ajaxify.data.allowMultipleBadges || (Array.isArray(selected) && selected.length > 1)) { + return; + } + var 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()); + } + } + } + $('[component="group/order/up"]').on('click', function () { + move(-1); + }); + $('[component="group/order/down"]').on('click', function () { + move(1); + }); + } return AccountEdit; }); diff --git a/src/controllers/accounts/edit.js b/src/controllers/accounts/edit.js index 39a5f94e25..4e13095e59 100644 --- a/src/controllers/accounts/edit.js +++ b/src/controllers/accounts/edit.js @@ -38,9 +38,21 @@ editController.get = async function (req, res, next) { if (!userData.allowMultipleBadges) { userData.groupTitle = userData.groupTitleArray[0]; } + + userData.groups.sort((a, b) => { + const i1 = userData.groupTitleArray.indexOf(a.name); + const i2 = userData.groupTitleArray.indexOf(b.name); + if (i1 === -1) { + return 1; + } else if (i2 === -1) { + return -1; + } + return i1 - i2; + }); userData.groups.forEach(function (group) { group.selected = userData.groupTitleArray.includes(group.name); }); + userData.groupSelectSize = Math.min(10, Math.max(5, userData.groups.length + 1)); userData.title = '[[pages:account/edit, ' + userData.username + ']]'; userData.breadcrumbs = helpers.buildBreadcrumbs([