diff options
Diffstat (limited to 'app/javascript/routes')
| -rw-r--r-- | app/javascript/routes/components/BSelect2.js | 23 | ||||
| -rw-r--r-- | app/javascript/routes/form_helper.js | 17 | ||||
| -rw-r--r-- | app/javascript/routes/reducers/stopPoints.js | 10 |
3 files changed, 30 insertions, 20 deletions
diff --git a/app/javascript/routes/components/BSelect2.js b/app/javascript/routes/components/BSelect2.js index 340d9df95..0d8d7787f 100644 --- a/app/javascript/routes/components/BSelect2.js +++ b/app/javascript/routes/components/BSelect2.js @@ -96,17 +96,26 @@ class BSelect2 extends Component{ data: function(params) { return { q: params.term, - target_type: 'zdep' + scope: 'route_editor' }; }, processResults: function(data, params) { return { - results: data.map( - item => _.assign( - {}, - item, - { text: item.name + ", " + item.zip_code + " " + item.short_city_name + " <small><em>(" + item.user_objectid + ")</em></small>" } - ) + results: data.map( + function(item) { + var text = item.name; + if (item.zip_code || item.short_city_name) { + text += "," + } + if (item.zip_code) { + text += ` ${item.zip_code}` + } + if (item.short_city_name) { + text += ` ${item.short_city_name}` + } + text += ` <small><em>(${item.area_type.toUpperCase()}, ${item.user_objectid})</em></small>`; + return _.assign({}, item, { text: text }); + } ) }; }, diff --git a/app/javascript/routes/form_helper.js b/app/javascript/routes/form_helper.js index 8a3277234..865722fb6 100644 --- a/app/javascript/routes/form_helper.js +++ b/app/javascript/routes/form_helper.js @@ -7,14 +7,14 @@ const formHelper = { input.setAttribute('name', formatedName) input.setAttribute('value', value) form.appendChild(input) - }, + }, addError: (ids) => { ids.forEach((id) => { if (!$(id).parents('.form-group').hasClass('has-error')) { $(id).parents('.form-group').addClass('has-error') $(id).parent().append(`<span class='help-block small'>${'doit être rempli(e)'}</span>`) } - }) + }) }, cleanInputs: (ids) => { ids.forEach((id) =>{ @@ -28,21 +28,22 @@ const formHelper = { ids.forEach(id => { $(id).val() == "" ? blankInputs.push(id) : filledInputs.push(id) }) - + if (filledInputs.length > 0) formHelper.cleanInputs(filledInputs) - if (blankInputs.length > 0) formHelper.addError(blankInputs) + if (blankInputs.length > 0) formHelper.addError(blankInputs) }, handleStopPoints: (event, state) => { if (state.stopPoints.length >= 2) { state.stopPoints.map((stopPoint, i) => { formHelper.addInput('id', stopPoint.stoppoint_id ? stopPoint.stoppoint_id : '', i) formHelper.addInput('stop_area_id', stopPoint.stoparea_id, i) - formHelper.addInput('position', i, i) + formHelper.addInput('position', stopPoint.index, i) formHelper.addInput('for_boarding', stopPoint.for_boarding, i) formHelper.addInput('for_alighting', stopPoint.for_alighting, i) }) - if ($('.alert.alert-danger').length > 0) $('.alert.alert-danger').remove() - } else { + if ($('.alert.alert-danger').length > 0) $('.alert.alert-danger').remove() + } + else { event.preventDefault() let msg = "L'itinéraire doit comporter au moins deux arrêts" if ($('.alert.alert-danger').length == 0) { @@ -52,4 +53,4 @@ const formHelper = { } } -export default formHelper
\ No newline at end of file +export default formHelper diff --git a/app/javascript/routes/reducers/stopPoints.js b/app/javascript/routes/reducers/stopPoints.js index eeec06327..0b42b504f 100644 --- a/app/javascript/routes/reducers/stopPoints.js +++ b/app/javascript/routes/reducers/stopPoints.js @@ -38,15 +38,15 @@ const stopPoints = (state = [], action) => { case 'MOVE_STOP_UP': return [ ...state.slice(0, 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 }), + _.assign({}, state[action.index], { index: action.index - 1 }), + _.assign({}, state[action.index - 1], { index: action.index }), ...state.slice(action.index + 1) ] case 'MOVE_STOP_DOWN': return [ ...state.slice(0, 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 }), + _.assign({}, state[action.index + 1], { index: action.index }), + _.assign({}, state[action.index], { index: action.index + 1 }), ...state.slice(action.index + 2) ] case 'DELETE_STOP': @@ -141,4 +141,4 @@ const stopPoints = (state = [], action) => { } } -export default stopPoints
\ No newline at end of file +export default stopPoints |
