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');
2016-05-11 12:17:40 +02:00
this.deleteView = new UserDeleteView();
2016-04-06 22:34:21 +02:00
this.summaryView = new UserSummaryView();
this.editView = new UserEditView();
}
2016-04-08 10:35:38 +02:00
render(ctx) {
const target = document.getElementById('content-holder');
2016-04-08 10:35:38 +02:00
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 = '';
}
2016-04-06 22:34:21 +02:00
}
let view = null;
2016-04-08 10:35:38 +02:00
if (ctx.section == 'edit') {
2016-04-06 22:34:21 +02:00
view = this.editView;
2016-04-09 09:52:00 +02:00
} else if (ctx.section == 'delete') {
2016-05-11 12:17:40 +02:00
view = this.deleteView;
2016-04-06 22:34:21 +02:00
} else {
view = this.summaryView;
}
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(target);
views.showView(target, source);
2016-04-06 22:34:21 +02:00
}
}
module.exports = UserView;