client/events: adjust event names

1. "change" should be used to passive changes.
2. "submit" should be used to form submits.

These are not interchangeable.
This commit is contained in:
rr- 2016-08-22 20:45:58 +02:00
parent 73a8542220
commit d8d4654849
12 changed files with 26 additions and 23 deletions

View File

@ -30,7 +30,7 @@ class CommentsController {
canViewPosts: api.hasPrivilege('posts:view'), canViewPosts: api.hasPrivilege('posts:view'),
}); });
const view = new CommentsPageView(pageCtx); const view = new CommentsPageView(pageCtx);
view.addEventListener('change', e => this._evtChange(e)); view.addEventListener('submit', e => this._evtUpdate(e));
view.addEventListener('score', e => this._evtScore(e)); view.addEventListener('score', e => this._evtScore(e));
view.addEventListener('delete', e => this._evtDelete(e)); view.addEventListener('delete', e => this._evtDelete(e));
return view; return view;
@ -38,7 +38,7 @@ class CommentsController {
}); });
} }
_evtChange(e) { _evtUpdate(e) {
// TODO: disable form // TODO: disable form
e.detail.comment.text = e.detail.text; e.detail.comment.text = e.detail.text;
e.detail.comment.save() e.detail.comment.save()

View File

@ -46,6 +46,7 @@ class PostController {
canCreateComments: api.hasPrivilege('comments:create'), canCreateComments: api.hasPrivilege('comments:create'),
parameters: parameters, parameters: parameters,
}); });
if (this._view.sidebarControl) { if (this._view.sidebarControl) {
this._view.sidebarControl.addEventListener( this._view.sidebarControl.addEventListener(
'favorite', e => this._evtFavoritePost(e)); 'favorite', e => this._evtFavoritePost(e));
@ -58,21 +59,23 @@ class PostController {
this._view.sidebarControl.addEventListener( this._view.sidebarControl.addEventListener(
'change', e => this._evtPostChange(e)); 'change', e => this._evtPostChange(e));
this._view.sidebarControl.addEventListener( this._view.sidebarControl.addEventListener(
'submit', e => this._evtPostEdit(e)); 'submit', e => this._evtUpdatePost(e));
this._view.sidebarControl.addEventListener( this._view.sidebarControl.addEventListener(
'feature', e => this._evtPostFeature(e)); 'feature', e => this._evtFeaturePost(e));
this._view.sidebarControl.addEventListener( this._view.sidebarControl.addEventListener(
'delete', e => this._evtPostDelete(e)); 'delete', e => this._evtDeletePost(e));
} }
if (this._view.commentFormControl) { if (this._view.commentFormControl) {
this._view.commentFormControl.addEventListener( this._view.commentFormControl.addEventListener(
'change', e => this._evtCommentChange(e)); 'change', e => this._evtCommentChange(e));
this._view.commentFormControl.addEventListener( this._view.commentFormControl.addEventListener(
'submit', e => this._evtCreateComment(e)); 'submit', e => this._evtCreateComment(e));
} }
if (this._view.commentListControl) { if (this._view.commentListControl) {
this._view.commentListControl.addEventListener( this._view.commentListControl.addEventListener(
'change', e => this._evtUpdateComment(e)); 'submit', e => this._evtUpdateComment(e));
this._view.commentListControl.addEventListener( this._view.commentListControl.addEventListener(
'score', e => this._evtScoreComment(e)); 'score', e => this._evtScoreComment(e));
this._view.commentListControl.addEventListener( this._view.commentListControl.addEventListener(
@ -104,7 +107,7 @@ class PostController {
settings.save(browsingSettings); settings.save(browsingSettings);
} }
_evtPostFeature(e) { _evtFeaturePost(e) {
this._view.sidebarControl.disableForm(); this._view.sidebarControl.disableForm();
this._view.sidebarControl.clearMessages(); this._view.sidebarControl.clearMessages();
e.detail.post.feature() e.detail.post.feature()
@ -117,7 +120,7 @@ class PostController {
}); });
} }
_evtPostDelete(e) { _evtDeletePost(e) {
this._view.sidebarControl.disableForm(); this._view.sidebarControl.disableForm();
this._view.sidebarControl.clearMessages(); this._view.sidebarControl.clearMessages();
e.detail.post.delete() e.detail.post.delete()
@ -131,7 +134,7 @@ class PostController {
}); });
} }
_evtPostEdit(e) { _evtUpdatePost(e) {
this._view.sidebarControl.disableForm(); this._view.sidebarControl.disableForm();
this._view.sidebarControl.clearMessages(); this._view.sidebarControl.clearMessages();
const post = e.detail.post; const post = e.detail.post;

View File

@ -11,10 +11,10 @@ class SettingsController {
this._view = new SettingsView({ this._view = new SettingsView({
settings: settings.get(), settings: settings.get(),
}); });
this._view.addEventListener('change', e => this._evtChange(e)); this._view.addEventListener('submit', e => this._evtSubmit(e));
} }
_evtChange(e) { _evtSubmit(e) {
this._view.clearMessages(); this._view.clearMessages();
settings.save(e.detail); settings.save(e.detail);
this._view.showSuccess('Settings saved.'); this._view.showSuccess('Settings saved.');

View File

@ -36,7 +36,7 @@ class TagController {
categories: categories, categories: categories,
}); });
this._view.addEventListener('change', e => this._evtChange(e)); this._view.addEventListener('submit', e => this._evtUpdate(e));
this._view.addEventListener('merge', e => this._evtMerge(e)); this._view.addEventListener('merge', e => this._evtMerge(e));
this._view.addEventListener('delete', e => this._evtDelete(e)); this._view.addEventListener('delete', e => this._evtDelete(e));
}, errorMessage => { }, errorMessage => {
@ -51,7 +51,7 @@ class TagController {
} }
} }
_evtChange(e) { _evtUpdate(e) {
this._view.clearMessages(); this._view.clearMessages();
this._view.disableForm(); this._view.disableForm();
if (e.detail.names !== undefined) { if (e.detail.names !== undefined) {

View File

@ -51,7 +51,7 @@ class UserController {
canDelete: api.hasPrivilege(`users:delete:${infix}`), canDelete: api.hasPrivilege(`users:delete:${infix}`),
ranks: ranks, ranks: ranks,
}); });
this._view.addEventListener('change', e => this._evtChange(e)); this._view.addEventListener('submit', e => this._evtUpdate(e));
this._view.addEventListener('delete', e => this._evtDelete(e)); this._view.addEventListener('delete', e => this._evtDelete(e));
}, errorMessage => { }, errorMessage => {
this._view = new EmptyView(); this._view = new EmptyView();
@ -66,7 +66,7 @@ class UserController {
} }
} }
_evtChange(e) { _evtUpdate(e) {
this._view.clearMessages(); this._view.clearMessages();
this._view.disableForm(); this._view.disableForm();
const isLoggedIn = api.isLoggedIn(e.detail.user); const isLoggedIn = api.isLoggedIn(e.detail.user);

View File

@ -39,7 +39,7 @@ class CommentControl extends events.EventTarget {
this._hostNode.querySelector('.comment-form-container'), this._hostNode.querySelector('.comment-form-container'),
this._comment, this._comment,
true); true);
events.proxyEvent(this._formControl, this, 'submit', 'change'); events.proxyEvent(this._formControl, this, 'submit');
this._installScore(); this._installScore();
} }

