mirror of
https://github.com/flarum/framework.git
synced 2025-06-03 22:43:10 +08: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:
43
ember/app/components/discussions/composer-reply.js
Normal file
43
ember/app/components/discussions/composer-reply.js
Normal file
@ -0,0 +1,43 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
import TaggedArray from '../../utils/tagged-array';
|
||||
|
||||
var precompileTemplate = Ember.Handlebars.compile;
|
||||
|
||||
export default Ember.Component.extend(Ember.Evented, {
|
||||
layoutName: 'components/discussions/composer-body',
|
||||
|
||||
placeholder: 'Write your reply...',
|
||||
submitLabel: 'Post Reply',
|
||||
value: '',
|
||||
|
||||
didInsertElement: function() {
|
||||
var headerItems = TaggedArray.create();
|
||||
this.trigger('populateHeader', headerItems);
|
||||
this.set('headerItems', headerItems);
|
||||
},
|
||||
|
||||
populateHeader: function(header) {
|
||||
var title = Ember.Component.create({
|
||||
tagName: 'h3',
|
||||
layout: precompileTemplate('Replying to <em>{{component.discussion.title}}</em>'),
|
||||
component: this
|
||||
});
|
||||
header.pushObjectWithTag(title, 'title');
|
||||
},
|
||||
|
||||
actions: {
|
||||
submit: function(value) {
|
||||
this.get('submit').call(this, value);
|
||||
},
|
||||
willExit: function(abort) {
|
||||
if (this.get('value') && ! confirm('You have not posted your reply. Do you wish to discard it?')) {
|
||||
abort();
|
||||
}
|
||||
},
|
||||
reset: function() {
|
||||
this.set('loading', false);
|
||||
this.set('value', '');
|
||||
},
|
||||
}
|
||||
});
|
@ -1,9 +1,37 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
import TaggedArray from '../../../utils/tagged-array';
|
||||
import ActionButton from './action-button';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
actions: {
|
||||
save: function() {
|
||||
this.sendAction('save', this.get('value'));
|
||||
}
|
||||
}
|
||||
classNames: ['text-editor'],
|
||||
|
||||
didInsertElement: function() {
|
||||
var controlItems = TaggedArray.create();
|
||||
this.trigger('populateControls', controlItems);
|
||||
this.set('controlItems', controlItems);
|
||||
|
||||
var component = this;
|
||||
this.$('textarea').bind('keydown', 'meta+return', function() {
|
||||
component.send('submit');
|
||||
});
|
||||
},
|
||||
|
||||
populateControls: function(controls) {
|
||||
var component = this;
|
||||
var submit = ActionButton.create({
|
||||
label: this.get('submitLabel'),
|
||||
className: 'btn btn-primary',
|
||||
action: function() {
|
||||
component.send('submit');
|
||||
}
|
||||
});
|
||||
controls.pushObjectWithTag(submit, 'submit');
|
||||
},
|
||||
|
||||
actions: {
|
||||
submit: function() {
|
||||
this.sendAction('submit', this.get('value'));
|
||||
}
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user