diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 528975c..006a1de 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.service.ConferenceService; +import ru.ulstu.deadline.model.Deadline; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -21,7 +22,6 @@ import static org.springframework.util.StringUtils.isEmpty; import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE; import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE; import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; -import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() @@ -55,12 +55,22 @@ public class ConferenceController { if (conferenceDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } - hasErrors(errors, CONFERENCE_PAGE); + if (errors.hasErrors()) + return CONFERENCE_PAGE; conferenceService.save(conferenceDto); return String.format(REDIRECT_TO, CONFERENCES_PAGE); } + @PostMapping(value = "/conference", params = "addDeadline") + public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) { + filterEmptyDeadlines(conferenceDto); + if (errors.hasErrors()) + return CONFERENCE_PAGE; + conferenceDto.getDeadlines().add(new Deadline()); + return CONFERENCE_PAGE; + } + private void filterEmptyDeadlines(ConferenceDto conferenceDto) { conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 3330bed..cbc0019 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -30,6 +30,9 @@ +

Incorrect title

+

@@ -61,14 +64,15 @@ $('#deadlines${rowStat.index}\\.date').val(''); $('#addDeadline').click();|"/>
-

Incorrect title

+

+
-
diff --git a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html index 31cc00f..45a945e 100644 --- a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html +++ b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html @@ -21,7 +21,7 @@
- Добавить конференцию + Новая конференцию