Blame view

framework/forms/ToggleCompositeField.php 1.85 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  <?php
  /**
   * Allows visibility of a group of fields to be toggled.
   *
   * @package forms
   * @subpackage fields-structural
   */
  class ToggleCompositeField extends CompositeField {
  
  	/**
  	 * @var bool
  	 */
  	protected $startClosed = true;
  
  	/**
  	 * @var $int
  	 */
  	protected $headingLevel = 3;
  
  	public function __construct($name, $title, $children) {
  		$this->name = $name;
  		$this->title = $title;
  
  		parent::__construct($children);
  	}
  
  	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());
  	}
  
  	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()
  			)
  		);
  	}
  
  	/**
  	 * @return bool
  	 */
  	public function getStartClosed() {
  		return $this->startClosed;
  	}
  
  	/**
  	 * Controls whether the field is open or closed by default. By default the
  	 * field is closed.
  	 *
  	 * @param bool $bool
  	 */
  	public function setStartClosed($bool) {
  		$this->startClosed = (bool) $bool;
  		return $this;
  	}
  
  	/**
  	 * @return int
  	 */
  	public function getHeadingLevel() {
  		return $this->headingLevel;
  	}
  
  	/**
  	 * @param int $level
  	 */
  	public function setHeadingLevel($level) {
  		$this->headingLevel = $level;
  		return $this;
  	}
  
  }