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;
|
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={};
|
|
|
|
}
|
2011-06-24 15:42:06 +02:00
|
|
|
if (!$type(this.params.time)) {
|
|
|
|
this.params.time = true;
|
2008-07-18 16:02:46 +02:00
|
|
|
}
|
2011-06-24 15:42:06 +02:00
|
|
|
if (!$type(this.params.manual)) {
|
|
|
|
this.params.manual = true;
|
2008-07-18 16:02:46 +02:00
|
|
|
}
|
2011-06-24 15:42:06 +02:00
|
|
|
|
|
|
|
if (!$type(this.params.style)) {
|
|
|
|
this.params.style = 'dashboard';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$type(this.params.format)) {
|
|
|
|
if (this.params.time) {
|
|
|
|
this.params.format = "%d/%m/%Y, %H:%M:%S";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.params.format = "%d/%m/%Y";
|
|
|
|
}
|
|
|
|
}
|
2011-06-24 17:32:38 +02:00
|
|
|
Date.defineParser(this.params.format);
|
2011-06-24 15:42:06 +02:00
|
|
|
|
|
|
|
this.calendar = new DatePicker(this.input, {
|
|
|
|
format: this.params.format,
|
|
|
|
timePicker: this.params.time,
|
|
|
|
pickerClass: 'datepicker_'+this.params.style,
|
|
|
|
blockKeydown: (!this.params.manual),
|
|
|
|
useFadeInOut: !Browser.ie
|
|
|
|
}
|
2008-07-18 16:02:46 +02:00
|
|
|
);
|
2011-06-24 15:42:06 +02:00
|
|
|
|
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));
|
2011-06-24 15:42:06 +02:00
|
|
|
this.nowBtn.injectAfter(this.input);
|
2009-02-03 17:16:58 +01:00
|
|
|
varLSdefault.addHelpInfo(this.nowBtn,'LSformElement_date','now');
|
2011-06-27 15:48:54 +02:00
|
|
|
|
|
|
|
this.todayBtn = new Element('img');
|
|
|
|
this.todayBtn.src = varLSdefault.imagePath('calendar.png');
|
|
|
|
this.todayBtn.addClass('btn');
|
|
|
|
this.todayBtn.addEvent('click',this.onTodayBtnClick.bind(this));
|
|
|
|
this.todayBtn.injectAfter(this.nowBtn);
|
|
|
|
varLSdefault.addHelpInfo(this.todayBtn,'LSformElement_date','today');
|
2008-07-18 16:02:46 +02:00
|
|
|
},
|
|
|
|
|
2009-02-03 17:16:58 +01:00
|
|
|
onNowBtnClick: function() {
|
2011-06-24 15:42:06 +02:00
|
|
|
this.input.value = new Date().format(this.params.format);
|
2011-06-27 15:48:54 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onTodayBtnClick: function() {
|
|
|
|
if (this.input.value) {
|
|
|
|
var cur = Date.parse(this.input.value,this.params.format);
|
|
|
|
if (cur == null) {
|
|
|
|
var cur = Date.parse(this.input.value);
|
|
|
|
}
|
|
|
|
if (cur) {
|
|
|
|
var now = new Date();
|
|
|
|
var today = cur.clone();
|
|
|
|
today.set({
|
|
|
|
year: now.get('year'),
|
|
|
|
mo: now.get('mo'),
|
|
|
|
date: now.get('date')
|
|
|
|
});
|
|
|
|
this.input.value = today.format(this.params.format);
|
|
|
|
}
|
|
|
|
}
|
2011-06-24 15:42:06 +02:00
|
|
|
}
|
2008-07-18 16:02:46 +02:00
|
|
|
});
|