diff options
| author | Thomas Haddad | 2016-11-15 17:53:46 +0100 |
|---|---|---|
| committer | Thomas Haddad | 2016-11-15 17:54:07 +0100 |
| commit | a98e911bb6f60b9414b9608e1fcd61561f033d0a (patch) | |
| tree | 780d342e4f5c5cfe6494821d1ea97e7aa6ee03d6 /app/assets/javascripts | |
| parent | 8e3734f097a93eb34a809e18cbbb57b0dde91835 (diff) | |
| download | chouette-core-a98e911bb6f60b9414b9608e1fcd61561f033d0a.tar.bz2 | |
Add for_boarding and for_alighting attributes for stop_points
Signed-off-by: Thomas Shawarma Haddad <thomas.haddad@af83.com>
Diffstat (limited to 'app/assets/javascripts')
6 files changed, 50 insertions, 29 deletions
diff --git a/app/assets/javascripts/es6_browserified/actions/index.js b/app/assets/javascripts/es6_browserified/actions/index.js index b92f9c913..7d225f2f6 100644 --- a/app/assets/javascripts/es6_browserified/actions/index.js +++ b/app/assets/javascripts/es6_browserified/actions/index.js @@ -24,11 +24,19 @@ const actions = { }, updateInputValue : (index, text) => { return { - type : "UPDATE_INPUT_VALUE", + type : 'UPDATE_INPUT_VALUE', index, text } + }, + updateSelectValue: (e, index) => { + return { + type :'UPDATE_SELECT_VALUE', + select_id: e.currentTarget.id, + select_value: e.currentTarget.value, + index + } } } -export default actions +module.exports = actions diff --git a/app/assets/javascripts/es6_browserified/components/Todo.js b/app/assets/javascripts/es6_browserified/components/Todo.js index 85aff9825..b5313876e 100644 --- a/app/assets/javascripts/es6_browserified/components/Todo.js +++ b/app/assets/javascripts/es6_browserified/components/Todo.js @@ -20,21 +20,17 @@ const Todo = (props) => { </div> <div style={secondBlock}> <div style={{display: 'inline-block', width: '100%', verticalAlign: 'middle'}}> - <select id="1"> - <option value="" disabled="disabled" selected="selected">Select...</option> - <option value="opt1">option #1</option> - <option value="opt2">option #2</option> - <option value="opt3">option #3</option> + <select value={props.value.for_boarding} id="for_boarding" onChange={props.onSelectChange}> + <option value="forbidden">interdit</option> + <option value="normal">normal</option> </select> </div> </div> <div style={secondBlock}> <div style={{display: 'inline-block', width: '100%', verticalAlign: 'middle'}}> - <select id="2"> - <option value="" disabled="disabled" selected="selected">Select...</option> - <option value="opt1">option #1</option> - <option value="opt2">option #2</option> - <option value="opt3">option #3</option> + <select value={props.value.for_alighting} id="for_alighting" onChange={props.onSelectChange}> + <option value="forbidden">interdit</option> + <option value="normal">normal</option> </select> </div> </div> @@ -70,6 +66,7 @@ Todo.propTypes = { onMoveUpClick: PropTypes.func.isRequired, onMoveDownClick: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, + onSelectChange: PropTypes.func.isRequired, first: PropTypes.bool, last: PropTypes.bool, index: PropTypes.number, diff --git a/app/assets/javascripts/es6_browserified/components/TodoList.js b/app/assets/javascripts/es6_browserified/components/TodoList.js index 79967e336..03bd4dbf6 100644 --- a/app/assets/javascripts/es6_browserified/components/TodoList.js +++ b/app/assets/javascripts/es6_browserified/components/TodoList.js @@ -1,7 +1,7 @@ import React, {PropTypes} from 'react' import Todo from './Todo' -const TodoList = ({ todos, onDeleteClick, onMoveUpClick, onMoveDownClick, onChange }) => { +const TodoList = ({ todos, onDeleteClick, onMoveUpClick, onMoveDownClick, onChange, onSelectChange }) => { return ( <div className='list-group'> {todos.map((todo, index) => @@ -13,6 +13,7 @@ const TodoList = ({ todos, onDeleteClick, onMoveUpClick, onMoveDownClick, onChan }} onMoveDownClick={() => onMoveDownClick(index)} onChange={ onChange } + onSelectChange={ (e) => onSelectChange(e, index) } first={ index === 0 } last={ index === (todos.length - 1) } index={ index } @@ -27,7 +28,8 @@ TodoList.propTypes = { todos: PropTypes.array.isRequired, onDeleteClick: PropTypes.func.isRequired, onMoveUpClick: PropTypes.func.isRequired, - onMoveDownClick: PropTypes.func.isRequired + onMoveDownClick: PropTypes.func.isRequired, + onSelectChange: PropTypes.func.isRequired } export default TodoList diff --git a/app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js b/app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js index 4bb4e6c05..a9b395279 100644 --- a/app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js +++ b/app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js @@ -21,6 +21,9 @@ const mapDispatchToProps = (dispatch) => { }, onChange: (index, text) =>{ dispatch(actions.updateInputValue(index, text)) + }, + onSelectChange: (e, index) =>{ + dispatch(actions.updateSelectValue(e, index)) } } } diff --git a/app/assets/javascripts/es6_browserified/reducers/todos.js b/app/assets/javascripts/es6_browserified/reducers/todos.js index cf3c0cbf7..cbbb59c37 100644 --- a/app/assets/javascripts/es6_browserified/reducers/todos.js +++ b/app/assets/javascripts/es6_browserified/reducers/todos.js @@ -5,19 +5,10 @@ const todo = (state = {}, action, length) => { case 'ADD_STOP': return { text: '', - index: length + index: length, + for_boarding: 'normal', + for_alighting: 'normal' } - case 'UPDATE_INPUT_VALUE': - console.log('reducer', action) - if (state.index !== action.index) { - return state - } - - return Object.assign( - {}, - state, - {text: action.text.text, stoparea_id: action.text.stoparea_id} - ) default: return state } @@ -64,7 +55,11 @@ const todos = (state = [], action) => { return state.map( (t, i) => { if (i === action.index) { updateFormForDeletion(t) - return action.text + return Object.assign( + {}, + t, + {text: action.text.text, stoparea_id: action.text.stoparea_id} + ) } else { return t } @@ -72,6 +67,16 @@ const todos = (state = [], action) => { // return state.map(t => // todo(t, action) // ) + case 'UPDATE_SELECT_VALUE': + return state.map( (t,i) => { + if (i === action.index) { + let stopState = Object.assign({}, t) + stopState[action.select_id] = action.select_value + return stopState + } else { + return t + } + }) default: return state } diff --git a/app/assets/javascripts/es6_browserified/stop_points.js b/app/assets/javascripts/es6_browserified/stop_points.js index 339264d51..f3ac81906 100644 --- a/app/assets/javascripts/es6_browserified/stop_points.js +++ b/app/assets/javascripts/es6_browserified/stop_points.js @@ -5,8 +5,10 @@ import { createStore } from 'redux' import todoApp from './reducers' import App from './components/App' import addInput from './form_helper' + +// logger, DO NOT REMOVE // var applyMiddleware = require('redux').applyMiddleware -// var createLogger = require('redux-logger').default +// var createLogger = require('redux-logger') // var thunkMiddleware = require('redux-thunk').default // var promise = require('redux-promise') @@ -25,7 +27,9 @@ const getInitialState = () => { index: index, city_name: value.city_name, zip_code: value.zip_code, - text: fancyText + text: fancyText, + for_boarding: value.for_boarding || "normal", + for_alighting: value.for_alighting || "normal" }) } return state @@ -55,5 +59,7 @@ document.querySelector('input[name=commit]').addEventListener('click', (event)=> addInput('id',todo.stoppoint_id, i) addInput('stop_area_id',todo.stoparea_id, i) addInput('position',i, i) + addInput('for_boarding',todo.for_boarding, i) + addInput('for_alighting',todo.for_alighting, i) } }) |
