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:
parent
73a8542220
commit
d8d4654849
|
@ -30,7 +30,7 @@ class CommentsController {
|
|||
canViewPosts: api.hasPrivilege('posts:view'),
|
||||
});
|
||||
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('delete', e => this._evtDelete(e));
|
||||
return view;
|
||||
|
@ -38,7 +38,7 @@ class CommentsController {
|
|||
});
|
||||
}
|
||||
|
||||
_evtChange(e) {
|
||||
_evtUpdate(e) {
|
||||
// TODO: disable form
|
||||
e.detail.comment.text = e.detail.text;
|
||||
e.detail.comment.save()
|
||||
|
|
|
@ -46,6 +46,7 @@ class PostController {
|
|||
canCreateComments: api.hasPrivilege('comments:create'),
|
||||
parameters: parameters,
|
||||
});
|
||||
|
||||
if (this._view.sidebarControl) {
|
||||
this._view.sidebarControl.addEventListener(
|
||||
'favorite', e => this._evtFavoritePost(e));
|
||||
|
@ -58,21 +59,23 @@ class PostController {
|
|||
this._view.sidebarControl.addEventListener(
|
||||
'change', e => this._evtPostChange(e));
|
||||
this._view.sidebarControl.addEventListener(
|
||||
'submit', e => this._evtPostEdit(e));
|
||||
'submit', e => this._evtUpdatePost(e));
|
||||
this._view.sidebarControl.addEventListener(
|
||||
'feature', e => this._evtPostFeature(e));
|
||||
'feature', e => this._evtFeaturePost(e));
|
||||
this._view.sidebarControl.addEventListener(
|
||||
'delete', e => this._evtPostDelete(e));
|
||||
'delete', e => this._evtDeletePost(e));
|
||||
}
|
||||
|
||||
if (this._view.commentFormControl) {
|
||||
this._view.commentFormControl.addEventListener(
|
||||
'change', e => this._evtCommentChange(e));
|
||||
this._view.commentFormControl.addEventListener(
|
||||
'submit', e => this._evtCreateComment(e));
|
||||
}
|
||||
|
||||
if (this._view.commentListControl) {
|
||||
this._view.commentListControl.addEventListener(
|
||||
'change', e => this._evtUpdateComment(e));
|
||||
'submit', e => this._evtUpdateComment(e));
|
||||
this._view.commentListControl.addEventListener(
|
||||
'score', e => this._evtScoreComment(e));
|
||||
this._view.commentListControl.addEventListener(
|
||||
|
@ -104,7 +107,7 @@ class PostController {
|
|||
settings.save(browsingSettings);
|
||||
}
|
||||
|
||||
_evtPostFeature(e) {
|
||||
_evtFeaturePost(e) {
|
||||
this._view.sidebarControl.disableForm();
|
||||
this._view.sidebarControl.clearMessages();
|
||||
e.detail.post.feature()
|
||||
|
@ -117,7 +120,7 @@ class PostController {
|
|||
});
|
||||
}
|
||||
|
||||
_evtPostDelete(e) {
|
||||
_evtDeletePost(e) {
|
||||
this._view.sidebarControl.disableForm();
|
||||
this._view.sidebarControl.clearMessages();
|
||||
e.detail.post.delete()
|
||||
|
@ -131,7 +134,7 @@ class PostController {
|
|||
});
|
||||
}
|
||||
|
||||
_evtPostEdit(e) {
|
||||
_evtUpdatePost(e) {
|
||||
this._view.sidebarControl.disableForm();
|
||||
this._view.sidebarControl.clearMessages();
|
||||
const post = e.detail.post;
|
||||
|
|
|
@ -11,10 +11,10 @@ class SettingsController {
|
|||
this._view = new SettingsView({
|
||||
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();
|
||||
settings.save(e.detail);
|
||||
this._view.showSuccess('Settings saved.');
|
||||
|
|
|
@ -36,7 +36,7 @@ class TagController {
|
|||
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('delete', e => this._evtDelete(e));
|
||||
}, errorMessage => {
|
||||
|
@ -51,7 +51,7 @@ class TagController {
|
|||
}
|
||||
}
|
||||
|
||||
_evtChange(e) {
|
||||
_evtUpdate(e) {
|
||||
this._view.clearMessages();
|
||||
this._view.disableForm();
|
||||
if (e.detail.names !== undefined) {
|
||||
|
|
|
@ -51,7 +51,7 @@ class UserController {
|
|||
canDelete: api.hasPrivilege(`users:delete:${infix}`),
|
||||
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));
|
||||
}, errorMessage => {
|
||||
this._view = new EmptyView();
|
||||
|
@ -66,7 +66,7 @@ class UserController {
|
|||
}
|
||||
}
|
||||
|
||||
_evtChange(e) {
|
||||
_evtUpdate(e) {
|
||||
this._view.clearMessages();
|
||||
this._view.disableForm();
|
||||
const isLoggedIn = api.isLoggedIn(e.detail.user);
|
||||
|
|
|
@ -39,7 +39,7 @@ class CommentControl extends events.EventTarget {
|
|||
this._hostNode.querySelector('.comment-form-container'),
|
||||
this._comment,
|
||||
true);
|
||||
events.proxyEvent(this._formControl, this, 'submit', 'change');
|
||||
events.proxyEvent(this._formControl, this, 'submit');
|
||||
|
||||
this._installScore();
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class CommentListControl extends events.EventTarget {
|
|||
const commentListItemNode = document.createElement('li');
|
||||
const commentControl = new CommentControl(
|
||||
commentListItemNode, comment);
|
||||
events.proxyEvent(commentControl, this, 'change');
|
||||
events.proxyEvent(commentControl, this, 'submit');
|
||||
events.proxyEvent(commentControl, this, 'score');
|
||||
events.proxyEvent(commentControl, this, 'delete');
|
||||
this._commentIdToNode[comment.id] = commentListItemNode;
|
||||
|
|
|
@ -19,7 +19,7 @@ class CommentsPageView extends events.EventTarget {
|
|||
`.comments-container[data-for="${post.id}"]`),
|
||||
post.comments,
|
||||
true);
|
||||
events.proxyEvent(commentListControl, this, 'change');
|
||||
events.proxyEvent(commentListControl, this, 'submit');
|
||||
events.proxyEvent(commentListControl, this, 'score');
|
||||
events.proxyEvent(commentListControl, this, 'delete');
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ class PostsHeaderView {
|
|||
}
|
||||
});
|
||||
|
||||
for (let safetyButton of this._safetyButtonNodes) {
|
||||
safetyButton.addEventListener(
|
||||
for (let safetyButtonNode of this._safetyButtonNodes) {
|
||||
safetyButtonNode.addEventListener(
|
||||
'click', e => this._evtSafetyButtonClick(e));
|
||||
}
|
||||
this._searchFormNode.addEventListener(
|
||||
|
|
|
@ -28,7 +28,7 @@ class SettingsView extends events.EventTarget {
|
|||
|
||||
_evtSubmit(e) {
|
||||
e.preventDefault();
|
||||
this.dispatchEvent(new CustomEvent('change', {
|
||||
this.dispatchEvent(new CustomEvent('submit', {
|
||||
detail: {
|
||||
upscaleSmallPosts: this._find('upscale-small-posts').checked,
|
||||
endlessScroll: this._find('endless-scroll').checked,
|
||||
|
|
|
@ -35,7 +35,7 @@ class TagView extends events.EventTarget {
|
|||
this._view = new TagEditView(ctx);
|
||||
this._view.addEventListener('submit', e => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent('change', {detail: e.detail}));
|
||||
new CustomEvent('submit', {detail: e.detail}));
|
||||
});
|
||||
} else if (ctx.section === 'merge') {
|
||||
this._view = new TagMergeView(ctx);
|
||||
|
|
|
@ -36,7 +36,7 @@ class UserView extends events.EventTarget {
|
|||
this._view = new UserEditView(ctx);
|
||||
this._view.addEventListener('submit', e => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent('change', {detail: e.detail}));
|
||||
new CustomEvent('submit', {detail: e.detail}));
|
||||
});
|
||||
} else if (ctx.section == 'delete') {
|
||||
this._view = new UserDeleteView(ctx);
|
||||
|
|
Loading…
Reference in New Issue