diff options
| author | cedricnjanga | 2017-08-03 17:19:20 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-08-16 09:28:48 +0200 |
| commit | 5f13f78bc5c116ca276e59fe39faa5d432bddece (patch) | |
| tree | b6cc0e6fa7c86eece44a077b5ef0faed5f22e25e /app/assets/javascripts | |
| parent | a24fd7121f2029e222648c9e45dfabea1ec64ecb (diff) | |
| download | chouette-core-5f13f78bc5c116ca276e59fe39faa5d432bddece.tar.bz2 | |
Timetable : Can't add period if it overlaps in_day
Diffstat (limited to 'app/assets/javascripts')
5 files changed, 25 insertions, 6 deletions
diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js index 05b042109..13ce8f59c 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js @@ -105,11 +105,12 @@ const actions = { group, selectType }), - validatePeriodForm: (modalProps, timeTablePeriods, metas) => ({ + validatePeriodForm: (modalProps, timeTablePeriods, metas, timeTableDates) => ({ type: 'VALIDATE_PERIOD_FORM', modalProps, timeTablePeriods, - metas + metas, + timeTableDates }), includeDateInPeriod: (index, dayTypes) => ({ type: 'INCLUDE_DATE_IN_PERIOD', @@ -207,7 +208,7 @@ const actions = { formatDate: (props) => { return props.year + '-' + props.month + '-' + props.day }, - checkErrorsInPeriods: (start, end, index, periods) => { + checkErrorsInPeriods: (start, end, index, periods, days) => { let error = '' start = new Date(start) end = new Date(end) @@ -219,6 +220,18 @@ const actions = { }) return error }, + checkErrorsInDates: (start, end, days) => { + let error = '' + start = new Date(start) + end = new Date(end) + + _.each(days, ({date}) => { + if (start <= new Date(date) && end >= new Date(date)) { + error = 'Une période ne peut chevaucher une date dans un calendrier' + } + }) + return error + }, fetchTimeTables: (dispatch, nextPage) => { let urlJSON = window.location.pathname.split('/', 5).join('/') // console.log(nextPage) diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js index 028974fc8..2194bd46a 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js @@ -1,5 +1,6 @@ var React = require('react') var PropTypes = require('react').PropTypes +var _ = require('lodash') let monthsArray = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'] const formatNumber = (val) => { @@ -107,7 +108,7 @@ const PeriodForm = ({modal, timetable, metas, onOpenAddPeriodForm, onClosePeriod <button type='button' className='btn btn-outline-primary mr-sm' - onClick={() => onValidatePeriodForm(modal.modalProps, timetable.time_table_periods, metas)} + onClick={() => onValidatePeriodForm(modal.modalProps, timetable.time_table_periods, metas, _.reject(timetable.current_month, ['include_date', false]))} > Valider </button> diff --git a/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js b/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js index 7f2db785a..d6ba64241 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js +++ b/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js @@ -27,8 +27,8 @@ const mapDispatchToProps = (dispatch) => { val = (val < 10) ? '0' + String(val) : String(val) dispatch(actions.updatePeriodForm(val, group, 'day')) }, - onValidatePeriodForm: (modalProps, timeTablePeriods, metas) => { - dispatch(actions.validatePeriodForm(modalProps, timeTablePeriods, metas)) + onValidatePeriodForm: (modalProps, timeTablePeriods, metas, timeTableDates) => { + dispatch(actions.validatePeriodForm(modalProps, timeTablePeriods, metas, timeTableDates)) } } } diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js index 3a4a10c64..4af2dc307 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js +++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js @@ -64,7 +64,9 @@ const modal = (state = {}, action) => { } let newPeriods = JSON.parse(JSON.stringify(action.timeTablePeriods)) + let newDays = JSON.parse(JSON.stringify(action.timeTableDates)) let error = actions.checkErrorsInPeriods(period_start, period_end, action.modalProps.index, newPeriods) + if (error == '') error = actions.checkErrorsInDates(period_start, period_end, newDays) newModalProps.error = error newModalProps.active = (error == '') ? false : true return _.assign({}, state, {modalProps: newModalProps}) diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js index 65cd9231a..aa3ea55e3 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js +++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js @@ -64,7 +64,10 @@ const timetable = (state = {}, action) => { return state } let newPeriods = JSON.parse(JSON.stringify(action.timeTablePeriods)) + let newDays = JSON.parse(JSON.stringify(action.timeTableDates)) let error = actions.checkErrorsInPeriods(period_start, period_end, action.modalProps.index, newPeriods) + if (error == '') error = actions.checkErrorsInDates(period_start, period_end, newDays) + if(error != ''){ return state } |
