mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-05 04:49:44 +01:00
Set customfields "date" and "date-time" widgets value correctly when they get initiated by storage value
This commit is contained in:
parent
82e259c407
commit
b6e2460e91
@ -35,8 +35,9 @@ var et2_date = et2_inputWidget.extend(
|
|||||||
"ignore": false
|
"ignore": false
|
||||||
},
|
},
|
||||||
"data_format": {
|
"data_format": {
|
||||||
"ignore": true,
|
"ignore": false,
|
||||||
"description": "Format data is in. This is not used client-side because it's always a timestamp client side."
|
"description": "Date/Time format. Can be set as an options to date widget",
|
||||||
|
"default": ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ var et2_date = et2_inputWidget.extend(
|
|||||||
this.createInputWidget();
|
this.createInputWidget();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
set_value: function(_value) {
|
set_value: function(_value) {
|
||||||
var old_value = this.getValue();
|
var old_value = this.getValue();
|
||||||
if(_value === null || _value === "" || _value === undefined ||
|
if(_value === null || _value === "" || _value === undefined ||
|
||||||
@ -121,7 +122,8 @@ var et2_date = et2_inputWidget.extend(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle just time as a string in the form H:i
|
// Handle just time as a string in the form H:i
|
||||||
if(typeof _value == 'string' && isNaN(_value)) {
|
if(typeof _value == 'string' && isNaN(_value))
|
||||||
|
{
|
||||||
// silently fix skiped minutes or times with just one digit, as parser is quite pedantic ;-)
|
// silently fix skiped minutes or times with just one digit, as parser is quite pedantic ;-)
|
||||||
var fix_reg = new RegExp((this._type == "date-timeonly"?'^':' ')+'([0-9]+)(:[0-9]*)?( ?(a|p)m?)?$','i');
|
var fix_reg = new RegExp((this._type == "date-timeonly"?'^':' ')+'([0-9]+)(:[0-9]*)?( ?(a|p)m?)?$','i');
|
||||||
var matches = _value.match(fix_reg);
|
var matches = _value.match(fix_reg);
|
||||||
@ -134,37 +136,56 @@ var et2_date = et2_inputWidget.extend(
|
|||||||
_value = _value.replace(fix_reg, (this._type == "date-timeonly"?'':' ')+matches[1]+matches[2]+matches[3]);
|
_value = _value.replace(fix_reg, (this._type == "date-timeonly"?'':' ')+matches[1]+matches[2]+matches[3]);
|
||||||
if (matches[4] !== undefined) matches[3] = matches[4].toLowerCase() == 'a' ? 'am' : 'pm';
|
if (matches[4] !== undefined) matches[3] = matches[4].toLowerCase() == 'a' ? 'am' : 'pm';
|
||||||
}
|
}
|
||||||
if(this._type == "date-timeonly") {
|
switch(this._type)
|
||||||
var parsed = jQuery.datepicker.parseTime(this.input_date.datepicker('option', 'timeFormat'), _value);
|
{
|
||||||
if (!parsed) // parseTime returns false
|
case "date-timeonly":
|
||||||
{
|
var parsed = jQuery.datepicker.parseTime(this.input_date.datepicker('option', 'timeFormat'), _value);
|
||||||
this.set_validation_error(this.egw().lang("'%1' has an invalid format !!!",_value));
|
if (!parsed) // parseTime returns false
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.set_validation_error(false);
|
|
||||||
this.date.setHours(parsed.hour);
|
|
||||||
this.date.setMinutes(parsed.minute);
|
|
||||||
if(old_value !== this.getValue())
|
|
||||||
{
|
|
||||||
this.input_date.timepicker('setTime',_value);
|
|
||||||
if (this._oldValue !== et2_no_init)
|
|
||||||
{
|
{
|
||||||
this.change(this.input_date);
|
this.set_validation_error(this.egw().lang("'%1' has an invalid format !!!",_value));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this._oldValue = _value;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
try { // parseDateTime throws exception
|
|
||||||
var parsed = jQuery.datepicker.parseDateTime(this.input_date.datepicker('option', 'dateFormat'),
|
|
||||||
this.input_date.datepicker('option', 'timeFormat'), _value);
|
|
||||||
this.date = new Date(parsed);
|
|
||||||
this.set_validation_error(false);
|
this.set_validation_error(false);
|
||||||
}
|
this.date.setHours(parsed.hour);
|
||||||
catch(e) {
|
this.date.setMinutes(parsed.minute);
|
||||||
this.set_validation_error(this.egw().lang("'%1' has an invalid format !!!",_value));
|
if(old_value !== this.getValue())
|
||||||
|
{
|
||||||
|
this.input_date.timepicker('setTime',_value);
|
||||||
|
if (this._oldValue !== et2_no_init)
|
||||||
|
{
|
||||||
|
this.change(this.input_date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._oldValue = _value;
|
||||||
return;
|
return;
|
||||||
}
|
default:
|
||||||
|
if (this.id.match(/^#/g) && this.options.value == _value) // Parse customfields's date with storage data_format to date object
|
||||||
|
{
|
||||||
|
switch (this._type)
|
||||||
|
{
|
||||||
|
case 'date':
|
||||||
|
var parsed = jQuery.datepicker.parseDate(this.egw().dateTimeFormat(this.options.data_format), _value);
|
||||||
|
break;
|
||||||
|
case 'date-time':
|
||||||
|
var DTformat = this.options.data_format.split(' ');
|
||||||
|
var parsed = jQuery.datepicker.parseDateTime(this.egw().dateTimeFormat(DTformat[0]),this.egw().dateTimeFormat(DTformat[1]), _value);
|
||||||
|
}
|
||||||
|
this.date = new Date(parsed);
|
||||||
|
}
|
||||||
|
else if(!jQuery.isEmptyObject(this._oldValue)) // Parse other date widgets date with timepicker date/time format to date onject
|
||||||
|
{
|
||||||
|
var parsed = jQuery.datepicker.parseDateTime(this.input_date.datepicker('option', 'dateFormat'),
|
||||||
|
this.input_date.datepicker('option', 'timeFormat'), _value);
|
||||||
|
if(!parsed)
|
||||||
|
{
|
||||||
|
this.set_validation_error(this.egw().lang("%1' han an invalid format !!!",_value));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.date = new Date(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.set_validation_error(false);
|
||||||
}
|
}
|
||||||
} else if (typeof _value == 'object' && _value.date) {
|
} else if (typeof _value == 'object' && _value.date) {
|
||||||
this.date = _value.date;
|
this.date = _value.date;
|
||||||
|
Loading…
Reference in New Issue
Block a user