From b009dfe4ee6bf7b63d04f64295460c80dda61d9c Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Fri, 14 May 2021 19:58:06 +0200 Subject: [PATCH] Always use bootstrap datepicker --- cps/static/js/edit_books.js | 69 ++++++++++------------------------ cps/static/js/libs/plugins.js | 5 --- cps/templates/book_edit.html | 22 ++++++----- cps/templates/search_form.html | 40 +++++++++++++------- cps/web.py | 12 +++++- 5 files changed, 68 insertions(+), 80 deletions(-) diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index 8ec020c0..dbacdfdb 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -21,57 +21,26 @@ if ($(".tiny_editor").length) { }); } -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 - var pubDate; - var results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value); // YYYY-MM-DD - if (results) { - 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"); -} +$(".datepicker").datepicker({ + format: "yyyy-mm-dd", + language: language +}).on("change", function () { + // Show localized date over top of the standard YYYY-MM-DD date + var pubDate; + var results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value); // YYYY-MM-DD + if (results) { + pubDate = new Date(results[1], parseInt(results[2], 10) - 1, results[3]) || new Date(this.value); + $(this).next('input') + .val(pubDate.toLocaleDateString(language)) + .removeClass("hidden"); + } +}).trigger("change"); - -if (!Modernizr.inputtypes.date) { - $("#Publishstart").datepicker({ - format: "yyyy-mm-dd", - language: language - }).on("change", function () { - // Show localized date over top of the standard YYYY-MM-DD date - var pubDate; - var results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value); // YYYY-MM-DD - if (results) { - pubDate = new Date(results[1], parseInt(results[2], 10) - 1, results[3]) || new Date(this.value); - $("#fake_Publishstart") - .val(pubDate.toLocaleDateString(language)) - .removeClass("hidden"); - } - }).trigger("change"); -} - -if (!Modernizr.inputtypes.date) { - $("#Publishend").datepicker({ - format: "yyyy-mm-dd", - language: language - }).on("change", function () { - // Show localized date over top of the standard YYYY-MM-DD date - var pubDate; - var results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value); // YYYY-MM-DD - if (results) { - pubDate = new Date(results[1], parseInt(results[2], 10) - 1, results[3]) || new Date(this.value); - $("#fake_Publishend") - .val(pubDate.toLocaleDateString(language)) - .removeClass("hidden"); - } - }).trigger("change"); -} +$(".datepicker_delete").click(function() { + var inputs = $(this).parent().siblings('input'); + $(inputs[0]).data('datepicker').clearDates(); + $(inputs[1]).addClass('hidden'); +}); /* diff --git a/cps/static/js/libs/plugins.js b/cps/static/js/libs/plugins.js index f69561a1..024f0b8c 100644 --- a/cps/static/js/libs/plugins.js +++ b/cps/static/js/libs/plugins.js @@ -1,8 +1,3 @@ -/* Function to select for custom build: form input types -/*! modernizr 3.6.0 (Custom Build) | MIT * - * https://modernizr.com/download/?-inputtypes-setclasses !*/ -!function(e,t,n){function a(e,t){return typeof e===t}function s(){var e,t,n,s,i,o,c;for(var u in r)if(r.hasOwnProperty(u)){if(e=[],t=r[u],t.name&&(e.push(t.name.toLowerCase()),t.options&&t.options.aliases&&t.options.aliases.length))for(n=0;nr;r++)p.setAttribute("type",a=e[r]),i="text"!==p.type&&"style"in p,i&&(p.value=l,p.style.cssText="position:absolute;visibility:hidden;",/^range$/.test(a)&&p.style.WebkitAppearance!==n?(u.appendChild(p),s=t.defaultView,i=s.getComputedStyle&&"textfield"!==s.getComputedStyle(p,null).WebkitAppearance&&0!==p.offsetHeight,u.removeChild(p)):/^(search|tel)$/.test(a)||(i=/^(url|email)$/.test(a)?p.checkValidity&&p.checkValidity()===!1:p.value!=l)),m[e[r]]=!!i;return m}(d),s(),i(l),delete c.addTest,delete c.addAsyncTest;for(var h=0;h {% endif %} {% endif %} -
- -
- - -
+ +
+ + + + +
@@ -150,15 +151,18 @@ {% endif %} {% if c.datatype == 'datetime' %} -
- + 0 %} value="{% if book['custom_column_' ~ c.id][0].value %}{{ book['custom_column_' ~ c.id][0].value|formatdateinput}}{% endif %}" {% endif %}> - 0 %} value="{% if book['custom_column_' ~ c.id][0].value %}{{book['custom_column_' ~ c.id][0].value|formatdate}}{% endif %}" {% endif %}> + + +
{% endif %} diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index efbf0159..b3d68cc3 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -18,16 +18,22 @@
-
- - +
+ + + + +
-
- - +
+ + + + +
@@ -170,17 +176,23 @@ {% if c.datatype == 'datetime' %}
- -
- - + +
+ + + + +
- -
- - + +
+ + + + +
diff --git a/cps/web.py b/cps/web.py index a207a948..78630315 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1274,10 +1274,18 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): column_start = term.get('custom_column_' + str(c.id) + '_start') column_end = term.get('custom_column_' + str(c.id) + '_end') if column_start: - searchterm.extend([u"{} >= {}".format(c.name, column_start)]) + searchterm.extend([u"{} >= {}".format(c.name, + format_date(datetime.strptime(column_start, "%Y-%m-%d"), + format='medium', + locale=get_locale()) + )]) cc_present = True if column_end: - searchterm.extend([u"{} <= {}".format(c.name, column_end)]) + searchterm.extend([u"{} <= {}".format(c.name, + format_date(datetime.strptime(column_end, "%Y-%m-%d").date(), + format='medium', + locale=get_locale()) + )]) cc_present = True elif term.get('custom_column_' + str(c.id)): searchterm.extend([(u"{}: {}".format(c.name, term.get('custom_column_' + str(c.id))))])