mirror of
https://github.com/flarum/core.git
synced 2025-08-10 18:35:56 +02:00
Implement discussion composition and creation
This commit is contained in:
57
ember/app/components/discussions/composer-discussion.js
Normal file
57
ember/app/components/discussions/composer-discussion.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
import TaggedArray from '../../utils/tagged-array';
|
||||
import { PositionEnum } from '../../controllers/composer';
|
||||
|
||||
var precompileTemplate = Ember.Handlebars.compile;
|
||||
|
||||
export default Ember.Component.extend(Ember.Evented, {
|
||||
layoutName: 'components/discussions/composer-body',
|
||||
|
||||
submitLabel: 'Post Discussion',
|
||||
titlePlaceholder: 'Discussion Title',
|
||||
placeholder: '',
|
||||
title: '',
|
||||
content: '',
|
||||
submit: null,
|
||||
loading: false,
|
||||
|
||||
disabled: Ember.computed.equal('composer.position', PositionEnum.MINIMIZED),
|
||||
|
||||
didInsertElement: function() {
|
||||
var controls = TaggedArray.create();
|
||||
this.trigger('populateControls', controls);
|
||||
this.set('controls', controls);
|
||||
},
|
||||
|
||||
populateControls: function(controls) {
|
||||
var title = Ember.Component.create({
|
||||
tagName: 'h3',
|
||||
layout: precompileTemplate('{{ui/controls/text-input value=component.title class="form-control" placeholder=component.titlePlaceholder disabled=component.disabled}}'),
|
||||
component: this
|
||||
});
|
||||
controls.pushObjectWithTag(title, 'title');
|
||||
},
|
||||
|
||||
actions: {
|
||||
submit: function(content) {
|
||||
this.get('submit')({
|
||||
title: this.get('title'),
|
||||
content: content
|
||||
});
|
||||
},
|
||||
|
||||
willExit: function(abort) {
|
||||
// If the user has typed something, prompt them before exiting
|
||||
// this composer state.
|
||||
if ((this.get('title') || this.get('content')) && !confirm('You have not posted your discussion. Do you wish to discard it?')) {
|
||||
abort();
|
||||
}
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.set('loading', false);
|
||||
this.set('content', '');
|
||||
}
|
||||
}
|
||||
});
|
18
ember/app/components/ui/controls/text-input.js
Normal file
18
ember/app/components/ui/controls/text-input.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default Ember.TextField.extend({
|
||||
didInsertElement: function() {
|
||||
var component = this;
|
||||
this.$().on('input', function() {
|
||||
var empty = !$(this).val();
|
||||
if (empty) {
|
||||
$(this).val(component.get('placeholder'));
|
||||
}
|
||||
$(this).css('width', 0);
|
||||
$(this).width($(this)[0].scrollWidth);
|
||||
if (empty) {
|
||||
$(this).val('');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user