Skip to content

Commit 00d426a

Browse files
committed
/series/{id}: don't populate date on a server, allow to user autofill it on client side.
1 parent 27cabb7 commit 00d426a

File tree

8 files changed

+66
-8
lines changed

8 files changed

+66
-8
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ 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.6";
92+
public static final String RESOURCES_VERSION = "v0.3.7";
9393

94-
// CheckStyle: ignore LineLength for next 4 lines
94+
// CheckStyle: ignore LineLength for next 6 lines
9595
public static final String MAIN_CSS = "/static/" + RESOURCES_VERSION + "/styles/main.min.css";
96-
public static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js";
97-
public static final String SERIES_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/series/add.min.js";
98-
public static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js";
96+
public static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js"; // NOPMD: AvoidDuplicateLiterals
97+
public static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/DateUtils.min.js"; // NOPMD: AvoidDuplicateLiterals
98+
public static final String SERIES_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/series/add.min.js"; // NOPMD: AvoidDuplicateLiterals
99+
public static final String SERIES_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/series/info.min.js"; // NOPMD: AvoidDuplicateLiterals
100+
public static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js"; // NOPMD: AvoidDuplicateLiterals
99101
public static final String FAVICON_ICO = "/favicon.ico";
100102

101103
// CheckStyle: ignore LineLength for next 4 lines
@@ -165,6 +167,7 @@ public static Map<String, String> asMap(boolean production) {
165167
map.put("BOOTSTRAP_JS", BOOTSTRAP_JS);
166168
map.put("CATALOG_UTILS_JS", CATALOG_UTILS_JS);
167169
map.put("COLLECTION_INFO_JS", COLLECTION_INFO_JS);
170+
map.put("DATE_UTILS_JS", DATE_UTILS_JS);
168171
map.put("FAVICON_ICO", FAVICON_ICO);
169172
map.put("GET_IMAGE_PAGE", GET_IMAGE_PAGE);
170173
map.put("GET_IMAGE_PREVIEW_PAGE", GET_IMAGE_PREVIEW_PAGE);
@@ -173,16 +176,19 @@ public static Map<String, String> asMap(boolean production) {
173176
map.put("SELECTIZE_CSS", SELECTIZE_CSS);
174177
map.put("SELECTIZE_JS", SELECTIZE_JS);
175178
map.put("SERIES_ADD_JS", SERIES_ADD_JS);
179+
map.put("SERIES_INFO_JS", SERIES_INFO_JS);
176180
} else {
177181
// Use a separate domain for our own resources
178182
// Constants sorted in an ascending order.
179183
map.put("FAVICON_ICO", STATIC_RESOURCES_URL + FAVICON_ICO);
180184
map.put("CATALOG_UTILS_JS", STATIC_RESOURCES_URL + CATALOG_UTILS_JS);
181185
map.put("COLLECTION_INFO_JS", STATIC_RESOURCES_URL + COLLECTION_INFO_JS);
186+
map.put("DATE_UTILS_JS", STATIC_RESOURCES_URL + DATE_UTILS_JS);
182187
map.put("GET_IMAGE_PAGE", STATIC_RESOURCES_URL + GET_IMAGE_PAGE);
183188
map.put("GET_IMAGE_PREVIEW_PAGE", STATIC_RESOURCES_URL + GET_IMAGE_PREVIEW_PAGE);
184189
map.put("MAIN_CSS", STATIC_RESOURCES_URL + MAIN_CSS);
185190
map.put("SERIES_ADD_JS", STATIC_RESOURCES_URL + SERIES_ADD_JS);
191+
map.put("SERIES_INFO_JS", STATIC_RESOURCES_URL + SERIES_INFO_JS);
186192

187193
// Use CDN for the external resources like libraries
188194
map.put("BOOTSTRAP_CSS", BOOTSTRAP_CSS_CDN);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.IOException;
2121
import java.time.Year;
2222
import java.util.Collections;
23-
import java.util.Date;
2423
import java.util.HashMap;
2524
import java.util.LinkedHashMap;
2625
import java.util.List;
@@ -606,7 +605,6 @@ private void addSeriesSalesFormToModel(Model model) {
606605

607606
if (!model.containsAttribute("addSeriesSalesForm")) {
608607
AddSeriesSalesForm form = new AddSeriesSalesForm();
609-
form.setDate(new Date());
610608
model.addAttribute("addSeriesSalesForm", form);
611609
}
612610

src/main/javascript/DateUtils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// IMPORTANT:
3+
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
4+
//
5+
6+
var DateUtils = {
7+
8+
/** @public */
9+
formatDateToDdMmYyyy: function(date) {
10+
return date
11+
.toISOString() // "2018-06-12T16:59:54.451Z"
12+
.split(/[-:T]/) // [ "2018", "06", "12", "17", "00", "26.244Z" ]
13+
.slice(0, 3) // [ "2018", "06", "12" ]
14+
.reverse() // [ "12", "06", "2018" ]
15+
.join('.'); // "12.06.2018"
16+
}
17+
18+
}

src/main/javascript/series/info.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// IMPORTANT:
3+
// You must update Url.RESOURCES_VERSION each time whenever you're modified this file!
4+
//
5+
6+
function populateTransactionDateWithTodayDate() {
7+
var today = DateUtils.formatDateToDdMmYyyy(new Date());
8+
$('#date').val(today);
9+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ t_add_image = Add image
144144
t_add_image_error = This series has enough images. Please, contact with admin if you want to add more images
145145
t_who_selling_series = Who was selling/buying this series
146146
t_add_info_who_selling_series = Add info about selling/buying this series
147+
t_dd_mm_yyyy = dd.mm.yyyy
148+
t_today = Today
147149
t_seller = Seller
148150
t_add_seller_hint = You can also <a tabindex="-1" href="{0}">add a new seller</a>
149151
t_price = Price

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ t_add_image = Добавить изображение
143143
t_add_image_error = Эта серия содержит все необходимые изображения. Пожалуйста, свяжитесь с администратором, если вы хотите добавить больше изображений
144144
t_who_selling_series = Покупки и продажи этой серии
145145
t_add_info_who_selling_series = Добавить покупки и продажи этой серии
146+
t_dd_mm_yyyy = дд.мм.гггг
147+
t_today = Сегодня
146148
t_seller = Продавец
147149
t_add_seller_hint = Вы также можете <a tabindex="-1" href="{0}">добавить нового продавца</a>
148150
t_price = Цена

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,17 @@ <h5 th:text="|#{t_add_info_who_selling_series}:|">Add info about selling/buying
441441
Date
442442
</label>
443443
<div class="col-sm-4">
444-
<input type="text" id="date" class="form-control" th:field="*{date}" />
444+
<input type="text" id="date" class="form-control" th:field="*{date}" th:placeholder="#{t_dd_mm_yyyy}" placeholder="dd.mm.yyyy" />
445445
<!--/*/
446446
<span id="date.errors" class="help-block" th:if="${#fields.hasErrors('date')}" th:each="error : ${#fields.errors('date')}" th:text="${error}"></span>
447447
/*/-->
448448
</div>
449+
<small>
450+
<a class="link-vcenter"
451+
href="javascript:populateTransactionDateWithTodayDate(); void(0);" th:text="#{t_today}">
452+
Today
453+
</a>
454+
</small>
449455
</div>
450456

451457
<div class="form-group form-group-sm" th:classappend="${#fields.hasErrors('sellerId') ? 'has-error' : ''}">
@@ -631,5 +637,14 @@ <h5 th:text="|#{t_add_info_who_selling_series}:|">Add info about selling/buying
631637
<!-- Placed at the end of the document so the pages load faster -->
632638
<script src="http://yandex.st/jquery/1.9.1/jquery.min.js" th:src="${JQUERY_JS}"></script>
633639
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" th:src="${BOOTSTRAP_JS}"></script>
640+
641+
<!--/*/
642+
<th:block togglz:active="SHOW_PURCHASES_AND_SALES" sec:authorize="hasAuthority('VIEW_SERIES_SALES')">
643+
/*/-->
644+
<script src="../../../../javascript/DateUtils.js" th:src="${DATE_UTILS_JS}"></script>
645+
<script src="../../../../javascript/series/info.js" th:src="${SERIES_INFO_JS}"></script>
646+
<!--/*/
647+
</th:block>
648+
/*/-->
634649
</body>
635650
</html>

src/test/javascript/DateUtilsSpec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
describe('DateUtils.formatDateToDdMmYyyy()', function() {
2+
3+
it('should return a string in a format dd.mm.yyyy', function() {
4+
var date = new Date('2018-06-12T16:59:54.451Z');
5+
expect(DateUtils.formatDateToDdMmYyyy(date)).toEqual('12.06.2018');
6+
});
7+
8+
});

0 commit comments

Comments
 (0)