diff options
| author | Thomas Haddad | 2017-03-24 15:47:14 +0100 | 
|---|---|---|
| committer | Thomas Haddad | 2017-03-24 15:47:14 +0100 | 
| commit | 986432ac2f1fbccd5185b837f2119e7035d44ad2 (patch) | |
| tree | 005d2f5053a42f6ce7275df7cf29704f8c0fd976 | |
| parent | 447f5d76ae24dfafed097cfeb5e21068871e31d6 (diff) | |
| download | chouette-core-986432ac2f1fbccd5185b837f2119e7035d44ad2.tar.bz2 | |
Use a fetch polyfill for jp or vj
Signed-off-by: Thomas Shawarma Haddad <thomas.haddad@af83.com>
| -rw-r--r-- | app/assets/javascripts/application.js | 1 | ||||
| -rw-r--r-- | app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js | 23 | ||||
| -rw-r--r-- | app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js | 22 | ||||
| -rw-r--r-- | package.json | 6 | 
4 files changed, 30 insertions, 22 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          } diff --git a/package.json b/package.json index 019e63063..4e975de5c 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,14 @@      "babelify": "7.3.0",      "browserify": "13.1.1",      "browserify-incremental": "3.1.1", -    "lodash": "^4.17.4", +    "lodash": "4.17.4", +    "promise-polyfill": "^6.0.2",      "react": "15.3.2",      "react-dom": "15.3.2",      "react-redux": "4.4.5",      "react-select2": "4.0.2", -    "redux": "3.6.0" +    "redux": "3.6.0", +    "whatwg-fetch": "2.0.3"    },    "license": "MIT",    "engines": { | 
