only call replace on _value of type string, otherwise (eg. null) gives exception

This commit is contained in:
Ralf Becker 2013-02-05 08:55:09 +00:00
parent f2cdcefda1
commit 1312a397f1

View File

@ -298,12 +298,12 @@ var et2_date_duration = et2_date.extend({
}, },
attachToDOM: function() { attachToDOM: function() {
var node = this.getInputNode(); var node = this.getInputNode();
if (node) if (node)
{ {
$j(node).bind("change.et2_inputWidget", this, function(e) { $j(node).bind("change.et2_inputWidget", this, function(e) {
e.data.change(this); e.data.change(this);
}); });
} }
et2_DOMWidget.prototype.attachToDOM.apply(this, arguments); et2_DOMWidget.prototype.attachToDOM.apply(this, arguments);
}, },
getDOMNode: function() { getDOMNode: function() {
@ -319,18 +319,18 @@ var et2_date_duration = et2_date.extend({
set_id: function(_value) { set_id: function(_value) {
this.id = _value; this.id = _value;
var node = this.getDOMNode(this); var node = this.getDOMNode(this);
if (node) if (node)
{ {
if (_value != "") if (_value != "")
{ {
node.setAttribute("id", _value); node.setAttribute("id", _value);
} }
else else
{ {
node.removeAttribute("id"); node.removeAttribute("id");
} }
} }
}, },
set_value: function(_value) { set_value: function(_value) {
this.options.value = _value; this.options.value = _value;
@ -369,9 +369,9 @@ var et2_date_duration = et2_date.extend({
*/ */
_convert_to_display: function(_value) { _convert_to_display: function(_value) {
if (_value) if (_value)
{ {
// Put value into minutes for further processing // Put value into minutes for further processing
switch(this.options.data_format) switch(this.options.data_format)
{ {
case 'd': case 'd':
_value *= this.options.hours_per_day; _value *= this.options.hours_per_day;
@ -380,31 +380,31 @@ var et2_date_duration = et2_date.extend({
_value *= 60; _value *= 60;
break; break;
} }
} }
// Figure out best unit for display // Figure out best unit for display
var _unit = this.options.display_format == "d" ? "d" : "h"; var _unit = this.options.display_format == "d" ? "d" : "h";
if (this.options.data_format.indexOf('m') > -1 && _value && _value < 60) if (this.options.data_format.indexOf('m') > -1 && _value && _value < 60)
{ {
_unit = 'm'; _unit = 'm';
} }
else if (this.options.data_format.indexOf('d') > -1 && _value >= 60*this.options.hours_per_day) else if (this.options.data_format.indexOf('d') > -1 && _value >= 60*this.options.hours_per_day)
{ {
_unit = 'd'; _unit = 'd';
} }
_value = this.options.empty_not_0 && _value === '' || !this.options.empty_not_0 && !_value ? '' : _value = this.options.empty_not_0 && _value === '' || !this.options.empty_not_0 && !_value ? '' :
(_unit == 'm' ? parseInt( _value) : (Math.round((_value / 60.0 / (_unit == 'd' ? this.options.hours_per_day : 1))*100)/100)); (_unit == 'm' ? parseInt( _value) : (Math.round((_value / 60.0 / (_unit == 'd' ? this.options.hours_per_day : 1))*100)/100));
if(_value === '') _unit = ''; if(_value === '') _unit = '';
// use decimal separator from user prefs // use decimal separator from user prefs
var sep = '.'; var sep = '.';
var format = this.egw().preference('number_format'); var format = this.egw().preference('number_format');
if (format && (sep = format[0]) && sep != '.') if (typeof _value == 'string' && format && (sep = format[0]) && sep != '.')
{ {
_value = _value.replace('.',sep); _value = _value.replace('.',sep);
} }
return {value: _value, unit:_unit}; return {value: _value, unit:_unit};
}, },