aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLuc Donnet2017-07-26 10:14:59 +0200
committerGitHub2017-07-26 10:14:59 +0200
commitd4df8c81179d0e396db562f1d7331ca6f3ed0a5a (patch)
tree4f25b8c5c08b7acd784db197440d1cf27632e7be /app
parentcada0f02d732dce25492d7f7eb6d6232d56188dd (diff)
parenta486dbe65187aade64c998e21dae139f8bccc6d1 (diff)
downloadchouette-core-d4df8c81179d0e396db562f1d7331ca6f3ed0a5a.tar.bz2
Merge pull request #39 from af83/4161_StopPoints_RouteEdit
4161 stop points route edit
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/es6_browserified/itineraries/index.js13
-rw-r--r--app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js19
2 files changed, 14 insertions, 18 deletions
diff --git a/app/assets/javascripts/es6_browserified/itineraries/index.js b/app/assets/javascripts/es6_browserified/itineraries/index.js
index a8f3048fa..2ffb84319 100644
--- a/app/assets/javascripts/es6_browserified/itineraries/index.js
+++ b/app/assets/javascripts/es6_browserified/itineraries/index.js
@@ -75,22 +75,9 @@ document.querySelector('input[name=commit]').addEventListener('click', (event)=>
addInput('for_boarding',stopPoint.for_boarding, i)
addInput('for_alighting',stopPoint.for_alighting, i)
})
- if(state.stopPoints.length < datas.length){
- for(var j= state.stopPoints.length; j < datas.length; j++){
- updateFormForDeletion(datas[j])
- }
- }
} else {
event.preventDefault()
let msg = "L'itinĂ©raire doit comporter au moins deux arrĂȘts"
$('#stop_points').find('.subform').after("<div class='alert alert-danger'><span class='fa fa-lg fa-exclamation-circle'></span><span>" + msg + "</span></div>")
}
})
-
-const updateFormForDeletion = (stop) =>{
- if (stop.stoppoint_id !== undefined){
- let now = Date.now()
- addInput('id', stop.stoppoint_id, now)
- addInput('_destroy', 'true', now)
- }
-}
diff --git a/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js b/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
index 24c3e5d87..a3b8accb3 100644
--- a/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
+++ b/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
@@ -20,6 +20,14 @@ const stopPoint = (state = {}, action, length) => {
}
}
+const updateFormForDeletion = (stop) =>{
+ if (stop.stoppoint_id !== undefined){
+ let now = Date.now()
+ addInput('id', stop.stoppoint_id, now)
+ addInput('_destroy', 'true', now)
+ }
+}
+
const stopPoints = (state = [], action) => {
switch (action.type) {
case 'ADD_STOP':
@@ -30,18 +38,19 @@ const stopPoints = (state = [], action) => {
case 'MOVE_STOP_UP':
return [
...state.slice(0, action.index - 1),
- state[action.index],
- state[action.index - 1],
+ _.assign({}, state[action.index], { stoppoint_id: state[action.index - 1].stoppoint_id }),
+ _.assign({}, state[action.index - 1], { stoppoint_id: state[action.index].stoppoint_id }),
...state.slice(action.index + 1)
]
case 'MOVE_STOP_DOWN':
return [
...state.slice(0, action.index),
- state[action.index + 1],
- state[action.index],
+ _.assign({}, state[action.index + 1], { stoppoint_id: state[action.index].stoppoint_id }),
+ _.assign({}, state[action.index], { stoppoint_id: state[action.index + 1].stoppoint_id }),
...state.slice(action.index + 2)
]
case 'DELETE_STOP':
+ updateFormForDeletion(state[action.index])
return [
...state.slice(0, action.index),
...state.slice(action.index + 1).map((stopPoint)=>{
@@ -56,7 +65,7 @@ const stopPoints = (state = [], action) => {
{},
t,
{
- stoppoint_id: "",
+ stoppoint_id: t.stoppoint_id,
text: action.text.text,
stoparea_id: action.text.stoparea_id,
user_objectid: action.text.user_objectid,