Commit 5b6f2861 authored by Florent Chehab's avatar Florent Chehab

University Semester date Editor operationnal

parent 9978774c
......@@ -13,16 +13,17 @@ import dateStrToDate from "../../../utils/dateStrToDate";
import getMapStateToPropsForEditor from "../shared/editorFunctions/getMapStateToPropsForEditor";
import getMapDispatchToPropsForEditor from "../shared/editorFunctions/getMapDispatchToPropsForEditor";
import Form from "../shared/Form";
import { withSnackbar } from "notistack";
const styles = theme => ({
...editorStyle(theme)
});
function onlyOneIsNull(a, b) {
return (a == null && b != null) || (b == null && a != null);
}
class UniversitySemestersDatesEditor extends Editor {
formHasError() {
class UniversitySemestersDatesForm extends Form {
hasError() {
let messages = Array();
const formData = this.getDataFromFields();
const { autumn_begin, autumn_end, spring_begin, spring_end } = formData;
......@@ -43,34 +44,27 @@ class UniversitySemestersDatesEditor extends Editor {
messages.push("Le début du semestre de printemps doit être antérieur à sa fin...");
}
return this.buildError(messages);
}
const formLevelErrors = this.buildError(messages),
fieldLevelErrors = super.hasError();
renderEditor() {
const { modelData } = this.props;
return this.combineErrors([fieldLevelErrors, formLevelErrors]);
}
render() {
return (
<div>
{this.renderObjModerationLevelField()}
<DateField label={"Date de début du semestre de printemps"}
value={dateStrToDate(modelData.spring_begin)}
formManager={this}
fieldMapping={"spring_begin"}
{...this.getReferenceAndValue("spring_begin", dateStrToDate)}
/>
<DateField label={"Date de fin du semestre de printemps"}
value={dateStrToDate(modelData.spring_end)}
formManager={this}
fieldMapping={"spring_end"}
{...this.getReferenceAndValue("spring_end", dateStrToDate)}
/>
<DateField label={"Date de début du semestre d'automne"}
value={dateStrToDate(modelData.autumn_begin)}
formManager={this}
fieldMapping={"autumn_begin"}
{...this.getReferenceAndValue("autumn_begin", dateStrToDate)}
/>
<DateField label={"Date de fin du semestre d'automne"}
value={dateStrToDate(modelData.autumn_end)}
formManager={this}
fieldMapping={"autumn_end"}
{...this.getReferenceAndValue("autumn_end", dateStrToDate)}
/>
{this.renderCommentField()}
{this.renderUsefulLinksField()}
......@@ -79,12 +73,29 @@ class UniversitySemestersDatesEditor extends Editor {
}
}
function onlyOneIsNull(a, b) {
return (a == null && b != null) || (b == null && a != null);
}
class UniversitySemestersDatesEditor extends Editor {
renderForm() {
return (
<UniversitySemestersDatesForm
modelData={this.props.modelData}
ref={this.formRef}
/>
);
}
}
UniversitySemestersDatesEditor.propTypes = {
modelData: PropTypes.object.isRequired,
};
export default compose(
withSnackbar,
withStyles(styles, { withTheme: true }),
connect(
getMapStateToPropsForEditor("universitiesSemestersDates"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment