Added image.php to permit fully dynamic image path
[ldapsaisie.git] / public_html / includes / js / LSformElement_date_field.js
1 var LSformElement_date_field = new Class({
2     initialize: function(name,input){
3       this.name = name;
4       this.input = input;
5       
6       this.params = varLSdefault.LSjsConfig[this.name];
7       if (!$type(this.params)) {
8         this.params={};
9       }
10       if (!$type(this.params.time)) {
11         this.params.time = true;
12       }
13       if (!$type(this.params.manual)) {
14         this.params.manual = true;
15       }
16
17       if (!$type(this.params.style)) {
18         this.params.style = 'dashboard';
19       }
20
21       if (!$type(this.params.format)) {
22         if (this.params.time) {
23           this.params.format = "%d/%m/%Y, %H:%M:%S";
24         }
25         else {
26           this.params.format = "%d/%m/%Y";
27         }
28       }
29       Date.defineParser(this.params.format);
30
31       this.calendar = new DatePicker(this.input, {
32           format: this.params.format,
33           timePicker: this.params.time,
34           pickerClass: 'datepicker_'+this.params.style,
35           blockKeydown: (!this.params.manual),
36           useFadeInOut: !Browser.ie
37         }
38       );
39
40       this.nowBtn = new Element('img');
41       this.nowBtn.src = varLSdefault.imagePath('now');
42       this.nowBtn.addClass('btn');
43       this.nowBtn.addEvent('click',this.onNowBtnClick.bind(this));
44       this.nowBtn.injectAfter(this.input);
45       varLSdefault.addHelpInfo(this.nowBtn,'LSformElement_date','now');
46
47       this.todayBtn = new Element('img');
48       this.todayBtn.src = varLSdefault.imagePath('calendar');
49       this.todayBtn.addClass('btn');
50       this.todayBtn.addEvent('click',this.onTodayBtnClick.bind(this));
51       this.todayBtn.injectAfter(this.nowBtn);
52       varLSdefault.addHelpInfo(this.todayBtn,'LSformElement_date','today');
53     },
54     
55     onNowBtnClick: function() {
56       this.input.value = new Date().format(this.params.format);
57     },
58
59     onTodayBtnClick: function() {
60       if (this.input.value) {
61         var cur = Date.parse(this.input.value,this.params.format);
62         if (cur == null) {
63           var cur = Date.parse(this.input.value);
64         }
65         if (cur) {
66           var now = new Date();
67           var today = cur.clone();
68           today.set({
69             year: now.get('year'),
70             mo: now.get('mo'),
71             date: now.get('date')
72           });
73           this.input.value = today.format(this.params.format);
74         }
75       }
76     }
77 });