mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Fix post tag input so it keeps the tag order
refs #5732 - patches ember-selectize to send the caret position to the create-item action handler - updates `addTag` method in PSM controller to insert new tag in the correct place
This commit is contained in:
parent
79f1bd2571
commit
06892cce42
3 changed files with 29 additions and 3 deletions
26
core/client/app/components/gh-selectize.js
Normal file
26
core/client/app/components/gh-selectize.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
import EmberSelectizeComponent from 'ember-cli-selectize/components/ember-selectize';
|
||||||
|
|
||||||
|
export default EmberSelectizeComponent.extend({
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event callback that is triggered when user creates a tag
|
||||||
|
* - modified to pass the caret position to the action
|
||||||
|
*/
|
||||||
|
_create(input, callback) {
|
||||||
|
var caret = this._selectize.caretPos;
|
||||||
|
|
||||||
|
// Delete user entered text
|
||||||
|
this._selectize.setTextboxValue('');
|
||||||
|
// Send create action
|
||||||
|
|
||||||
|
// allow the observers and computed properties to run first
|
||||||
|
Ember.run.schedule('actions', this, function () {
|
||||||
|
this.sendAction('create-item', input, caret);
|
||||||
|
});
|
||||||
|
// We cancel the creation here, so it's up to you to include the created element
|
||||||
|
// in the content and selection property
|
||||||
|
callback(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
|
@ -469,7 +469,7 @@ export default Ember.Controller.extend(SettingsMenuMixin, {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
addTag: function (tagName) {
|
addTag: function (tagName, index) {
|
||||||
var self = this,
|
var self = this,
|
||||||
currentTags = this.get('model.tags'),
|
currentTags = this.get('model.tags'),
|
||||||
currentTagNames = currentTags.map(function (tag) { return tag.get('name').toLowerCase(); }),
|
currentTagNames = currentTags.map(function (tag) { return tag.get('name').toLowerCase(); }),
|
||||||
|
@ -500,7 +500,7 @@ export default Ember.Controller.extend(SettingsMenuMixin, {
|
||||||
}
|
}
|
||||||
|
|
||||||
// push tag onto post relationship
|
// push tag onto post relationship
|
||||||
if (tagToAdd) { self.get('model.tags').pushObject(tagToAdd); }
|
if (tagToAdd) { self.get('model.tags').insertAt(index, tagToAdd); }
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="tag-input">Tags</label>
|
<label for="tag-input">Tags</label>
|
||||||
{{ember-selectize
|
{{gh-selectize
|
||||||
id="tag-input"
|
id="tag-input"
|
||||||
multiple=true
|
multiple=true
|
||||||
selection=model.tags
|
selection=model.tags
|
||||||
|
|
Loading…
Add table
Reference in a new issue