disable tabs independent of using short or full name, eg. $readonlys["tabs"]["test"] = true works as well as $readonlys["tabs"]["app.something.test"] = true

This commit is contained in:
Ralf Becker 2013-10-25 07:31:15 +00:00
parent acf0d0fc3f
commit 3c5c33dba8

View File

@ -0,0 +1,232 @@
<?php
/**
* eGroupWare - eTemplate Extension - Tab Widget
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage extensions
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker@outdoor-training.de>
* @version $Id$
*/
/**
* eTemplate Extension: widget that shows one row of tabs and an other row with the eTemplate of the selected tab
*
* See the example in 'etemplate.tab_widget.test'
*
* This widget is independent of the UI as it only uses etemplate-widgets and has therefor no render-function
*/
class tab_widget
{
/**
* exported methods of this class
* @var array
*/
var $public_functions = array(
'pre_process' => True,
'post_process' => True,
'noReadonlysALL' => true, // mark extension as not to set readonly for $readonlys['__ALL__']
);
/**
* availible extensions and there names for the editor
* @var string
*/
var $human_name = 'Tabs'; // this is the name for the editor
/**
* Constructor of the extension
*
* @param string $ui '' for html
*/
function tab_widget($ui)
{
}
/**
* pre-processing of the extension
*
* This function is called before the extension gets rendered
*
* @param string $name form-name of the control
* @param mixed &$value value / existing content, can be modified
* @param array &$cell array with the widget, can be modified for ui-independent widgets
* @param array &$readonlys names of widgets as key, to be made readonly
* @param mixed &$extension_data data the extension can store persisten between pre- and post-process
* @param etemplate &$tmpl reference to the template we belong too
* @return boolean true if extra label is allowed, false otherwise
*/
function pre_process($form_name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
{
//echo "<p>tab_widget::pre_process('$form_name',".array2string($value).','.array2string($readonlys).','.array2string($extension_data).")</p>\n";
if (!$cell['onchange']) // onchange allows to use the old behavior (submit for each new tab)
{
$dom_enabled = true;
}
$labels = explode('|',$cell['label']);
$helps = explode('|',$cell['help']);
if (strpos($cell_name=$tab_names=$cell['name'],'=') !== false)
{
list($cell_name,$tab_names) = explode('=',$cell['name']);
$cell['name'] = $cell_name;
}
$names = explode('|',$tab_names);
// disable tab mentioned in readonlys
foreach(is_array($readonlys) ? $readonlys : array($readonlys => true) as $name => $disable)
{
// check full name AND last component name
if (strpos($name, '.') === false)
{
$name2 = $tmpl->name.'.'.$name;
}
else
{
$nparts = explode('.', $name);
$name2 = array_pop($nparts);
}
if ($name && $disable && (($key = array_search($name, $names)) !== false ||
($key = array_search($name2, $names)) !== false))
{
unset($names[$key]);
$names = array_values($names);
unset($helps[$key]);
$helps = array_values($helps);
unset($labels[$key]);
$labels = array_values($labels);
}
}
$all_names = implode('|',$names);
$tab_widget = new etemplate('etemplate.tab_widget');
$tab_widget->no_onclick = true;
if ($value && strpos($value,'.') === false)
{
$value = $tmpl->name . '.' . $value;
}
foreach($names as $k => $name)
{
if (strpos($name,'.') === false)
{
$name = $names[$k] = $tmpl->name . '.' . $name;
}
if ($value == $name)
{
$selected_tab = $name;
}
}
if (empty($selected_tab))
{
$value = $selected_tab = $names[0];
}
$extension_data = $value; // remember the active tab in the extension_data
foreach($names as $k => $name)
{
if (strpos($name,'.') === false)
{
$name = $names[$k] = $tmpl->name . '.' . $name;
}
$tcell =& $tab_widget->empty_cell();
if ($value == $name)
{
$tcell['span'] = ',etemplate_tab_active';
}
else
{
$tcell['span'] = ',etemplate_tab';
}
if ($dom_enabled)
{
$tcell['onclick'] = "activate_tab('$name','$all_names','$form_name');";
$tcell['id'] = $name.'-tab';
}
elseif ($value != $name)
{
$tcell['type'] = 'button';
$tcell['onchange'] = '1';
$tcell['name'] = $cell_name.'['.$name.']';
}
$tcell['label'] = $labels[$k];
$tcell['help'] = $helps[$k];
$tab_widget->set_cell_attribute('tabs',1+$k,$tcell);
}
$tab_widget->set_cell_attribute('tabs','type','hbox');
$tab_widget->set_cell_attribute('tabs','size',count($names));
$tab_widget->set_cell_attribute('tabs','name','');
if ($dom_enabled)
{
foreach($names as $n => $name)
{
$bcell = $tab_widget->empty_cell('template',$name);
$bcell['obj'] = new etemplate($name,$tmpl->as_array());
$tab_widget->set_cell_attribute('body',$n+1,$bcell);
}
$tab_widget->set_cell_attribute('body','type','deck');
$tab_widget->set_cell_attribute('body','size',count($names));
$tab_widget->set_cell_attribute('body','span',',tab_body');
$tab_widget->set_cell_attribute('body','name',$cell_name);
}
else
{
$stab = new etemplate($selected_tab,$tmpl->as_array());
$tab_widget->set_cell_attribute('body','type','template');
$tab_widget->set_cell_attribute('body','size',''); // the deck has a '1' there
$tab_widget->set_cell_attribute('body','obj',$stab);
}
$tab_widget->set_cell_attribute('body','name',$selected_tab);
$cell['type'] = 'template';
$cell['obj'] = &$tab_widget;
$cell['label'] = $cell['help'] = '';
return False; // NO extra Label
}
/**
* postprocessing method, called after the submission of the form
*
* It has to copy the allowed/valid data from $value_in to $value, otherwise the widget
* will return no data (if it has a preprocessing method). The framework insures that
* the post-processing of all contained widget has been done before.
*
* Only used by select-dow so far
*
* @param string $name form-name of the widget
* @param mixed &$value the extension returns here it's input, if there's any
* @param mixed &$extension_data persistent storage between calls or pre- and post-process
* @param boolean &$loop can be set to true to request a re-submision of the form/dialog
* @param object &$tmpl the eTemplate the widget belongs too
* @param mixed &value_in the posted values (already striped of magic-quotes)
* @return boolean true if $value has valid content, on false no content will be returned!
*/
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
{
//echo "<p>tab_widget::post_process($name): value_in = "; _debug_array($value_in);
if (is_array($value_in))
{
foreach ($value_in as $tab => $button_pressed)
{
if ($button_pressed)
{
$value = $tab;
$loop = True;
}
}
}
else
{
$value = $value_in;
}
// if value not set (other button pressed), set the value we remembered in the extension_data
if (!$value)
{
$value = $extension_data;
}
return True;
}
}