Jump To …
backend.ckan.js backend.couchdb.js backend.csv.js backend.dataproxy.js backend.elasticsearch.js backend.gdocs.js backend.memory.js data.transform.js ecma-fixes.js model.js view.graph.js view.grid.js view.map.js view.multiview.js view.slickgrid.js view.timeline.js view.transform.js widget.facetviewer.js widget.fields.js widget.filtereditor.js widget.pager.js widget.queryeditor.js

# backend.dataproxy.js

¶

    this.recline = this.recline || {};
    this.recline.Backend = this.recline.Backend || {};
    this.recline.Backend.DataProxy = this.recline.Backend.DataProxy || {};

    (function($, my) {
      my.__type__ = 'dataproxy';

¶

URL for the dataproxy

      my.dataproxy_url = 'http://jsonpdataproxy.appspot.com';

¶

Timeout for dataproxy (after this time if no response we error) Needed because use JSONP so do not receive e.g. 500 errors

      my.timeout = 5000;

¶

## load

Load data from a URL via the DataProxy.

Returns array of field names and array of arrays for records

      my.fetch = function(dataset) {
        var data = {
          url: dataset.url,
          'max-results':  dataset.size || dataset.rows || 1000,
          type: dataset.format || ''
        };
        var jqxhr = $.ajax({
          url: my.dataproxy_url,
          data: data,
          dataType: 'jsonp'
        });
        var dfd = $.Deferred();
        _wrapInTimeout(jqxhr).done(function(results) {
          if (results.error) {
            dfd.reject(results.error);
          }

          dfd.resolve({
            records: results.data,
            fields: results.fields,
            useMemoryStore: true
          });
        })
        .fail(function(arguments) {
          dfd.reject(arguments);
        });
        return dfd.promise();
      };

¶

## _wrapInTimeout

Convenience method providing a crude way to catch backend errors on JSONP calls. Many of backends use JSONP and so will not get error messages and this is a crude way to catch those errors.

      var _wrapInTimeout = function(ourFunction) {
        var dfd = $.Deferred();
        var timer = setTimeout(function() {
          dfd.reject({
            message: 'Request Error: Backend did not respond after ' + (my.timeout / 1000) + ' seconds'
          });
        }, my.timeout);
        ourFunction.done(function(arguments) {
            clearTimeout(timer);
            dfd.resolve(arguments);
          })
          .fail(function(arguments) {
            clearTimeout(timer);
            dfd.reject(arguments);
          })
          ;
        return dfd.promise();
      }

    }(jQuery, this.recline.Backend.DataProxy));