Revision 561cc25d
Added by Sjon Hortensius almost 10 years ago
usr/local/www/classes/Modal.class.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 | 3 |
require_once('classes/Form.class.php'); |
4 |
foreach (glob('classes/Form/*.class.php') as $file) |
|
5 |
require_once($file); |
|
6 | 4 |
|
7 |
class Modal extends Form |
|
5 |
class Modal extends Form_Section
|
|
8 | 6 |
{ |
9 |
protected $_id = ''; |
|
10 |
protected $_title = ''; |
|
11 |
protected $_groups = array(); |
|
12 |
protected $_footer = array(); |
|
13 |
protected $_html = ''; |
|
14 |
protected $_modal_class_size = ''; |
|
15 |
|
|
16 |
public function __construct($title, $id, $size = '') |
|
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) |
|
17 | 21 |
{ |
18 |
switch ($size) { |
|
19 |
case 'small': |
|
20 |
$this->_modal_class_size = 'modal-sm'; |
|
21 |
break; |
|
22 |
case 'large': |
|
23 |
$this->_modal_class_size = 'modal-lg'; |
|
24 |
break; |
|
25 |
case '': |
|
26 |
break; |
|
27 |
default: |
|
28 |
throw new Exception('Incorrect size, pass either large or small'); |
|
29 |
} |
|
30 |
$this->_id = $id; |
|
31 | 22 |
$this->_title = $title; |
23 |
$this->_attributes['id'] = $this->_attributes['aria-labelledby'] = $id; |
|
24 |
$this->_isLarge = $isLarge; |
|
32 | 25 |
|
33 |
$this->addClass('modal', 'fade'); |
|
34 |
|
|
35 |
return $this; |
|
36 |
} |
|
37 |
|
|
38 |
public function add(Form_Group $group) |
|
39 |
{ |
|
40 |
array_push($this->_groups, $group); |
|
41 |
$group->_setParent($this); |
|
42 |
|
|
43 |
return $group; |
|
44 |
} |
|
45 |
|
|
46 |
public function addInput(Form_Input $input) |
|
47 |
{ |
|
48 |
$group = new Form_Group($input->getTitle()); |
|
49 |
$group->add($input); |
|
50 |
|
|
51 |
$this->add($group); |
|
52 |
|
|
53 |
return $input; |
|
54 |
} |
|
55 |
|
|
56 |
public function addHtml($html) |
|
57 |
{ |
|
58 |
$this->_html .= $html; |
|
59 |
|
|
60 |
return $this; |
|
61 |
} |
|
62 |
|
|
63 |
public function addFooter(Form_Input $input) |
|
64 |
{ |
|
65 |
array_push($this->_footer, $input); |
|
26 |
if (gettype($submit) == 'string') |
|
27 |
$submit = (new Form_Button( |
|
28 |
'save', |
|
29 |
$submit |
|
30 |
))->setAttribute('data-dismiss', 'modal'); |
|
66 | 31 |
|
67 |
return $input; |
|
32 |
if (false !== $submit) |
|
33 |
$this->addGlobal($submit); |
|
68 | 34 |
} |
69 | 35 |
|
70 | 36 |
public function __toString() |
71 | 37 |
{ |
72 |
if (empty($this->_footer)) { |
|
73 |
$this->addFooter(new Form_Button( |
|
74 |
'submit', |
|
75 |
'Submit' |
|
76 |
)); |
|
77 |
|
|
78 |
$this->addFooter(new Form_Button( |
|
79 |
'close', |
|
80 |
'Close', |
|
81 |
'' |
|
82 |
))->setAttribute('data-dismiss', 'modal'); |
|
83 |
} |
|
84 |
|
|
85 |
$title = gettext($title); |
|
86 |
|
|
87 |
$html = implode('', $this->_groups); |
|
88 |
$html .= $this->_html; |
|
89 |
|
|
38 |
$element = Form_Element::__toString(); |
|
39 |
$title = htmlspecialchars(gettext($this->_title)); |
|
40 |
$body = implode('', $this->_groups); |
|
90 | 41 |
$footer = implode('', $this->_global); |
91 |
$footer .= implode('', $this->_footer);
|
|
42 |
$modalClass = $this->_isLarge ? 'modal-lg' : 'modal-sm';
|
|
92 | 43 |
|
93 | 44 |
return <<<EOT |
94 |
<div {$this->getHtmlClass()} id="{$this->_id}" role="dialog" aria-labelledby="{$this->_id}" aria-hidden="true">
|
|
95 |
<div class="modal-dialog {$this->_modal_class_size}">
|
|
45 |
{$element}
|
|
46 |
<div class="modal-dialog {$modalClass}">
|
|
96 | 47 |
<div class="modal-content"> |
97 | 48 |
<div class="modal-header"> |
98 | 49 |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> |
99 | 50 |
<span aria-hidden="true">×</span> |
100 | 51 |
</button> |
101 |
<h3 class="modal-title">{$this->_title}</h3>
|
|
52 |
<h3 class="modal-title">{$title}</h3> |
|
102 | 53 |
</div> |
103 |
<form class="form-horizontal" action="{$this->_action}" method="post">
|
|
54 |
<form class="form-horizontal" action="" method="post"> |
|
104 | 55 |
<div class="modal-body"> |
105 | 56 |
{$html} |
106 | 57 |
</div> |
... | ... | |
113 | 64 |
</div> |
114 | 65 |
EOT; |
115 | 66 |
} |
116 |
} |
|
67 |
} |
Also available in: Unified diff
Modal - refactored using new attributes
refs #30