2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Defines a set of tabs in a form.
|
|
|
|
* The tabs are build with our standard tabstrip javascript library. By default, the HTML is
|
|
|
|
* generated using FieldHolder.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-structural
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class TabSet extends CompositeField {
|
2008-10-10 18:00:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name Identifier
|
|
|
|
* @param string $title (Optional) Natural language title of the tabset
|
|
|
|
* @param Tab|TabSet $unknown All further parameters are inserted as children into the TabSet
|
|
|
|
*/
|
|
|
|
public function __construct($name) {
|
|
|
|
$args = func_get_args();
|
|
|
|
|
|
|
|
$name = array_shift($args);
|
|
|
|
if(!is_string($name)) user_error('TabSet::__construct(): $name parameter to a valid string', E_USER_ERROR);
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
$this->id = $name;
|
|
|
|
|
|
|
|
// Legacy handling: only assume second parameter as title if its a string,
|
|
|
|
// otherwise it might be a formfield instance
|
|
|
|
if(isset($args[0]) && is_string($args[0])) {
|
|
|
|
$title = array_shift($args);
|
|
|
|
}
|
|
|
|
$this->title = (isset($title)) ? $title : FormField::name_to_label($name);
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-10-10 18:00:50 +02:00
|
|
|
if($args) foreach($args as $tab) {
|
|
|
|
$isValidArg = (is_object($tab) && (!($tab instanceof Tab) || !($tab instanceof TabSet)));
|
|
|
|
if(!$isValidArg) user_error('TabSet::__construct(): Parameter not a valid Tab instance', E_USER_ERROR);
|
|
|
|
|
|
|
|
$tab->setTabSet($this);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-10-10 18:00:50 +02:00
|
|
|
parent::__construct($args);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function id() {
|
|
|
|
if($this->tabSet) return $this->tabSet->id() . '_' . $this->id . '_set';
|
|
|
|
else return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a tab-strip and the associated tabs.
|
|
|
|
* The HTML is a standardised format, containing a <ul;
|
|
|
|
*/
|
|
|
|
public function FieldHolder() {
|
2009-11-21 03:29:59 +01:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/jquery_improvements.js");
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.core.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.tabs.js');
|
2009-11-21 03:30:21 +01:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-cookie/jquery.cookie.js');
|
2009-11-21 03:22:49 +01:00
|
|
|
|
2009-11-21 03:29:59 +01:00
|
|
|
Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/ui.all.css');
|
|
|
|
Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/ui.tabs.css');
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2009-11-21 03:22:52 +01:00
|
|
|
// concrete
|
2009-11-21 03:31:55 +01:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-selector/src/jquery.class.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-selector/src/jquery.selector.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-selector/src/jquery.selector.specifity.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-selector/src/jquery.selector.matches.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/src/jquery.dat.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/src/jquery.concrete.js');
|
2009-11-21 03:22:52 +01:00
|
|
|
|
2009-11-21 03:22:49 +01:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js');
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->renderWith("TabSetFieldHolder");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a dataobject set of all this classes tabs
|
|
|
|
*/
|
|
|
|
public function Tabs() {
|
|
|
|
return $this->children;
|
|
|
|
}
|
|
|
|
public function setTabs($children){
|
|
|
|
$this->children = $children;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTabSet($val) {
|
|
|
|
$this->tabSet = $val;
|
|
|
|
}
|
|
|
|
public function getTabSet() {
|
2008-04-01 03:50:34 +02:00
|
|
|
if(isset($this->tabSet)) return $this->tabSet;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the named tab
|
|
|
|
*/
|
|
|
|
public function fieldByName($name) {
|
2009-07-06 23:53:50 +02:00
|
|
|
if(strpos($name,'.') !== false) list($name, $remainder) = explode('.',$name,2);
|
|
|
|
else $remainder = null;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach($this->children as $child) {
|
2009-07-06 23:53:50 +02:00
|
|
|
if(trim($name) == trim($child->Name) || $name == $child->id) {
|
|
|
|
if($remainder) {
|
|
|
|
if($child->isComposite()) {
|
|
|
|
return $child->fieldByName($remainder);
|
|
|
|
} else {
|
|
|
|
user_error("Trying to get field '$remainder' from non-composite field $child->class.$name", E_USER_WARNING);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $child;
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new child field to the end of the set.
|
|
|
|
*/
|
2007-11-04 22:35:51 +01:00
|
|
|
public function push($field) {
|
2007-07-19 12:40:28 +02:00
|
|
|
parent::push($field);
|
|
|
|
$field->setTabSet($this);
|
|
|
|
}
|
2008-11-11 03:35:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts a field before a particular field in a FieldSet.
|
|
|
|
*
|
|
|
|
* @param FormField $item The form field to insert
|
|
|
|
* @param string $name Name of the field to insert before
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
public function insertBefore($field, $insertBefore) {
|
|
|
|
parent::insertBefore($field, $insertBefore);
|
2008-11-11 03:35:54 +01:00
|
|
|
if($field instanceof Tab) $field->setTabSet($this);
|
|
|
|
$this->sequentialSet = null;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-11-11 03:35:54 +01:00
|
|
|
public function insertAfter($field, $insertAfter) {
|
|
|
|
parent::insertAfter($field, $insertAfter);
|
|
|
|
if($field instanceof Tab) $field->setTabSet($this);
|
|
|
|
$this->sequentialSet = null;
|
2007-09-16 18:05:59 +02:00
|
|
|
}
|
|
|
|
|
2008-09-12 06:42:24 +02:00
|
|
|
public function removeByName( $tabName, $dataFieldOnly = false ) {
|
|
|
|
parent::removeByName( $tabName, $dataFieldOnly );
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2009-02-02 00:49:53 +01:00
|
|
|
?>
|