aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js22
-rw-r--r--app/javascript/vehicle_journeys/reducers/vehicleJourneys.js7
-rw-r--r--app/models/chouette/vehicle_journey.rb1
-rw-r--r--app/views/vehicle_journeys/show.rabl2
4 files changed, 29 insertions, 3 deletions
diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
index 08d74baba..b46857d19 100644
--- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
+++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
@@ -2,10 +2,12 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import actions from '../../actions'
import CompanySelect2 from './select2s/CompanySelect2'
+import Select2 from 'react-select2-wrapper'
export default class EditVehicleJourney extends Component {
constructor(props) {
super(props)
+ this.custom_fields = {}
}
handleSubmit() {
@@ -15,8 +17,8 @@ export default class EditVehicleJourney extends Component {
company = this.props.modal.modalProps.selectedCompany
} else if (typeof this.props.modal.modalProps.vehicleJourney.company === "object") {
company = this.props.modal.modalProps.vehicleJourney.company
- }
- this.props.onEditVehicleJourney(this.refs, company)
+ }
+ this.props.onEditVehicleJourney(_.assign({}, this.refs, {custom_fields: this.custom_fields}), company)
this.props.onModalClose()
$('#EditVehicleJourneyModal').modal('hide')
}
@@ -140,6 +142,22 @@ export default class EditVehicleJourney extends Component {
defaultValue={this.props.modal.modalProps.vehicleJourney.checksum}
/>
</div>
+ {_.map(this.props.modal.modalProps.vehicleJourney.custom_fields, (cf, code) =>
+ <div className='form-group' key={code}>
+ <label className='control-label'>{cf.name}</label>
+ <Select2
+ data={_.map(cf.options.list_values, (v, k) => {
+ return {id: k, text: v}
+ })}
+ ref={'custom_fields.' + code}
+ className='form-control'
+ value={cf.value}
+ disabled={!this.props.editMode}
+ options={{theme: 'bootstrap'}}
+ onSelect={(e) => this.custom_fields[code] = e.params.data.id }
+ />
+ </div>
+ )}
</div>
{
diff --git a/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js b/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js
index 0549c7adc..4ed85316f 100644
--- a/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js
+++ b/app/javascript/vehicle_journeys/reducers/vehicleJourneys.js
@@ -144,10 +144,17 @@ export default function vehicleJourneys(state = [], action) {
case 'EDIT_VEHICLEJOURNEY':
return state.map((vj, i) => {
if (vj.selected){
+ let custom_fields = _.assign({}, vj.custom_fields)
+ _.each(custom_fields, (cf, code) => {
+ console.log(action.data.custom_fields)
+ let value = action.data.custom_fields[code]
+ custom_fields[code] = _.assign({}, custom_fields[code], {value})
+ })
return _.assign({}, vj, {
company: action.selectedCompany,
published_journey_name: action.data.published_journey_name.value,
published_journey_identifier: action.data.published_journey_identifier.value,
+ custom_fields: custom_fields,
})
}else{
return vj
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 32f3cb731..3bd83f83e 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -218,6 +218,7 @@ module Chouette
['company', 'journey_pattern'].map do |association|
attrs["#{association}_id"] = item[association]['id'] if item[association]
end
+ attrs["custom_field_values"] = Hash[*(item["custom_fields"] || {}).map{|k, v| [k, v["value"]]}.flatten]
attrs
end
diff --git a/app/views/vehicle_journeys/show.rabl b/app/views/vehicle_journeys/show.rabl
index eeed79b34..487dd8670 100644
--- a/app/views/vehicle_journeys/show.rabl
+++ b/app/views/vehicle_journeys/show.rabl
@@ -1,6 +1,6 @@
object @vehicle_journey
-[:objectid, :published_journey_name, :published_journey_identifier, :company_id, :comment, :checksum].each do |attr|
+[:objectid, :published_journey_name, :published_journey_identifier, :company_id, :comment, :checksum, :custom_fields].each do |attr|
attributes attr, :unless => lambda { |m| m.send( attr).nil?}
end