Show tag selection modal after submitting discussion

This commit is contained in:
Toby Zerner
2015-08-26 09:34:12 +09:30
parent 190714b658
commit cf6e2dd4ef

View File

@ -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 || {};