1
0
mirror of https://github.com/flarum/core.git synced 2025-07-20 08:11:27 +02:00

Massive JavaScript cleanup

- Use JSX for templates
- Docblock/comment everything
- Mostly passes ESLint (still some work to do)
- Lots of renaming, refactoring, etc.

CSS hasn't been updated yet.
This commit is contained in:
Toby Zerner
2015-07-15 14:00:11 +09:30
parent 4480e0a83f
commit ab6c03c0cc
220 changed files with 9785 additions and 5919 deletions

View File

@@ -0,0 +1,140 @@
import EditPostComposer from 'flarum/components/EditPostComposer';
import Button from 'flarum/components/Button';
import Separator from 'flarum/components/Separator';
import ItemList from 'flarum/utils/ItemList';
/**
* The `PostControls` utility constructs a list of buttons for a post which
* perform actions on it.
*/
export default {
/**
* Get a list of controls for a post.
*
* @param {Post} post
* @param {*} context The parent component under which the controls menu will
* be displayed.
* @return {ItemList}
* @public
*/
controls(post, context) {
const items = new ItemList();
['user', 'moderation', 'destructive'].forEach(section => {
const controls = this[section + 'Controls'](post, context).toArray();
if (controls.length) {
items.add(section, controls);
items.add(section + 'Separator', Separator.component());
}
});
return items;
},
/**
* Get controls for a post pertaining to the current user (e.g. report).
*
* @param {Post} post
* @param {*} context The parent component under which the controls menu will
* be displayed.
* @return {ItemList}
* @protected
*/
userControls() {
return new ItemList();
},
/**
* Get controls for a post pertaining to moderation (e.g. edit).
*
* @param {Post} post
* @param {*} context The parent component under which the controls menu will
* be displayed.
* @return {ItemList}
* @protected
*/
moderationControls(post) {
const items = new ItemList();
if (post.contentType() === 'comment' && post.canEdit()) {
if (post.isHidden()) {
items.add('restore', Button.component({
icon: 'reply',
children: 'Restore',
onclick: this.restoreAction.bind(post)
}));
} else {
items.add('edit', Button.component({
icon: 'pencil',
children: 'Edit',
onclick: this.editAction.bind(post)
}));
}
}
return items;
},
/**
* Get controls for a post that are destructive (e.g. delete).
*
* @param {Post} post
* @param {*} context The parent component under which the controls menu will
* be displayed.
* @return {ItemList}
* @protected
*/
destructiveControls(post) {
const items = new ItemList();
if (post.number() !== 1) {
if (post.contentType() === 'comment' && !post.isHidden() && post.canEdit()) {
items.add('hide', Button.component({
icon: 'times',
children: 'Delete',
onclick: this.hideAction.bind(post)
}));
} else if ((post.contentType() !== 'comment' || post.isHidden()) && post.canDelete()) {
items.add('delete', Button.component({
icon: 'times',
children: 'Delete Forever',
onclick: this.deleteAction.bind(post)
}));
}
}
return items;
},
/**
* Open the composer to edit a post.
*/
editAction() {
app.composer.load(new EditPostComposer({ post: this }));
app.composer.show();
},
/**
* Hide a post.
*/
hideAction() {
this.save({ isHidden: true });
this.pushAttributes({ hideTime: new Date(), hideUser: app.session.user });
},
/**
* Restore a post.
*/
restoreAction() {
this.save({ isHidden: false });
this.pushAttributes({ hideTime: null, hideUser: null });
},
/**
* Delete a post.
*/
deleteAction() {
this.delete();
this.discussion().removePost(this.id());
}
};