From 7963d41a8bef65205e7507b36c11383ce68298ed Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 19 Jan 2016 01:06:57 +0100 Subject: Allow to put in the date in short format --- static/js/kosten.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'static/js/kosten.js') diff --git a/static/js/kosten.js b/static/js/kosten.js index e2fa06a..a1c30fb 100644 --- a/static/js/kosten.js +++ b/static/js/kosten.js @@ -1,11 +1,17 @@ // Generated by LiveScript 1.2.0 (function(){ - var jq, setLang, addJS, showJS, statJS, catsJS, out$ = typeof exports != 'undefined' && exports || this; + var jq, setLang, extendDate, addJS, showJS, statJS, catsJS, out$ = typeof exports != 'undefined' && exports || this; jQuery.fn.extend({ copy: function(){ return this.clone().removeAttr('id class'); } }); + String.prototype.splitAt = function(pos){ + return [this.slice(0, pos), this.slice(pos)]; + }; + Date.prototype.format = function(){ + return $.datepicker.formatDate('dd.mm.yy', this); + }; jq = function(f){ return function(){ $(f); @@ -24,6 +30,20 @@ } }); }; + extendDate = function(input){ + var that, now, _, day, month, year; + if (that = /^([12][0-9]|3[01]|0?[1-9])(?:(0?[1-9]|1[0-2])((?:20)?[0-9][0-9])?)?$/.exec(input.val())) { + now = new Date(); + _ = that[0], day = that[1], month = that[2], year = that[3]; + year == null && (year = now.getFullYear()); + month == null && (month = now.getMonth() + 1); + if (!(year > 99)) { + year = "20" + year; + } + input.val( + new Date(year, month - 1, day).format()); + } + }; $(function(){ $('form.search').hide(); $('li.search').click(function(){ @@ -39,10 +59,15 @@ }); }); out$.addJS = addJS = jq(function(){ - $('input[name=date]').datepicker({ + var x$; + x$ = $('input[name=date]'); + x$.datepicker({ dateFormat: 'dd.mm.yy', firstDay: 1 }); + x$.blur(function(){ + extendDate(x$); + }); }); out$.showJS = showJS = jq(function(){ setLang(); -- cgit v1.2.3-54-g00ecf