Fix line endings
[MAILPOET-929]
This commit is contained in:
@ -1,74 +1,73 @@
|
|||||||
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
||||||
'use strict';
|
|
||||||
MailPoet.Ajax = {
|
MailPoet.Ajax = {
|
||||||
version: 0.5,
|
version: 0.5,
|
||||||
options: {},
|
options: {},
|
||||||
defaults: {
|
defaults: {
|
||||||
url: null,
|
url: null,
|
||||||
api_version: null,
|
api_version: null,
|
||||||
endpoint: null,
|
endpoint: null,
|
||||||
action: null,
|
action: null,
|
||||||
token: null,
|
token: null,
|
||||||
data: {}
|
data: {}
|
||||||
},
|
},
|
||||||
post: function(options) {
|
post: function(options) {
|
||||||
return this.request('post', options);
|
return this.request('post', options);
|
||||||
},
|
},
|
||||||
init: function(options) {
|
init: function(options) {
|
||||||
// merge options
|
// merge options
|
||||||
this.options = jQuery.extend({}, this.defaults, options);
|
this.options = jQuery.extend({}, this.defaults, options);
|
||||||
|
|
||||||
// set default url
|
// set default url
|
||||||
if(this.options.url === null) {
|
if(this.options.url === null) {
|
||||||
this.options.url = ajaxurl;
|
this.options.url = ajaxurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set default token
|
// set default token
|
||||||
if(this.options.token === null) {
|
if(this.options.token === null) {
|
||||||
this.options.token = window.mailpoet_token;
|
this.options.token = window.mailpoet_token;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getParams: function() {
|
getParams: function() {
|
||||||
return {
|
return {
|
||||||
action: 'mailpoet',
|
action: 'mailpoet',
|
||||||
api_version: this.options.api_version,
|
api_version: this.options.api_version,
|
||||||
token: this.options.token,
|
token: this.options.token,
|
||||||
endpoint: this.options.endpoint,
|
endpoint: this.options.endpoint,
|
||||||
method: this.options.action,
|
method: this.options.action,
|
||||||
data: this.options.data || {}
|
data: this.options.data || {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
request: function(method, options) {
|
request: function(method, options) {
|
||||||
// set options
|
// set options
|
||||||
this.init(options);
|
this.init(options);
|
||||||
|
|
||||||
// set request params
|
// set request params
|
||||||
var params = this.getParams();
|
var params = this.getParams();
|
||||||
var deferred = jQuery.Deferred();
|
|
||||||
|
// remove null values from the data object
|
||||||
// remove null values from the data object
|
if (_.isObject(params.data)) {
|
||||||
if (_.isObject(params.data)) {
|
params.data = _.pick(params.data, function(value) {
|
||||||
params.data = _.pick(params.data, function(value) {
|
return (value !== null)
|
||||||
return (value !== null)
|
})
|
||||||
})
|
}
|
||||||
}
|
|
||||||
|
// ajax request
|
||||||
// ajax request
|
var deferred = jQuery.post(
|
||||||
deferred = jQuery.post(
|
this.options.url,
|
||||||
this.options.url,
|
params,
|
||||||
params,
|
null,
|
||||||
null,
|
'json'
|
||||||
'json'
|
).then(function(data) {
|
||||||
).then(function(data) {
|
return data;
|
||||||
return data;
|
}, function(xhr) {
|
||||||
}, function(xhr) {
|
return xhr.responseJSON;
|
||||||
return xhr.responseJSON;
|
});
|
||||||
});
|
|
||||||
|
// clear options
|
||||||
// clear options
|
this.options = {};
|
||||||
this.options = {};
|
|
||||||
|
return deferred;
|
||||||
return deferred;
|
}
|
||||||
}
|
};
|
||||||
};
|
});
|
||||||
});
|
|
||||||
|
Reference in New Issue
Block a user