2014-12-20 14:26:46 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-01-03 19:21:47 +08:00
|
|
|
import TaggedArray from '../utils/tagged-array';
|
|
|
|
import ActionButton from '../components/ui/controls/action-button';
|
|
|
|
import DropdownSplit from '../components/ui/controls/dropdown-split';
|
2015-01-16 14:56:10 +08:00
|
|
|
import StreamScrubber from '../components/discussions/stream-scrubber';
|
|
|
|
|
2015-01-21 11:59:00 +08:00
|
|
|
var $ = Ember.$;
|
|
|
|
|
2015-01-16 14:56:10 +08:00
|
|
|
export default Ember.View.extend(Ember.Evented, {
|
|
|
|
|
|
|
|
sidebarItems: null,
|
|
|
|
|
|
|
|
didInsertElement: function() {
|
|
|
|
// Create and populate an array of items to be rendered in the sidebar.
|
|
|
|
var sidebarItems = TaggedArray.create();
|
|
|
|
this.trigger('populateSidebar', sidebarItems);
|
|
|
|
this.set('sidebarItems', sidebarItems);
|
|
|
|
|
2015-02-06 08:00:38 +08:00
|
|
|
this.get('controller').on('loaded', this, this.loaded);
|
|
|
|
this.get('controller').on('startWasChanged', this, this.startWasChanged);
|
2015-01-16 14:56:10 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement: function() {
|
2015-02-06 08:00:38 +08:00
|
|
|
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-06 08:00:38 +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-06 08:00:38 +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-30 09:42:30 +08:00
|
|
|
},
|
|
|
|
|
2015-01-16 14:56:10 +08:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// OBSERVERS
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Whenever the model's title changes, we want to update that document's
|
|
|
|
// title the reflect the new title.
|
|
|
|
updateTitle: function() {
|
|
|
|
this.set('controller.controllers.application.pageTitle', this.get('controller.model.title'));
|
|
|
|
}.observes('controller.model.title'),
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// LISTENERS
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
populateSidebarDefault: function(sidebar) {
|
|
|
|
var controls = TaggedArray.create();
|
|
|
|
this.trigger('populateControls', controls);
|
|
|
|
sidebar.pushObjectWithTag(DropdownSplit.create({
|
|
|
|
items: controls,
|
|
|
|
icon: 'reply',
|
|
|
|
buttonClass: 'btn-primary'
|
|
|
|
}), 'controls');
|
|
|
|
|
|
|
|
sidebar.pushObjectWithTag(StreamScrubber.create({
|
|
|
|
streamContent: this.get('streamContent')
|
|
|
|
}), 'scrubber');
|
|
|
|
}.on('populateSidebar'),
|
|
|
|
|
|
|
|
populateControlsDefault: function(controls) {
|
|
|
|
var view = this;
|
2015-01-30 09:52:19 +08:00
|
|
|
var reply = ActionButton.create({
|
2015-01-16 14:56:10 +08:00
|
|
|
label: 'Reply',
|
|
|
|
icon: 'reply',
|
|
|
|
action: function() {
|
2015-01-30 10:35:42 +08:00
|
|
|
view.get('streamContent').send('goToLast');
|
2015-01-16 14:56:10 +08:00
|
|
|
view.get('controller').send('reply');
|
|
|
|
},
|
|
|
|
});
|
2015-01-30 09:52:19 +08:00
|
|
|
controls.pushObjectWithTag(reply, 'reply');
|
2015-01-16 14:56:10 +08:00
|
|
|
}.on('populateControls')
|
2014-12-20 14:26:46 +08:00
|
|
|
});
|