diff --git a/app/models/build.js b/app/models/build.js index 57a96ec9..7f556557 100644 --- a/app/models/build.js +++ b/app/models/build.js @@ -22,6 +22,7 @@ if (Config.useV3API) { Build.reopen({ ajax: Ember.inject.service(), + v3Ajax: Ember.inject.service(), state: attr(), number: attr('number'), message: attr('string'), @@ -125,11 +126,11 @@ Build.reopen({ canRestart: Ember.computed.alias('isFinished'), cancel() { - return this.get('ajax').post("/builds/" + (this.get('id')) + "/cancel"); + return this.get('v3Ajax').post("/build/" + (this.get('id')) + "/cancel"); }, restart() { - return this.get('ajax').post("/builds/" + (this.get('id')) + "/restart"); + return this.get('v3Ajax').post("/build/" + (this.get('id')) + "/restart"); }, formattedFinishedAt: function() { diff --git a/app/models/job.js b/app/models/job.js index f2284e5f..dbcafc1f 100644 --- a/app/models/job.js +++ b/app/models/job.js @@ -9,6 +9,7 @@ import { hasMany, belongsTo } from 'ember-data/relationships'; export default Model.extend(DurationCalculations, { ajax: Ember.inject.service(), + v3Ajax: Ember.inject.service(), logId: attr(), queue: attr(), state: attr(), @@ -111,7 +112,7 @@ export default Model.extend(DurationCalculations, { canRestart: Ember.computed.alias('isFinished'), cancel() { - return this.get('ajax').post("/jobs/" + (this.get('id')) + "/cancel"); + return this.get('v3Ajax').post("/job/" + (this.get('id')) + "/cancel"); }, removeLog() { @@ -126,7 +127,7 @@ export default Model.extend(DurationCalculations, { }, restart() { - return this.get('ajax').post("/jobs/" + (this.get('id')) + "/restart"); + return this.get('v3Ajax').post("/job/" + (this.get('id')) + "/restart"); }, appendLog(part) { diff --git a/app/services/ajax.js b/app/services/ajax.js index 4f62c57e..9ef679bc 100644 --- a/app/services/ajax.js +++ b/app/services/ajax.js @@ -1,18 +1,17 @@ import Ember from 'ember'; import config from 'travis/config/environment'; -var default_options; jQuery.support.cors = true; -default_options = { - accepts: { - json: 'application/json; version=2' - } -}; - export default Ember.Service.extend({ auth: Ember.inject.service(), + default_options: { + accepts: { + json: 'application/json; version=2' + } + }, + get(url, callback, errorCallback) { return this.ajax(url, 'get', { success: callback, @@ -38,11 +37,15 @@ export default Ember.Service.extend({ return true; }, + getEndpoint() { + return config.apiEndpoint || ''; + }, + ajax(url, method, options) { var accepts, base, data, delimeter, endpoint, error, key, name, params, promise, ref, ref1, ref2, reject, resolve, success, token, value, xhr; method = method || "GET"; method = method.toUpperCase(); - endpoint = config.apiEndpoint || ''; + endpoint = this.getEndpoint(); options = options || {}; token = Ember.get(this, 'auth').token(); if (token && (this.needsAuth(method, url) || options.forceAuth)) { @@ -83,7 +86,7 @@ export default Ember.Service.extend({ return error.call(this, data, status, xhr); }; - options = $.extend(options, default_options); + options = $.extend(options, this.default_options); if (options.data && (method === "GET" || method === "HEAD")) { params = jQuery.param(options.data); diff --git a/app/services/v3-ajax.js b/app/services/v3-ajax.js new file mode 100644 index 00000000..160dc151 --- /dev/null +++ b/app/services/v3-ajax.js @@ -0,0 +1,17 @@ +import Ember from 'ember'; +import config from 'travis/config/environment'; +import Ajax from 'travis/services/ajax'; + +jQuery.support.cors = true; + +export default Ajax.extend({ + default_options: { + accepts: { + json: 'application/json' + } + }, + + getEndpoint() { + return config.apiEndpoint + '/v3'; + } +});