From a1166396999cce6d7d0825e2ce72157267ce8abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 9 Oct 2022 21:43:42 -0400 Subject: [PATCH] breaking: move ban/mute modals breaking: add accounts/moderate module and move ban/mute there --- public/scss/generics.scss | 14 -- public/src/admin/manage/users.js | 2 +- public/src/client/account/header.js | 153 ++------------------ public/src/client/flags/detail.js | 12 +- public/src/modules/accounts/moderate.js | 108 ++++++++++++++ src/views/admin/partials/temporary-ban.tpl | 32 ---- src/views/admin/partials/temporary-mute.tpl | 27 ---- src/views/modals/temporary-ban.tpl | 33 +++++ src/views/modals/temporary-mute.tpl | 24 +++ 9 files changed, 185 insertions(+), 220 deletions(-) create mode 100644 public/src/modules/accounts/moderate.js delete mode 100644 src/views/admin/partials/temporary-ban.tpl delete mode 100644 src/views/admin/partials/temporary-mute.tpl create mode 100644 src/views/modals/temporary-ban.tpl create mode 100644 src/views/modals/temporary-mute.tpl diff --git a/public/scss/generics.scss b/public/scss/generics.scss index 2e15ff48e5..3f2a9aa14f 100644 --- a/public/scss/generics.scss +++ b/public/scss/generics.scss @@ -116,20 +116,6 @@ } } -.ban-modal { - .form-inline, .form-group { - width: 100%; - } - - .units { - line-height: 5rem; - } -} - -.admin .ban-modal .units { - line-height: 1.846; -} - #crop-picture-modal { #cropped-image { max-width: 100%; diff --git a/public/src/admin/manage/users.js b/public/src/admin/manage/users.js index cf2acb75f5..811c6a00d7 100644 --- a/public/src/admin/manage/users.js +++ b/public/src/admin/manage/users.js @@ -166,7 +166,7 @@ define('admin/manage/users', [ return false; // specifically to keep the menu open } - Benchpress.render('admin/partials/temporary-ban', {}).then(function (html) { + Benchpress.render('modals/temporary-ban', {}).then(function (html) { bootbox.dialog({ className: 'ban-modal', title: '[[user:ban_account]]', diff --git a/public/src/client/account/header.js b/public/src/client/account/header.js index ed443cf81a..e04133de2e 100644 --- a/public/src/client/account/header.js +++ b/public/src/client/account/header.js @@ -6,32 +6,26 @@ define('forum/account/header', [ 'pictureCropper', 'components', 'translator', - 'benchpress', 'accounts/delete', + 'accounts/moderate', 'api', 'bootbox', 'alerts', -], function (coverPhoto, pictureCropper, components, translator, Benchpress, AccountsDelete, api, bootbox, alerts) { +], function (coverPhoto, pictureCropper, components, translator, AccountsDelete, AccountsModerate, api, bootbox, alerts) { const AccountHeader = {}; let isAdminOrSelfOrGlobalMod; AccountHeader.init = function () { isAdminOrSelfOrGlobalMod = ajaxify.data.isAdmin || ajaxify.data.isSelf || ajaxify.data.isGlobalModerator; - hidePrivateLinks(); selectActivePill(); if (isAdminOrSelfOrGlobalMod) { setupCoverPhoto(); } - components.get('account/follow').on('click', function () { - toggleFollow('follow'); - }); - - components.get('account/unfollow').on('click', function () { - toggleFollow('unfollow'); - }); + components.get('account/follow').on('click', () => toggleFollow('follow')); + components.get('account/unfollow').on('click', () => toggleFollow('unfollow')); components.get('account/chat').on('click', async function () { const roomId = await socket.emit('modules.chats.hasPrivateChat', ajaxify.data.uid); @@ -50,45 +44,20 @@ define('forum/account/header', [ }); }); - - components.get('account/ban').on('click', function () { - banAccount(ajaxify.data.theirid); - }); - components.get('account/mute').on('click', function () { - muteAccount(ajaxify.data.theirid); - }); - components.get('account/unban').on('click', function () { - unbanAccount(ajaxify.data.theirid); - }); - components.get('account/unmute').on('click', function () { - unmuteAccount(ajaxify.data.theirid); - }); - components.get('account/delete-account').on('click', handleDeleteEvent.bind(null, 'account')); - components.get('account/delete-content').on('click', handleDeleteEvent.bind(null, 'content')); - components.get('account/delete-all').on('click', handleDeleteEvent.bind(null, 'purge')); + components.get('account/ban').on('click', () => AccountsModerate.banAccount(ajaxify.data.theirid)); + components.get('account/mute').on('click', () => AccountsModerate.muteAccount(ajaxify.data.theirid)); + components.get('account/unban').on('click', () => AccountsModerate.unbanAccount(ajaxify.data.theirid)); + components.get('account/unmute').on('click', () => AccountsModerate.unmuteAccount(ajaxify.data.theirid)); + components.get('account/delete-account').on('click', () => AccountsDelete.account(ajaxify.data.theirid)); + components.get('account/delete-content').on('click', () => AccountsDelete.content(ajaxify.data.theirid)); + components.get('account/delete-all').on('click', () => AccountsDelete.purge(ajaxify.data.theirid)); components.get('account/flag').on('click', flagAccount); components.get('account/block').on('click', toggleBlockAccount); }; - function handleDeleteEvent(type) { - AccountsDelete[type](ajaxify.data.theirid); - } - - // TODO: This exported method is used in forum/flags/detail -- refactor?? - AccountHeader.banAccount = banAccount; - AccountHeader.muteAccount = muteAccount; - AccountHeader.unbanAccount = unbanAccount; - AccountHeader.unmuteAccount = unmuteAccount; - - function hidePrivateLinks() { - if (!app.user.uid || app.user.uid !== parseInt(ajaxify.data.theirid, 10)) { - $('.account-sub-links .plugin-link.private').addClass('hide'); - } - } - function selectActivePill() { - $('.account-sub-links li').removeClass('active').each(function () { - const href = $(this).find('a').attr('href'); + $('.account-sub-links li a').removeClass('active').each(function () { + const href = $(this).attr('href'); if (decodeURIComponent(href) === decodeURIComponent(window.location.pathname)) { $(this).addClass('active'); @@ -139,102 +108,6 @@ define('forum/account/header', [ return false; } - function banAccount(theirid, onSuccess) { - theirid = theirid || ajaxify.data.theirid; - - Benchpress.render('admin/partials/temporary-ban', {}).then(function (html) { - bootbox.dialog({ - className: 'ban-modal', - title: '[[user:ban_account]]', - message: html, - show: true, - buttons: { - close: { - label: '[[global:close]]', - className: 'btn-link', - }, - submit: { - label: '[[user:ban_account]]', - callback: function () { - const formData = $('.ban-modal form').serializeArray().reduce(function (data, cur) { - data[cur.name] = cur.value; - return data; - }, {}); - - const until = formData.length > 0 ? ( - Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) - ) : 0; - - api.put('/users/' + theirid + '/ban', { - until: until, - reason: formData.reason || '', - }).then(() => { - if (typeof onSuccess === 'function') { - return onSuccess(); - } - - ajaxify.refresh(); - }).catch(alerts.error); - }, - }, - }, - }); - }); - } - - function unbanAccount(theirid) { - api.del('/users/' + theirid + '/ban').then(() => { - ajaxify.refresh(); - }).catch(alerts.error); - } - - function muteAccount(theirid, onSuccess) { - theirid = theirid || ajaxify.data.theirid; - Benchpress.render('admin/partials/temporary-mute', {}).then(function (html) { - bootbox.dialog({ - className: 'mute-modal', - title: '[[user:mute_account]]', - message: html, - show: true, - buttons: { - close: { - label: '[[global:close]]', - className: 'btn-link', - }, - submit: { - label: '[[user:mute_account]]', - callback: function () { - const formData = $('.mute-modal form').serializeArray().reduce(function (data, cur) { - data[cur.name] = cur.value; - return data; - }, {}); - - const until = formData.length > 0 ? ( - Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) - ) : 0; - - api.put('/users/' + theirid + '/mute', { - until: until, - reason: formData.reason || '', - }).then(() => { - if (typeof onSuccess === 'function') { - return onSuccess(); - } - ajaxify.refresh(); - }).catch(alerts.error); - }, - }, - }, - }); - }); - } - - function unmuteAccount(theirid) { - api.del('/users/' + theirid + '/mute').then(() => { - ajaxify.refresh(); - }).catch(alerts.error); - } - function flagAccount() { require(['flags'], function (flags) { flags.showFlagModal({ diff --git a/public/src/client/flags/detail.js b/public/src/client/flags/detail.js index fdffc096f2..dcaa804d4d 100644 --- a/public/src/client/flags/detail.js +++ b/public/src/client/flags/detail.js @@ -1,8 +1,8 @@ 'use strict'; define('forum/flags/detail', [ - 'components', 'translator', 'benchpress', 'forum/account/header', 'accounts/delete', 'api', 'bootbox', 'alerts', -], function (components, translator, Benchpress, AccountHeader, AccountsDelete, api, bootbox, alerts) { + 'components', 'translator', 'benchpress', 'accounts/moderate', 'accounts/delete', 'api', 'bootbox', 'alerts', +], function (components, translator, Benchpress, AccountModerate, AccountsDelete, api, bootbox, alerts) { const Detail = {}; Detail.init = function () { @@ -66,19 +66,19 @@ define('forum/flags/detail', [ break; case 'ban': - AccountHeader.banAccount(uid, ajaxify.refresh); + AccountModerate.banAccount(uid, ajaxify.refresh); break; case 'unban': - AccountHeader.unbanAccount(uid); + AccountModerate.unbanAccount(uid); break; case 'mute': - AccountHeader.muteAccount(uid, ajaxify.refresh); + AccountModerate.muteAccount(uid, ajaxify.refresh); break; case 'unmute': - AccountHeader.unmuteAccount(uid); + AccountModerate.unmuteAccount(uid); break; case 'delete-account': diff --git a/public/src/modules/accounts/moderate.js b/public/src/modules/accounts/moderate.js new file mode 100644 index 0000000000..fe882b5ded --- /dev/null +++ b/public/src/modules/accounts/moderate.js @@ -0,0 +1,108 @@ +'use strict'; + +define('forum/account/moderate', [ + 'benchpress', + 'api', + 'bootbox', + 'alerts', +], function (Benchpress, api, bootbox, alerts) { + const AccountModerate = {}; + + AccountModerate.banAccount = function (theirid, onSuccess) { + theirid = theirid || ajaxify.data.theirid; + + Benchpress.render('modals/temporary-ban', {}).then(function (html) { + bootbox.dialog({ + className: 'ban-modal', + title: '[[user:ban_account]]', + message: html, + show: true, + buttons: { + close: { + label: '[[global:close]]', + className: 'btn-link', + }, + submit: { + label: '[[user:ban_account]]', + callback: function () { + const formData = $('.ban-modal form').serializeArray().reduce(function (data, cur) { + data[cur.name] = cur.value; + return data; + }, {}); + + const until = formData.length > 0 ? ( + Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) + ) : 0; + + api.put('/users/' + theirid + '/ban', { + until: until, + reason: formData.reason || '', + }).then(() => { + if (typeof onSuccess === 'function') { + return onSuccess(); + } + + ajaxify.refresh(); + }).catch(alerts.error); + }, + }, + }, + }); + }); + }; + + AccountModerate.unbanAccount = function (theirid) { + api.del('/users/' + theirid + '/ban').then(() => { + ajaxify.refresh(); + }).catch(alerts.error); + }; + + AccountModerate.muteAccount = function (theirid, onSuccess) { + theirid = theirid || ajaxify.data.theirid; + Benchpress.render('modals/temporary-mute', {}).then(function (html) { + bootbox.dialog({ + className: 'mute-modal', + title: '[[user:mute_account]]', + message: html, + show: true, + buttons: { + close: { + label: '[[global:close]]', + className: 'btn-link', + }, + submit: { + label: '[[user:mute_account]]', + callback: function () { + const formData = $('.mute-modal form').serializeArray().reduce(function (data, cur) { + data[cur.name] = cur.value; + return data; + }, {}); + + const until = formData.length > 0 ? ( + Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) + ) : 0; + + api.put('/users/' + theirid + '/mute', { + until: until, + reason: formData.reason || '', + }).then(() => { + if (typeof onSuccess === 'function') { + return onSuccess(); + } + ajaxify.refresh(); + }).catch(alerts.error); + }, + }, + }, + }); + }); + }; + + AccountModerate.unmuteAccount = function (theirid) { + api.del('/users/' + theirid + '/mute').then(() => { + ajaxify.refresh(); + }).catch(alerts.error); + }; + + return AccountModerate; +}); diff --git a/src/views/admin/partials/temporary-ban.tpl b/src/views/admin/partials/temporary-ban.tpl deleted file mode 100644 index 11931147f6..0000000000 --- a/src/views/admin/partials/temporary-ban.tpl +++ /dev/null @@ -1,32 +0,0 @@ -
-
-
-
- - -
-
-
-
- - -
-
-
-
-
-
- - -    - - -
-
-
-

- [[admin/manage/users:temp-ban.explanation]] -

-
-
-
diff --git a/src/views/admin/partials/temporary-mute.tpl b/src/views/admin/partials/temporary-mute.tpl deleted file mode 100644 index d203f1c606..0000000000 --- a/src/views/admin/partials/temporary-mute.tpl +++ /dev/null @@ -1,27 +0,0 @@ -
-
-
-
- - -
-
-
-
- - -
-
-
-
-
-
- - -    - - -
-
-
-
diff --git a/src/views/modals/temporary-ban.tpl b/src/views/modals/temporary-ban.tpl new file mode 100644 index 0000000000..19b1047fed --- /dev/null +++ b/src/views/modals/temporary-ban.tpl @@ -0,0 +1,33 @@ +
+
+
+
+

+ [[admin/manage/users:temp-ban.explanation]] +

+
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
diff --git a/src/views/modals/temporary-mute.tpl b/src/views/modals/temporary-mute.tpl new file mode 100644 index 0000000000..87fab1890e --- /dev/null +++ b/src/views/modals/temporary-mute.tpl @@ -0,0 +1,24 @@ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+