Project

General

Profile

Download (1.55 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
require_once('classes/Form.class.php');
4

    
5
class Modal extends Form_Section
6
{
7
	protected $_attributes = array(
8
		'id' => null,
9
		'class' => array(
10
			'modal' => true,
11
			'fade' => true,
12
		),
13
		'role' => 'dialog',
14
		'aria-labelledby' => null,
15
		'aria-hidden' => 'true',
16
	);
17
	protected $_global = array();
18
	protected $_isLarge;
19

    
20
	public function __construct($title, $id, $isLarge = false, $submit = null)
21
	{
22
		$this->_title = $title;
23
		$this->_attributes['id'] = $this->_attributes['aria-labelledby'] = $id;
24
		$this->_isLarge = $isLarge;
25

    
26
		if (gettype($submit) == 'string')
27
			$submit = (new Form_Button(
28
				'save',
29
				$submit
30
			))->setAttribute('data-dismiss', 'modal');
31

    
32
		if (false !== $submit)
33
			array_push($this->_global, $submit);
34
	}
35

    
36
	public function __toString()
37
	{
38
		$element = Form_Element::__toString();
39
		$title = htmlspecialchars(gettext($this->_title));
40
		$html = implode('', $this->_groups);
41
		$footer = implode('', $this->_global);
42
		$modalClass = $this->_isLarge ? 'modal-lg' : 'modal-sm';
43

    
44
		return <<<EOT
45
	{$element}
46
		<div class="modal-dialog {$modalClass}">
47
			<div class="modal-content">
48
				<div class="modal-header">
49
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
50
						<span aria-hidden="true">&times;</span>
51
					</button>
52
					<h3 class="modal-title">{$title}</h3>
53
				</div>
54
<!--				<form class="form-horizontal" action="" method="post"> -->
55
					<div class="modal-body">
56
						{$html}
57
					</div>
58
					<div class="modal-footer">
59
						{$footer}
60
					</div>
61
<!--				</form> -->
62
			</div>
63
		</div>
64
	</div>
65
EOT;
66
	}
67
}
(2-2/2)