From b2b57d49bf5b0d0d2906c3f0054499d5818872bf Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 6 Jan 2018 12:03:52 -0500 Subject: [PATCH] WIP add user modal --- public/language/en-GB/global.json | 4 ++- public/language/en-GB/modules.json | 2 ++ public/src/client/chats.js | 46 ++++++++++++++++++++++++++---- src/socket.io/modules.js | 8 ++++++ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/public/language/en-GB/global.json b/public/language/en-GB/global.json index b61d8f27b9..1195d792a0 100644 --- a/public/language/en-GB/global.json +++ b/public/language/en-GB/global.json @@ -134,5 +134,7 @@ "edited": "Edited", "disabled": "Disabled", - "select": "Select" + "select": "Select", + + "user-search-prompt": "Type something here to find users..." } diff --git a/public/language/en-GB/modules.json b/public/language/en-GB/modules.json index 529e015c0f..93433d1008 100644 --- a/public/language/en-GB/modules.json +++ b/public/language/en-GB/modules.json @@ -21,6 +21,8 @@ "chat.three_months": "3 Months", "chat.delete_message_confirm": "Are you sure you wish to delete this message?", "chat.add-users-to-room": "Add users to room", + "chat.retrieving-users": "Retrieving users...", + "chat.manage-room": "Manage Chat Room", "chat.confirm-chat-with-dnd-user": "This user has set their status to DnD(Do not disturb). Do you still want to chat with them?", "chat.rename-room": "Rename room", "chat.rename-placeholder": "Enter your room name here", diff --git a/public/src/client/chats.js b/public/src/client/chats.js index 3988843c08..94ecdbe2e2 100644 --- a/public/src/client/chats.js +++ b/public/src/client/chats.js @@ -48,7 +48,15 @@ define('forum/chats', [ Chats.addEventListeners = function () { Chats.addSendHandlers(ajaxify.data.roomId, $('.chat-input'), $('.expanded-chat button[data-action="send"]')); + Chats.addPopoutHandler(); + Chats.addActionHandlers(components.get('chat/messages'), ajaxify.data.roomId); + Chats.addMemberHandler(ajaxify.data.roomId, components.get('chat/controls').find('[data-action="members"]')); + Chats.addRenameHandler(ajaxify.data.roomId, components.get('chat/controls').find('[data-action="rename"]')); + Chats.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content')); + Chats.addCharactersLeftHandler($('[component="chat/main-wrapper"]')); + }; + Chats.addPopoutHandler = function () { $('[data-action="pop-out"]').on('click', function () { var text = components.get('chat/input').val(); var roomId = ajaxify.data.roomId; @@ -66,11 +74,6 @@ define('forum/chats', [ components.get('chat/input').val(text); }); }); - - Chats.addActionHandlers(components.get('chat/messages'), ajaxify.data.roomId); - Chats.addRenameHandler(ajaxify.data.roomId, components.get('expanded-chat/controls').find('[data-action="rename"]')); - Chats.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content')); - Chats.addCharactersLeftHandler($('[component="chat/main-wrapper"]')); }; Chats.addScrollHandler = function (roomId, uid, el) { @@ -170,6 +173,39 @@ define('forum/chats', [ }); }; + Chats.addMemberHandler = function (roomId, buttonEl) { + var modal; + + buttonEl.on('click', function () { + Benchpress.parse('partials/modals/manage_room', {}, function (html) { + translator.translate(html, function (html) { + modal = bootbox.dialog({ + title: '[[modules:chat.manage-room]]', + message: html, + }); + + modal.attr('component', 'chat/manage-modal'); + + socket.emit('modules.chats.getUsersInRoom', { roomId: roomId }, function (err, users) { + var listEl = modal.find('.list-group'); + + if (err) { + return translator.translate('[[error:invalid-data]]', function (translated) { + listEl.find('li').text(translated); + }); + } + + Benchpress.parse('partials/modals/manage_room_users', { + users: users, + }, function (html) { + listEl.html(html); + }); + }); + }); + }); + }); + }; + Chats.addRenameHandler = function (roomId, buttonEl, roomName) { var modal; diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index 7ff5accf40..cb8c43cbfa 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -167,6 +167,14 @@ SocketModules.chats.loadRoom = function (socket, data, callback) { ], callback); }; +SocketModules.chats.getUsersInRoom = function (socket, data, callback) { + if (!data || !data.roomId) { + return callback(new Error('[[error:invalid-data]]')); + } + + Messaging.getUsersInRoom(data.roomId, 0, -1, callback); +}; + SocketModules.chats.addUserToRoom = function (socket, data, callback) { if (!data || !data.roomId || !data.username) { return callback(new Error('[[error:invalid-data]]'));