mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 03:55:26 +03:00
85f7e1d269
closes #2883, closes #2951 - introduce custom findQuery in ApplicationAdapter - posts/post route and editor/edit route now use custom findQuery to find a single post by id with query params - create a sorting function in PostsController for out-of-order loading - refresh updated posts in posts.index to make PostsList highlight latest draft after returning from a save in editor
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import ghostPaths from 'ghost/utils/ghost-paths';
|
|
|
|
// export default DS.FixtureAdapter.extend({});
|
|
|
|
var ApplicationAdapter = DS.RESTAdapter.extend({
|
|
host: window.location.origin,
|
|
namespace: ghostPaths().apiRoot.slice(1),
|
|
headers: {
|
|
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
|
|
},
|
|
|
|
findQuery: function (store, type, query) {
|
|
var id;
|
|
|
|
if (query.id) {
|
|
id = query.id;
|
|
delete query.id;
|
|
}
|
|
|
|
return this.ajax(this.buildURL(type.typeKey, id), 'GET', { data: query });
|
|
},
|
|
|
|
buildURL: function (type, id) {
|
|
// Ensure trailing slashes
|
|
var url = this._super(type, id);
|
|
|
|
if (url.slice(-1) !== '/') {
|
|
url += '/';
|
|
}
|
|
|
|
return url;
|
|
},
|
|
|
|
// Override deleteRecord to disregard the response body on 2xx responses.
|
|
// This is currently needed because the API is returning status 200 along
|
|
// with the JSON object for the deleted entity and Ember expects an empty
|
|
// response body for successful DELETEs.
|
|
// Non-2xx (failure) responses will still work correctly as Ember will turn
|
|
// them into rejected promises.
|
|
deleteRecord: function () {
|
|
var response = this._super.apply(this, arguments);
|
|
|
|
return response.then(function () {
|
|
return null;
|
|
});
|
|
}
|
|
});
|
|
|
|
export default ApplicationAdapter;
|