remote_json_provider.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //= require ./ajax
  2. AmCharts.RB.RemoteJSONProvider = AmCharts.RB.Util.Class.create(function()
  3. {
  4. function state_changed()
  5. {
  6. var response = this.request.response;
  7. if (response.ready_state() == 4)
  8. {
  9. if (response.status() == 200)
  10. {
  11. this.completed = true;
  12. this.started = false;
  13. this.data = response.get_json();
  14. if (this.chart) this.chart.load_data(this.data);
  15. }
  16. else if (this.chart)
  17. {
  18. this.chart.failed("Error loading chart data: " + this.url);
  19. }
  20. }
  21. }
  22. return {
  23. request: null,
  24. initialize: function(chart, url, params, method)
  25. {
  26. this.url = url;
  27. this.completed = this.started = false
  28. this.params = params;
  29. this.method = method || 'GET';
  30. if (chart) this.chart = new AmCharts.RB.Chart(chart);
  31. },
  32. load: function(defer)
  33. {
  34. this.started = true;
  35. setTimeout(function(){
  36. this.request = new AmCharts.RB.Ajax.Request(this.url, this.params, this.method, state_changed.bind(this));
  37. }.bind(this), defer || 0)
  38. },
  39. loaded: function()
  40. {
  41. return this.completed;
  42. },
  43. loading: function()
  44. {
  45. return !this.loaded() && this.started;
  46. }
  47. }
  48. }());