Clean Up ToggleCompositeField

This commit is contained in:
Christopher Pitt 2015-04-27 15:08:56 +12:00
parent 72ee96cd65
commit c59eb1bb70

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;
}
}