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,
|
|
|
|
|
2015-01-30 09:42:30 +08:00
|
|
|
loadingNumber: false,
|
|
|
|
|
2015-01-16 14:56:10 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
// By this stage the discussion controller has initialized the post
|
|
|
|
// stream object, and there may or may not be posts loaded into it.
|
|
|
|
// Either way, we want to tell our stream content component to jump
|
|
|
|
// down to the start position specified in the controller's query
|
|
|
|
// params.
|
|
|
|
this.loadStreamContentForNewDiscussion();
|
|
|
|
|
|
|
|
// For that matter, whenever the controller's start query param
|
|
|
|
// changes, we want to tell our stream content component to jump down
|
|
|
|
// to it.
|
|
|
|
this.get('controller').on('startWasChanged', this, this.goToNumber);
|
2015-01-30 09:42:30 +08:00
|
|
|
this.get('streamContent').on('loadedNumber', this, this.loadedNumber);
|
2015-01-16 14:56:10 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement: function() {
|
|
|
|
this.get('controller').off('startWasChanged', this, this.goToNumber);
|
2015-01-30 09:42:30 +08:00
|
|
|
this.get('streamContent').off('loadedNumber', this, this.loadedNumber);
|
2015-01-16 14:56:10 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
goToNumber: function(start) {
|
|
|
|
// We can only proceed if the controller has loaded the discussion
|
|
|
|
// details and the view has been rendered.
|
2015-01-30 09:42:30 +08:00
|
|
|
if (this.get('controller.loaded') && this.get('streamContent') && ! this.get('loadingNumber')) {
|
2015-01-16 14:56:10 +08:00
|
|
|
this.get('streamContent').send('goToNumber', start);
|
2015-01-30 09:42:30 +08:00
|
|
|
this.set('loadingNumber', true);
|
2015-01-16 14:56:10 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-01-30 09:42:30 +08:00
|
|
|
loadedNumber: function() {
|
|
|
|
this.set('loadingNumber', false);
|
|
|
|
},
|
|
|
|
|
2015-01-16 14:56:10 +08:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// OBSERVERS
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Whenever the controller has switched out the old discussion model for a
|
|
|
|
// new one, we want to
|
|
|
|
loadStreamContentForNewDiscussion: function() {
|
|
|
|
if (this.get('controller.loaded')) {
|
|
|
|
this.goToNumber(this.get('controller.start'));
|
|
|
|
}
|
|
|
|
}.observes('controller.loaded'),
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
var ReplyItem = ActionButton.extend({
|
|
|
|
label: 'Reply',
|
|
|
|
icon: 'reply',
|
|
|
|
classNameBindings: ['className', 'replying:disabled'],
|
|
|
|
replying: function() {
|
|
|
|
return this.get('parentController.controllers.composer.showing');
|
|
|
|
}.property('parentController.controllers.composer.showing'),
|
|
|
|
action: function() {
|
|
|
|
var lastPost = $('.posts .item:last');
|
|
|
|
$('html, body').animate({scrollTop: lastPost.offset().top + lastPost.outerHeight() - $(window).height() + $('.composer').height() + 19}, 'fast');
|
|
|
|
view.get('controller').send('reply');
|
|
|
|
},
|
|
|
|
parentController: this.get('controller'),
|
|
|
|
});
|
|
|
|
controls.pushObjectWithTag(ReplyItem.create(), 'reply');
|
|
|
|
}.on('populateControls')
|
2014-12-20 14:26:46 +08:00
|
|
|
});
|