From 21caa82b6196ca3c3ff39fdcf1f2c4920fa5a158 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 5 Jul 2016 11:22:40 -0400 Subject: [PATCH] ban controls on frontend, closes #4807 --- public/less/admin/manage/users.less | 14 ---------- public/less/generics.less | 12 +++++++++ public/src/client/account/header.js | 42 +++++++++++++++++++---------- src/user/data.js | 2 +- 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/public/less/admin/manage/users.less b/public/less/admin/manage/users.less index 604c944ad8..bed33b77a1 100644 --- a/public/less/admin/manage/users.less +++ b/public/less/admin/manage/users.less @@ -45,18 +45,4 @@ } } } -} - -.page-manage-users { - .ban-modal { - input[type="number"] { - width: 5rem; - text-align: center; - margin-left: 1rem; - } - - .form-inline, .form-group { - width: 100%; - } - } } \ No newline at end of file diff --git a/public/less/generics.less b/public/less/generics.less index 33af3bfa11..bca1b45649 100644 --- a/public/less/generics.less +++ b/public/less/generics.less @@ -103,4 +103,16 @@ &.avatar-rounded { border-radius: 50%; } +} + +.ban-modal { + input[type="number"] { + width: 7rem; + text-align: center; + margin-left: 1rem; + } + + .form-inline, .form-group { + width: 100%; + } } \ No newline at end of file diff --git a/public/src/client/account/header.js b/public/src/client/account/header.js index 520224d9ef..0e2477c6d1 100644 --- a/public/src/client/account/header.js +++ b/public/src/client/account/header.js @@ -103,18 +103,34 @@ define('forum/account/header', [ } function banAccount() { - translator.translate('[[user:ban_account_confirm]]', function(translated) { - bootbox.confirm(translated, function(confirm) { - if (!confirm) { - return; - } - socket.emit('user.banUsers', [ajaxify.data.theirid], function(err) { - if (err) { - return app.alertError(err.message); + templates.parse('admin/partials/temporary-ban', {}, 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() { + var formData = $('.ban-modal form').serializeArray().reduce(function(data, cur) { + data[cur.name] = cur.value; + return data; + }, {}); + var until = Date.now() + formData.length * 1000*60*60 * (parseInt(formData.unit, 10) ? 24 : 1); + socket.emit('user.banUsers', { uids: [ajaxify.data.theirid], until: until }, function(err) { + if (err) { + return app.alertError(err.message); + } + ajaxify.refresh(); + }); + } } - components.get('account/ban').parent().addClass('hide'); - components.get('account/unban').parent().removeClass('hide'); - }); + } }); }); } @@ -124,9 +140,7 @@ define('forum/account/header', [ if (err) { return app.alertError(err.message); } - - components.get('account/ban').parent().removeClass('hide'); - components.get('account/unban').parent().addClass('hide'); + ajaxify.refresh(); }); } diff --git a/src/user/data.js b/src/user/data.js index 9b8c0e93d1..8e179ca119 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -60,7 +60,7 @@ module.exports = function(User) { db.sortedSetScores('users:banned:expire', uids, function(err, scores) { users = users.map(function(userObj, idx) { userObj.banned_until = scores[idx] || 0; - userObj.banned_until_readable = scores[idx] ? new Date(scores[idx]).toISOString() : 'Not Banned'; + userObj.banned_until_readable = scores[idx] ? new Date(scores[idx]).toString() : 'Not Banned'; }); }); }