Project

General

Profile

Download (2.33 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2015 Sjon Hortensius
10
 * All rights reserved.
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24

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

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

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

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

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

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