2014-12-20 14:26:46 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
import HasItemLists from 'flarum/mixins/has-item-lists';
|
|
|
|
import DropdownSplit from 'flarum/components/ui/dropdown-split';
|
|
|
|
import StreamScrubber from 'flarum/components/discussion/stream-scrubber';
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-01-21 11:59:00 +08:00
|
|
|
var $ = Ember.$;
|
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
export default Ember.View.extend(HasItemLists, {
|
|
|
|
itemLists: ['sidebar'],
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-12 12:47:20 +08:00
|
|
|
discussion: Ember.computed.alias('controller.model'),
|
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
didInsertElement: function() {
|
|
|
|
this.get('controller').on('loaded', this, this.loaded);
|
|
|
|
this.get('controller').on('startWasChanged', this, this.startWasChanged);
|
|
|
|
},
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
willDestroyElement: function() {
|
|
|
|
this.get('controller').off('loaded', this, this.loaded);
|
|
|
|
this.get('controller').off('startWasChanged', this, this.startWasChanged);
|
|
|
|
},
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
// When the controller has finished loading, we want to scroll down to the
|
|
|
|
// appropriate post instantly (without animation).
|
|
|
|
loaded: function() {
|
|
|
|
this.get('streamContent').send('goToNumber', this.get('controller.start'), true);
|
|
|
|
},
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
// When the start position of the discussion changes, we want to scroll
|
|
|
|
// down to the appropriate post.
|
|
|
|
startWasChanged: function(start) {
|
|
|
|
this.get('streamContent').send('goToNumber', start);
|
|
|
|
},
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// OBSERVERS
|
|
|
|
// ------------------------------------------------------------------------
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
// Whenever the model's title changes, we want to update that document's
|
|
|
|
// title the reflect the new title.
|
|
|
|
updateTitle: Ember.observer('controller.model.title', function() {
|
|
|
|
this.set('controller.controllers.application.pageTitle', this.get('controller.model.title'));
|
|
|
|
}),
|
2015-01-30 09:42:30 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// LISTENERS
|
|
|
|
// ------------------------------------------------------------------------
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
populateSidebar: function(items) {
|
2015-02-26 07:13:53 +08:00
|
|
|
items.pushObjectWithTag(DropdownSplit.extend({
|
2015-02-10 15:35:40 +08:00
|
|
|
items: this.populateItemList('controls'),
|
|
|
|
icon: 'reply',
|
|
|
|
buttonClass: 'btn-primary'
|
|
|
|
}), 'controls');
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-26 07:13:53 +08:00
|
|
|
items.pushObjectWithTag(StreamScrubber.extend({
|
2015-02-10 15:35:40 +08:00
|
|
|
streamContent: this.get('streamContent')
|
|
|
|
}), 'scrubber');
|
|
|
|
},
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
populateControls: function(items) {
|
|
|
|
var view = this;
|
2015-02-12 12:47:20 +08:00
|
|
|
|
|
|
|
this.addActionItem(items, 'reply', 'Reply', 'reply', 'discussion.canReply', function() {
|
2015-02-10 15:35:40 +08:00
|
|
|
view.get('streamContent').send('goToLast');
|
|
|
|
view.get('controller').send('reply');
|
|
|
|
});
|
2015-02-12 12:48:17 +08:00
|
|
|
|
|
|
|
this.addSeparatorItem(items);
|
|
|
|
|
|
|
|
this.addActionItem(items, 'rename', 'Rename', 'pencil', 'discussion.canEdit', function() {
|
|
|
|
var discussion = view.get('controller.model');
|
2015-02-13 07:53:38 +08:00
|
|
|
var currentTitle = discussion.get('title');
|
|
|
|
var title = prompt('Enter a new title for this discussion:', currentTitle);
|
|
|
|
if (title && title !== currentTitle) {
|
2015-02-12 12:48:17 +08:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
2015-02-10 15:35:40 +08:00
|
|
|
}
|
2014-12-20 14:26:46 +08:00
|
|
|
});
|