diff --git a/config.js b/config.js index 743b99002..02e395c73 100644 --- a/config.js +++ b/config.js @@ -129,6 +129,7 @@ require.config({ "chatroom": "src/templates/chatroom", "chatroom_bookmark_form": "src/templates/chatroom_bookmark_form", "chatroom_bookmark_toggle": "src/templates/chatroom_bookmark_toggle", + "chatroom_features": "src/templates/chatroom_features", "chatroom_form": "src/templates/chatroom_form", "chatroom_head": "src/templates/chatroom_head", "chatroom_nickname_form": "src/templates/chatroom_nickname_form", diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 38b644546..ef1fc4993 100755 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -13,6 +13,8 @@ available to plugins, has been renamed from `converse` to `_converse`. The public API is accessible via a global `converse` object. * The `keepalive` and `roster_groups` options are now set to `true` by default. + * Templates are no longer stored as attributes on the `_converse` object. + If you need a particular template, use `require` to load it. - The chat room `description` is now shown in the heading, not the `subject`. [jcbrand] diff --git a/src/converse-muc.js b/src/converse-muc.js index fc1991a0f..117b59d91 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -14,12 +14,13 @@ "converse-core", "tpl!chatarea", "tpl!chatroom", + "tpl!chatroom_features", "tpl!chatroom_form", + "tpl!chatroom_head", "tpl!chatroom_nickname_form", "tpl!chatroom_password_form", "tpl!chatroom_sidebar", "tpl!chatroom_toolbar", - "tpl!chatroom_head", "tpl!chatrooms_tab", "tpl!info", "tpl!occupant", @@ -33,12 +34,13 @@ converse, tpl_chatarea, tpl_chatroom, + tpl_chatroom_features, tpl_chatroom_form, + tpl_chatroom_head, tpl_chatroom_nickname_form, tpl_chatroom_password_form, tpl_chatroom_sidebar, tpl_chatroom_toolbar, - tpl_chatroom_head, tpl_chatrooms_tab, tpl_info, tpl_occupant, @@ -398,9 +400,7 @@ */ this.occupantsview = new _converse.ChatRoomOccupantsView({ 'model': new _converse.ChatRoomOccupants(), - 'attributes': { - 'chatroomview': this - } + 'attributes': { 'chatroomview': this } // Hack }); var id = b64_sha1('converse.occupants'+_converse.bare_jid+this.model.get('jid')); this.occupantsview.model.browserStorage = new Backbone.BrowserStorage.session(id); @@ -1959,21 +1959,25 @@ initialize: function () { this.model.on("add", this.onOccupantAdded, this); - var debounced_render = _.debounce(this.render, 100); + var debouncedRenderRoomFeatures = _.debounce(this.renderRoomFeatures, 100); + + // This is an ugly hack (misusing view attributes) this.chatroomview = this.attributes.chatroomview; - this.chatroomview.model.on('change:hidden', debounced_render, this); - this.chatroomview.model.on('change:mam_enabled', debounced_render, this); - this.chatroomview.model.on('change:membersonly', debounced_render, this); - this.chatroomview.model.on('change:moderated', debounced_render, this); - this.chatroomview.model.on('change:nonanonymous', debounced_render, this); - this.chatroomview.model.on('change:open', debounced_render, this); - this.chatroomview.model.on('change:passwordprotected', debounced_render, this); - this.chatroomview.model.on('change:persistent', debounced_render, this); - this.chatroomview.model.on('change:public', debounced_render, this); - this.chatroomview.model.on('change:semianonymous', debounced_render, this); - this.chatroomview.model.on('change:temporary', debounced_render, this); - this.chatroomview.model.on('change:unmoderated', debounced_render, this); - this.chatroomview.model.on('change:unsecured', debounced_render, this); + delete this.attributes.chatroomview; + + this.chatroomview.model.on('change:hidden', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:mam_enabled', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:membersonly', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:moderated', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:nonanonymous', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:open', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:passwordprotected', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:persistent', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:public', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:semianonymous', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:temporary', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:unmoderated', debouncedRenderRoomFeatures, this); + this.chatroomview.model.on('change:unsecured', debouncedRenderRoomFeatures, this); }, render: function () { @@ -1982,13 +1986,26 @@ _.extend(this.chatroomview.model.toJSON(), { 'allow_muc_invitations': _converse.allow_muc_invitations, 'label_features': __('Features'), + 'label_invitation': __('Invite'), + 'label_occupants': __('Occupants'), + })) + ); + if (_converse.allow_muc_invitations) { + _converse.api.waitUntil('rosterContactsFetched').then(this.initInviteWidget.bind(this)); + } + return this.renderRoomFeatures(); + }, + + renderRoomFeatures: function () { + this.$('.features-list').html( + tpl_chatroom_features( + _.extend(this.chatroomview.model.toJSON(), { 'label_hidden': __('Hidden'), 'label_invitation': __('Invite'), 'label_mam_enabled': __('Message archiving'), 'label_membersonly': __('Members only'), 'label_moderated': __('Moderated'), 'label_nonanonymous': __('Non-anonymous'), - 'label_occupants': __('Occupants'), 'label_open': __('Open'), 'label_passwordprotected': __('Password protected'), 'label_persistent': __('Persistent'), @@ -2012,9 +2029,6 @@ 'tt_unsecured': __('This room does not require a password upon entry') })) ); - if (_converse.allow_muc_invitations) { - _converse.api.waitUntil('rosterContactsFetched').then(this.initInviteWidget.bind(this)); - } return this; }, diff --git a/src/templates/chatroom_features.html b/src/templates/chatroom_features.html new file mode 100644 index 000000000..42875e9c0 --- /dev/null +++ b/src/templates/chatroom_features.html @@ -0,0 +1,39 @@ +{[ if (passwordprotected) { ]} +
  • {{{ label_passwordprotected }}}
  • +{[ } ]} +{[ if (unsecured) { ]} +
  • {{{ label_unsecured }}}
  • +{[ } ]} +{[ if (hidden) { ]} +
  • {{{ label_hidden }}}
  • +{[ } ]} +{[ if (public) { ]} +
  • {{{ label_public }}}
  • +{[ } ]} +{[ if (membersonly) { ]} +
  • {{{ label_membersonly }}}
  • +{[ } ]} +{[ if (open) { ]} +
  • {{{ label_open }}}
  • +{[ } ]} +{[ if (persistent) { ]} +
  • {{{ label_persistent }}}
  • +{[ } ]} +{[ if (temporary) { ]} +
  • {{{ label_temporary }}}
  • +{[ } ]} +{[ if (nonanonymous) { ]} +
  • {{{ label_nonanonymous }}}
  • +{[ } ]} +{[ if (semianonymous) { ]} +
  • {{{ label_semianonymous }}}
  • +{[ } ]} +{[ if (moderated) { ]} +
  • {{{ label_moderated }}}
  • +{[ } ]} +{[ if (unmoderated) { ]} +
  • {{{ label_unmoderated }}}
  • +{[ } ]} +{[ if (mam_enabled) { ]} +
  • {{{ label_mam_enabled }}}
  • +{[ } ]} diff --git a/src/templates/chatroom_sidebar.html b/src/templates/chatroom_sidebar.html index e4e89c4f9..4c724165c 100644 --- a/src/templates/chatroom_sidebar.html +++ b/src/templates/chatroom_sidebar.html @@ -10,46 +10,5 @@

    {{{label_features}}}

    - - +