Skip to content

Commit

Permalink
Implement discussion deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Feb 12, 2015
1 parent 36787bc commit 2bd5471
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
13 changes: 11 additions & 2 deletions ember/app/components/index/discussion-listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
});
7 changes: 7 additions & 0 deletions ember/app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
7 changes: 6 additions & 1 deletion ember/app/controllers/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
});
3 changes: 2 additions & 1 deletion ember/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
discussion=discussion
searchQuery=index.searchQuery
terminalPostType=index.terminalPostType
countType=index.countType}}
countType=index.countType
discussionRemoved="discussionRemoved"}}
{{/each}}
</ul>

Expand Down

0 comments on commit 2bd5471

Please sign in to comment.