mirror of
https://github.com/flarum/core.git
synced 2025-07-25 10:41:24 +02:00
Improve post composer + replying
- Make it modular so that different entry points can show different things and respond differently (reply, new discussion, edit post) - Resizable - Fullscreen - Confirm on close
This commit is contained in:
@@ -1,41 +1,72 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
export default Ember.Controller.extend(Ember.Evented, {
|
||||
|
||||
needs: ['index', 'application'],
|
||||
|
||||
user: Ember.Object.create({avatarNumber: 1}),
|
||||
content: null,
|
||||
|
||||
discussion: null,
|
||||
|
||||
showing: true,
|
||||
showing: false,
|
||||
minimized: false,
|
||||
fullScreen: false,
|
||||
|
||||
title: 'Replying to <em>Some Discussion Title</em>',
|
||||
switchContent: function(newContent) {
|
||||
var composer = this;
|
||||
this.confirmExit().then(function() {
|
||||
composer.set('content', null);
|
||||
Ember.run.next(function() {
|
||||
composer.set('content', newContent);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
confirmExit: function() {
|
||||
var composer = this;
|
||||
var promise = new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
var content = composer.get('content');
|
||||
if (content) {
|
||||
content.send('willExit', reject);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
return promise;
|
||||
},
|
||||
|
||||
actions: {
|
||||
close: function() {
|
||||
var composer = this;
|
||||
this.confirmExit().then(function() {
|
||||
composer.send('hide');
|
||||
});
|
||||
},
|
||||
hide: function() {
|
||||
this.set('showing', false);
|
||||
this.set('fullScreen', false);
|
||||
var content = this.get('content');
|
||||
if (content) {
|
||||
content.send('reset');
|
||||
}
|
||||
},
|
||||
minimize: function() {
|
||||
this.set('minimized', true);
|
||||
this.set('minimized', true);
|
||||
this.set('fullScreen', false);
|
||||
},
|
||||
show: function() {
|
||||
this.set('minimized', false);
|
||||
var composer = this;
|
||||
Ember.run.next(function() {
|
||||
composer.set('showing', true);
|
||||
composer.set('minimized', false);
|
||||
composer.trigger('focus');
|
||||
});
|
||||
},
|
||||
save: function(value) {
|
||||
var store = this.store;
|
||||
var discussion = this.get('discussion');
|
||||
var controller = this;
|
||||
|
||||
var post = store.createRecord('post', {
|
||||
content: value,
|
||||
discussion: discussion
|
||||
});
|
||||
post.save().then(function(post) {
|
||||
discussion.set('posts', discussion.get('posts')+','+post.get('id'));
|
||||
controller.get('delegate').send('replyAdded', post);
|
||||
});
|
||||
fullScreen: function() {
|
||||
this.set('fullScreen', true);
|
||||
this.set('minimized', false);
|
||||
this.trigger('focus');
|
||||
},
|
||||
exitFullScreen: function() {
|
||||
this.set('fullScreen', false);
|
||||
this.trigger('focus');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user