* Preferences: opening forced preferences set selectboxes for not set values to first real value not "Users Choice"

caused by etemplate_widget_menupopup not being run, it is now run by etemplate_new::exec / etemplate_new::fix_sel_options for everything in sel_options
This commit is contained in:
Ralf Becker 2014-09-30 14:27:29 +00:00
parent 648649e03f
commit 3e12e8f2f9
2 changed files with 33 additions and 9 deletions

View File

@ -109,7 +109,7 @@ class etemplate_new extends etemplate_widget_template
self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup
self::$request->content = self::$cont = $content;
self::$request->changes = $changes;
self::$request->sel_options = $sel_options ? $sel_options : array();
self::$request->sel_options = is_array($sel_options) ? self::fix_sel_options($sel_options) : array();
self::$request->readonlys = $readonlys ? $readonlys : array();
self::$request->preserv = $preserv ? $preserv : array();
self::$request->method = $method;
@ -233,6 +233,28 @@ class etemplate_new extends etemplate_widget_template
self::$request = null;
}
/**
* Fix all sel_options, as etemplate_widget_menupopup::beforeSendToClient is not run for auto-repeated stuff not understood by server
*
* @param array $sel_options
* @return array
*/
static protected function fix_sel_options(array $sel_options)
{
foreach($sel_options as &$options)
{
foreach($options as $key => $value)
{
if (is_numeric($key) && (!is_array($value) || !isset($value['value'])))
{
etemplate_widget_menupopup::fix_encoded_options($options, true);
break;
}
}
}
return $sel_options;
}
/**
* Process via Ajax submitted content
*

View File

@ -48,7 +48,7 @@ class etemplate_widget_menupopup extends etemplate_widget
* Reimplemented to parse our differnt attributes
*
* @param string|XMLReader $xml
* @param boolean $cloned=true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object
* @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object
* @return etemplate_widget_template current object or clone, if any attribute was set
* @todo Use legacy_attributes instead of leaving it to typeOptions method to parse them
*/
@ -212,6 +212,8 @@ class etemplate_widget_menupopup extends etemplate_widget
// typeOptions thinks # of rows is the first thing in options
($this->attrs['rows'] && strpos($this->attrs['options'], $this->attrs['rows']) !== 0 ? $this->attrs['rows'].','.$this->attrs['options'] : $this->attrs['options']),
$no_lang, $this->attrs['readonly'], self::get_array(self::$request->content, $form_name));
// need to run that here manually, automatic run through etemplate_new::exec() already happend
self::fix_encoded_options(self::$request->sel_options[$form_name]);
// if no_lang was modified, forward modification to the client
if ($no_lang != $this->attr['no_lang'])
@ -224,8 +226,6 @@ class etemplate_widget_menupopup extends etemplate_widget
$options = (self::$request->sel_options[$form_name] ? $form_name : $this->id);
if(is_array(self::$request->sel_options[$options]))
{
self::fix_encoded_options(self::$request->sel_options[$options]);
// 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)
{
@ -239,10 +239,12 @@ class etemplate_widget_menupopup extends etemplate_widget
}
/**
* Fix already html-encoded options, eg. "&nbps"
* Fix already html-encoded options, eg. "&nbps" AND optinal re-index array to keep order
*
* Get run automatic for everything in $sel_options by etemplate_new::exec / etemplate_new::fix_sel_options
*
* @param array $options
* @param boolean $use_array_of_options Re-indexes options, making everything more complicated
* @param boolean $use_array_of_objects Re-indexes options, making everything more complicated
*/
public static function fix_encoded_options(array &$options, $use_array_of_objects=null)
{
@ -303,7 +305,7 @@ class etemplate_widget_menupopup extends etemplate_widget
* Get options from $sel_options array for a given selectbox name
*
* @param string $name
* @param boolean $return_values=false true: return array with option values, instead of value => label pairs
* @param boolean $return_values =false true: return array with option values, instead of value => label pairs
* @return array
*/
public static function selOptions($name, $return_values=false)
@ -663,7 +665,7 @@ class etemplate_widget_menupopup extends etemplate_widget
/**
* Get available apps as options
*
* @param string $type2='installed' 'user'=apps of current user, 'enabled', 'installed' (default), 'all' = not installed ones too
* @param string $type2 ='installed' 'user'=apps of current user, 'enabled', 'installed' (default), 'all' = not installed ones too
* @return array app => label pairs sorted by label
*/
public static function app_options($type2)
@ -701,7 +703,7 @@ class etemplate_widget_menupopup extends etemplate_widget
* internal function to format account-data
*
* @param int $id
* @param array $acc=null optional values for keys account_(type|lid|lastname|firstname) to not read them again
* @param array $acc =null optional values for keys account_(type|lid|lastname|firstname) to not read them again
* @param int $longnames
* @param boolean $show_type true: return array with values for keys label and icon, false: only label
* @return string|array