Skip to content

Commit 7d31061

Browse files
committed
/participant/add: try to auto-choose a group based on the provided url.
UX-related change.
1 parent ff5cf96 commit 7d31061

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/main/java/ru/mystamps/web/Url.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ public final class Url {
8989
public static final String ADD_SERIES_WITH_COUNTRY_PAGE = "/series/add/country/{slug}";
9090

9191
// MUST be updated when any of our resources were modified
92-
public static final String RESOURCES_VERSION = "v0.3.7";
92+
public static final String RESOURCES_VERSION = "v0.3.8";
9393

94-
// CheckStyle: ignore LineLength for next 6 lines
94+
// CheckStyle: ignore LineLength for next 7 lines
9595
public static final String MAIN_CSS = "/static/" + RESOURCES_VERSION + "/styles/main.min.css";
9696
public static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js"; // NOPMD: AvoidDuplicateLiterals
9797
public static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/DateUtils.min.js"; // NOPMD: AvoidDuplicateLiterals
98+
public static final String PARTICIPANT_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/participant/add.min.js"; // NOPMD: AvoidDuplicateLiterals
9899
public static final String SERIES_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/series/add.min.js"; // NOPMD: AvoidDuplicateLiterals
99100
public static final String SERIES_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/series/info.min.js"; // NOPMD: AvoidDuplicateLiterals
100101
public static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js"; // NOPMD: AvoidDuplicateLiterals
@@ -173,6 +174,7 @@ public static Map<String, String> asMap(boolean production) {
173174
map.put("GET_IMAGE_PREVIEW_PAGE", GET_IMAGE_PREVIEW_PAGE);
174175
map.put("JQUERY_JS", JQUERY_JS);
175176
map.put("MAIN_CSS", MAIN_CSS);
177+
map.put("PARTICIPANT_ADD_JS", PARTICIPANT_ADD_JS);
176178
map.put("SELECTIZE_CSS", SELECTIZE_CSS);
177179
map.put("SELECTIZE_JS", SELECTIZE_JS);
178180
map.put("SERIES_ADD_JS", SERIES_ADD_JS);
@@ -187,6 +189,7 @@ public static Map<String, String> asMap(boolean production) {
187189
map.put("GET_IMAGE_PAGE", STATIC_RESOURCES_URL + GET_IMAGE_PAGE);
188190
map.put("GET_IMAGE_PREVIEW_PAGE", STATIC_RESOURCES_URL + GET_IMAGE_PREVIEW_PAGE);
189191
map.put("MAIN_CSS", STATIC_RESOURCES_URL + MAIN_CSS);
192+
map.put("PARTICIPANT_ADD_JS", STATIC_RESOURCES_URL + PARTICIPANT_ADD_JS);
190193
map.put("SERIES_ADD_JS", STATIC_RESOURCES_URL + SERIES_ADD_JS);
191194
map.put("SERIES_INFO_JS", STATIC_RESOURCES_URL + SERIES_INFO_JS);
192195

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// IMPORTANT:
3+
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
4+
//
5+
6+
function initPage() {
7+
$('#url').on('change', function tryToSetParticipantGroup() {
8+
var currentGroup = $('#group option:selected').val();
9+
if (currentGroup != '') {
10+
// don't change what has been selected already to prevent
11+
// overwriting user's choice
12+
return;
13+
}
14+
15+
try {
16+
var url = new URL($(this).val());
17+
var newGroupName = url.hostname.replace(/^www\./, '');
18+
$('#group option')
19+
.filter(function findGroupByName() {
20+
return this.text.replace(/^www\./, '') == newGroupName;
21+
})
22+
.prop('selected', true);
23+
24+
} catch (ignoredError) {
25+
// if we aren't able to parse URL, it's a non-fatal error: maybe
26+
// user provided an invalid URL? Anyway, user always can select
27+
// group manually.
28+
}
29+
});
30+
}

src/main/webapp/WEB-INF/views/participant/add.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<link rel="stylesheet" href="https://cdn.rawgit.com/usrz/bootstrap-languages/3ac2a3d2b27ac43a471cd99e79d378a03b2c6b5f/languages.min.css" th:href="${BOOTSTRAP_LANGUAGE}" />
1515
<link rel="stylesheet" href="../../static/styles/main.css" th:href="${MAIN_CSS}" />
1616
</head>
17-
<body>
17+
<body onload="initPage()">
1818
<div class="container-fluid">
1919
<div class="row" id="header">
2020
<div id="logo" class="col-sm-9 vcenter">
@@ -118,7 +118,7 @@ <h3 th:text="${#strings.capitalize(header)}">
118118
</option>
119119
/*/-->
120120
<!--/*-->
121-
<option value="1">Musicians</option>
121+
<option value="1">example.com</option>
122122
<!--*/-->
123123
</select>
124124
<!--/*/
@@ -171,5 +171,6 @@ <h3 th:text="${#strings.capitalize(header)}">
171171
<!-- Placed at the end of the document so the pages load faster -->
172172
<script src="http://yandex.st/jquery/1.9.1/jquery.min.js" th:src="${JQUERY_JS}"></script>
173173
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" th:src="${BOOTSTRAP_JS}"></script>
174+
<script src="../../../../javascript/participant/add.js" th:src="${PARTICIPANT_ADD_JS}"></script>
174175
</body>
175176
</html>

0 commit comments

Comments
 (0)