Project

General

Profile

Download (1.51 KB) Statistics
| Branch: | Tag: | Revision:
1 65866f79 Thane Gill
<?php
2
3 561cc25d Sjon Hortensius
class Modal extends Form_Section
4 65866f79 Thane Gill
{
5 561cc25d Sjon Hortensius
	protected $_attributes = array(
6
		'id' => null,
7
		'class' => array(
8
			'modal' => true,
9
			'fade' => true,
10
		),
11
		'role' => 'dialog',
12
		'aria-labelledby' => null,
13
		'aria-hidden' => 'true',
14
	);
15
	protected $_global = array();
16
	protected $_isLarge;
17
18
	public function __construct($title, $id, $isLarge = false, $submit = null)
19 65866f79 Thane Gill
	{
20
		$this->_title = $title;
21 561cc25d Sjon Hortensius
		$this->_attributes['id'] = $this->_attributes['aria-labelledby'] = $id;
22
		$this->_isLarge = $isLarge;
23 65866f79 Thane Gill
24 561cc25d Sjon Hortensius
		if (gettype($submit) == 'string')
25
			$submit = (new Form_Button(
26
				'save',
27
				$submit
28
			))->setAttribute('data-dismiss', 'modal');
29 65866f79 Thane Gill
30 561cc25d Sjon Hortensius
		if (false !== $submit)
31 aa49b6b3 Sjon Hortensius
			array_push($this->_global, $submit);
32 65866f79 Thane Gill
	}
33
34
	public function __toString()
35
	{
36 561cc25d Sjon Hortensius
		$element = Form_Element::__toString();
37
		$title = htmlspecialchars(gettext($this->_title));
38 aeeda8b4 Stephen Beaver
		$html = implode('', $this->_groups);
39 65866f79 Thane Gill
		$footer = implode('', $this->_global);
40 561cc25d Sjon Hortensius
		$modalClass = $this->_isLarge ? 'modal-lg' : 'modal-sm';
41 65866f79 Thane Gill
42
		return <<<EOT
43 561cc25d Sjon Hortensius
	{$element}
44
		<div class="modal-dialog {$modalClass}">
45 65866f79 Thane Gill
			<div class="modal-content">
46
				<div class="modal-header">
47
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
48
						<span aria-hidden="true">&times;</span>
49
					</button>
50 561cc25d Sjon Hortensius
					<h3 class="modal-title">{$title}</h3>
51 65866f79 Thane Gill
				</div>
52 309e8f8f Stephen Beaver
<!--				<form class="form-horizontal" action="" method="post"> -->
53 65866f79 Thane Gill
					<div class="modal-body">
54
						{$html}
55
					</div>
56
					<div class="modal-footer">
57
						{$footer}
58
					</div>
59 309e8f8f Stephen Beaver
<!--				</form> -->
60 65866f79 Thane Gill
			</div>
61
		</div>
62
	</div>
63
EOT;
64
	}
65 561cc25d Sjon Hortensius
}