From d3090f80bcc05443ee52d93ac2b1e475539325b7 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 2 Nov 2016 22:08:20 +0000 Subject: [PATCH] Remember which panel was open when reloading the page. --- src/converse-controlbox.js | 26 +++++++++++++++++++++----- src/converse-core.js | 14 ++++++++------ src/converse-muc.js | 14 ++++++++++++-- src/converse-register.js | 2 +- src/templates/chatrooms_tab.html | 5 ++++- src/templates/contacts_tab.html | 5 ++++- 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/converse-controlbox.js b/src/converse-controlbox.js index be9dca45b..a1e123707 100644 --- a/src/converse-controlbox.js +++ b/src/converse-controlbox.js @@ -58,6 +58,8 @@ converse.templates.search_contact = tpl_search_contact; converse.templates.status_option = tpl_status_option; + var USERS_PANEL_ID = 'users'; + // Strophe methods for building stanzas var Strophe = converse_api.env.Strophe, utils = converse_api.env.utils; @@ -323,6 +325,9 @@ }, renderContactsPanel: function () { + if (_.isUndefined(this.model.get('active-panel'))) { + this.model.save({'active-panel': USERS_PANEL_ID}); + } this.contactspanel = new converse.ContactsPanel({ '$parent': this.$el.find('.controlbox-panes') }); @@ -366,11 +371,12 @@ }, onControlBoxToggleHidden: function () { + var that = this; this.$el.show('fast', function () { converse.controlboxtoggle.updateOnlineCount(); utils.refreshWebkit(); - converse.emit('controlBoxOpened', this); - }.bind(this)); + converse.emit('controlBoxOpened', that); + }); }, show: function () { @@ -386,10 +392,13 @@ var $tab = $(ev.target), $sibling = $tab.parent().siblings('li').children('a'), $tab_panel = $($tab.attr('href')); - $($sibling.attr('href')).hide(); + $($sibling.attr('href')).addClass('hidden'); $sibling.removeClass('current'); $tab.addClass('current'); - $tab_panel.show(); + $tab_panel.removeClass('hidden'); + if (converse.connection.connected) { + this.model.save({'active-panel': $tab.data('id')}); + } return this; }, @@ -631,7 +640,11 @@ include_offline_state: converse.include_offline_state, allow_logout: converse.allow_logout }); - this.$tabs.append(converse.templates.contacts_tab({label_contacts: LABEL_CONTACTS})); + var controlbox = converse.chatboxes.get('controlbox'); + this.$tabs.append(converse.templates.contacts_tab({ + 'label_contacts': LABEL_CONTACTS, + 'is_current': controlbox.get('active-panel') === USERS_PANEL_ID + })); if (converse.xhr_user_search) { markup = converse.templates.search_contact({ label_contact_name: __('Contact name'), @@ -651,6 +664,9 @@ } this.$el.html(widgets); this.$el.find('.search-xmpp ul').append(markup); + if (controlbox.get('active-panel') !== USERS_PANEL_ID) { + this.$el.addClass('hidden'); + } return this; }, diff --git a/src/converse-core.js b/src/converse-core.js index 9597e7abb..c72aa02c4 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -680,11 +680,7 @@ // XXX: Deprecate in favor of init_deferred converse.callback(); } - if (converse.connection.service === 'jasmine tests') { - init_deferred.resolve(converse); - } else { - init_deferred.resolve(); - } + init_deferred.resolve(); converse.emit('initialized'); }; @@ -1961,7 +1957,13 @@ converse.emit('pluginsInitialized'); converse._initialize(); converse.registerGlobalEventHandlers(); - return init_deferred.promise(); + + if (!_.isUndefined(converse.connection) && + converse.connection.service === 'jasmine tests') { + return converse; + } else { + return init_deferred.promise(); + } }; return converse; })); diff --git a/src/converse-muc.js b/src/converse-muc.js index d1770a013..7ea6d105a 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -60,6 +60,8 @@ converse.templates.room_item = tpl_room_item; converse.templates.room_panel = tpl_room_panel; + var ROOMS_PANEL_ID = 'chatrooms'; + // Strophe methods for building stanzas var Strophe = converse_api.env.Strophe, $iq = converse_api.env.$iq, @@ -1434,9 +1436,17 @@ 'label_join': __('Join Room'), 'label_show_rooms': __('Show rooms') }) - ).hide()); + )); this.$tabs = this.$parent.parent().find('#controlbox-tabs'); - this.$tabs.append(converse.templates.chatrooms_tab({label_rooms: __('Rooms')})); + + var controlbox = converse.chatboxes.get('controlbox'); + this.$tabs.append(converse.templates.chatrooms_tab({ + 'label_rooms': __('Rooms'), + 'is_current': controlbox.get('active-panel') === ROOMS_PANEL_ID + })); + if (controlbox.get('active-panel') !== ROOMS_PANEL_ID) { + this.$el.addClass('hidden'); + } return this; }, diff --git a/src/converse-register.js b/src/converse-register.js index c84bafc94..eebfb536e 100644 --- a/src/converse-register.js +++ b/src/converse-register.js @@ -81,7 +81,7 @@ '$parent': this.$el.find('.controlbox-panes'), 'model': this }); - this.registerpanel.render().$el.hide(); + this.registerpanel.render().$el.addClass('hidden'); } return this; } diff --git a/src/templates/chatrooms_tab.html b/src/templates/chatrooms_tab.html index 6920d976d..cc754cca6 100644 --- a/src/templates/chatrooms_tab.html +++ b/src/templates/chatrooms_tab.html @@ -1 +1,4 @@ -
  • {{label_rooms}}
  • +
  • + {{label_rooms}} +
  • diff --git a/src/templates/contacts_tab.html b/src/templates/contacts_tab.html index 9151c50ad..891446b60 100644 --- a/src/templates/contacts_tab.html +++ b/src/templates/contacts_tab.html @@ -1 +1,4 @@ -
  • {{label_contacts}}
  • +
  • + {{label_contacts}} +