Add getPosts endpoint to fetch a list of posts for search
This commit is contained in:
@ -81,15 +81,14 @@ define([
|
||||
},
|
||||
fetchAvailablePosts: function() {
|
||||
var that = this;
|
||||
// TODO: Move this logic to new AJAX query format
|
||||
//mailpoet_post_wpi('posts.php', this.toJSON(), function(response) {
|
||||
//console.log('Posts fetched', arguments);
|
||||
//that.get('_availablePosts').reset(response);
|
||||
//that.get('_selectedPosts').reset(); // Empty out the collection
|
||||
//that.trigger('change:_availablePosts');
|
||||
//}, function() {
|
||||
//console.log('Posts fetchPosts error', arguments);
|
||||
//});
|
||||
WordpressComponent.getPosts(this.toJSON()).done(function(posts) {
|
||||
console.log('Posts fetched', arguments);
|
||||
that.get('_availablePosts').reset(posts);
|
||||
that.get('_selectedPosts').reset(); // Empty out the collection
|
||||
that.trigger('change:_availablePosts');
|
||||
}).fail(function() {
|
||||
console.log('Posts fetchPosts error', arguments);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Batch more changes during a specific time, instead of fetching
|
||||
|
@ -7,8 +7,9 @@ define([
|
||||
|
||||
var Module = {};
|
||||
var postTypesCache,
|
||||
taxonomiesCache = [],
|
||||
termsCache = [];
|
||||
taxonomiesCache = {},
|
||||
termsCache = {},
|
||||
postsCache = {};
|
||||
|
||||
Module.getPostTypes = function() {
|
||||
if (!postTypesCache) {
|
||||
@ -51,6 +52,19 @@ define([
|
||||
return termsCache[key];
|
||||
};
|
||||
|
||||
Module.getPosts = function(options) {
|
||||
var key = JSON.stringify(options);
|
||||
if (!postsCache[key]) {
|
||||
postsCache[key] = MailPoet.Ajax.post({
|
||||
endpoint: 'wordpress',
|
||||
action: 'getPosts',
|
||||
data: options || {},
|
||||
});
|
||||
}
|
||||
|
||||
return postsCache[key];
|
||||
};
|
||||
|
||||
App.on('start', function(options) {
|
||||
// Prefetch post types
|
||||
Module.getPostTypes();
|
||||
|
Reference in New Issue
Block a user