Commit 7a37ef79 authored by Florent Chehab's avatar Florent Chehab
Browse files

Full validation of UniversitySemestersDates

parent b3022780
Pipeline #27298 passed with stages
in 2 minutes and 36 seconds
...@@ -42,9 +42,13 @@ class Editor extends MyComponent { ...@@ -42,9 +42,13 @@ class Editor extends MyComponent {
lastUpdateTime: this.props.lastUpdateTime, lastUpdateTime: this.props.lastUpdateTime,
} }
buildError(messages) {
return { status: messages.length > 0, messages };
}
formHasError() { formHasError() {
// to override if you need to perform some checks at the form level // to override if you need to perform some checks at the form level
return { status: false, messages: Array() }; return this.buildError(Array())
} }
formFieldsHaveError() { formFieldsHaveError() {
...@@ -53,7 +57,7 @@ class Editor extends MyComponent { ...@@ -53,7 +57,7 @@ class Editor extends MyComponent {
const field = this.fields[fieldKey]; const field = this.fields[fieldKey];
messages = messages.concat(field.getError().messages); messages = messages.concat(field.getError().messages);
} }
return { status: messages.length > 0, messages }; return this.buildError(messages);
} }
getDataFromFields() { getDataFromFields() {
...@@ -115,7 +119,6 @@ class Editor extends MyComponent { ...@@ -115,7 +119,6 @@ class Editor extends MyComponent {
} else { } else {
const errors = formHasError.messages.concat(formFieldsHaveError.messages); const errors = formHasError.messages.concat(formFieldsHaveError.messages);
console.log(errors);
this.setState({ this.setState({
notification: { notification: {
open: true, open: true,
...@@ -189,7 +192,6 @@ class Editor extends MyComponent { ...@@ -189,7 +192,6 @@ class Editor extends MyComponent {
} }
handleCloseEditorRequest() { handleCloseEditorRequest() {
console.log("close asked !")
const formData = this.getDataFromFields(); const formData = this.getDataFromFields();
const { modelData } = this.props; const { modelData } = this.props;
if (this.hasChangesToSave(formData, modelData)) { if (this.hasChangesToSave(formData, modelData)) {
......
...@@ -23,8 +23,34 @@ const styles = theme => ({ ...@@ -23,8 +23,34 @@ const styles = theme => ({
...editorStyle(theme) ...editorStyle(theme)
}); });
function onlyOneIsNull(a, b) {
return (a == null && b != null) || (b == null && a != null)
}
class UniversitySemestersDatesEditor extends Editor { class UniversitySemestersDatesEditor extends Editor {
formHasError() {
let messages = Array();
const formData = this.getDataFromFields();
const { autumn_begin, autumn_end, spring_begin, spring_end } = formData;
if (onlyOneIsNull(autumn_begin, autumn_end)) {
messages.push("Si une date est saisie pour le semestre d'automne, l'autre doit l'être aussi.");
}
if (onlyOneIsNull(spring_begin, spring_end)) {
messages.push("Si une date est saisie pour le semestre de printemps, l'autre doit l'être aussi.");
}
if (autumn_begin && autumn_end && autumn_begin > autumn_end) {
messages.push("Le début du semestre d'automne doit être antérieur à sa fin...");
}
if (spring_begin && spring_end && spring_begin > spring_end) {
messages.push("Le début du semestre de printemps doit être antérieur à sa fin...");
}
return this.buildError(messages);
}
renderEditor() { renderEditor() {
const { modelData } = this.props; const { modelData } = this.props;
......
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