summaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--static/js/kosten.js29
-rw-r--r--static/js/kosten.ls33
2 files changed, 57 insertions, 5 deletions
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();
diff --git a/static/js/kosten.ls b/static/js/kosten.ls
index e3a60d2..163d670 100644
--- a/static/js/kosten.ls
+++ b/static/js/kosten.ls
@@ -1,6 +1,12 @@
jQuery.fn.extend do
copy : -> @clone!remove-attr 'id class'
+String::splitAt = (pos) -> return
+ @slice 0 pos
+ @slice pos
+
+Date::format = -> $.datepicker.formatDate \dd.mm.yy @
+
jq = (f) -> !-> $ f
# Call this to localize Highcharts
@@ -20,6 +26,25 @@ set-lang = !->
range-selector-to: \bis
range-selector-zoom: null
+extend-date = (input) !->
+ if input.val! is //^
+ ([12][0-9]|3[01]|0?[1-9]) # day
+ (?:
+ (0?[1-9]|1[0-2]) # month
+ ((?:20)?[0-9][0-9])? # year
+ )?
+ $//
+ then
+ now = new Date!
+ [_, day, month, year] = that
+ year ?= now.get-full-year!
+ month ?= now.get-month! + 1
+
+ year = "20" + year unless year > 99
+
+ new Date year, month - 1, day .format! |> input.val
+
+
# The Search Stuff
$ !->
$ \form.search .hide!
@@ -34,9 +59,11 @@ $ !->
# Add
export addJS = jq !->
- $ 'input[name=date]' .datepicker do
- date-format: \dd.mm.yy
- first-day: 1
+ $ 'input[name=date]'
+ .. .datepicker do
+ date-format: \dd.mm.yy
+ first-day: 1
+ .. .blur !-> extend-date ..
# Show
export showJS = jq !->