From a82182e1e3397fd33cd23d15b28ee7455b738fd6 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 28 Dec 2016 12:42:45 -0500 Subject: [PATCH] FIX: error when trying to create new tag groups --- .../discourse/controllers/tag-groups.js.es6 | 5 +++-- .../javascripts/discourse/models/tag-group.js.es6 | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/tag-groups.js.es6 b/app/assets/javascripts/discourse/controllers/tag-groups.js.es6 index d4785f36aa7..7ea16868797 100644 --- a/app/assets/javascripts/discourse/controllers/tag-groups.js.es6 +++ b/app/assets/javascripts/discourse/controllers/tag-groups.js.es6 @@ -1,3 +1,5 @@ +import TagGroup from 'discourse/models/tag-group'; + export default Ember.Controller.extend({ actions: { selectTagGroup(tagGroup) { @@ -9,8 +11,7 @@ export default Ember.Controller.extend({ }, newTagGroup() { - const newTagGroup = this.store.createRecord('tag-group'); - newTagGroup.set('name', I18n.t('tagging.groups.new_name')); + const newTagGroup = TagGroup.create({ id: 'new', name: I18n.t('tagging.groups.new_name') }); this.get('model').pushObject(newTagGroup); this.send('selectTagGroup', newTagGroup); } diff --git a/app/assets/javascripts/discourse/models/tag-group.js.es6 b/app/assets/javascripts/discourse/models/tag-group.js.es6 index f27adad26b4..cfbd83e1640 100644 --- a/app/assets/javascripts/discourse/models/tag-group.js.es6 +++ b/app/assets/javascripts/discourse/models/tag-group.js.es6 @@ -9,9 +9,10 @@ const TagGroup = RestModel.extend({ }, save() { - var url = "/tag_groups", - self = this; - if (this.get('id')) { + let url = "/tag_groups"; + const self = this, + isNew = this.get('id') === 'new'; + if (!isNew) { url = "/tag_groups/" + this.get('id'); } @@ -25,9 +26,11 @@ const TagGroup = RestModel.extend({ parent_tag_name: this.get('parent_tag_name') ? this.get('parent_tag_name') : undefined, one_per_topic: this.get('one_per_topic') }, - type: this.get('id') ? 'PUT' : 'POST' + type: isNew ? 'POST' : 'PUT' }).then(function(result) { - if(result.id) { self.set('id', result.id); } + if(result.tag_group && result.tag_group.id) { + self.set('id', result.tag_group.id); + } self.set('savingStatus', I18n.t('saved')); self.set('saving', false); });