mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
c922821c7a
Issue #4683 - Finish setting up pagination in tag management page. - Add post count warning to delete tag modal. Fix styling. - Make sure tag input menu is loading all tags. - Only include saved tags in tag input suggestion list. - Unload tag records from store when entering tag route so that we get accurate post count. - Add a resetPagination action to pagination-controller-mixin for cases where we want to start fresh. - Include tag.id when sending tag payload to API.
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
import { getRequestErrorMessage } from 'ghost/utils/ajax';
|
|
|
|
var PaginationControllerMixin = Ember.Mixin.create({
|
|
// set from PaginationRouteMixin
|
|
paginationSettings: null,
|
|
|
|
// indicates whether we're currently loading the next page
|
|
isLoading: null,
|
|
|
|
/**
|
|
* Takes an ajax response, concatenates any error messages, then generates an error notification.
|
|
* @param {jqXHR} response The jQuery ajax reponse object.
|
|
* @return
|
|
*/
|
|
reportLoadError: function (response) {
|
|
var message = 'A problem was encountered while loading more records';
|
|
|
|
if (response) {
|
|
// Get message from response
|
|
message += ': ' + getRequestErrorMessage(response, true);
|
|
} else {
|
|
message += '.';
|
|
}
|
|
|
|
this.notifications.showError(message);
|
|
},
|
|
|
|
actions: {
|
|
/**
|
|
* Loads the next paginated page of posts into the ember-data store. Will cause the posts list UI to update.
|
|
* @return
|
|
*/
|
|
loadNextPage: function () {
|
|
var self = this,
|
|
store = this.get('store'),
|
|
recordType = this.get('model').get('type'),
|
|
metadata = this.store.metadataFor(recordType),
|
|
nextPage = metadata.pagination && metadata.pagination.next,
|
|
paginationSettings = this.get('paginationSettings');
|
|
|
|
if (nextPage) {
|
|
this.set('isLoading', true);
|
|
this.set('paginationSettings.page', nextPage);
|
|
|
|
store.find(recordType, paginationSettings).then(function () {
|
|
self.set('isLoading', false);
|
|
}, function (response) {
|
|
self.reportLoadError(response);
|
|
});
|
|
}
|
|
},
|
|
|
|
resetPagination: function () {
|
|
this.set('paginationSettings.page', 1);
|
|
this.store.metaForType('tag', {pagination: undefined});
|
|
}
|
|
}
|
|
});
|
|
|
|
export default PaginationControllerMixin;
|