2007-10-22 01:05:46 +02:00
|
|
|
<?php
|
2015-04-27 05:08:56 +02:00
|
|
|
|
2007-10-22 01:05:46 +02:00
|
|
|
/**
|
2012-06-13 06:20:07 +02:00
|
|
|
* Allows visibility of a group of fields to be toggled.
|
2012-04-14 07:32:29 +02:00
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-structural
|
2007-10-22 01:05:46 +02:00
|
|
|
*/
|
|
|
|
class ToggleCompositeField extends CompositeField {
|
2012-06-13 06:20:07 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $startClosed = true;
|
|
|
|
|
2007-10-22 01:05:46 +02:00
|
|
|
/**
|
2015-04-27 05:08:56 +02:00
|
|
|
* @var int
|
2007-10-22 01:05:46 +02:00
|
|
|
*/
|
2012-06-13 06:20:07 +02:00
|
|
|
protected $headingLevel = 3;
|
|
|
|
|
2015-04-27 05:08:56 +02:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param string $title
|
|
|
|
* @param array|FieldList $children
|
|
|
|
*/
|
2012-06-13 06:20:07 +02:00
|
|
|
public function __construct($name, $title, $children) {
|
2007-11-05 04:18:18 +01:00
|
|
|
$this->name = $name;
|
2007-10-22 01:05:46 +02:00
|
|
|
$this->title = $title;
|
|
|
|
|
|
|
|
parent::__construct($children);
|
|
|
|
}
|
2012-06-13 06:20:07 +02:00
|
|
|
|
2015-04-27 05:08:56 +02:00
|
|
|
/**
|
|
|
|
* @param array $properties
|
|
|
|
*
|
|
|
|
* @return HTMLText
|
|
|
|
*/
|
2012-04-11 08:07:55 +02:00
|
|
|
public function FieldHolder($properties = array()) {
|
2012-06-13 06:20:07 +02:00
|
|
|
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');
|
2015-04-27 05:08:56 +02:00
|
|
|
|
2015-12-21 22:45:01 +01:00
|
|
|
Requirements::css(FRAMEWORK_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css');
|
2012-06-13 06:20:07 +02:00
|
|
|
|
2015-04-27 05:08:56 +02:00
|
|
|
$context = $this;
|
|
|
|
|
|
|
|
if(count($properties)) {
|
|
|
|
$context = $this->customise($properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $context->renderWith($this->getTemplates());
|
2012-06-13 06:20:07 +02:00
|
|
|
}
|
|
|
|
|
2015-04-27 05:08:56 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2012-06-13 06:20:07 +02:00
|
|
|
public function getAttributes() {
|
2015-04-27 05:08:56 +02:00
|
|
|
$attributes = array(
|
|
|
|
'id' => $this->id(),
|
|
|
|
'class' => $this->extraClass(),
|
|
|
|
);
|
|
|
|
|
2012-06-13 06:20:07 +02:00
|
|
|
if($this->getStartClosed()) {
|
2015-04-27 05:08:56 +02:00
|
|
|
$attributes['class'] .= ' ss-toggle ss-toggle-start-closed';
|
2012-06-13 06:20:07 +02:00
|
|
|
} else {
|
2015-04-27 05:08:56 +02:00
|
|
|
$attributes['class'] .= ' ss-toggle';
|
2012-06-13 06:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return array_merge(
|
|
|
|
$this->attributes,
|
2015-04-27 05:08:56 +02:00
|
|
|
$attributes
|
2012-06-13 06:20:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-10-22 01:05:46 +02:00
|
|
|
/**
|
2012-06-13 06:20:07 +02:00
|
|
|
* @return bool
|
2007-10-22 01:05:46 +02:00
|
|
|
*/
|
2012-06-13 06:20:07 +02:00
|
|
|
public function getStartClosed() {
|
|
|
|
return $this->startClosed;
|
2007-10-22 01:05:46 +02:00
|
|
|
}
|
2012-06-13 06:20:07 +02:00
|
|
|
|
2007-10-22 01:05:46 +02:00
|
|
|
/**
|
2015-04-27 05:08:56 +02:00
|
|
|
* Controls whether the field is open or closed by default. By default the field is closed.
|
|
|
|
*
|
|
|
|
* @param bool $startClosed
|
2012-06-13 06:20:07 +02:00
|
|
|
*
|
2015-04-27 05:08:56 +02:00
|
|
|
* @return $this
|
2007-10-22 01:05:46 +02:00
|
|
|
*/
|
2015-04-27 05:08:56 +02:00
|
|
|
public function setStartClosed($startClosed) {
|
|
|
|
$this->startClosed = (bool) $startClosed;
|
|
|
|
|
2012-07-15 21:28:09 +02:00
|
|
|
return $this;
|
2012-06-13 06:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getHeadingLevel() {
|
2007-10-22 01:05:46 +02:00
|
|
|
return $this->headingLevel;
|
|
|
|
}
|
|
|
|
|
2012-06-13 06:20:07 +02:00
|
|
|
/**
|
2015-04-27 05:08:56 +02:00
|
|
|
* @param int $headingLevel
|
|
|
|
*
|
|
|
|
* @return $this
|
2012-06-13 06:20:07 +02:00
|
|
|
*/
|
2015-04-27 05:08:56 +02:00
|
|
|
public function setHeadingLevel($headingLevel) {
|
2016-04-20 06:16:59 +02:00
|
|
|
$this->headingLevel = (int) $headingLevel;
|
2015-04-27 05:08:56 +02:00
|
|
|
|
2012-07-15 21:28:09 +02:00
|
|
|
return $this;
|
2007-10-22 01:05:46 +02:00
|
|
|
}
|
|
|
|
}
|