diff options
Diffstat (limited to 'app')
3 files changed, 26 insertions, 20 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 3bce3ec7d..38cadd369 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,3 +21,4 @@ //= require footable/footable.sort //= require_directory ./plugins //= require_directory . +require('whatwg-fetch') diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js b/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js index a31f89841..709686f21 100644 --- a/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js +++ b/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js @@ -1,3 +1,10 @@ +var Promise = require('promise-polyfill') + +// To add to window +if (!window.Promise) { + window.Promise = Promise; +} + const actions = { receiveJourneyPatterns : (json) => ({ type: "RECEIVE_JOURNEY_PATTERNS", @@ -101,7 +108,8 @@ const actions = { submitJourneyPattern : (dispatch, state, next) => { dispatch(actions.fetchingApi()) let urlJSON = window.location.pathname + ".json" - let req = new Request(urlJSON, { + let hasError = false + fetch(urlJSON, { credentials: 'same-origin', method: 'PATCH', contentType: 'application/json; charset=utf-8', @@ -110,10 +118,7 @@ const actions = { headers: { 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') } - }) - let hasError = false - fetch(req) - .then(response => { + }).then(response => { if(!response.ok) { hasError = true } @@ -158,12 +163,10 @@ const actions = { str = '.json?page=' + page.toString() } let urlJSON = window.location.pathname + str - let req = new Request(urlJSON, { - credentials: 'same-origin', - }) let hasError = false - fetch(req) - .then(response => { + fetch(urlJSON, { + credentials: 'same-origin', + }).then(response => { if(response.status == 500) { hasError = true } diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js index 14e127d3c..4e67482da 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js @@ -1,3 +1,9 @@ +var Promise = require('promise-polyfill') + +// To add to window +if (!window.Promise) { + window.Promise = Promise; +} var batchActions = require('../batch').batchActions const actions = { @@ -271,12 +277,10 @@ const actions = { if (queryString){ urlJSON = urlJSON + sep + queryString } - let req = new Request(urlJSON, { - credentials: 'same-origin', - }) let hasError = false - fetch(req) - .then(response => { + fetch(urlJSON, { + credentials: 'same-origin', + }).then(response => { if(response.status == 500) { hasError = true } @@ -322,7 +326,8 @@ const actions = { submitVehicleJourneys : (dispatch, state, next) => { dispatch(actions.fetchingApi()) let urlJSON = window.location.pathname + "_collection.json" - let req = new Request(urlJSON, { + let hasError = false + fetch(urlJSON, { credentials: 'same-origin', method: 'PATCH', contentType: 'application/json; charset=utf-8', @@ -331,10 +336,7 @@ const actions = { headers: { 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') } - }) - let hasError = false - fetch(req) - .then(response => { + }).then(response => { if(!response.ok) { hasError = true } |
