gallery.accords-library.com/client/js/views/settings_view.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

'use strict';
const events = require('../events.js');
const views = require('../util/views.js');
const template = views.getTemplate('settings');
class SettingsView extends events.EventTarget {
constructor(ctx) {
super();
this._hostNode = document.getElementById('content-holder');
views.replaceContent(
this._hostNode, template({browsingSettings: ctx.settings}));
2016-07-13 15:18:28 +00:00
views.syncScrollPosition();
2016-07-13 15:18:28 +00:00
views.decorateValidator(this._formNode);
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
}
clearMessages() {
views.clearMessages(this._hostNode);
}
showSuccess(text) {
views.showSuccess(this._hostNode, text);
}
_evtSubmit(e) {
e.preventDefault();
this.dispatchEvent(new CustomEvent('change', {
detail: {
2016-08-05 18:09:11 +00:00
upscaleSmallPosts: this._find('upscale-small-posts').checked,
endlessScroll: this._find('endless-scroll').checked,
keyboardShortcuts: this._find('keyboard-shortcuts').checked,
transparencyGrid: this._find('transparency-grid').checked,
tagSuggestions: this._find('tag-suggestions').checked,
postsPerPage: this._find('posts-per-page').value,
},
}));
}
get _formNode() {
return this._hostNode.querySelector('form');
}
2016-08-05 18:09:11 +00:00
_find(nodeName) {
return this._formNode.querySelector('[name=' + nodeName + ']');
}
}
module.exports = SettingsView;