diff --git a/core/client/controllers/modals/delete-tag.js b/core/client/controllers/modals/delete-tag.js index b0977c0352..bd8ce677d0 100644 --- a/core/client/controllers/modals/delete-tag.js +++ b/core/client/controllers/modals/delete-tag.js @@ -1,7 +1,7 @@ -var DeleteTagController = Ember.Controller.extend({ - inflection: function () { - return this.get('model').get('post_count') > 1 ? 'posts' : 'post'; - }.property('model'), +var DeleteTagController = Ember.ObjectController.extend({ + postInflection: Ember.computed('post_count', function () { + return this.get('post_count') > 1 ? 'posts' : 'post'; + }), actions: { confirmAccept: function () { diff --git a/core/client/controllers/post-tags-input.js b/core/client/controllers/post-tags-input.js index ae415623df..189d9d7dad 100644 --- a/core/client/controllers/post-tags-input.js +++ b/core/client/controllers/post-tags-input.js @@ -33,7 +33,7 @@ var PostTagsInputController = Ember.Controller.extend({ // queries hit a full store cache and we don't see empty or out-of-date // suggestion lists loadAllTags: function () { - this.store.find('tag'); + this.store.find('tag', {limit: 'all'}); }, addNewTag: function () { @@ -52,8 +52,13 @@ var PostTagsInputController = Ember.Controller.extend({ // add existing tag if we have a match existingTags = this.store.all('tag').filter(function (tag) { + if (tag.get('isNew')) { + return false; + } + return tag.get('name').toLowerCase() === searchTerm; }); + if (existingTags.get('length')) { this.send('addTag', existingTags.get('firstObject')); } else { @@ -185,7 +190,7 @@ var PostTagsInputController = Ember.Controller.extend({ findMatchingTags: function (searchTerm) { var matchingTags, self = this, - allTags = this.store.all('tag'), + allTags = this.store.all('tag').filterBy('isNew', false), deDupe = {}; if (allTags.get('length') === 0) { diff --git a/core/client/controllers/settings/tags.js b/core/client/controllers/settings/tags.js index 63d145a2ec..fd730328a9 100644 --- a/core/client/controllers/settings/tags.js +++ b/core/client/controllers/settings/tags.js @@ -92,7 +92,7 @@ var TagsController = Ember.ArrayController.extend(PaginationMixin, SettingsMenuM actions: { newTag: function () { - this.set('activeTag', this.store.createRecord('tag')); + this.set('activeTag', this.store.createRecord('tag', {post_count: 0})); this.send('openSettingsMenu'); }, diff --git a/core/client/mixins/pagination-controller.js b/core/client/mixins/pagination-controller.js index b4f910cb2e..847316e62d 100644 --- a/core/client/mixins/pagination-controller.js +++ b/core/client/mixins/pagination-controller.js @@ -4,26 +4,9 @@ var PaginationControllerMixin = Ember.Mixin.create({ // set from PaginationRouteMixin paginationSettings: null, - // holds the next page to load during infinite scroll - nextPage: null, - // indicates whether we're currently loading the next page isLoading: null, - /** - * - * @param {object} options: { - * modelType: name of the model that will be paginated - * } - */ - init: function (options) { - this._super(options); - - var metadata = this.store.metadataFor(options.modelType); - - this.set('nextPage', metadata.pagination.next); - }, - /** * Takes an ajax response, concatenates any error messages, then generates an error notification. * @param {jqXHR} response The jQuery ajax reponse object. @@ -51,7 +34,8 @@ var PaginationControllerMixin = Ember.Mixin.create({ var self = this, store = this.get('store'), recordType = this.get('model').get('type'), - nextPage = this.get('nextPage'), + metadata = this.store.metadataFor(recordType), + nextPage = metadata.pagination && metadata.pagination.next, paginationSettings = this.get('paginationSettings'); if (nextPage) { @@ -59,14 +43,16 @@ var PaginationControllerMixin = Ember.Mixin.create({ this.set('paginationSettings.page', nextPage); store.find(recordType, paginationSettings).then(function () { - var metadata = store.metadataFor(recordType); - - self.set('nextPage', metadata.pagination.next); self.set('isLoading', false); }, function (response) { self.reportLoadError(response); }); } + }, + + resetPagination: function () { + this.set('paginationSettings.page', 1); + this.store.metaForType('tag', {pagination: undefined}); } } }); diff --git a/core/client/routes/settings/tags.js b/core/client/routes/settings/tags.js index 927fc80a25..ba9a80ceaa 100644 --- a/core/client/routes/settings/tags.js +++ b/core/client/routes/settings/tags.js @@ -2,7 +2,16 @@ import AuthenticatedRoute from 'ghost/routes/authenticated'; import CurrentUserSettings from 'ghost/mixins/current-user-settings'; import PaginationRouteMixin from 'ghost/mixins/pagination-route'; -var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, { +var TagsRoute, + paginationSettings; + +paginationSettings = { + page: 1, + include: 'post_count', + limit: 15 +}; + +TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, { actions: { willTransition: function () { @@ -22,12 +31,16 @@ var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMi }, model: function () { - return this.store.find('tag', {include: 'post_count'}); + this.store.unloadAll('tag'); + + return this.store.filter('tag', paginationSettings, function (tag) { + return !tag.get('isNew'); + }); }, setupController: function (controller, model) { this._super(controller, model); - this.setupPagination(); + this.setupPagination(paginationSettings); }, renderTemplate: function (controller, model) { @@ -37,6 +50,10 @@ var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMi outlet: 'settings-menu', view: 'settings/tags/settings-menu' }); + }, + + deactivate: function () { + this.controller.send('resetPagination'); } }); diff --git a/core/client/serializers/post.js b/core/client/serializers/post.js index 6a1216bde2..ba8704bff6 100644 --- a/core/client/serializers/post.js +++ b/core/client/serializers/post.js @@ -47,6 +47,7 @@ var PostSerializer = ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, { serializeIntoHash: function (hash, type, record, options) { options = options || {}; + options.includeId = true; // We have a plural root in the API var root = Ember.String.pluralize(type.typeKey), diff --git a/core/client/serializers/tag.js b/core/client/serializers/tag.js index 60792e81c4..0879a5b9a6 100644 --- a/core/client/serializers/tag.js +++ b/core/client/serializers/tag.js @@ -1,21 +1,20 @@ -import ApplicationSerializer from 'ghost/serializers/application'; - -var TagSerializer = ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, { - - serializeIntoHash: function (hash, type, record, options) { - options = options || {}; - - // We have a plural root in the API - var root = Ember.String.pluralize(type.typeKey), - data = this.serialize(record, options); - - // Properties that exist on the model but we don't want sent in the payload - - delete data.post_count; - delete data.uuid; - - hash[root] = [data]; - } -}); - -export default TagSerializer; +import ApplicationSerializer from 'ghost/serializers/application'; + +var TagSerializer = ApplicationSerializer.extend({ + serializeIntoHash: function (hash, type, record, options) { + options = options || {}; + options.includeId = true; + + var root = Ember.String.pluralize(type.typeKey), + data = this.serialize(record, options); + + // Properties that exist on the model but we don't want sent in the payload + + delete data.uuid; + delete data.post_count; + + hash[root] = [data]; + } +}); + +export default TagSerializer; diff --git a/core/client/templates/modals/delete-tag.hbs b/core/client/templates/modals/delete-tag.hbs index 467ace9a29..5627007b59 100644 --- a/core/client/templates/modals/delete-tag.hbs +++ b/core/client/templates/modals/delete-tag.hbs @@ -1,10 +1,9 @@ -{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide,centered" animation="fade" +{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide" title="Are you sure you want to delete this tag?" confirm=confirm}} -

You're about to delete "{{model.name}}".
- {{#if model.post_count}} - This tag will be removed from {{model.post_count}} {{inflection}}. + {{#if post_count}} + WARNING: This tag is attached to {{post_count}} {{postInflection}}. You're about to delete "{{name}}". This is permanent! No backups, no restores, no magic undo button. We warned you, ok? + {{else}} + WARNING: You're about to delete "{{name}}". This is permanent! No backups, no restores, no magic undo button. We warned you, ok?

{{/if}} - This is permanent! No backups, no restores, no magic undo button.
We warned you, ok?

- -{{/gh-modal-dialog}} \ No newline at end of file +{{/gh-modal-dialog}}