Skip to content

Commit 487ef61

Browse files
committed
task: implement AddCatalogNumbersForm
Fix #1341
1 parent ea5fecf commit 487ef61

File tree

3 files changed

+181
-3
lines changed

3 files changed

+181
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
//
2+
// IMPORTANT:
3+
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
4+
//
5+
6+
class AddCatalogNumbersForm extends React.Component {
7+
constructor(props) {
8+
super(props);
9+
this.state = {
10+
numbers: null,
11+
catalog: 'michel',
12+
hasServerError: false,
13+
validationErrors: [],
14+
isDisabled: false
15+
};
16+
this.handleSubmit = this.handleSubmit.bind(this);
17+
this.handleChangeNumbers = this.handleChangeNumbers.bind(this);
18+
this.handleChangeCatalog = this.handleChangeCatalog.bind(this);
19+
}
20+
21+
handleChangeNumbers(event) {
22+
event.preventDefault();
23+
this.setState({
24+
numbers: event.target.value
25+
});
26+
}
27+
28+
handleChangeCatalog(event) {
29+
event.preventDefault();
30+
this.setState({
31+
catalog: event.target.value
32+
});
33+
}
34+
35+
handleSubmit(event) {
36+
event.preventDefault();
37+
38+
this.setState({
39+
isDisabled: true,
40+
hasServerError: false,
41+
validationErrors: []
42+
});
43+
44+
axios.patch(
45+
this.props.url,
46+
[
47+
{
48+
op: 'add',
49+
path: `/${this.state.catalog}_numbers`,
50+
value: this.state.numbers.split(',')
51+
}
52+
],
53+
{
54+
headers: {
55+
[this.props.csrfHeaderName]: this.props.csrfTokenValue,
56+
'Cache-Control': 'no-store'
57+
},
58+
validateStatus: status => {
59+
return status == 204 || status == 400;
60+
}
61+
}
62+
)
63+
.then(response => {
64+
const data = response.data;
65+
if (data.hasOwnProperty('fieldErrors')) {
66+
const fieldErrors = [];
67+
if (data.fieldErrors.numbers) {
68+
fieldErrors.push(...data.fieldErrors.numbers);
69+
}
70+
71+
this.setState({
72+
isDisabled: false,
73+
validationErrors: fieldErrors
74+
});
75+
return;
76+
}
77+
78+
// no need to reset the state as page will be reloaded
79+
window.location.reload();
80+
})
81+
.catch(error => {
82+
console.error(error);
83+
this.setState({ isDisabled: false, hasServerError: true });
84+
});
85+
}
86+
render() {
87+
const hasValidationErrors = this.state.validationErrors.length > 0;
88+
return (
89+
<div className="col-sm-12 form-group">
90+
<form className={`form-horizontal ${hasValidationErrors ? 'has-error' : ''}`} onSubmit={this.handleSubmit}>
91+
<div
92+
id="add-catalog-numbers-failed-msg"
93+
className={`alert alert-danger text-center col-sm-8 col-sm-offset-2 ${this.state.hasServerError ? '' : 'hidden'}`}>
94+
{ this.props.l10n['t_server_error'] || 'Server error' }
95+
</div>
96+
<div className="form-group form-group-sm">
97+
<label className="control-label col-sm-3">
98+
{ this.props.l10n['t_catalog'] || 'Catalog' }
99+
</label>
100+
<div className="col-sm-6">
101+
<select
102+
id="catalog-name"
103+
name="catalogName"
104+
className="form-control"
105+
onChange={this.handleChangeCatalog}>
106+
<option value="michel">
107+
{ this.props.l10n['t_michel'] || 'Michel' }
108+
</option>
109+
<option value="scott">
110+
{ this.props.l10n['t_scott'] || 'Scott' }
111+
</option>
112+
<option value="yvert">
113+
{ this.props.l10n['t_yvert'] || 'Yvert et Tellier' }
114+
</option>
115+
<option value="gibbons">
116+
{ this.props.l10n['t_sg'] || 'Stanley Gibbons' }
117+
</option>
118+
<option value="solovyov">
119+
{ this.props.l10n['t_solovyov'] || 'Solovyov' }
120+
</option>
121+
<option value="zagorski">
122+
{ this.props.l10n['t_zagorski'] || 'Zagorski' }
123+
</option>
124+
</select>
125+
</div>
126+
</div>
127+
<div className="form-group form-group-sm">
128+
<label className="control-label col-sm-3">
129+
{ this.props.l10n['t_numbers'] || 'Numbers' }
130+
</label>
131+
<div className="row">
132+
<div className="col-sm-6">
133+
<input
134+
id="catalog-numbers"
135+
type="text"
136+
className="form-control"
137+
size="5"
138+
required="required"
139+
onChange={ this.handleChangeNumbers } />
140+
</div>
141+
</div>
142+
</div>
143+
<div className="col-sm-offset-3 col-sm-4">
144+
<span
145+
id="catalog-numbers.errors"
146+
className={`help-block ${hasValidationErrors ? '' : 'hidden'}`}>
147+
{ this.state.validationErrors.join(', ') }
148+
</span>
149+
<button
150+
type="submit"
151+
className="btn btn-primary btn-sm"
152+
disabled={ this.state.isDisabled }>
153+
{ this.props.l10n['t_add'] || 'Add' }
154+
</button>
155+
</div>
156+
</form>
157+
</div>
158+
);
159+
}
160+
}

