szurubooru/client/js/views/user_view.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-04-06 22:34:21 +02:00
'use strict';
const views = require('../util/views.js');
2016-05-11 12:17:40 +02:00
const UserDeleteView = require('./user_delete_view.js');
2016-04-06 22:34:21 +02:00
const UserSummaryView = require('./user_summary_view.js');
const UserEditView = require('./user_edit_view.js');
class UserView {
2016-04-06 22:34:21 +02:00
constructor() {
this._template = views.getTemplate('user');
this._deleteView = new UserDeleteView();
this._summaryView = new UserSummaryView();
this._editView = new UserEditView();
2016-04-06 22:34:21 +02:00
}
2016-04-08 10:35:38 +02:00
render(ctx) {
const target = document.getElementById('content-holder');
const source = this._template(ctx);
2016-04-08 10:35:38 +02:00
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 = '';
}
2016-04-06 22:34:21 +02:00
}
let view = null;
2016-04-08 10:35:38 +02:00
if (ctx.section == 'edit') {
view = this._editView;
2016-04-09 09:52:00 +02:00
} else if (ctx.section == 'delete') {
view = this._deleteView;
2016-04-06 22:34:21 +02:00
} else {
view = this._summaryView;
2016-04-06 22:34:21 +02:00
}
2016-04-08 10:35:38 +02:00
ctx.target = source.querySelector('#user-content-holder');
view.render(ctx);
2016-04-06 22:34:21 +02:00
views.listenToMessages(source);
views.showView(target, source);
2016-04-06 22:34:21 +02:00
}
}
module.exports = UserView;