Implement discussion deletion

This commit is contained in:
Toby Zerner 2015-02-12 14:35:40 +10:30
parent b97887b612
commit 7001c83fb3
4 changed files with 26 additions and 4 deletions

View File

@ -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);
}
}
}
});

View File

@ -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);
}
}
});

View File

@ -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));
}
}
});

View File

@ -32,7 +32,8 @@
discussion=discussion
searchQuery=index.searchQuery
terminalPostType=index.terminalPostType
countType=index.countType}}
countType=index.countType
discussionRemoved="discussionRemoved"}}
{{/each}}
</ul>