Skip to content

Commit 7256cdb

Browse files
committed
refactor: extract code for initialization catalog related fields to a function
1 parent adf67ea commit 7256cdb

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class ResourceUrl {
3131
public static final String STATIC_RESOURCES_URL = "https://stamps.filezz.ru";
3232

3333
// MUST be updated when any of our resources were modified
34-
public static final String RESOURCES_VERSION = "v0.4.7.1";
34+
public static final String RESOURCES_VERSION = "v0.4.7.2";
3535

3636
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/utils/CatalogUtils.min.js";
3737
private static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js";

src/main/javascript/series/info.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,25 @@ function getCurrencyByCatalogName(catalog) {
2222
return [ '\u20BD', 'RUB' ];
2323
}
2424
}
25+
26+
function initPriceCatalog() {
27+
var catalogNameElem = document.getElementById('price-catalog-name');
28+
if (catalogNameElem == null) {
29+
console.error("Couldn't initialize catalog name selector: element not found");
30+
return;
31+
}
32+
catalogNameElem.addEventListener('change', function changeCatalogCurrency(elem) {
33+
var name = this.value;
34+
var info = getCurrencyByCatalogName(this.value);
35+
var symbolElem = document.getElementById('js-catalog-price-symbol');
36+
if (symbolElem == null) {
37+
console.error("Couldn't change currency symbol: element not found");
38+
}
39+
var titleElem = document.getElementById('catalog-price');
40+
if (titleElem == null) {
41+
console.error("Couldn't change currency title: element not found");
42+
}
43+
symbolElem.innerText = info[0];
44+
titleElem.title = info[1];
45+
});
46+
}

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,25 +1126,7 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
11261126

11271127
<script sec:authorize="hasAuthority('CREATE_SERIES')">
11281128
window.addEventListener('DOMContentLoaded', function initPage() {
1129-
var catalogNameElem = document.getElementById('price-catalog-name');
1130-
if (catalogNameElem == null) {
1131-
console.error("Couldn't initialize catalog name selector: element not found");
1132-
return;
1133-
}
1134-
catalogNameElem.addEventListener('change', function changeCatalogCurrency(elem) {
1135-
var name = this.value;
1136-
var info = getCurrencyByCatalogName(this.value);
1137-
var symbolElem = document.getElementById('js-catalog-price-symbol');
1138-
if (symbolElem == null) {
1139-
console.error("Couldn't change currency symbol: element not found");
1140-
}
1141-
var titleElem = document.getElementById('catalog-price');
1142-
if (titleElem == null) {
1143-
console.error("Couldn't change currency title: element not found");
1144-
}
1145-
symbolElem.innerText = info[0];
1146-
titleElem.title = info[1];
1147-
});
1129+
initPriceCatalog();
11481130
});
11491131
</script>
11501132

0 commit comments

Comments
 (0)