From 4bac78a568ee8109c44ff3a2f38bd169a4ccef96 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 27 Apr 2018 15:37:00 -0400 Subject: [PATCH] wrapping up basic blocking UCP for #6463 --- public/language/en-GB/user.json | 1 + public/src/client/account/blocks.js | 29 +++++++++++++++++++++++++++-- src/socket.io/user/profile.js | 9 +++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/public/language/en-GB/user.json b/public/language/en-GB/user.json index 3ff3c47cac..44db14eba6 100644 --- a/public/language/en-GB/user.json +++ b/public/language/en-GB/user.json @@ -32,6 +32,7 @@ "followers": "Followers", "following": "Following", "blocks": "Blocks", + "block_toggle": "Toggle Block", "aboutme": "About me", "signature": "Signature", "birthday": "Birthday", diff --git a/public/src/client/account/blocks.js b/public/src/client/account/blocks.js index 4e6230e00e..de6ba1e731 100644 --- a/public/src/client/account/blocks.js +++ b/public/src/client/account/blocks.js @@ -1,12 +1,37 @@ 'use strict'; -define('forum/account/blocks', ['forum/account/header'], function (header) { +define('forum/account/blocks', ['forum/account/header', 'autocomplete'], function (header, autocomplete) { var Blocks = {}; Blocks.init = function () { header.init(); - console.log('derpp'); + autocomplete.user($('#user-search'), function (ev, ui) { + app.parseAndTranslate('account/blocks', 'edit', { + edit: [ui.item.user], + }, function (html) { + $('.block-edit').html(html); + }); + }); + + $('.block-edit').on('click', '[data-action="toggle"]', function () { + var uid = parseInt(this.getAttribute('data-uid'), 10); + socket.emit('user.toggleBlock', { + uid: uid, + }, Blocks.refreshList); + }); + }; + + Blocks.refreshList = function () { + $.get(config.relative_path + '/api/' + ajaxify.currentPage) + .done(function (payload) { + app.parseAndTranslate('account/blocks', 'users', payload, function (html) { + $('#users-container').html(html); + }); + }) + .fail(function () { + ajaxify.go(ajaxify.currentPage); + }); }; return Blocks; diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js index 1391ba2f3c..b14f12bc1e 100644 --- a/src/socket.io/user/profile.js +++ b/src/socket.io/user/profile.js @@ -200,4 +200,13 @@ module.exports = function (SocketUser) { }, ], callback); }; + + SocketUser.toggleBlock = function (socket, data, callback) { + async.waterfall([ + async.apply(user.blocks.is, data.uid, socket.uid), + function (is, next) { + user.blocks[is ? 'remove' : 'add'](data.uid, socket.uid, next); + }, + ], callback); + }; };