Allow applications to add additional options to selectbox type options.

This commit is contained in:
Nathan Gray 2015-04-13 21:57:46 +00:00
parent f11804c5f5
commit 5cfd583904
3 changed files with 44 additions and 7 deletions

View File

@ -303,6 +303,12 @@ class etemplate_widget_menupopup extends etemplate_widget
$options = (isset(self::$request->sel_options[$form_name]) ? $form_name : $this->id);
if(is_array(self::$request->sel_options[$options]))
{
if(in_array($this->attrs['type'], self::$cached_types) && !isset($form_names_done[$options]))
{
// Fix any custom options from application
self::fix_encoded_options(self::$request->sel_options[$options],true);
$form_names_done[$options] = true;
}
// Turn on search, if there's a lot of rows (unless explicitly set)
if(!array_key_exists('search',$this->attrs) && count(self::$request->sel_options[$options]) >= self::SEARCH_ROW_LIMIT)
{

View File

@ -2399,7 +2399,7 @@ var et2_nextmatch_header_bar = et2_DOMWidget.extend(et2_INextmatchHeader,
}
// Legacy: Add in 'All' option for cat_id, if not provided.
if(name == 'cat_id' && options != null && (typeof options[''] == 'undefined' || typeof options[0] != 'undefined' && options[0].value != ''))
if(name == 'cat_id' && options != null && (typeof options[''] == 'undefined' && typeof options[0] != 'undefined' && options[0].value != ''))
{
widget_options.empty_label = this.egw().lang('All');
}

View File

@ -495,7 +495,9 @@ var et2_selectbox = et2_inputWidget.extend(
}
else
{
this.egw().debug("warn", "Tried to set value '%s' that isn't an option", _value, this);
var debug_value = _value;
if(debug_value === null) debug_value == 'NULL';
this.egw().debug("warn", "Tried to set value '%s' that isn't an option", debug_value, this);
}
return;
}
@ -527,7 +529,9 @@ var et2_selectbox = et2_inputWidget.extend(
{
if(jQuery("input[value='"+_value+"']", this.multiOptions).prop("checked", true).length == 0)
{
this.egw().debug("warn", "Tried to set value that isn't an option", this, _value);
var debug_value = _value;
if(debug_value === null) debug_value == 'NULL';
this.egw().debug("warn", "Tried to set value '%s' that isn't an option", debug_value, this);
}
}
@ -770,6 +774,7 @@ jQuery.extend(et2_selectbox,
{
var name_parts = widget.id.replace(/[/g,'[').replace(/]|]/g,'').split('[');
var type_options = [];
var content_options = {};
// First check type, there may be static options. There's some special handling
@ -780,12 +785,12 @@ jQuery.extend(et2_selectbox,
{
var old_type = widget._type;
widget._type = type;
content_options = this[type_function].call(this, widget, attrs);
type_options = this[type_function].call(this, widget, attrs);
widget._type = old_type;
}
// Try to find the options inside the "sel-options"
if(jQuery.isEmptyObject(content_options) && widget.getArrayMgr("sel_options"))
if(widget.getArrayMgr("sel_options"))
{
// Try first according to ID
content_options = widget.getArrayMgr("sel_options").getEntry(widget.id);
@ -875,6 +880,32 @@ jQuery.extend(et2_selectbox,
{
content_options = {};
}
// Include type options, preferring any content options
if(type_options.length || !jQuery.isEmptyObject(type_options))
{
for(var i in content_options)
{
var value = typeof content_options[i] == 'object' && typeof content_options[i].value !== 'undefined' ? content_options[i].value : i;
var added = false;
// Override any existing
for(var j in type_options)
{
if(type_options[j].value === value)
{
added = true;
type_options[j] = content_options[i];
break;
}
}
if(!added)
{
type_options.splice(i,0,content_options[i]);
}
}
content_options = type_options;
}
return content_options;
},
@ -1060,10 +1091,10 @@ jQuery.extend(et2_selectbox,
attrs.select_options = egw.window.et2_selectbox.type_cache[this.cache_id];
egw.window.setTimeout(jQuery.proxy(function() {
this.widget.set_select_options(egw.window.et2_selectbox.type_cache[this.cache_id]||{});
this.widget.set_select_options(et2_selectbox.find_select_options(this.widget,{}, this.widget.options));
},this),1);
},{widget:widget,cache_id:cache_id}));
return {};
return [];
}
else
{