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:
Toby Zerner
2015-02-02 16:57:59 +10:30
parent 6568d7d269
commit 12b0418eb7
13 changed files with 454 additions and 107 deletions

View 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', '');
},
}
});

View File

@ -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'));
}
}
});