Stop error on invalid format, use a default

This commit is contained in:
Nathan Gray 2012-03-30 14:30:26 +00:00
parent fc981118c1
commit 26f5f2e504

View File

@ -234,6 +234,13 @@ var et2_date_duration = et2_date.extend({
this.options.display_format = this.options.display_format.replace("%",""); this.options.display_format = this.options.display_format.replace("%","");
} }
// Clean formats
this.options.display_format = this.options.display_format.replace(/[^dhm]/,'');
if(!this.options.display_format)
{
this.options.display_format = this.attributes.display_format["default"];
}
// Get translations // Get translations
this.time_formats = { this.time_formats = {
"d": this.options.short_labels ? this.egw().lang("m") : this.egw().lang("Days"), "d": this.options.short_labels ? this.egw().lang("m") : this.egw().lang("Days"),
@ -257,8 +264,14 @@ var et2_date_duration = et2_date.extend({
for(var i = 0; i < this.options.display_format.length; i++) { for(var i = 0; i < this.options.display_format.length; i++) {
this.format.append("<option value='"+this.options.display_format[i]+"'>"+this.time_formats[this.options.display_format[i]]+"</option>"); this.format.append("<option value='"+this.options.display_format[i]+"'>"+this.time_formats[this.options.display_format[i]]+"</option>");
} }
} else { }
this.format = $j(document.createElement("<span>"+this.time_formats[this.options.display_format])+"</span>").appendTo(this.node); else if (this.time_formats[this.options.display_format])
{
this.format = $j("<span>"+this.time_formats[this.options.display_format]+"</span>").appendTo(this.node);
}
else
{
this.format = $j("<span>"+this.time_formats["m"]+"</span>").appendTo(this.node);
} }
}, },
attachToDOM: function() { attachToDOM: function() {
@ -315,7 +328,7 @@ var et2_date_duration = et2_date.extend({
// Set unit as figured for display // Set unit as figured for display
if(display.unit != this.options.display_format) if(display.unit != this.options.display_format)
{ {
if(this.format.children().length > 1) { if(this.format && this.format.children().length > 1) {
$j("option[value='"+display.unit+"']",this.format).attr('selected','selected'); $j("option[value='"+display.unit+"']",this.format).attr('selected','selected');
} }
else else