src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public final class ResourceUrl {
3232
public static final String STATIC_RESOURCES_URL = "https://stamps.filezz.ru";
3333

3434
// MUST be updated when any of our resources were modified
35-
public static final String RESOURCES_VERSION = "v0.4.3.3";
35+
public static final String RESOURCES_VERSION = "v0.4.3.4";
3636

37-
// CheckStyle: ignore LineLength for next 14 lines
37+
// CheckStyle: ignore LineLength for next 15 lines
3838
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js";
3939
private static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js";
4040
private static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/DateUtils.min.js";
@@ -47,6 +47,7 @@ public final class ResourceUrl {
4747
private static final String SIMILAR_SERIES_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/SimilarSeriesForm.js";
4848
private static final String ADD_COMMENT_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCommentForm.js";
4949
private static final String CATALOG_PRICE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogPriceForm.js";
50+
private static final String CATALOG_NUMBERS_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogNumbersForm.js";
5051
private static final String RELEASE_YEAR_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddReleaseYearForm.js";
5152
private static final String BOOTSTRAP_LANGUAGE = "https://cdn.jsdelivr.net/gh/usrz/bootstrap-languages@3ac2a3d2b27ac43a471cd99e79d378a03b2c6b5f/languages.min.css";
5253
private static final String FAVICON_ICO = "/favicon.ico";
@@ -85,6 +86,7 @@ public static void exposeResourcesToView(Map<String, String> resources, String h
8586
put(resources, host, "SIMILAR_SERIES_FORM_JS", SIMILAR_SERIES_FORM_JS);
8687
put(resources, host, "ADD_COMMENT_FORM_JS", ADD_COMMENT_FORM_JS);
8788
put(resources, host, "CATALOG_PRICE_FORM_JS", CATALOG_PRICE_FORM_JS);
89+
put(resources, host, "CATALOG_NUMBERS_FORM_JS", CATALOG_NUMBERS_FORM_JS);
8890
put(resources, host, "RELEASE_YEAR_FORM_JS", RELEASE_YEAR_FORM_JS);
8991
}
9092

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ <h5 th:text="#{t_hidden_images}">Hidden images</h5>
395395
<div id="add-release-year" sec:authorize="hasAuthority('CREATE_SERIES')"></div>
396396

397397
<div id="add-catalog-price" sec:authorize="hasAuthority('CREATE_SERIES')"></div>
398+
399+
<div id="add-catalog-numbers" sec:authorize="hasAuthority('CREATE_SERIES')"></div>
398400

399401
<div id="add-comment" sec:authorize="hasAuthority('ADD_COMMENTS_TO_SERIES')"></div>
400402

@@ -931,7 +933,8 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
931933
'fieldErrors': {
932934
'comment': ['Comment error'],
933935
'year': ['Year error'],
934-
'price': ['Price error']
936+
'price': ['Price error'],
937+
'numbers': ['Numbers error']
935938
}
936939
}
937940
},
@@ -977,6 +980,8 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
977980
/*/-->
978981
<script src="../../../../../../target/classes/js/components/AddReleaseYearForm.js" th:src="${RELEASE_YEAR_FORM_JS}"></script>
979982
<script src="../../../../../../target/classes/js/components/AddCatalogPriceForm.js" th:src="${CATALOG_PRICE_FORM_JS}"></script>
983+
<script src="../../../../../../target/classes/js/components/AddCatalogNumbersForm.js" th:src="${CATALOG_NUMBERS_FORM_JS}"></script>
984+
980985
<script th:inline="javascript">
981986
/*[+
982987
var addReleaseYearProps = {
@@ -992,6 +997,12 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
992997
'l10n': {
993998
}
994999
};
1000+
var addCatalogNumbersProps = {
1001+
'csrfHeaderName': [[ ${_csrf.headerName} ]],
1002+
'csrfTokenValue': [[ ${_csrf.token} ]],
1003+
'l10n': {
1004+
}
1005+
};
9951006
+]*/
9961007

9971008
/*[- */
@@ -1005,10 +1016,15 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
10051016
'url': '/series/100',
10061017
'l10n': {}
10071018
};
1019+
var addCatalogNumbersProps = {
1020+
'url': '/series/100',
1021+
'l10n': {}
1022+
};
10081023
/* -]*/
10091024

10101025
renderComponent(AddReleaseYearForm, addReleaseYearProps, 'add-release-year');
10111026
renderComponent(AddCatalogPriceForm, addCatalogPriceProps, 'add-catalog-price');
1027+
renderComponent(AddCatalogNumbersForm, addCatalogNumbersProps, 'add-catalog-numbers');
10121028
</script>
10131029
<!--/*/
10141030
</th:block>

0 commit comments

Comments
 (0)