application.js 880 B

1234567891011121314151617181920212223242526272829303132
  1. import Ember from 'ember';
  2. import DRFAdapter from './drf';
  3. import getCsrfToken from 'misago/utils/csrf';
  4. export default DRFAdapter.extend({
  5. headers: function() {
  6. return {
  7. 'X-CSRFToken': getCsrfToken()
  8. };
  9. }.property().volatile(),
  10. // Simple ajax util for RPC requests
  11. // raison d'etre: because default ones are processing server responses
  12. // and there isn't response standard to allow that for RPC's
  13. rpcAjax: function(url, data) {
  14. var adapter = this;
  15. return new Ember.RSVP.Promise(function(resolve, reject) {
  16. var hash = adapter.ajaxOptions(url, 'POST', {data: data || null});
  17. hash.success = function(json) {
  18. Ember.run(null, resolve, json);
  19. };
  20. hash.error = function(jqXHR) {
  21. Ember.run(null, reject, jqXHR);
  22. };
  23. Ember.$.ajax(hash);
  24. }, 'DS: MisagoAdapter#rpc-ajax POST to ' + url);
  25. }
  26. });