From: Janusz Dobrowolski Date: Sat, 14 Jul 2012 20:18:50 +0000 (+0200) Subject: Improved date input fields keyboard support (fast day/day+month edition) X-Git-Tag: 2.3-final~438 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=3a179c3c7d947efea18c1fb381b48d293b162499;hp=2365132e0607eddcc648ad3b9e4a051689f1c7ca;p=fa-stable.git Improved date input fields keyboard support (fast day/day+month edition) --- diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index ace6aa3f..0ffa0247 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -37,6 +37,7 @@ function find_submit($prefix, $numeric=true) } return $numeric ? -1 : null; } + //------------------------------------------------------------------------------ // // Helper function for simple db table editor pages @@ -633,15 +634,14 @@ function date_cells($label, $name, $title = null, $check=null, $inc_days=0, echo ""; - $class = $submit_on_change ? 'class="searchbox"' : ''; + $class = $submit_on_change ? 'date active' : 'date'; $aspect = $check ? 'aspect="cdate"' : ''; if ($check && (get_post($name) != Today())) $aspect .= ' style="color:#FF0000"'; default_focus($name); - - echo " $post_label"; echo "\n"; diff --git a/js/inserts.js b/js/inserts.js index 0db3c714..2e706fb5 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -207,6 +207,57 @@ function passBack(value) { close(); } +/* + Normalize date format using previous input value to guess missing date elements. + Helps fast date input field change with only single or double numbers (for day or day-and-month fragments) +*/ +function fix_date(date, last) +{ + var regex = /(\d+)[^\d]*(\d+)*[^\d]*(\d+)*/; + var dat = regex.exec(last); + var cur = regex.exec(date); + var day, month, year; + +// TODO: user.date as default? +// TODO: user.datesys + if (!dat || !cur) return date; + + if (cur[3] != undefined) // full date entered + dat = cur; + + if (user.datefmt == 0) // set defaults + { + day = dat[2]; month = dat[1]; year = dat[3]; + } else if (user.datefmt == 1) + { + day = dat[1]; month = dat[2]; year = dat[3]; + } else { + day = dat[3]; month = dat[2]; year = dat[1]; + } + + if (cur[2] == undefined) // only day entred + day = cur[1]; + else // day + month + if (cur[2] != undefined) + { + if (user.datefmt==1) + { day = cur[1]; month = cur[2] } + else + { day = cur[2]; month = cur[1] } + } + + if (day<10) day = '0'+parseInt(day, 10); + if (month<10) month = '0'+parseInt(month, 10); + if (year<100) year = year<60 ? (2000+parseInt(year,10)) : (1900+parseInt(year,10)); + +// console.info(day,month,year) + if (user.datefmt == 0) + return month+user.datesep+day+user.datesep+year; + if (user.datefmt == 1) + return day+user.datesep+month+user.datesep+year; + return year+user.datesep+month+user.datesep+day; +} + /* Behaviour definitions */ @@ -299,6 +350,20 @@ var inserts = { } } }, + '.date': + function(e) { + e.setAttribute('_last_val', e.value); + e.setAttribute('autocomplete', 'off'); + e.onblur = function() { + var val = this.getAttribute('_last_val'); + if (val != this.value) { + this.value = fix_date(this.value, val); + this.setAttribute('_last_val', this.value); + if (e.className.match(/\bactive\b/)) + JsHttpRequest.request('_'+this.name+'_changed', this.form); + } + } + }, 'button[aspect*selector], button[aspect*abort], input[aspect*selector]': function(e) { e.onclick = function() { passBack(this.getAttribute('rel'));