szurubooru/client/js/views/user_view.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-04-06 22:34:21 +02:00
'use strict';
const events = require('../events.js');
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');
const template = views.getTemplate('user');
2016-04-06 22:34:21 +02:00
class UserView extends events.EventTarget {
constructor(ctx) {
super();
2016-04-08 10:35:38 +02:00
this._hostNode = document.getElementById('content-holder');
2016-04-08 10:35:38 +02:00
ctx.section = ctx.section || 'summary';
views.replaceContent(this._hostNode, template(ctx));
2016-04-08 10:35:38 +02:00
for (let item of this._hostNode.querySelectorAll('[data-name]')) {
2016-04-08 10:35:38 +02:00
if (item.getAttribute('data-name') === ctx.section) {
item.className = 'active';
} else {
item.className = '';
}
2016-04-06 22:34:21 +02:00
}
ctx.hostNode = this._hostNode.querySelector('#user-content-holder');
2016-04-08 10:35:38 +02:00
if (ctx.section == 'edit') {
this._view = new UserEditView(ctx);
this._view.addEventListener('submit', e => {
this.dispatchEvent(
new CustomEvent('change', {detail: e.detail}));
});
2016-04-09 09:52:00 +02:00
} else if (ctx.section == 'delete') {
this._view = new UserDeleteView(ctx);
this._view.addEventListener('submit', e => {
this.dispatchEvent(
new CustomEvent('delete', {detail: e.detail}));
});
2016-04-06 22:34:21 +02:00
} else {
this._view = new UserSummaryView(ctx);
2016-04-06 22:34:21 +02:00
}
}
clearMessages() {
this._view.clearMessages();
}
showSuccess(message) {
this._view.showSuccess(message);
}
showError(message) {
this._view.showError(message);
}
enableForm() {
this._view.enableForm();
}
2016-04-06 22:34:21 +02:00
disableForm() {
this._view.disableForm();
2016-04-06 22:34:21 +02:00
}
}
module.exports = UserView;