From 755414cd7a772fd6e80404251a56f55984cf9da0 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 15 Jul 2015 19:52:05 -0800 Subject: [PATCH] Refactor ajax request --- app/pods/users/new/verify/route.js | 16 +++------------- app/utils/ajax-request.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 app/utils/ajax-request.js diff --git a/app/pods/users/new/verify/route.js b/app/pods/users/new/verify/route.js index 3878445..0593ba8 100644 --- a/app/pods/users/new/verify/route.js +++ b/app/pods/users/new/verify/route.js @@ -1,4 +1,5 @@ import Ember from 'ember'; +import ajaxRequest from '../../../../utils/ajax-request'; export default Ember.Route.extend({ apiURL: function() { @@ -10,19 +11,8 @@ export default Ember.Route.extend({ }.property(), model: function(params) { - let url = this.get('apiURL') + '/api/' + this.get('genus') + '/users/verify/' + params.nonce; - return new Ember.RSVP.Promise(function(resolve, reject) { - let options = { - success: function(data){ - resolve(data); - }, - error: function(jqXHR, status, error){ - reject(jqXHR, status, error); - }, - dataType: 'text json', - }; - Ember.$.ajax(url, options); - }); + let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`; + return ajaxRequest(url); }, diff --git a/app/utils/ajax-request.js b/app/utils/ajax-request.js new file mode 100644 index 0000000..6225ee4 --- /dev/null +++ b/app/utils/ajax-request.js @@ -0,0 +1,13 @@ +export default function ajaxRequest(url, options) { + return new Ember.RSVP.Promise(function(resolve, reject) { + options = options || {}; + options.url = url; + options.success = function(data) { + resolve(data); + }; + options.error = function(jqXHR, status, error) { + reject(jqXHR, status, error); + }; + Ember.$.ajax(options); + }); +}