mirror of
https://github.com/flarum/core.git
synced 2025-07-31 13:40:20 +02:00
Implement "renamed" posts
Record when the discussion was renamed, from what, and by whom. Information is stored in the `content` field as a serialised JSON object because proper polymorphism will be too difficult with Ember Data and especially when extensions try to add new post types.
This commit is contained in:
48
ember/app/components/discussion/post-renamed.js
Normal file
48
ember/app/components/discussion/post-renamed.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
import FadeIn from 'flarum/mixins/fade-in';
|
||||
import HasItemLists from 'flarum/mixins/has-item-lists';
|
||||
|
||||
var precompileTemplate = Ember.Handlebars.compile;
|
||||
|
||||
/**
|
||||
Component for a `renamed`-typed post.
|
||||
*/
|
||||
export default Ember.Component.extend(FadeIn, HasItemLists, {
|
||||
layoutName: 'components/discussion/post-renamed',
|
||||
tagName: 'article',
|
||||
classNames: ['post', 'post-renamed', 'post-activity'],
|
||||
itemLists: ['controls'],
|
||||
|
||||
// The stream-content component instansiates this component and sets the
|
||||
// `content` property to the content of the item in the post-stream object.
|
||||
// This happens to be our post model!
|
||||
post: Ember.computed.alias('content'),
|
||||
|
||||
decodedContent: Ember.computed('post.content', function() {
|
||||
return JSON.parse(this.get('post.content'));
|
||||
}),
|
||||
oldTitle: Ember.computed.alias('decodedContent.0'),
|
||||
newTitle: Ember.computed.alias('decodedContent.1'),
|
||||
|
||||
populateControls: function(items) {
|
||||
this.addActionItem(items, 'delete', 'Delete', 'times', 'post.canDelete');
|
||||
},
|
||||
|
||||
actions: {
|
||||
// In the template, we render the "controls" dropdown with the contents of
|
||||
// the `renderControls` property. This way, when a post is initially
|
||||
// rendered, it doesn't have to go to the trouble of rendering the
|
||||
// controls right away, which speeds things up. When the dropdown button
|
||||
// is clicked, this will fill in the actual controls.
|
||||
renderControls: function() {
|
||||
this.set('renderControls', this.get('controls'));
|
||||
},
|
||||
|
||||
delete: function() {
|
||||
var post = this.get('post');
|
||||
post.destroyRecord();
|
||||
this.sendAction('postRemoved', post);
|
||||
}
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user