forked from extern/egroupware
- no longer translating options on server-side
- sending evtl. necessary no_lang attribute via modifications to client - deprecated template->(get|set|disable)_cell(_attribute) in favor of new etemplate_widget::(get|set|disable)Element(Attribute) --> options via sel_options are currenlty not working on clientside
This commit is contained in:
parent
57767df461
commit
04aa3d35b9
@ -133,11 +133,11 @@ class etemplate_new extends etemplate_widget_template
|
||||
|
||||
$data = array(
|
||||
'etemplate_exec_id' => self::$request->id(),
|
||||
'app_header' => $GLOBALS['egw_info']['flags']['app_header'],
|
||||
'content' => $content,
|
||||
'app_header' => self::$request->app_header,
|
||||
'content' => self::$request->content,
|
||||
'sel_options' => self::$request->sel_options,
|
||||
'readonlys' => $readonlys,
|
||||
'modifications' => $this->modifications,
|
||||
'readonlys' => self::$request->readonlys,
|
||||
'modifications' => self::$request->modifications,
|
||||
'validation_errors' => self::$validation_errors,
|
||||
);
|
||||
if (self::$response) // call is within an ajax event / form submit
|
||||
@ -249,13 +249,6 @@ class etemplate_new extends etemplate_widget_template
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifications on the instancated template
|
||||
*
|
||||
* Get collected here to be send to the server
|
||||
*/
|
||||
protected $modifications = array();
|
||||
|
||||
/**
|
||||
* Returns reference to an attribute in a named cell
|
||||
*
|
||||
@ -265,12 +258,11 @@ class etemplate_new extends etemplate_widget_template
|
||||
* @param string $name cell-name
|
||||
* @param string $attr attribute-name
|
||||
* @return mixed reference to attribute, usually NULL
|
||||
* @deprecated use getElementAttribute($name, $attr)
|
||||
*/
|
||||
public function &get_cell_attribute($name,$attr)
|
||||
{
|
||||
error_log(__METHOD__."('$name', '$attr')");
|
||||
|
||||
return $this->modifications[$name][$attr];
|
||||
return self::getElementAttribute($name, $attr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,16 +271,12 @@ class etemplate_new extends etemplate_widget_template
|
||||
* @param string $name cell-name
|
||||
* @param string $attr attribute-name
|
||||
* @param mixed $val if not NULL sets attribute else returns it
|
||||
* @return mixed number of changed cells or False, if none changed
|
||||
* @return reference to attribute
|
||||
* @deprecated use setElementAttribute($name, $attr, $val)
|
||||
*/
|
||||
public function &set_cell_attribute($name,$attr,$val)
|
||||
{
|
||||
error_log(__METHOD__."('$name', '$attr', ".array2string($val).')');
|
||||
|
||||
$attr =& $this->get_cell_attribute($name, $attr);
|
||||
if (!is_null($val)) $attr = $val;
|
||||
|
||||
return $attr;
|
||||
return self::setElementAttribute($name, $attr, $val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -296,11 +284,12 @@ class etemplate_new extends etemplate_widget_template
|
||||
*
|
||||
* @param sting $name cell-name
|
||||
* @param boolean $disabled=true disable or enable a cell, default true=disable
|
||||
* @return mixed number of changed cells or False, if none changed
|
||||
* @return reference to attribute
|
||||
* @deprecated use disableElement($name, $disabled=true)
|
||||
*/
|
||||
public function disable_cells($name,$disabled=True)
|
||||
{
|
||||
return $this->set_cell_attribute($name,'disabled',$disabled);
|
||||
return self::disableElement($name, $disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -649,6 +649,51 @@ class etemplate_widget
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns reference to an attribute in a named cell
|
||||
*
|
||||
* Currently we always return a reference to an not set value, unless it was set before.
|
||||
* We do not return a reference to the actual cell, as it get's contructed on client-side!
|
||||
*
|
||||
* @param string $name cell-name
|
||||
* @param string $attr attribute-name
|
||||
* @return mixed reference to attribute, usually NULL
|
||||
*/
|
||||
public function &getElementAttribute($name, $attr)
|
||||
{
|
||||
error_log(__METHOD__."('$name', '$attr')");
|
||||
return self::$request->modifications[$name][$attr];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an attribute in a named cell if val is not NULL else return the attribute
|
||||
*
|
||||
* @param string $name cell-name
|
||||
* @param string $attr attribute-name
|
||||
* @param mixed $val if not NULL sets attribute else returns it
|
||||
* @return reference to attribute
|
||||
*/
|
||||
public function &setElementAttribute($name,$attr,$val)
|
||||
{
|
||||
$attr =& self::$request->modifications[$name][$attr];
|
||||
if (!is_null($val)) $attr = $val;
|
||||
|
||||
error_log(__METHOD__."('$name', '$attr', ".array2string($val).')');
|
||||
return $attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* disables all cells with name == $name
|
||||
*
|
||||
* @param sting $name cell-name
|
||||
* @param boolean $disabled=true disable or enable a cell, default true=disable
|
||||
* @return reference to attribute
|
||||
*/
|
||||
public function disableElement($name,$disabled=True)
|
||||
{
|
||||
return self::setElementAttribute($name, 'disabled', $disabled);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ class etemplate_widget_menupopup extends etemplate_widget
|
||||
}
|
||||
else*/
|
||||
{
|
||||
$allowed += self::selOptions($form_name, $this->attrs['no_lang']);
|
||||
$allowed += self::selOptions($form_name);
|
||||
}
|
||||
foreach((array) $value as $val)
|
||||
{
|
||||
@ -121,7 +121,14 @@ class etemplate_widget_menupopup extends etemplate_widget
|
||||
$form_name = self::form_name($cname, $this->id);
|
||||
// += to keep further options set by app code
|
||||
if (!is_array(self::$request->sel_options[$form_name])) self::$request->sel_options[$form_name] = array();
|
||||
self::$request->sel_options[$form_name] += (array)self::typeOptions($this->attrs['type'], $this->attrs['options']);
|
||||
self::$request->sel_options[$form_name] += self::typeOptions($this->attrs['type'], $this->attrs['options'],
|
||||
$no_lang, $this->attrs['readonly'], self::get_array(self::$request->content, $form_name));
|
||||
|
||||
// if no_lang was modified, forward modification to the client
|
||||
if ($no_lang != $this->attr['no_lang'])
|
||||
{
|
||||
self::setElementAttribute($form_name, 'no_lang', $no_lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,7 +139,7 @@ class etemplate_widget_menupopup extends etemplate_widget
|
||||
* @param boolean $no_lang=false value of no_lang attribute
|
||||
* @return array
|
||||
*/
|
||||
public static function selOptions($name, $no_lang=false)
|
||||
public static function selOptions($name)
|
||||
{
|
||||
$options = array();
|
||||
if (isset(self::$request->sel_options[$name]) && is_array(self::$request->sel_options[$name]))
|
||||
@ -159,10 +166,6 @@ class etemplate_widget_menupopup extends etemplate_widget
|
||||
{
|
||||
$options += self::$request->content['options-'.$name];
|
||||
}
|
||||
if (!$no_lang)
|
||||
{
|
||||
$options = self::translateOptions($options);
|
||||
}
|
||||
//error_log(__METHOD__."('$name') returning ".array2string($options));
|
||||
return $options;
|
||||
}
|
||||
@ -177,11 +180,12 @@ class etemplate_widget_menupopup extends etemplate_widget
|
||||
* @param mixed $value=null value for readonly
|
||||
* @return array with value => label pairs
|
||||
*/
|
||||
public static function typeOptions($widget_type, $legacy_options, $no_lang=false, $readonly=false, $value=null)
|
||||
public static function typeOptions($widget_type, $legacy_options, &$no_lang=false, $readonly=false, $value=null)
|
||||
{
|
||||
list($rows,$type,$type2,$type3,$type4,$type5,$type6) = explode(',',$legacy_options);
|
||||
|
||||
$no_lang = false;
|
||||
$options = array();
|
||||
switch ($widget_type)
|
||||
{
|
||||
case 'select-percent': // options: #row,decrement(default=10)
|
||||
@ -318,12 +322,6 @@ class etemplate_widget_menupopup extends etemplate_widget
|
||||
|
||||
case 'select-account': // options: #rows,{accounts(default)|both|groups|owngroups},{0(=lid)|1(default=name)|2(=lid+name),expand-multiselect-rows,not-to-show-accounts,...)}
|
||||
//echo "<p>select-account widget: name=$cell[name], type='$type', rows=$rows, readonly=".(int)($cell['readonly'] || $readonlys)."</p>\n";
|
||||
if($type == 'owngroups')
|
||||
{
|
||||
$type = 'groups';
|
||||
$owngroups = true;
|
||||
foreach($GLOBALS['egw']->accounts->membership() as $group) $mygroups[] = $group['account_id'];
|
||||
}
|
||||
// in case of readonly, we read/create only the needed entries, as reading accounts is expensive
|
||||
if ($readonly)
|
||||
{
|
||||
@ -336,6 +334,12 @@ class etemplate_widget_menupopup extends etemplate_widget
|
||||
}
|
||||
break;
|
||||
}
|
||||
if($type == 'owngroups')
|
||||
{
|
||||
$type = 'groups';
|
||||
$owngroups = true;
|
||||
foreach($GLOBALS['egw']->accounts->membership() as $group) $mygroups[] = $group['account_id'];
|
||||
}
|
||||
/* account-selection for hughe number of accounts
|
||||
if ($this->ui == 'html' && $type != 'groups') // use eGW's new account-selection (html only)
|
||||
{
|
||||
@ -568,34 +572,7 @@ class etemplate_widget_menupopup extends etemplate_widget
|
||||
unset($options['']);
|
||||
}
|
||||
|
||||
if (!$no_lang)
|
||||
{
|
||||
$options = self::translateOptions($options);
|
||||
}
|
||||
//error_log(__METHOD__."('$widget_type', '$legacy_options', ...) returning ".array2string($options));
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate options incl. optional title (label is an array with values for keys 'label' and optionally 'title'
|
||||
*
|
||||
* @param array $options
|
||||
* @return $options
|
||||
*/
|
||||
public static function translateOptions(array $options)
|
||||
{
|
||||
foreach($options as $value => &$label)
|
||||
{
|
||||
if (!is_array($label))
|
||||
{
|
||||
$label = lang($label);
|
||||
}
|
||||
else
|
||||
{
|
||||
$label['label'] = lang($label['label']);
|
||||
if (isset($label['title'])) $label['title'] = lang($label['title']);
|
||||
}
|
||||
}
|
||||
//error_log(__METHOD__."('$widget_type', '$legacy_options', no_lang=".array2string($no_lang).', readonly='.array2string($readonly).", value=$value) returning ".array2string($options));
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user