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
|
|
|
}
|
2017-10-12 14:58:31 +02:00
|
|
|
if (!$type(this.params.showNowButton)) {
|
|
|
|
this.params.showNowButton = true;
|
|
|
|
}
|
|
|
|
if (!$type(this.params.showTodayButton)) {
|
|
|
|
this.params.showNowButton = true;
|
|
|
|
}
|
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
|
|
|
|
2017-10-12 14:58:31 +02:00
|
|
|
if (this.params.showNowButton) {
|
|
|
|
this.nowBtn = new Element('img');
|
|
|
|
this.nowBtn.src = varLSdefault.imagePath('now');
|
|
|
|
this.nowBtn.addClass('btn');
|
|
|
|
this.nowBtn.addEvent('click',this.onNowBtnClick.bind(this));
|
|
|
|
this.nowBtn.injectAfter(this.input);
|
|
|
|
varLSdefault.addHelpInfo(this.nowBtn,'LSformElement_date','now');
|
|
|
|
}
|
2011-06-27 15:48:54 +02:00
|
|
|
|
2017-10-12 14:58:31 +02:00
|
|
|
if (this.params.showTodayButton) {
|
|
|
|
this.todayBtn = new Element('img');
|
|
|
|
this.todayBtn.src = varLSdefault.imagePath('calendar');
|
|
|
|
this.todayBtn.addClass('btn');
|
|
|
|
this.todayBtn.addEvent('click',this.onTodayBtnClick.bind(this));
|
|
|
|
if (!$type(this.nowBtn)) {
|
|
|
|
this.todayBtn.injectAfter(this.input);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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
|
|
|
});
|