Rename and delete discussion controls

This commit is contained in:
Toby Zerner 2015-02-12 15:18:17 +10:30
parent 6138825db6
commit 87159bd9a0
3 changed files with 30 additions and 1 deletions

View File

@ -102,6 +102,19 @@ export default Ember.Controller.extend(Ember.Evented, UseComposerMixin, {
postRemoved: function(post) {
this.get('stream').removePost(post);
},
rename: function(title) {
var discussion = this.get('model');
discussion.set('title', title);
discussion.save();
},
delete: function() {
var controller = this;
this.get('model').destroyRecord().then(function() {
controller.transitionToRoute('index');
});
}
}
});

View File

@ -1,6 +1,6 @@
<header class="hero discussion-hero">
<div class="container">
<h2>{{model.title}}</h2>
<h2 class="discussion-title">{{model.title}}</h2>
</div>
</header>

View File

@ -66,5 +66,21 @@ export default Ember.View.extend(HasItemLists, {
view.get('streamContent').send('goToLast');
view.get('controller').send('reply');
});
this.addSeparatorItem(items);
this.addActionItem(items, 'rename', 'Rename', 'pencil', 'discussion.canEdit', function() {
var discussion = view.get('controller.model');
var title = prompt('Enter a new title for this discussion:', discussion.get('title'));
if (title) {
view.get('controller').send('rename', title);
}
});
this.addActionItem(items, 'delete', 'Delete', 'times', 'discussion.canDelete', function() {
if (confirm('Are you sure you want to delete this discussion?')) {
view.get('controller').send('delete');
}
});
}
});