View File

@ -35,7 +35,7 @@ class CommentListControl extends events.EventTarget {
const commentListItemNode = document.createElement('li'); const commentListItemNode = document.createElement('li');
const commentControl = new CommentControl( const commentControl = new CommentControl(
commentListItemNode, comment); commentListItemNode, comment);
events.proxyEvent(commentControl, this, 'change'); events.proxyEvent(commentControl, this, 'submit');
events.proxyEvent(commentControl, this, 'score'); events.proxyEvent(commentControl, this, 'score');
events.proxyEvent(commentControl, this, 'delete'); events.proxyEvent(commentControl, this, 'delete');
this._commentIdToNode[comment.id] = commentListItemNode; this._commentIdToNode[comment.id] = commentListItemNode;

View File

@ -19,7 +19,7 @@ class CommentsPageView extends events.EventTarget {
`.comments-container[data-for="${post.id}"]`), `.comments-container[data-for="${post.id}"]`),
post.comments, post.comments,
true); true);
events.proxyEvent(commentListControl, this, 'change'); events.proxyEvent(commentListControl, this, 'submit');
events.proxyEvent(commentListControl, this, 'score'); events.proxyEvent(commentListControl, this, 'score');
events.proxyEvent(commentListControl, this, 'delete'); events.proxyEvent(commentListControl, this, 'delete');
} }

View File

@ -37,8 +37,8 @@ class PostsHeaderView {
} }
}); });
for (let safetyButton of this._safetyButtonNodes) { for (let safetyButtonNode of this._safetyButtonNodes) {
safetyButton.addEventListener( safetyButtonNode.addEventListener(
'click', e => this._evtSafetyButtonClick(e)); 'click', e => this._evtSafetyButtonClick(e));
} }
this._searchFormNode.addEventListener( this._searchFormNode.addEventListener(

View File

@ -28,7 +28,7 @@ class SettingsView extends events.EventTarget {
_evtSubmit(e) { _evtSubmit(e) {
e.preventDefault(); e.preventDefault();
this.dispatchEvent(new CustomEvent('change', { this.dispatchEvent(new CustomEvent('submit', {
detail: { detail: {
upscaleSmallPosts: this._find('upscale-small-posts').checked, upscaleSmallPosts: this._find('upscale-small-posts').checked,
endlessScroll: this._find('endless-scroll').checked, endlessScroll: this._find('endless-scroll').checked,

View File

@ -35,7 +35,7 @@ class TagView extends events.EventTarget {
this._view = new TagEditView(ctx); this._view = new TagEditView(ctx);
this._view.addEventListener('submit', e => { this._view.addEventListener('submit', e => {
this.dispatchEvent( this.dispatchEvent(
new CustomEvent('change', {detail: e.detail})); new CustomEvent('submit', {detail: e.detail}));
}); });
} else if (ctx.section === 'merge') { } else if (ctx.section === 'merge') {
this._view = new TagMergeView(ctx); this._view = new TagMergeView(ctx);

View File

@ -36,7 +36,7 @@ class UserView extends events.EventTarget {
this._view = new UserEditView(ctx); this._view = new UserEditView(ctx);
this._view.addEventListener('submit', e => { this._view.addEventListener('submit', e => {
this.dispatchEvent( this.dispatchEvent(
new CustomEvent('change', {detail: e.detail})); new CustomEvent('submit', {detail: e.detail}));
}); });
} else if (ctx.section == 'delete') { } else if (ctx.section == 'delete') {
this._view = new UserDeleteView(ctx); this._view = new UserDeleteView(ctx);