From 5715d27c974867355f1722ca64d4433e5adf3ad2 Mon Sep 17 00:00:00 2001 From: Jonathan Rehm Date: Tue, 18 Jul 2017 08:51:52 -0700 Subject: [PATCH] Show localized date over top of date input Also move datepicker logic into edit_books.js and edit_books.js below the datepicker file declaration(s) --- cps/static/js/edit_books.js | 17 ++++++++++++++++- cps/templates/book_edit.html | 15 ++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index 14f38f63..d96bbcc2 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -1,8 +1,23 @@ /** * Created by SpeedProg on 05.04.2015. */ -/* global Bloodhound */ +/* global Bloodhound, language */ +if (!Modernizr.inputtypes.date) { + $('#pubdate').datepicker({ + format: 'yyyy-mm-dd', + language: language + }).on('change', function () { + // Show localized date over top of the standard YYYY-MM-DD date + let pubDate, results; + if ((results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value))) { // YYYY-MM-DD + pubDate = new Date(results[1], parseInt(results[2], 10)-1, results[3]) || new Date(this.value); + } + $('#fake_pubdate') + .val(pubDate.toLocaleDateString(language)) + .removeClass('hidden'); + }).trigger('change'); +} /* Takes a prefix, query typeahead callback, Bloodhound typeahead adapter diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index 3897bcb3..c6aaf7e1 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -54,7 +54,10 @@
- +
+ + +
@@ -187,9 +190,9 @@ 'description': {{_('Description')|safe|tojson}}, 'source': {{_('Source')|safe|tojson}}, }; + var language = '{{ g.user.locale }}'; - @@ -204,14 +207,8 @@ menubar: 'edit view format', language: '{{ g.user.locale }}' }); - - if (!Modernizr.inputtypes.date) { - $('#pubdate').datepicker({ - format: 'yyyy-mm-dd', - language: '{{ g.user.locale }}' - }); - } + {% endblock %} {% block header %}