diff --git a/core/client/controllers/post-tags-input.js b/core/client/controllers/post-tags-input.js index e60fb5a65b..9f82125e8e 100644 --- a/core/client/controllers/post-tags-input.js +++ b/core/client/controllers/post-tags-input.js @@ -1,6 +1,33 @@ var PostTagsInputController = Ember.Controller.extend({ - tags: Ember.computed.alias('parentController.tags'), + tagEnteredOrder: Ember.A(), + + tags: Ember.computed('parentController.tags', function () { + var proxyTags = Ember.ArrayProxy.create({ + content: this.get('parentController.tags') + }), + + temp = proxyTags.get('arrangedContent').slice(); + + proxyTags.get('arrangedContent').clear(); + + this.get('tagEnteredOrder').forEach(function (tagName) { + var tag = temp.find(function (tag) { + return tag.get('name') === tagName; + }); + + if (tag) { + proxyTags.get('arrangedContent').addObject(tag); + temp.removeObject(tag); + } + }); + + temp.forEach(function (tag) { + proxyTags.get('arrangedContent').addObject(tag); + }); + + return proxyTags; + }), suggestions: null, newTagText: null, @@ -36,21 +63,25 @@ var PostTagsInputController = Ember.Controller.extend({ // otherwise create a new one newTag = this.store.createRecord('tag'); newTag.set('name', newTagText); - this.get('tags').pushObject(newTag); + + this.send('addTag', newTag); } this.send('reset'); }, addTag: function (tag) { - if (!Ember.isEmpty(tag) && !this.hasTag(tag.get('name'))) { - this.get('tags').pushObject(tag); + if (!Ember.isEmpty(tag)) { + this.get('tags').addObject(tag); + this.get('tagEnteredOrder').addObject(tag.get('name')); } + this.send('reset'); }, deleteTag: function (tag) { this.get('tags').removeObject(tag); + this.get('tagEnteredOrder').removeObject(tag.get('name')); }, deleteLastTag: function () { diff --git a/core/client/templates/post-tags-input.hbs b/core/client/templates/post-tags-input.hbs index 6d0457446d..6d92101c83 100644 --- a/core/client/templates/post-tags-input.hbs +++ b/core/client/templates/post-tags-input.hbs @@ -1,6 +1,6 @@
-{{#each tags}} +{{#each controller.tags}} {{#view view.tagView tag=this}} {{view.tag.name}} {{/view}}