szurubooru/client/js/views/user_view.js
rr- 2a4241641c client/events: improve event dispatching
This commit introduces timer-less retry system:

1. Any change to URL is going to stop listening to any messages.
2. If a message is sent and there's no handler that could pick it up,
   the message gets enqueued.
3. The message is sent again to the first handler that attaches itself
   to given event type.

While in theory this is full of holes (no control over the first
handler), in practice, it works quite well.

Additionally, views.listenToMessages was attaching to completely wrong
DOM node; this commit fixes this as well.
2016-05-11 23:47:50 +02:00

46 lines
1.3 KiB
JavaScript

'use strict';
const views = require('../util/views.js');
const UserDeleteView = require('./user_delete_view.js');
const UserSummaryView = require('./user_summary_view.js');
const UserEditView = require('./user_edit_view.js');
class UserView {
constructor() {
this.template = views.getTemplate('user');
this.deleteView = new UserDeleteView();
this.summaryView = new UserSummaryView();
this.editView = new UserEditView();
}
render(ctx) {
const target = document.getElementById('content-holder');
const source = this.template(ctx);
ctx.section = ctx.section || 'summary';
for (let item of source.querySelectorAll('[data-name]')) {
if (item.getAttribute('data-name') === ctx.section) {
item.className = 'active';
} else {
item.className = '';
}
}
let view = null;
if (ctx.section == 'edit') {
view = this.editView;
} else if (ctx.section == 'delete') {
view = this.deleteView;
} else {
view = this.summaryView;
}
ctx.target = source.querySelector('#user-content-holder');
view.render(ctx);
views.listenToMessages(source);
views.showView(target, source);
}
}
module.exports = UserView;