Render "create account" link via a VDOMView and hide when connecting

This commit is contained in:
JC Brand 2017-12-13 22:04:49 +00:00
parent 9fca25b6a9
commit 5eabf4008e
3 changed files with 24 additions and 11 deletions

View File

@ -128,7 +128,7 @@
7: 'DISCONNECTING', 7: 'DISCONNECTING',
8: 'ATTACHED', 8: 'ATTACHED',
9: 'REDIRECT', 9: 'REDIRECT',
10: 'RECONNECTING' 10: 'RECONNECTING',
}; };
_converse.DEFAULT_IMAGE_TYPE = 'image/png'; _converse.DEFAULT_IMAGE_TYPE = 'image/png';
@ -1459,7 +1459,7 @@
this.ConnectionFeedback = Backbone.Model.extend({ this.ConnectionFeedback = Backbone.Model.extend({
defaults: { defaults: {
'connection_status': undefined, 'connection_status': Strophe.Status.DISCONNECTED,
'message': '' 'message': ''
}, },

View File

@ -64,15 +64,14 @@
render: function (cfg) { render: function (cfg) {
const { _converse } = this.__super__; const { _converse } = this.__super__;
const form = this.el.querySelector('form');
this.__super__.render.apply(this, arguments); this.__super__.render.apply(this, arguments);
if (_.isNull(form)) { if (_converse.allow_registration) {
if (_converse.allow_registration) { if (_.isUndefined(this.registerlinkview)) {
this.el.insertAdjacentHTML( this.registerlinkview = new _converse.RegisterLinkView({'model': this.model});
'beforeend', this.registerlinkview.render();
tpl_register_link({'__': _converse.__}) this.el.insertAdjacentElement('beforeend', this.registerlinkview.el);
);
} }
this.registerlinkview.render();
} }
return this; return this;
} }
@ -156,6 +155,18 @@
_converse.router.route('converse/register', _.partial(setActiveForm, 'register')); _converse.router.route('converse/register', _.partial(setActiveForm, 'register'));
_converse.RegisterLinkView = Backbone.VDOMView.extend({
toHTML () {
return tpl_register_link(
_.extend(this.model.toJSON(), {
'__': _converse.__,
'_converse': _converse,
'connection_status': _converse.connfeedback.get('connection_status'),
}));
}
});
_converse.RegisterPanel = Backbone.View.extend({ _converse.RegisterPanel = Backbone.View.extend({
tagName: 'div', tagName: 'div',
id: "converse-register-panel", id: "converse-register-panel",

View File

@ -1,4 +1,6 @@
<div class="switch-form"> <div class="switch-form">
<p>{{{ o.__("Don't have a chat account?") }}}</p> {[ if (!o._converse.auto_login && o._converse.CONNECTION_STATUS[o.connection_status] !== 'CONNECTING') { ]}
<p><a class="register-account toggle-register-login" href="#converse/register">{{{o.__("Create an account")}}}</a></p> <p>{{{ o.__("Don't have a chat account?") }}}</p>
<p><a class="register-account toggle-register-login" href="#converse/register">{{{o.__("Create an account")}}}</a></p>
{[ } ]}
</div> </div>