Skip to content

Commit 2bd5471

Browse files
committed
Implement discussion deletion
1 parent 36787bc commit 2bd5471

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

ember/app/components/index/discussion-listing.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default Ember.Component.extend(FadeIn, HasItemLists, {
5555
}),
5656

5757
populateControls: function(items) {
58-
58+
this.addActionItem(items, 'delete', 'Delete', 'times', 'discussion.canDelete');
5959
},
6060

6161
populateInfo: function(items) {
@@ -78,10 +78,19 @@ export default Ember.Component.extend(FadeIn, HasItemLists, {
7878
},
7979

8080
markAsRead: function() {
81-
if (this.get('discussion.isUnread')) {
81+
var discussion = this.get('discussion');
82+
if (discussion.get('isUnread')) {
8283
discussion.set('readNumber', discussion.get('lastPostNumber'));
8384
discussion.save();
8485
}
86+
},
87+
88+
delete: function() {
89+
if (confirm('Are you sure you want to delete this discussion?')) {
90+
var discussion = this.get('discussion.content');
91+
discussion.destroyRecord();
92+
this.sendAction('discussionRemoved', discussion);
93+
}
8594
}
8695
}
8796
});

ember/app/controllers/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export default Ember.Controller.extend(UseComposer, Paneable, {
5454
}
5555
});
5656
});
57+
},
58+
59+
discussionRemoved: function(discussion) {
60+
if (this.get('controllers.discussion.model') === discussion) {
61+
this.transitionToRoute('index');
62+
}
63+
this.get('index').send('discussionRemoved', discussion);
5764
}
5865
}
5966
});

ember/app/controllers/index/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ export default Ember.Controller.extend({
104104
controller.set('meta', results.get('meta'));
105105
controller.set('resultsLoading', false);
106106
});
107-
}
107+
},
108+
109+
discussionRemoved: function(discussion) {
110+
var model = this.get('model');
111+
model.removeObject(model.findBy('content', discussion));
112+
}
108113
}
109114
});

ember/app/templates/index.hbs

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
discussion=discussion
3333
searchQuery=index.searchQuery
3434
terminalPostType=index.terminalPostType
35-
countType=index.countType}}
35+
countType=index.countType
36+
discussionRemoved="discussionRemoved"}}
3637
{{/each}}
3738
</ul>
3839

0 commit comments

Comments
 (0)