mirror of
https://github.com/flarum/framework.git
synced 2024-12-05 09:03:36 +08:00
8683025ef6
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.
42 lines
1.2 KiB
JavaScript
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();
|
|
}
|
|
}
|
|
}
|
|
});
|