From 16a774d2f7cf499c564358e633fb23120e86fddc Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 2 Feb 2018 09:39:08 +0100 Subject: Refs #5825 @1h; Fix info window behaviour on VJs editor --- app/javascript/vehicle_journeys/actions/index.js | 4 +++ .../vehicle_journeys/components/VehicleJourney.js | 5 ++-- .../components/tools/EditVehicleJourney.js | 33 +++++++++++++--------- .../components/tools/VehicleJourneyInfoButton.js | 30 ++++++++++++++++++++ .../containers/tools/VehicleJourneyInfoButton.js | 20 +++++++++++++ app/javascript/vehicle_journeys/reducers/modal.js | 9 ++++++ 6 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 app/javascript/vehicle_journeys/components/tools/VehicleJourneyInfoButton.js create mode 100644 app/javascript/vehicle_journeys/containers/tools/VehicleJourneyInfoButton.js (limited to 'app/javascript') diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js index 74a333b53..bb4ccf417 100644 --- a/app/javascript/vehicle_journeys/actions/index.js +++ b/app/javascript/vehicle_journeys/actions/index.js @@ -69,6 +69,10 @@ const actions = { type : 'EDIT_VEHICLEJOURNEY_MODAL', vehicleJourney }), + openInfoModal : (vehicleJourney) => ({ + type : 'INFO_VEHICLEJOURNEY_MODAL', + vehicleJourney + }), openNotesEditModal : (vehicleJourney) => ({ type : 'EDIT_NOTES_VEHICLEJOURNEY_MODAL', vehicleJourney diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js index e7d4b5b30..99a458f50 100644 --- a/app/javascript/vehicle_journeys/components/VehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import actions from '../actions' import EditVehicleJourney from '../containers/tools/EditVehicleJourney' +import VehicleJourneyInfoButton from '../containers/tools/VehicleJourneyInfoButton' export default class VehicleJourney extends Component { constructor(props) { @@ -60,7 +61,7 @@ export default class VehicleJourney extends Component {
- ($(e.target).parents("a").length == 0) && this.props.onSelectVehicleJourney(this.props.index) + !this.props.disabled && ($(e.target).parents("a").length == 0) && this.props.onSelectVehicleJourney(this.props.index) } >
{this.props.value.short_id || '-'}
@@ -93,7 +94,7 @@ export default class VehicleJourney extends Component { >
} - {this.props.disabled && } + {this.props.disabled && } {this.props.value.vehicle_journey_at_stops.map((vj, i) =>
diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js index f814c0459..f6a0e3c61 100644 --- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js @@ -7,6 +7,7 @@ import CustomFieldsInputs from './CustomFieldsInputs' export default class EditVehicleJourney extends Component { constructor(props) { super(props) + this.updateValue = this.updateValue.bind(this) } handleSubmit() { @@ -23,8 +24,14 @@ export default class EditVehicleJourney extends Component { } } - getSelected() { - return this.props.vehicleJourney ? [this.props.vehicleJourney] : actions.getSelected(this.props.vehicleJourneys) + updateValue(attribute, e) { + this.props.modal.modalProps.vehicleJourney[attribute] = e.target.value + actions.resetValidation(e.currentTarget) + this.forceUpdate() + } + + editMode() { + return !this.props.modal.modalProps.info && this.props.editMode } render() { @@ -39,10 +46,10 @@ export default class EditVehicleJourney extends Component {
  • @@ -67,9 +74,9 @@ export default class EditVehicleJourney extends Component { type='text' ref='published_journey_name' className='form-control' - disabled={!this.props.editMode} - defaultValue={this.props.modal.modalProps.vehicleJourney.published_journey_name} - onKeyDown={(e) => actions.resetValidation(e.currentTarget)} + disabled={!this.editMode()} + value={this.props.modal.modalProps.vehicleJourney.published_journey_name} + onChange={(e) => this.updateValue('published_journey_name', e)} />
  • @@ -94,9 +101,9 @@ export default class EditVehicleJourney extends Component { type='text' ref='published_journey_identifier' className='form-control' - disabled={!this.props.editMode} - defaultValue={this.props.modal.modalProps.vehicleJourney.published_journey_identifier} - onKeyDown={(e) => actions.resetValidation(e.currentTarget)} + disabled={!this.editMode()} + value={this.props.modal.modalProps.vehicleJourney.published_journey_identifier} + onChange={(e) => this.updateValue('published_journey_identifier', e)} /> @@ -105,7 +112,7 @@ export default class EditVehicleJourney extends Component { this.props.onSelect2Company(e)} onUnselect2Company = {() => this.props.onUnselect2Company()} @@ -152,13 +159,13 @@ export default class EditVehicleJourney extends Component { this.custom_fields[code]["value"] = value} - disabled={!this.props.editMode} + disabled={!this.editMode()} /> { - this.props.editMode && + this.editMode() &&
    + + ) + } +} + +VehicleJourneyInfoButton.propTypes = { + onOpenEditModal: PropTypes.func.isRequired, + vehicleJourney: PropTypes.object.isRequired, +} diff --git a/app/javascript/vehicle_journeys/containers/tools/VehicleJourneyInfoButton.js b/app/javascript/vehicle_journeys/containers/tools/VehicleJourneyInfoButton.js new file mode 100644 index 000000000..19010c312 --- /dev/null +++ b/app/javascript/vehicle_journeys/containers/tools/VehicleJourneyInfoButton.js @@ -0,0 +1,20 @@ +import actions from '../../actions' +import { connect } from 'react-redux' +import VehicleJourneyInfoButtonComponent from '../../components/tools/VehicleJourneyInfoButton' + +const mapStateToProps = (state, ownProps) => { + return { + } +} + +const mapDispatchToProps = (dispatch) => { + return { + onOpenEditModal: (vj) =>{ + dispatch(actions.openInfoModal(vj)) + }, + } +} + +const VehicleJourneyInfoButton = connect(mapStateToProps, mapDispatchToProps)(VehicleJourneyInfoButtonComponent) + +export default VehicleJourneyInfoButton diff --git a/app/javascript/vehicle_journeys/reducers/modal.js b/app/javascript/vehicle_journeys/reducers/modal.js index fb7e16547..bcfc6ea0b 100644 --- a/app/javascript/vehicle_journeys/reducers/modal.js +++ b/app/javascript/vehicle_journeys/reducers/modal.js @@ -37,6 +37,15 @@ export default function modal(state = {}, action) { }, confirmModal: {} } + case 'INFO_VEHICLEJOURNEY_MODAL': + return { + type: 'edit', + modalProps: { + vehicleJourney: action.vehicleJourney, + info: true + }, + confirmModal: {} + } case 'EDIT_CALENDARS_VEHICLEJOURNEY_MODAL': vehicleJourneysModal = JSON.parse(JSON.stringify(action.vehicleJourneys)) let uniqTimetables = [] -- cgit v1.2.3