2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Web\Widget;
|
|
|
|
|
|
|
|
use Icinga\Exception\ProgrammingError;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A single tab, usually used through the tabs widget
|
|
|
|
*
|
|
|
|
* Will generate an <li> list item, with an optional link and icon
|
|
|
|
*
|
|
|
|
* @property string $name Tab identifier
|
|
|
|
* @property string $title Tab title
|
|
|
|
* @property string $icon Icon URL, preferrably relative to the Icinga
|
|
|
|
* base URL
|
|
|
|
* @property string $url Action URL, preferrably relative to the Icinga
|
|
|
|
* base URL
|
|
|
|
* @property string $urlParams Action URL Parameters
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2013 Icinga-Web Team <info@icinga.org>
|
|
|
|
* @author Icinga-Web Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
|
|
|
|
*/
|
2013-08-06 18:00:33 +02:00
|
|
|
class Tab implements Widget
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Whether this tab is currently active
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
2013-08-06 18:00:33 +02:00
|
|
|
private $active = false;
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default values for widget properties
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-08-06 18:00:33 +02:00
|
|
|
private $name = null;
|
|
|
|
|
|
|
|
private $title = '';
|
|
|
|
private $url = null;
|
|
|
|
private $urlParams = array();
|
|
|
|
private $icon = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $icon
|
|
|
|
*/
|
|
|
|
public function setIcon($icon)
|
|
|
|
{
|
|
|
|
$this->icon = $icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return $this->icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $name
|
|
|
|
*/
|
|
|
|
public function setName($name)
|
|
|
|
{
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $title
|
|
|
|
*/
|
|
|
|
public function setTitle($title)
|
|
|
|
{
|
|
|
|
$this->title = $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getTitle()
|
|
|
|
{
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $url
|
|
|
|
*/
|
|
|
|
public function setUrl($url)
|
|
|
|
{
|
|
|
|
$this->url = $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
return $this->url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __construct(array $properties = array())
|
|
|
|
{
|
|
|
|
foreach ($properties as $name=>$value) {
|
|
|
|
$setter = 'set'.ucfirst($name);
|
|
|
|
if (method_exists($this, $setter)) {
|
|
|
|
$this->$setter($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Health check at initialization time
|
2013-06-27 10:14:15 +02:00
|
|
|
*
|
|
|
|
* @throws Icinga\Exception\ProgrammingError if tab name is missing
|
|
|
|
*
|
2013-06-07 11:44:37 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function init()
|
|
|
|
{
|
|
|
|
if ($this->name === null) {
|
2013-08-06 18:00:33 +02:00
|
|
|
throw new ProgrammingError('Cannot create a nameless tab');
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this tab active (default) or inactive
|
|
|
|
*
|
|
|
|
* This is usually done through the tabs container widget, therefore it
|
|
|
|
* is not a good idea to directly call this function
|
|
|
|
*
|
|
|
|
* @param bool $active Whether the tab should be active
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setActive($active = true)
|
|
|
|
{
|
2013-06-27 10:14:15 +02:00
|
|
|
$this->active = (bool) $active;
|
2013-06-07 11:44:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this tab is currently active
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isActive()
|
|
|
|
{
|
|
|
|
return $this->active;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is where the list item HTML is created
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-08-06 18:00:33 +02:00
|
|
|
public function render(\Zend_View_Abstract $view)
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
$class = $this->isActive() ? ' class="active"' : '';
|
|
|
|
$caption = $this->title;
|
|
|
|
if ($this->icon !== null) {
|
2013-06-27 10:14:15 +02:00
|
|
|
$caption = $view->img($this->icon, array(
|
2013-08-06 18:00:33 +02:00
|
|
|
'width' => 16,
|
|
|
|
'height' => 16
|
|
|
|
)) . ' ' . $caption;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
if ($this->url !== null) {
|
|
|
|
$tab = $view->qlink(
|
|
|
|
$caption,
|
|
|
|
$this->url,
|
|
|
|
$this->urlParams,
|
|
|
|
array('quote' => false)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$tab = $caption;
|
|
|
|
}
|
2013-08-06 18:00:33 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
return "<li $class>$tab</li>\n";
|
|
|
|
}
|
2013-08-06 18:00:33 +02:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|