2015-02-10 15:35:40 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
import humanTime from 'flarum/utils/human-time';
|
|
|
|
|
|
|
|
var precompileTemplate = Ember.Handlebars.compile;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Component for the edited pencil icon in a post header. Shows a tooltip on
|
|
|
|
hover which details who edited the post and when.
|
|
|
|
*/
|
|
|
|
export default Ember.Component.extend({
|
2015-02-10 17:25:22 +08:00
|
|
|
tagName: 'li',
|
2015-02-10 15:35:40 +08:00
|
|
|
classNames: ['post-edited'],
|
2015-02-10 17:25:22 +08:00
|
|
|
classNameBindings: ['hidden'],
|
2015-02-10 15:35:40 +08:00
|
|
|
attributeBindings: ['title'],
|
|
|
|
layout: precompileTemplate('{{fa-icon "pencil"}}'),
|
|
|
|
|
|
|
|
title: Ember.computed('post.editTime', 'post.editUser', function() {
|
|
|
|
return 'Edited by '+this.get('post.editUser.username')+' '+humanTime(this.get('post.editTime'));
|
|
|
|
}),
|
|
|
|
|
|
|
|
// In the context of an item list, this item will be hidden if the post
|
|
|
|
// hasn't been edited, or if it's been hidden.
|
2015-02-10 17:25:22 +08:00
|
|
|
hidden: Ember.computed('post.isEdited', 'post.isHidden', function() {
|
2015-02-10 15:35:40 +08:00
|
|
|
return !this.get('post.isEdited') || this.get('post.isHidden');
|
|
|
|
}),
|
|
|
|
|
|
|
|
didInsertElement: function() {
|
|
|
|
this.$().tooltip();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Whenever the title changes, we need to tell the tooltip to update to
|
|
|
|
// reflect the new value.
|
|
|
|
updateTooltip: Ember.observer('title', function() {
|
|
|
|
Ember.run.scheduleOnce('afterRender', this, function() {
|
|
|
|
this.$().tooltip('fixTitle');
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|