Skip to content

Commit

Permalink
Rename and delete discussion controls
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Feb 12, 2015
1 parent 6138825 commit 87159bd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
13 changes: 13 additions & 0 deletions ember/app/controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
}
});
2 changes: 1 addition & 1 deletion ember/app/templates/discussion.hbs
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
16 changes: 16 additions & 0 deletions ember/app/views/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
}
});

0 comments on commit 87159bd

Please sign in to comment.