Skip to content

Commit d18efd1

Browse files
committed
Show message about successful operation after adding country/category.
Fix #177
1 parent 3678cd0 commit d18efd1

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

src/main/java/ru/mystamps/web/controller/CategoryController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.web.bind.annotation.RequestMapping;
3030
import org.springframework.web.bind.annotation.RequestMethod;
3131
import org.springframework.web.bind.WebDataBinder;
32+
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
3233
import org.springframework.web.util.UriComponentsBuilder;
3334
import org.springframework.validation.BindingResult;
3435

@@ -66,7 +67,8 @@ public AddCategoryForm showForm() {
6667
public String processInput(
6768
@Valid AddCategoryForm form,
6869
BindingResult result,
69-
User currentUser) {
70+
User currentUser,
71+
RedirectAttributes redirectAttributes) {
7072

7173
if (result.hasErrors()) {
7274
return null;
@@ -78,6 +80,8 @@ public String processInput(
7880
.buildAndExpand(categoryUrl.getId(), categoryUrl.getSlug())
7981
.toString();
8082

83+
redirectAttributes.addFlashAttribute("justAddedCategory", true);
84+
8185
return "redirect:" + dstUrl;
8286
}
8387

src/main/java/ru/mystamps/web/controller/CountryController.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.web.bind.annotation.RequestMapping;
3030
import org.springframework.web.bind.annotation.RequestMethod;
3131
import org.springframework.web.bind.WebDataBinder;
32+
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
3233
import org.springframework.web.util.UriComponentsBuilder;
3334
import org.springframework.validation.BindingResult;
3435

@@ -63,7 +64,11 @@ public AddCountryForm showForm() {
6364
}
6465

6566
@RequestMapping(value = Url.ADD_COUNTRY_PAGE, method = RequestMethod.POST)
66-
public String processInput(@Valid AddCountryForm form, BindingResult result, User currentUser) {
67+
public String processInput(
68+
@Valid AddCountryForm form,
69+
BindingResult result,
70+
User currentUser,
71+
RedirectAttributes redirectAttributes) {
6772

6873
if (result.hasErrors()) {
6974
return null;
@@ -75,6 +80,8 @@ public String processInput(@Valid AddCountryForm form, BindingResult result, Use
7580
.buildAndExpand(countryUrl.getId(), countryUrl.getSlug())
7681
.toString();
7782

83+
redirectAttributes.addFlashAttribute("justAddedCountry", true);
84+
7885
return "redirect:" + dstUrl;
7986
}
8087

src/main/resources/ru/mystamps/i18n/Messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ t_create_category_ucfirst = Add category
114114

115115
# category/info.html
116116
t_category_info = Category info
117+
t_category_just_added = Category has been added.<br />Now you could <a href="{0}" class="alert-link">proceed with creating series</a>.
117118

118119
# country/add.html
119120
t_add_country_ucfirst = Add country
120121

121122
# country/info.html
122123
t_country_info = Country info
124+
t_country_just_added = Country has been added.<br />Now you could <a href="{0}" class="alert-link">proceed with creating series</a>.
123125

124126
# collection/info.html
125127
t_collection_of = {0}'s collection

src/main/resources/ru/mystamps/i18n/Messages_ru.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ t_create_category_ucfirst = Создать категорию
114114

115115
# category/info.html
116116
t_category_info = Информация о категории
117+
t_category_just_added = Категория добавлена. Теперь вы можете <a href="{0}" class="alert-link">создать серию</a>.
117118

118119
# country/add.html
119120
t_add_country_ucfirst = Добавить страну
120121

121122
# country/info.html
122123
t_country_info = Информация о стране
124+
t_country_just_added = Страна добавлена. Теперь вы можете <a href="{0}" class="alert-link">создать серию</a>.
123125

124126
# collection/info.html
125127
t_collection_of = Коллекция пользователя {0}

src/main/webapp/WEB-INF/views/category/info.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ <h3 th:text="${category.getLocalizedName(#locale)}">
5555
Animals
5656
</h3>
5757

58+
<!--/*/
59+
<div class="row" th:if="${justAddedCategory}">
60+
<div class="alert alert-success text-center col-sm-4 col-sm-offset-4" th:utext="#{t_category_just_added(@{${ADD_SERIES_PAGE}})}">
61+
Category has been added.<br />
62+
Now you could <a href="../series/add.html" class="alert-link">proceed with creating series</a>.
63+
</div>
64+
</div>
65+
/*/-->
66+
5867
<ul th:if="${not #lists.isEmpty(seriesOfCategory)}" th:remove="all-but-first">
5968
<li th:each="series: ${seriesOfCategory}">
6069
<span th:if="${series.country.id != null}" th:remove="tag">

src/main/webapp/WEB-INF/views/country/info.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ <h3 th:text="${country.getLocalizedName(#locale)}">
5555
Italy
5656
</h3>
5757

58+
<!--/*/
59+
<div class="row" th:if="${justAddedCountry}">
60+
<div class="alert alert-success text-center col-sm-4 col-sm-offset-4" th:utext="#{t_country_just_added(@{${ADD_SERIES_PAGE}})}">
61+
Country has been added.<br />
62+
Now you could <a href="../series/add.html" class="alert-link">proceed with creating series</a>.
63+
</div>
64+
</div>
65+
/*/-->
66+
5867
<ul th:if="${not #lists.isEmpty(seriesOfCountry)}" th:remove="all-but-first">
5968
<li th:each="series : ${seriesOfCountry}">
6069
<span th:if="${series.category.id != null}" th:remove="tag">

0 commit comments

Comments
 (0)