2015-02-06 08:04:12 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
import DiscussionResult from 'flarum/models/discussion-result';
|
|
|
|
import PostResult from 'flarum/models/post-result';
|
|
|
|
import Paneable from 'flarum/mixins/paneable';
|
|
|
|
import ComposerDiscussion from 'flarum/components/composer/composer-discussion';
|
|
|
|
import AlertMessage from 'flarum/components/ui/alert-message';
|
|
|
|
import UseComposer from 'flarum/mixins/use-composer';
|
|
|
|
|
|
|
|
export default Ember.Controller.extend(UseComposer, Paneable, {
|
|
|
|
needs: ['application', 'index/index', 'discussion'],
|
|
|
|
composer: Ember.inject.controller('composer'),
|
|
|
|
alerts: Ember.inject.controller('alerts'),
|
|
|
|
|
|
|
|
index: Ember.computed.alias('controllers.index/index'),
|
|
|
|
|
|
|
|
paneDisabled: Ember.computed.not('index.model.length'),
|
|
|
|
|
|
|
|
saveDiscussion: function(data) {
|
|
|
|
var discussion = this.store.createRecord('discussion', {
|
|
|
|
title: data.title,
|
|
|
|
content: data.content
|
|
|
|
});
|
|
|
|
|
|
|
|
var controller = this;
|
|
|
|
return this.saveAndDismissComposer(discussion).then(function(discussion) {
|
2015-02-26 10:18:23 +08:00
|
|
|
if (discussion) {
|
|
|
|
controller.get('index').send('loadResults');
|
|
|
|
controller.transitionToRoute('discussion', discussion);
|
|
|
|
}
|
2015-02-10 15:35:40 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
loadMore: function() {
|
|
|
|
this.get('index').send('loadMore');
|
|
|
|
},
|
2015-02-06 11:37:15 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
markAllAsRead: function() {
|
|
|
|
var user = this.get('session.user');
|
|
|
|
user.set('readTime', new Date);
|
|
|
|
user.save();
|
|
|
|
},
|
2015-02-06 11:37:15 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
newDiscussion: function() {
|
|
|
|
var controller = this;
|
2015-02-26 10:18:23 +08:00
|
|
|
if (this.get('session.isAuthenticated')) {
|
|
|
|
this.showComposer(function() {
|
|
|
|
return ComposerDiscussion.create({
|
|
|
|
user: controller.get('session.user'),
|
|
|
|
submit: function(data) {
|
|
|
|
controller.saveDiscussion(data);
|
|
|
|
}
|
|
|
|
});
|
2015-02-10 15:35:40 +08:00
|
|
|
});
|
2015-02-26 10:18:23 +08:00
|
|
|
} else {
|
|
|
|
this.send('signup');
|
|
|
|
}
|
2015-02-12 12:05:40 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
discussionRemoved: function(discussion) {
|
|
|
|
if (this.get('controllers.discussion.model') === discussion) {
|
|
|
|
this.transitionToRoute('index');
|
|
|
|
}
|
|
|
|
this.get('index').send('discussionRemoved', discussion);
|
2015-02-10 15:35:40 +08:00
|
|
|
}
|
|
|
|
}
|
2015-02-06 08:04:12 +08:00
|
|
|
});
|