2008-07-18 16:02:46 +02:00
|
|
|
var LSformElement_date_field = new Class({
|
2008-10-16 17:00:21 +02:00
|
|
|
initialize: function(name,input){
|
|
|
|
this.name = name;
|
|
|
|
this.input = input;
|
|
|
|
this.calendarBtn = new Element('img');
|
|
|
|
this.calendarBtn.src = varLSdefault.imagePath('calendar.png');
|
|
|
|
this.calendarBtn.addClass('btn');
|
2008-07-18 16:02:46 +02:00
|
|
|
this.calendarBtn.addEvent('click',this.onCalendarBtnClick.bind(this));
|
2008-10-16 17:00:21 +02:00
|
|
|
this.calendarBtn.injectAfter(this.input);
|
2008-11-10 03:32:18 +01:00
|
|
|
varLSdefault.addHelpInfo(this.calendarBtn,'LSformElement_date','calendar');
|
2008-07-18 16:02:46 +02:00
|
|
|
|
2008-10-16 17:00:21 +02:00
|
|
|
this.params = varLSdefault.LSjsConfig[this.name];
|
2008-07-18 16:02:46 +02:00
|
|
|
if (!$type(this.params)) {
|
|
|
|
this.params={};
|
|
|
|
}
|
|
|
|
if (!$type(this.params.format)) {
|
|
|
|
this.params.format = "%d/%m/%Y, %H:%M:%S";
|
|
|
|
}
|
|
|
|
if (!$type(this.params.firstDayOfWeek)) {
|
|
|
|
this.params.firstDayOfWeek=0;
|
|
|
|
}
|
|
|
|
|
2009-04-14 17:21:17 +02:00
|
|
|
this.firstInputClick = 1;
|
|
|
|
this.input.addEvent('click',this.onInputClick.bind(this));
|
2008-07-18 16:02:46 +02:00
|
|
|
|
|
|
|
this.date = Date.parseDate(this.input.value,this.params.format);
|
|
|
|
|
|
|
|
this.calendar = new Calendar(
|
|
|
|
this.params.firstDayOfWeek,
|
|
|
|
this.date,
|
|
|
|
this.onChangeCalendar.bind(this),
|
|
|
|
this.onCloseCalendar.bind(this)
|
|
|
|
);
|
|
|
|
this.calendar.setDateFormat(this.params.format);
|
|
|
|
this.calendar.showsTime = true;
|
|
|
|
this.calendar.create();
|
2009-02-03 17:16:58 +01:00
|
|
|
|
|
|
|
this.nowBtn = new Element('img');
|
|
|
|
this.nowBtn.src = varLSdefault.imagePath('now.png');
|
|
|
|
this.nowBtn.addClass('btn');
|
|
|
|
this.nowBtn.addEvent('click',this.onNowBtnClick.bind(this));
|
|
|
|
this.nowBtn.injectAfter(this.calendarBtn);
|
|
|
|
varLSdefault.addHelpInfo(this.nowBtn,'LSformElement_date','now');
|
2008-07-18 16:02:46 +02:00
|
|
|
},
|
|
|
|
|
2009-04-14 17:21:17 +02:00
|
|
|
onInputClick: function() {
|
|
|
|
if(this.firstInputClick==1) {
|
|
|
|
this.toogle();
|
|
|
|
this.firstInputClick=0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-07-18 16:02:46 +02:00
|
|
|
onCalendarBtnClick: function() {
|
2009-04-14 17:21:17 +02:00
|
|
|
this.toogle();
|
|
|
|
},
|
|
|
|
|
|
|
|
open: function() {
|
|
|
|
this.opened = 1;
|
2008-07-18 16:02:46 +02:00
|
|
|
this.calendar.showAtElement(this.calendarBtn);
|
|
|
|
},
|
|
|
|
|
2009-04-14 17:21:17 +02:00
|
|
|
close: function() {
|
|
|
|
this.opened = 0;
|
|
|
|
this.calendar.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
toogle: function() {
|
|
|
|
if (this.opened) {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-07-18 16:02:46 +02:00
|
|
|
onChangeCalendar: function(calendar, date) {
|
|
|
|
this.input.value = date;
|
|
|
|
},
|
|
|
|
|
|
|
|
onCloseCalendar: function() {
|
2009-04-14 17:21:17 +02:00
|
|
|
this.close();
|
2009-02-03 17:16:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onNowBtnClick: function() {
|
|
|
|
this.input.value = new Date().print(this.params.format);
|
|
|
|
},
|
2008-07-18 16:02:46 +02:00
|
|
|
});
|