diff --git a/framework/core/ember/app/components/discussions/post-comment.js b/framework/core/ember/app/components/discussions/post-comment.js
new file mode 100644
index 000000000..b6f0b3c7f
--- /dev/null
+++ b/framework/core/ember/app/components/discussions/post-comment.js
@@ -0,0 +1,149 @@
+import Ember from 'ember';
+
+import TaggedArray from '../../utils/tagged-array';
+import ActionButton from '../ui/controls/action-button';
+import ComposerEdit from '../discussions/composer-edit';
+import AlertMessage from '../alert-message';
+import humanTime from '../../utils/human-time';
+
+var precompileTemplate = Ember.Handlebars.compile;
+
+// @todo extend a base post class
+export default Ember.Component.extend({
+ tagName: 'article',
+ layoutName: 'components/discussions/post-comment',
+
+ editDescription: function() {
+ return 'Edited by '+this.get('post.editUser.username')+' '+humanTime(this.get('post.editTime'));
+ }.property('post.editTime', 'post.editUser'),
+
+ post: Ember.computed.alias('content'),
+
+ classNames: ['post'],
+ classNameBindings: ['post.deleted', 'post.edited'],
+
+ didInsertElement: function() {
+ var $this = this.$();
+ $this.css({opacity: 0});
+
+ setTimeout(function() {
+ $this.animate({opacity: 1}, 'fast');
+ }, 100);
+
+ this.set('controls', TaggedArray.create());
+ this.trigger('populateControls', this.get('controls'));
+
+ this.set('header', TaggedArray.create());
+ this.trigger('populateHeader', this.get('header'));
+ },
+
+ populateControlsDefault: function(controls) {
+ if (this.get('post.deleted')) {
+ this.addControl('restore', 'Restore', 'reply', 'canEdit');
+ this.addControl('delete', 'Delete', 'times', 'canDelete');
+ } else {
+ this.addControl('edit', 'Edit', 'pencil', 'canEdit');
+ this.addControl('hide', 'Delete', 'times', 'canEdit');
+ }
+ }.on('populateControls'),
+
+ populateHeaderDefault: function(header) {
+ header.pushObjectWithTag(Ember.Component.create({
+ tagName: 'h3',
+ classNames: ['user'],
+ layout: precompileTemplate('{{#link-to "user" post.user}}{{user-avatar post.user}} {{post.user.username}}{{/link-to}}'),
+ post: this.get('post')
+ }));
+
+ header.pushObjectWithTag(Ember.Component.create({
+ tagName: 'li',
+ layout: precompileTemplate('{{#link-to "discussion" post.discussion (query-params start=post.number) class="time"}}{{human-time post.time}}{{/link-to}}'),
+ post: this.get('post')
+ }));
+
+ header.pushObjectWithTag(Ember.Component.extend({
+ tagName: 'li',
+ hideItem: Ember.computed.not('parent.post.isEdited'),
+ layout: precompileTemplate('{{fa-icon "pencil"}}'),
+ parent: this,
+ didInsertElement: function() {
+ this.$('.post-edited').tooltip();
+ },
+ updateTooltip: function() {
+ Ember.run.scheduleOnce('afterRender', this, function() {
+ this.$('.post-edited').tooltip('fixTitle');
+ });
+ }.observes('parent.editDescription')
+ }).create());
+ }.on('populateHeader'),
+
+ addControl: function(tag, label, icon, permissionAttribute) {
+ if (permissionAttribute && !this.get('post').get(permissionAttribute)) {
+ return;
+ }
+
+ var self = this;
+ var action = function() {
+ self.get('controller').send(tag);
+ };
+
+ var item = ActionButton.create({label: label, icon: icon, action: action});
+ this.get('controls').pushObjectWithTag(item, tag);
+ },
+
+ savePost: function(post, data) {
+ var controller = this;
+ var composer = this.get('composer');
+
+ composer.set('content.loading', true);
+ this.get('alerts').send('clearAlerts');
+
+ post.set('content', data.content);
+
+ return post.save().then(function(post) {
+ composer.send('hide');
+ },
+ function(reason) {
+ var errors = reason.errors;
+ for (var i in reason.errors) {
+ var message = AlertMessage.create({
+ type: 'warning',
+ message: reason.errors[i]
+ });
+ controller.get('alerts').send('alert', message);
+ }
+ })
+ .finally(function() {
+ composer.set('content.loading', false);
+ });
+ },
+
+ actions: {
+ renderControls: function() {
+ this.set('renderControls', this.get('controls'));
+ // if (!this.get('controls.length')) {
+ // this.get('controls').pushObject(Ember.Component.create({tagName: 'li', classNames: ['dropdown-header'], layout: Ember.Handlebars.compile('No actions available')}));
+ // }
+ },
+
+ edit: function() {
+ var component = this;
+ var post = this.get('post');
+ var composer = this.get('composer');
+
+ // If the composer is already set up for this post, then we
+ // don't need to change its content - we can just show it.
+ if (!(composer.get('content') instanceof ComposerEdit) || composer.get('content.post') !== post) {
+ composer.switchContent(ComposerEdit.create({
+ user: post.get('user'),
+ post: post,
+ submit: function(data) {
+ component.savePost(post, data);
+ }
+ }));
+ }
+
+ composer.send('show');
+ }
+ }
+});
diff --git a/framework/core/ember/app/components/discussions/post-content-comment.js b/framework/core/ember/app/components/discussions/post-content-comment.js
deleted file mode 100644
index 7ed7d64b6..000000000
--- a/framework/core/ember/app/components/discussions/post-content-comment.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import Ember from 'ember';
-
-export default Ember.Component.extend({
- tagName: 'article',
- layoutName: 'components/discussions/post-content-comment',
-
- editDescription: ''
-});
diff --git a/framework/core/ember/app/components/discussions/post-wrapper.js b/framework/core/ember/app/components/discussions/post-wrapper.js
deleted file mode 100644
index fb8e3cde7..000000000
--- a/framework/core/ember/app/components/discussions/post-wrapper.js
+++ /dev/null
@@ -1,62 +0,0 @@
-import Ember from 'ember';
-
-// import TaggedArray from '../../utils/tagged-array';
-// import ActionButton from '../ui/controls/action-button';
-
-export default Ember.Component.extend({
- tagName: 'article',
- layoutName: 'components/discussions/post-wrapper',
-
- // controls: null,
-
- post: Ember.computed.alias('content'),
-
- contentComponent: function() {
- return 'discussions/post-content-'+this.get('post.type');
- }.property('post.type'),
-
- classNames: ['post'],
- classNameBindings: ['post.deleted', 'post.edited'],
-
- // construct: function() {
- // // this.set('controls', Menu.create());
-
- // // var post = this.get('post');
-
- // // if (post.get('deleted')) {
- // // this.addControl('restore', 'Restore', 'reply', 'canEdit');
- // // this.addControl('delete', 'Delete', 'times', 'canDelete');
- // // } else {
- // // if (post.get('type') == 'comment') {
- // // this.addControl('edit', 'Edit', 'pencil', 'canEdit');
- // // this.addControl('hide', 'Delete', 'times', 'canEdit');
- // // } else {
- // // this.addControl('delete', 'Delete', 'times', 'canDelete');
- // // }
- // // }
- // }.on('init'),
-
- didInsertElement: function() {
- var $this = this.$();
- $this.css({opacity: 0});
-
- setTimeout(function() {
- $this.animate({opacity: 1}, 'fast');
- }, 100);
- },
-
- // addControl: function(tag, title, icon, permissionAttribute) {
- // if (permissionAttribute && ! this.get('post').get(permissionAttribute)) {
- // return;
- // }
-
- // var self = this;
- // var action = function(post) {
- // self.get('controller').send(actionName, post);
- // };
-
- // var item = MenuItem.extend({title: title, icon: icon, action: action});
- // this.get('controls').addItem(tag, item);
- // }
-
-});
diff --git a/framework/core/ember/app/components/ui/controls/item-list.js b/framework/core/ember/app/components/ui/controls/item-list.js
index 367d3de7b..e50f9fbc4 100644
--- a/framework/core/ember/app/components/ui/controls/item-list.js
+++ b/framework/core/ember/app/components/ui/controls/item-list.js
@@ -12,7 +12,7 @@ export default Ember.Component.extend({
}
var listItems = [];
this.get('items').forEach(function(item) {
- if (item.tagName !== 'li') {
+ if (item.get('tagName') !== 'li') {
item = ComponentItem.extend({component: item});
}
listItems.push(item);
diff --git a/framework/core/ember/app/models/post-stream.js b/framework/core/ember/app/models/post-stream.js
index 7c7233072..4478c507d 100644
--- a/framework/core/ember/app/models/post-stream.js
+++ b/framework/core/ember/app/models/post-stream.js
@@ -168,11 +168,17 @@ export default Ember.ArrayProxy.extend(Ember.Evented, {
},
makeItem: function(indexStart, indexEnd, post) {
- return Ember.Object.create({
+ var item = Ember.Object.create({
indexStart: indexStart,
- indexEnd: indexEnd,
- content: post
+ indexEnd: indexEnd
});
+ if (post) {
+ item.setProperties({
+ content: post,
+ component: 'discussions/post-'+post.get('type')
+ });
+ }
+ return item;
},
findNearestTo: function(index, property) {
diff --git a/framework/core/ember/app/templates/components/discussions/post-comment.hbs b/framework/core/ember/app/templates/components/discussions/post-comment.hbs
new file mode 100644
index 000000000..e5492ff40
--- /dev/null
+++ b/framework/core/ember/app/templates/components/discussions/post-comment.hbs
@@ -0,0 +1,24 @@
+{{#if controls}}
+ {{ui/controls/dropdown-button
+ items=renderControls
+ class="contextual-controls"
+ buttonClass="btn btn-default btn-icon btn-sm btn-naked"
+ buttonClick="renderControls"
+ menuClass="pull-right"}}
+{{/if}}
+
+{{#if post.isDeleted}}
+ {{fa-icon "trash-o" class="post-icon"}}
+{{/if}}
+
+