diff options
| author | Zog | 2018-01-29 10:32:05 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-29 10:32:05 +0100 | 
| commit | ddd83906ce4fab3d6dce0c404ec39c3b500ba96f (patch) | |
| tree | 0cc2cbddf35273ba3a93f10240c0f71dffcebf33 /app/javascript | |
| parent | 05bc96db48a0a84fd2c50e457dc767f88950a9b4 (diff) | |
| download | chouette-core-ddd83906ce4fab3d6dce0c404ec39c3b500ba96f.tar.bz2 | |
Refs #5750; Add a validation on VehicleJourneys
Ensure a time is set for all non-commercial stops
Diffstat (limited to 'app/javascript')
6 files changed, 36 insertions, 2 deletions
diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js index 2675328e3..b01158212 100644 --- a/app/javascript/vehicle_journeys/actions/index.js +++ b/app/javascript/vehicle_journeys/actions/index.js @@ -380,6 +380,32 @@ const actions = {          }        })    }, + +  validate : (dispatch, vehicleJourneys, next) => { +    let valid = true +    let vj, vjas +    for (vj of vehicleJourneys){ +      vj.errors = false +      for(vjas of vj.vehicle_journey_at_stops){ +        vjas.errors = null +        if (vjas.area_kind == "non_commercial" && parseInt(vjas.departure_time.hour) == 0 && parseInt(vjas.departure_time.minute) == 0){ +          vjas.errors = "Champ requis" +          vj.errors = true +          valid = false +        } +      } +    } +    dispatch(actions.didValidateVehicleJourneys(vehicleJourneys)) +    if(valid){ +      actions.submitVehicleJourneys(dispatch, vehicleJourneys, next) +    } +  }, + +  didValidateVehicleJourneys : (vehicleJourneys) => ({ +    type: 'DID_VALIDATE_VEHICLE_JOURNEYS', +    vehicleJourneys +  }), +    submitVehicleJourneys : (dispatch, state, next) => {      dispatch(actions.fetchingApi())      let urlJSON = window.location.pathname + "_collection.json" diff --git a/app/javascript/vehicle_journeys/components/SaveVehicleJourneys.js b/app/javascript/vehicle_journeys/components/SaveVehicleJourneys.js index 6e94b04a3..fb921df9c 100644 --- a/app/javascript/vehicle_journeys/components/SaveVehicleJourneys.js +++ b/app/javascript/vehicle_journeys/components/SaveVehicleJourneys.js @@ -13,7 +13,7 @@ export default class SaveVehicleJourneys extends SaveButton{    }    submitForm(){ -    this.props.onSubmitVehicleJourneys(this.props.dispatch, this.props.vehicleJourneys) +    this.props.validate(this.props.vehicleJourneys, this.props.dispatch)    }  } diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js index d240757a3..2b5783dda 100644 --- a/app/javascript/vehicle_journeys/components/VehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js @@ -153,6 +153,9 @@ export default class VehicleJourney extends Component {                        />                    </span>                  </div> +                {vj.errors && <div className="errors"> +                  {vj.errors} +                </div>}              </div>            </div>          )} diff --git a/app/javascript/vehicle_journeys/components/VehicleJourneys.js b/app/javascript/vehicle_journeys/components/VehicleJourneys.js index b188962c2..256ca81f9 100644 --- a/app/javascript/vehicle_journeys/components/VehicleJourneys.js +++ b/app/javascript/vehicle_journeys/components/VehicleJourneys.js @@ -89,7 +89,7 @@ export default class VehicleJourneys extends Component {                </div>              )} -            { _.some(this.props.vehicleJourneys, 'errors') && ( +            { this.props.vehicleJourneys.errors && this.props.vehicleJourneys.errors.length && _.some(this.props.vehicleJourneys, 'errors') && (                <div className="alert alert-danger mt-sm">                  <strong>Erreur : </strong>                  {this.props.vehicleJourneys.map((vj, index) => diff --git a/app/javascript/vehicle_journeys/containers/SaveVehicleJourneys.js b/app/javascript/vehicle_journeys/containers/SaveVehicleJourneys.js index f5f879ed8..3daf831f8 100644 --- a/app/javascript/vehicle_journeys/containers/SaveVehicleJourneys.js +++ b/app/javascript/vehicle_journeys/containers/SaveVehicleJourneys.js @@ -23,6 +23,9 @@ const mapDispatchToProps = (dispatch) => {      },      onSubmitVehicleJourneys: (next, state) => {        actions.submitVehicleJourneys(dispatch, state, next) +    }, +    validate: (state) =>{ +      actions.validate(dispatch, state)      }    }  } diff --git a/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js b/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js index ae45993a8..1a15ec46d 100644 --- a/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js +++ b/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js @@ -273,6 +273,8 @@ export default function vehicleJourneys(state = [], action) {            return vj          }        }) +    case 'DID_VALIDATE_VEHICLE_JOURNEYS': +      return [...action.vehicleJourneys]      default:        return state    }  | 
