Project

General

Profile

Download (2.25 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * Modal.class.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2015 Sjon Hortensius
8
 * All rights reserved.
9
 *
10
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13
 *
14
 * http://www.apache.org/licenses/LICENSE-2.0
15
 *
16
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21
 */
22

    
23
class Modal extends Form_Section
24
{
25
	protected $_attributes = array(
26
		'id' => null,
27
		'class' => array(
28
			'modal' => true,
29
			'fade' => true,
30
		),
31
		'role' => 'dialog',
32
		'aria-labelledby' => null,
33
		'aria-hidden' => 'true',
34
	);
35
	protected $_global = array();
36
	protected $_isLarge;
37

    
38
	public function __construct($title, $id, $isLarge = false, $submit = null)
39
	{
40
		$this->_title = $title;
41
		$this->_attributes['id'] = $this->_attributes['aria-labelledby'] = $id;
42
		$this->_isLarge = $isLarge;
43

    
44
		if (gettype($submit) == 'string')
45
			$submit = (new Form_Button(
46
				'save',
47
				$submit
48
			))->setAttribute('data-dismiss', 'modal');
49

    
50
		if (false !== $submit)
51
			array_push($this->_global, $submit);
52
	}
53

    
54
	public function __toString()
55
	{
56
		$element = Form_Element::__toString();
57
		$title = htmlspecialchars(gettext($this->_title));
58
		$html = implode('', $this->_groups);
59
		$footer = implode('', $this->_global);
60
		$modalClass = $this->_isLarge ? 'modal-lg' : 'modal-sm';
61

    
62
		return <<<EOT
63
	{$element}
64
		<div class="modal-dialog {$modalClass}">
65
			<div class="modal-content">
66
				<div class="modal-header">
67
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
68
						<span aria-hidden="true">&times;</span>
69
					</button>
70
					<h3 class="modal-title">{$title}</h3>
71
				</div>
72
<!--				<form class="form-horizontal" action="" method="post"> -->
73
					<div class="modal-body">
74
						{$html}
75
					</div>
76
					<div class="modal-footer">
77
						{$footer}
78
					</div>
79
<!--				</form> -->
80
			</div>
81
		</div>
82
	</div>
83
EOT;
84
	}
85
}
(2-2/3)