2015-02-02 14:27:59 +08:00
|
|
|
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',
|
|
|
|
|
|
|
|
submitLabel: 'Post Reply',
|
2015-02-03 14:29:53 +08:00
|
|
|
placeholder: '',
|
2015-02-02 14:27:59 +08:00
|
|
|
value: '',
|
2015-02-03 14:29:53 +08:00
|
|
|
submit: null,
|
|
|
|
loading: false,
|
2015-02-02 14:27:59 +08:00
|
|
|
|
|
|
|
didInsertElement: function() {
|
2015-02-03 14:29:53 +08:00
|
|
|
var controls = TaggedArray.create();
|
|
|
|
this.trigger('populateControls', controls);
|
|
|
|
this.set('controls', controls);
|
2015-02-02 14:27:59 +08:00
|
|
|
},
|
|
|
|
|
2015-02-03 14:29:53 +08:00
|
|
|
populateControls: function(controls) {
|
2015-02-02 14:27:59 +08:00
|
|
|
var title = Ember.Component.create({
|
|
|
|
tagName: 'h3',
|
|
|
|
layout: precompileTemplate('Replying to <em>{{component.discussion.title}}</em>'),
|
|
|
|
component: this
|
|
|
|
});
|
2015-02-03 14:29:53 +08:00
|
|
|
controls.pushObjectWithTag(title, 'title');
|
2015-02-02 14:27:59 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
submit: function(value) {
|
2015-02-03 14:29:53 +08:00
|
|
|
this.get('submit')(value);
|
2015-02-02 14:27:59 +08:00
|
|
|
},
|
2015-02-03 14:29:53 +08:00
|
|
|
|
2015-02-02 14:27:59 +08:00
|
|
|
willExit: function(abort) {
|
2015-02-03 14:29:53 +08:00
|
|
|
// If the user has typed something, prompt them before exiting
|
|
|
|
// this composer state.
|
2015-02-02 14:27:59 +08:00
|
|
|
if (this.get('value') && ! confirm('You have not posted your reply. Do you wish to discard it?')) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
},
|
2015-02-03 14:29:53 +08:00
|
|
|
|
2015-02-02 14:27:59 +08:00
|
|
|
reset: function() {
|
|
|
|
this.set('loading', false);
|
|
|
|
this.set('value', '');
|
2015-02-03 14:29:53 +08:00
|
|
|
}
|
2015-02-02 14:27:59 +08:00
|
|
|
}
|
|
|
|
});
|