2013-05-10 22:39:12 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware - eTemplate serverside Tabs widget
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright 2013 Nathan Gray
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eTemplate Tabs widget stacks multiple sub-templates and lets you switch between them
|
2014-03-18 12:01:46 +01:00
|
|
|
*
|
|
|
|
* Available attributes:
|
|
|
|
* - add_tabs: true: tabs contain addtional tabs, false: tabs replace tabs in template
|
|
|
|
* - tabs: array with (additional) tabs with values for following keys
|
|
|
|
* + label: label of tab
|
|
|
|
* + template: template name with optional '?'.filemtime as cache-buster
|
|
|
|
* optional:
|
|
|
|
* + prepend: true prepend tab to existing ones, false (default) append tabs
|
|
|
|
* + hidden:
|
|
|
|
* + id: optinal namespace (content attribute of template)
|
2013-05-10 22:39:12 +02:00
|
|
|
*/
|
2013-06-11 20:59:34 +02:00
|
|
|
class etemplate_widget_tabbox extends etemplate_widget
|
2013-05-10 22:39:12 +02:00
|
|
|
{
|
2013-06-11 20:59:34 +02:00
|
|
|
/**
|
2014-07-22 23:26:03 +02:00
|
|
|
* Run a given method on all children
|
2013-12-12 21:15:36 +01:00
|
|
|
*
|
2014-07-22 23:26:03 +02:00
|
|
|
* Default implementation only calls method on itself and run on all children.
|
|
|
|
* Overridden here to apply readonlys for the tabbox to disabled on the tab
|
|
|
|
* content. This prevents running the method on disabled tabs.
|
|
|
|
*
|
|
|
|
* @param string $method_name
|
2016-02-03 16:20:50 +01:00
|
|
|
* @param array $params =array('') parameter(s) first parameter has to be the cname, second $expand!
|
|
|
|
* @param boolean $respect_disabled =false false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children
|
2013-12-12 21:15:36 +01:00
|
|
|
*/
|
2014-07-22 23:26:03 +02:00
|
|
|
public function run($method_name, $params=array(''), $respect_disabled=false)
|
2013-12-12 21:15:36 +01:00
|
|
|
{
|
2014-07-22 23:26:03 +02:00
|
|
|
// Make sure additional tabs are processed for any method
|
2014-09-06 12:00:42 +02:00
|
|
|
if($this->attrs['tabs'] && !$this->tabs_attr_evaluated)
|
2014-07-22 23:26:03 +02:00
|
|
|
{
|
2014-09-06 12:00:42 +02:00
|
|
|
$this->tabs_attr_evaluated = true; // we must not evaluate tabs attribte more then once!
|
|
|
|
|
2014-07-22 23:33:41 +02:00
|
|
|
// add_tabs toggles replacing or adding to existing tabs
|
|
|
|
if(!$this->attrs['add_tabs'])
|
|
|
|
{
|
|
|
|
$this->children[1]->children = array();
|
|
|
|
}
|
|
|
|
|
2016-02-03 16:20:50 +01:00
|
|
|
$this->tabs = array();
|
2014-07-22 23:33:41 +02:00
|
|
|
foreach($this->attrs['tabs'] as $tab)
|
|
|
|
{
|
|
|
|
$template= clone etemplate_widget_template::instance($tab['template']);
|
|
|
|
if($tab['id']) $template->attrs['content'] = $tab['id'];
|
|
|
|
$this->children[1]->children[] = $template;
|
2016-02-03 16:20:50 +01:00
|
|
|
$tab['url'] = etemplate_widget_template::rel2url($template->rel_path);
|
|
|
|
$this->tabs[] = $tab;
|
2014-07-22 23:33:41 +02:00
|
|
|
unset($template);
|
|
|
|
}
|
2014-07-22 23:26:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for disabled tabs set via readonly, and set them as disabled
|
|
|
|
$form_name = self::form_name($params[0], $this->id, $params[1]);
|
|
|
|
$readonlys = self::get_array(self::$request->readonlys, $form_name);
|
|
|
|
if($respect_disabled && $readonlys)
|
|
|
|
{
|
|
|
|
foreach($this->children[1]->children as $tab)
|
2013-06-11 20:59:34 +02:00
|
|
|
{
|
2016-02-03 16:20:50 +01:00
|
|
|
$parts = explode('.',$tab->template ? $tab->template : $tab->id);
|
|
|
|
$ro_id = array_pop($parts);
|
2014-07-22 23:26:03 +02:00
|
|
|
if($readonlys[$ro_id])
|
|
|
|
{
|
|
|
|
$tab->attrs['disabled'] = $readonlys[$ro_id];
|
|
|
|
}
|
2013-06-11 20:59:34 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-22 23:26:03 +02:00
|
|
|
|
|
|
|
// Tabs are set up now, continue as normal
|
|
|
|
parent::run($method_name, $params, $respect_disabled);
|
2013-06-11 20:59:34 +02:00
|
|
|
}
|
|
|
|
|
2016-02-03 16:20:50 +01:00
|
|
|
/**
|
|
|
|
* Implemented to send tab-urls incl. cache-buster and mobile template switch to client-side
|
|
|
|
*
|
|
|
|
* They are send as tab_urls object via modifications.
|
|
|
|
*
|
|
|
|
* @param string $cname
|
|
|
|
*/
|
|
|
|
public function beforeSendToClient($cname)
|
|
|
|
{
|
|
|
|
$form_name = self::form_name($cname, $this->id);
|
|
|
|
|
|
|
|
if (!empty($this->tabs))
|
|
|
|
{
|
|
|
|
self::setElementAttribute($form_name, 'tabs', $this->tabs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-10 22:39:12 +02:00
|
|
|
/**
|
|
|
|
* Validate input - just pass through, tabs doesn't care
|
|
|
|
*
|
|
|
|
* @param string $cname current namespace
|
|
|
|
* @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
|
|
|
|
* @param array $content
|
|
|
|
* @param array &$validated=array() validated content
|
|
|
|
* @param array $expand=array values for keys 'c', 'row', 'c_', 'row_', 'cont'
|
|
|
|
*/
|
|
|
|
public function validate($cname, array $expand, array $content, &$validated=array())
|
|
|
|
{
|
2013-07-17 11:38:37 +02:00
|
|
|
$form_name = self::form_name($cname, $this->id, $expand);
|
2013-11-12 17:38:23 +01:00
|
|
|
|
|
|
|
if (!empty($form_name))
|
2013-05-10 22:39:12 +02:00
|
|
|
{
|
|
|
|
$value = self::get_array($content, $form_name);
|
|
|
|
$valid =& self::get_array($validated, $form_name, true);
|
2014-09-06 12:00:42 +02:00
|
|
|
if (true) $valid = $value;
|
2013-05-10 22:39:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
etemplate_widget::registerWidget('etemplate_widget_tabbox', array('tabbox'));
|