LSformElement_date : Fixed parsing date problem with some formats
[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.png');
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     
48     onNowBtnClick: function() {
49       this.input.value = new Date().format(this.params.format);
50     }
51 });