Skip to content

Commit

Permalink
first crack
Browse files Browse the repository at this point in the history
include resource specific CORS options for Tasks

fixed linting
  • Loading branch information
jgravois committed Oct 1, 2014
1 parent e73ad12 commit 0fcc125
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Tasks/Task.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
L.esri.Tasks.Task = L.Class.extend({

options: {
proxy: false,
useCors: true
},

generateSetter: function(param, context){
var isArray = param.match(/([a-zA-Z]+)\[\]/);

Expand All @@ -21,7 +27,7 @@ L.esri.Tasks.Task = L.Class.extend({
}, context);
}
},
initialize: function(endpoint){
initialize: function(endpoint, options){
if(endpoint.url && endpoint.get){
this._service = endpoint;
this.url = endpoint.url;
Expand All @@ -37,6 +43,8 @@ L.esri.Tasks.Task = L.Class.extend({
this[setter] = this.generateSetter(param, this);
}
}

L.Util.setOptions(this, options);
},
token: function(token){
if(this._service){
Expand All @@ -50,7 +58,15 @@ L.esri.Tasks.Task = L.Class.extend({
if(this._service){
return this._service.request(this.path, this.params, callback, context);
} else {
return L.esri.request(this.url + this.path, this.params, callback, context);
return this._request('request', this.path, this.params, callback, context);
}
},
_request: function(method, path, params, callback, context){
var url = (this.options.proxy) ? this.options.proxy + '?' + this.url + path : this.url + path;
if((method === 'get' || method === 'request') && !this.options.useCors){
return L.esri.Request.get.JSONP(url, params, callback, context);
} else {
return L.esri[method](url, params, callback, context);
}
}
}
});

0 comments on commit 0fcc125

Please sign in to comment.