mirror of
https://github.com/flarum/framework.git
synced 2025-06-23 19:11:23 +08:00
Show tag selection modal after submitting discussion
This commit is contained in:
@ -6,19 +6,12 @@ import TagDiscussionModal from 'tags/components/TagDiscussionModal';
|
|||||||
import tagsLabel from 'tags/helpers/tagsLabel';
|
import tagsLabel from 'tags/helpers/tagsLabel';
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
override(IndexPage.prototype, 'composeNewDiscussion', function(original, deferred) {
|
extend(IndexPage.prototype, 'composeNewDiscussion', function(promise) {
|
||||||
const tag = app.store.getBy('tags', 'slug', this.params().tags);
|
const tag = app.store.getBy('tags', 'slug', this.params().tags);
|
||||||
|
|
||||||
app.modal.show(
|
if (tag) {
|
||||||
new TagDiscussionModal({
|
promise.then(component => component.tags = [tag]);
|
||||||
selectedTags: tag ? [tag] : [],
|
}
|
||||||
onsubmit: tags => {
|
|
||||||
original(deferred).then(component => component.tags = tags);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add tag-selection abilities to the discussion composer.
|
// Add tag-selection abilities to the discussion composer.
|
||||||
@ -40,11 +33,27 @@ export default function() {
|
|||||||
extend(DiscussionComposer.prototype, 'headerItems', function(items) {
|
extend(DiscussionComposer.prototype, 'headerItems', function(items) {
|
||||||
items.add('tags', (
|
items.add('tags', (
|
||||||
<a className="DiscussionComposer-changeTags" onclick={this.chooseTags.bind(this)}>
|
<a className="DiscussionComposer-changeTags" onclick={this.chooseTags.bind(this)}>
|
||||||
{tagsLabel(this.tags)}
|
{this.tags.length
|
||||||
|
? tagsLabel(this.tags)
|
||||||
|
: <span className="TagLabel untagged">Choose Tags</span>}
|
||||||
</a>
|
</a>
|
||||||
), 10);
|
), 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
override(DiscussionComposer.prototype, 'onsubmit', function(original) {
|
||||||
|
if (!this.tags.length) {
|
||||||
|
app.modal.show(
|
||||||
|
new TagDiscussionModal({
|
||||||
|
selectedTags: [],
|
||||||
|
onsubmit: tags => {
|
||||||
|
this.tags = tags;
|
||||||
|
original();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add the selected tags as data to submit to the server.
|
// Add the selected tags as data to submit to the server.
|
||||||
extend(DiscussionComposer.prototype, 'data', function(data) {
|
extend(DiscussionComposer.prototype, 'data', function(data) {
|
||||||
data.relationships = data.relationships || {};
|
data.relationships = data.relationships || {};
|
||||||
|
Reference in New Issue
Block a user