Merge pull request #4115 from assertchris/clean-up-toggle-composite-field

Clean Up ToggleCompositeField
This commit is contained in:
Damian Mooyman 2015-06-12 13:09:44 +12:00
commit 07c166f7af

View File

@ -1,4 +1,5 @@
<?php
/**
* Allows visibility of a group of fields to be toggled.
*
@ -6,17 +7,21 @@
* @subpackage fields-structural
*/
class ToggleCompositeField extends CompositeField {
/**
* @var bool
*/
protected $startClosed = true;
/**
* @var $int
* @var int
*/
protected $headingLevel = 3;
/**
* @param string $name
* @param string $title
* @param array|FieldList $children
*/
public function __construct($name, $title, $children) {
$this->name = $name;
$this->title = $title;
@ -24,30 +29,46 @@ class ToggleCompositeField extends CompositeField {
parent::__construct($children);
}
/**
* @param array $properties
*
* @return HTMLText
*/
public function FieldHolder($properties = array()) {
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(FRAMEWORK_DIR . '/javascript/ToggleCompositeField.js');
Requirements::css(FRAMEWORK_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery.ui.css');
$obj = $properties ? $this->customise($properties) : $this;
return $obj->renderWith($this->getTemplates());
$context = $this;
if(count($properties)) {
$context = $this->customise($properties);
}
return $context->renderWith($this->getTemplates());
}
/**
* {@inheritdoc}
*/
public function getAttributes() {
$attributes = array(
'id' => $this->id(),
'class' => $this->extraClass(),
);
if($this->getStartClosed()) {
$class = 'ss-toggle ss-toggle-start-closed';
$attributes['class'] .= ' ss-toggle ss-toggle-start-closed';
} else {
$class = 'ss-toggle';
$attributes['class'] .= ' ss-toggle';
}
return array_merge(
$this->attributes,
array(
'id' => $this->id(),
'class' => $class . ' ' . $this->extraClass()
)
$attributes
);
}
@ -59,13 +80,15 @@ class ToggleCompositeField extends CompositeField {
}
/**
* Controls whether the field is open or closed by default. By default the
* field is closed.
* Controls whether the field is open or closed by default. By default the field is closed.
*
* @param bool $bool
* @param bool $startClosed
*
* @return $this
*/
public function setStartClosed($bool) {
$this->startClosed = (bool) $bool;
public function setStartClosed($startClosed) {
$this->startClosed = (bool) $startClosed;
return $this;
}
@ -77,12 +100,13 @@ class ToggleCompositeField extends CompositeField {
}
/**
* @param int $level
* @param int $headingLevel
*
* @return $this
*/
public function setHeadingLevel($level) {
$this->headingLevel = $level;
public function setHeadingLevel($headingLevel) {
$this->headingLevel = $headingLevel;
return $this;
}
}