framework/ember/app/components/composer/composer-discussion.js
Toby Zerner 8683025ef6 Use component prototypes instead of instances
This means the component instance is created in the template, meaning
properties can be overridden in the view helper. It also just makes
more sense - a view instance doesn’t need to exist until it is rendered
in the template.
2015-02-26 09:43:53 +10:30

42 lines
1.2 KiB
JavaScript

import Ember from 'ember';
import ComposerBody from 'flarum/components/composer/composer-body';
var precompileTemplate = Ember.Handlebars.compile;
/**
The composer body for starting a new discussion. Adds a text field as a
control so the user can enter the title of their discussion. Also overrides
the `submit` and `willExit` actions to account for the title.
*/
export default ComposerBody.extend({
submitLabel: 'Post Discussion',
confirmExit: 'You have not posted your discussion. Do you wish to discard it?',
titlePlaceholder: 'Discussion Title',
title: '',
populateControls: function(items) {
var title = Ember.Component.extend({
tagName: 'h3',
layout: precompileTemplate('{{ui/text-input value=component.title class="form-control" placeholder=component.titlePlaceholder disabled=component.disabled autoGrow=true}}'),
component: this
});
items.pushObjectWithTag(title, 'title');
},
actions: {
submit: function(content) {
this.get('submit')({
title: this.get('title'),
content: content
});
},
willExit: function(abort) {
if ((this.get('title') || this.get('content')) && !confirm(this.get('confirmExit'))) {
abort();
}
}
}
});