mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
926834db27
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92550 467b73ca-7a2a-4603-9d3b-597d59a354a9
144 lines
4.6 KiB
PHP
144 lines
4.6 KiB
PHP
<?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.
|
|
* @package forms
|
|
* @subpackage fields-structural
|
|
*/
|
|
class TabSet extends CompositeField {
|
|
|
|
/**
|
|
* @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);
|
|
|
|
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);
|
|
}
|
|
|
|
parent::__construct($args);
|
|
}
|
|
|
|
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() {
|
|
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');
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-cookie/jquery.cookie.js');
|
|
|
|
Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/ui.all.css');
|
|
Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/ui.tabs.css');
|
|
|
|
// concrete
|
|
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');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js');
|
|
|
|
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() {
|
|
if(isset($this->tabSet)) return $this->tabSet;
|
|
}
|
|
|
|
/**
|
|
* Returns the named tab
|
|
*/
|
|
public function fieldByName($name) {
|
|
if(strpos($name,'.') !== false) list($name, $remainder) = explode('.',$name,2);
|
|
else $remainder = null;
|
|
|
|
foreach($this->children as $child) {
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add a new child field to the end of the set.
|
|
*/
|
|
public function push($field) {
|
|
parent::push($field);
|
|
$field->setTabSet($this);
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
public function insertBefore($field, $insertBefore) {
|
|
parent::insertBefore($field, $insertBefore);
|
|
if($field instanceof Tab) $field->setTabSet($this);
|
|
$this->sequentialSet = null;
|
|
}
|
|
|
|
public function insertAfter($field, $insertAfter) {
|
|
parent::insertAfter($field, $insertAfter);
|
|
if($field instanceof Tab) $field->setTabSet($this);
|
|
$this->sequentialSet = null;
|
|
}
|
|
|
|
public function removeByName( $tabName, $dataFieldOnly = false ) {
|
|
parent::removeByName( $tabName, $dataFieldOnly );
|
|
}
|
|
}
|
|
?>
|