* 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->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup
self::$request->content = self::$cont = $content; self::$request->content = self::$cont = $content;
self::$request->changes = $changes; 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->readonlys = $readonlys ? $readonlys : array();
self::$request->preserv = $preserv ? $preserv : array(); self::$request->preserv = $preserv ? $preserv : array();
self::$request->method = $method; self::$request->method = $method;
@ -233,6 +233,28 @@ class etemplate_new extends etemplate_widget_template
self::$request = null; 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 * Process via Ajax submitted content
* *

View File

@ -212,6 +212,8 @@ class etemplate_widget_menupopup extends etemplate_widget
// typeOptions thinks # of rows is the first thing in options // 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']), ($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)); $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 was modified, forward modification to the client
if ($no_lang != $this->attr['no_lang']) 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); $options = (self::$request->sel_options[$form_name] ? $form_name : $this->id);
if(is_array(self::$request->sel_options[$options])) 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) // 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) 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 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) public static function fix_encoded_options(array &$options, $use_array_of_objects=null)
{ {