application.js 842 B

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