2007-10-22 01:05:46 +02:00
|
|
|
<?php
|
|
|
|
/**
|
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
|
|
|
/**
|
2012-06-13 06:20:07 +02:00
|
|
|
* @var $int
|
2007-10-22 01:05:46 +02:00
|
|
|
*/
|
2012-06-13 06:20:07 +02:00
|
|
|
protected $headingLevel = 3;
|
|
|
|
|
|
|
|
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
|
|
|
|
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');
|
|
|
|
Requirements::css(FRAMEWORK_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery.ui.css');
|
|
|
|
|
2012-04-11 08:07:55 +02:00
|
|
|
$obj = $properties ? $this->customise($properties) : $this;
|
2012-04-14 07:32:29 +02:00
|
|
|
return $obj->renderWith($this->getTemplates());
|
2012-06-13 06:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAttributes() {
|
|
|
|
if($this->getStartClosed()) {
|
|
|
|
$class = 'ss-toggle ss-toggle-start-closed';
|
|
|
|
} else {
|
|
|
|
$class = 'ss-toggle';
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_merge(
|
|
|
|
$this->attributes,
|
|
|
|
array(
|
|
|
|
'id' => $this->id(),
|
|
|
|
'class' => $class . ' ' . $this->extraClass()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
2012-06-13 06:20:07 +02:00
|
|
|
* Controls whether the field is open or closed by default. By default the
|
|
|
|
* field is closed.
|
|
|
|
*
|
|
|
|
* @param bool $bool
|
2007-10-22 01:05:46 +02:00
|
|
|
*/
|
2012-06-13 06:20:07 +02:00
|
|
|
public function setStartClosed($bool) {
|
|
|
|
$this->startClosed = (bool) $bool;
|
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
|
|
|
/**
|
|
|
|
* @param int $level
|
|
|
|
*/
|
|
|
|
public function setHeadingLevel($level) {
|
|
|
|
$this->headingLevel = $level;
|
2012-07-15 21:28:09 +02:00
|
|
|
return $this;
|
2007-10-22 01:05:46 +02:00
|
|
|
}
|
2012-06-13 06:20:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated 3.0
|
|
|
|
*/
|
|
|
|
public function startClosed($bool) {
|
|
|
|
Deprecation::notice('3.0', 'Please use ToggleCompositeField->setStartClosed()');
|
|
|
|
$this->setStartClosed($bool);
|
|
|
|
}
|
|
|
|
|
2007-10-22 01:05:46 +02:00
|
|
|
}
|
|
|
|
|