diff --git a/framework/core/ember/app/components/index/discussion-listing.js b/framework/core/ember/app/components/index/discussion-listing.js index 438c6177b..8ac83f2ec 100755 --- a/framework/core/ember/app/components/index/discussion-listing.js +++ b/framework/core/ember/app/components/index/discussion-listing.js @@ -55,7 +55,7 @@ export default Ember.Component.extend(FadeIn, HasItemLists, { }), populateControls: function(items) { - + this.addActionItem(items, 'delete', 'Delete', 'times', 'discussion.canDelete'); }, populateInfo: function(items) { @@ -78,10 +78,19 @@ export default Ember.Component.extend(FadeIn, HasItemLists, { }, markAsRead: function() { - if (this.get('discussion.isUnread')) { + var discussion = this.get('discussion'); + if (discussion.get('isUnread')) { discussion.set('readNumber', discussion.get('lastPostNumber')); discussion.save(); } + }, + + delete: function() { + if (confirm('Are you sure you want to delete this discussion?')) { + var discussion = this.get('discussion.content'); + discussion.destroyRecord(); + this.sendAction('discussionRemoved', discussion); + } } } }); diff --git a/framework/core/ember/app/controllers/index.js b/framework/core/ember/app/controllers/index.js index 959ca8662..2fd308603 100644 --- a/framework/core/ember/app/controllers/index.js +++ b/framework/core/ember/app/controllers/index.js @@ -54,6 +54,13 @@ export default Ember.Controller.extend(UseComposer, Paneable, { } }); }); + }, + + discussionRemoved: function(discussion) { + if (this.get('controllers.discussion.model') === discussion) { + this.transitionToRoute('index'); + } + this.get('index').send('discussionRemoved', discussion); } } }); diff --git a/framework/core/ember/app/controllers/index/index.js b/framework/core/ember/app/controllers/index/index.js index 56a6227fe..6c09a2055 100644 --- a/framework/core/ember/app/controllers/index/index.js +++ b/framework/core/ember/app/controllers/index/index.js @@ -104,6 +104,11 @@ export default Ember.Controller.extend({ controller.set('meta', results.get('meta')); controller.set('resultsLoading', false); }); - } + }, + + discussionRemoved: function(discussion) { + var model = this.get('model'); + model.removeObject(model.findBy('content', discussion)); + } } }); diff --git a/framework/core/ember/app/templates/index.hbs b/framework/core/ember/app/templates/index.hbs index 4c7389875..d703f65c4 100644 --- a/framework/core/ember/app/templates/index.hbs +++ b/framework/core/ember/app/templates/index.hbs @@ -32,7 +32,8 @@ discussion=discussion searchQuery=index.searchQuery terminalPostType=index.terminalPostType - countType=index.countType}} + countType=index.countType + discussionRemoved="discussionRemoved"}} {{/each}}