From 65ac389625683e1d081f286e2f1de2f305b34c99 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 10 May 2018 13:43:03 +0200 Subject: [PATCH] Add a way to show a user's vcard --- src/converse-chatboxes.js | 4 +++ src/converse-chatview.js | 34 +++++++++++++++++++++++-- src/templates/chatbox_head.html | 2 +- src/templates/user_details_modal.html | 36 +++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/templates/user_details_modal.html diff --git a/src/converse-chatboxes.js b/src/converse-chatboxes.js index 3e15253cb..3f4dc914a 100644 --- a/src/converse-chatboxes.js +++ b/src/converse-chatboxes.js @@ -261,6 +261,10 @@ }); }, + getDisplayName () { + return this.vcard.get('fullname') || this.get('jid'); + }, + createMessageStanza (message) { /* Given a _converse.Message Backbone.Model, return the XML * stanza that represents it. diff --git a/src/converse-chatview.js b/src/converse-chatview.js index b08001756..88ee88fd1 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -19,11 +19,13 @@ "tpl!help_message", "tpl!info", "tpl!new_day", + "tpl!user_details_modal", "tpl!toolbar_fileupload", "tpl!spinner", "tpl!spoiler_button", "tpl!status_message", "tpl!toolbar", + "converse-modal", "converse-chatboxes", "converse-message-view" ], factory); @@ -41,6 +43,7 @@ tpl_help_message, tpl_info, tpl_new_day, + tpl_user_details_modal, tpl_toolbar_fileupload, tpl_spinner, tpl_spoiler_button, @@ -66,7 +69,7 @@ * * NB: These plugins need to have already been loaded via require.js. */ - dependencies: ["converse-chatboxes", "converse-disco", "converse-message-view"], + dependencies: ["converse-chatboxes", "converse-disco", "converse-message-view", "converse-modal"], overrides: { // Overrides mentioned here will be picked up by converse.js's @@ -200,8 +203,8 @@ } }); - _converse.ChatBoxHeading = _converse.ViewWithAvatar.extend({ + _converse.ChatBoxHeading = _converse.ViewWithAvatar.extend({ initialize () { this.model.on('change:status', this.onStatusMessageChanged, this); this.model.vcard.on('change', this.render, this); @@ -231,6 +234,25 @@ }); + _converse.UserDetailsModal = _converse.BootstrapModal.extend({ + toHTML () { + return tpl_user_details_modal(_.extend( + this.model.toJSON(), + this.model.vcard.toJSON(), { + 'alt_profile_image': __("The User's Profile Image"), + 'display_name': this.model.getDisplayName(), + 'label_close': __('Close'), + 'label_email': __('Email'), + 'label_fullname': __('Full Name'), + 'label_nickname': __('Nickname'), + 'label_role': __('Role'), + 'label_save': __('Save'), + 'label_url': __('URL'), + })); + } + }); + + _converse.ChatBoxView = Backbone.NativeView.extend({ length: 200, className: 'chatbox hidden', @@ -239,6 +261,7 @@ events: { 'change input.fileupload': 'onFileSelection', 'click .close-chatbox-button': 'close', + 'click .show-user-details-modal': 'showUserDetailsModal', 'click .new-msgs-indicator': 'viewUnreadMessages', 'click .send-button': 'onFormSubmitted', 'click .toggle-call': 'toggleCall', @@ -328,6 +351,13 @@ this.renderToolbar(); }, + showUserDetailsModal (ev) { + if (_.isUndefined(this.user_details_modal)) { + this.user_details_modal = new _converse.UserDetailsModal({model: this.model}); + } + this.user_details_modal.show(ev); + }, + toggleFileUpload (ev) { this.el.querySelector('input.fileupload').click(); }, diff --git a/src/templates/chatbox_head.html b/src/templates/chatbox_head.html index fb5311c29..0d6aeb86e 100644 --- a/src/templates/chatbox_head.html +++ b/src/templates/chatbox_head.html @@ -16,6 +16,6 @@
- +
diff --git a/src/templates/user_details_modal.html b/src/templates/user_details_modal.html new file mode 100644 index 000000000..c462fbe24 --- /dev/null +++ b/src/templates/user_details_modal.html @@ -0,0 +1,36 @@ +