summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-05-21 15:16:11 +0200
committerYorhel <git@yorhel.nl>2009-05-21 15:19:28 +0200
commit1ee636e3a68f9d03509563e2a833e11ed332fccb (patch)
treebe76cbec5d0aee2ec86129f81171d9186f61a9a6 /static
parent94330e09f1ad42b1048e1192a1ac6d3580c2a3a7 (diff)
Implemented the date selector in JavaScript
This way, we can just use our internal database date format for client-side communication as well. The calculation is now done in a centralized place in script.js, rather than all over the place in the Perl code. This'll also make it possible to make the date selector more interactive. But that doesn't have a very high priority at the moment, the good old three-selection-boxes-thing works fine. Current implementation has only been tested on FF3, though I doubt other browsers will complain.
Diffstat (limited to 'static')
-rw-r--r--static/f/script.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/static/f/script.js b/static/f/script.js
index 9e87fd65..48002287 100644
--- a/static/f/script.js
+++ b/static/f/script.js
@@ -391,6 +391,40 @@ function tvsSet(lvl, lim) {
+/* date input */
+var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
+function dtLoad(obj) {
+ var r = Math.floor(obj.value) || 0;
+ var v = [ Math.floor(r/10000), Math.floor(r/100)%100, r%100 ];
+ var i;
+ r = '<select onchange="dtSerialize(this)" style="width: 70px"><option value="0">-year-</option>';
+ for(i=1980; i<=(new Date()).getFullYear()+5; i++)
+ r += '<option value="'+i+'"'+(i == v[0] ? ' selected="selected"':'')+'>'+i+'</option>';
+ r += '<option value="9999"'+(v[0] == 9999 ? ' selected="selected"':'')+'>TBA</option>';
+ r += '</select><select onchange="dtSerialize(this)" style="width: 100px"><option value="99">-month-</option>';
+ for(i=1; i<=12; i++)
+ r += '<option value="'+i+'"'+(i == v[1] ? ' selected="selected"':'')+'>'+months[i-1]+'</option>';
+ r += '</select><select onchange="dtSerialize(this)" style="width: 70px"><option value="99">-day-</option>';
+ for(i=1; i<=31; i++)
+ r += '<option value="'+i+'"'+(i == v[2] ? ' selected="selected"':'')+'>'+i+'</option>';
+ r += '</select>';
+ v = document.createElement('div');
+ v.obj = obj;
+ v.innerHTML = r;
+ obj.parentNode.insertBefore(v, obj);
+}
+function dtSerialize(obj) {
+ obj = obj.parentNode;
+ var l = obj.getElementsByTagName('select');
+ var v = [ l[0].options[l[0].selectedIndex].value*1, l[1].options[l[1].selectedIndex].value*1, l[2].options[l[2].selectedIndex].value*1 ];
+ obj = obj.obj;
+ if(v[0] == 0) obj.value = 0;
+ else if(v[0] == 9999) obj.value = 99999999;
+ else obj.value = v[0]*10000 + v[1]*100 + (v[1]==99?99:v[2]);
+}
+
+
+
/* O N L O A D E V E N T */
DOMLoad(function() {
@@ -580,6 +614,12 @@ DOMLoad(function() {
document.body.appendChild(d);
}
+ // date selector
+ l = document.getElementsByTagName('input');
+ for(i=0;i<l.length;i++)
+ if(l[i].className == 'dateinput')
+ dtLoad(l[i]);
+
// forms.js
if(x('relations'))
relLoad();