-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Modal.php
144 lines (130 loc) · 3.55 KB
/
Modal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
/**
* This file is part of the EaseTWBootstrap3 package
*
* https://github.com/VitexSoftware/php-ease-twbootstrap
*
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Ease\TWB;
class Modal extends \Ease\Html\DivTag
{
/**
* Spodek dialogu s tlačítky.
*/
public \Ease\Html\DivTag $footer;
/**
* Jméno dialogu.
*/
public string $name;
/**
* Titulek dialogu.
*/
public string $title;
/**
* Tělo dialogu.
*/
public \Ease\Html\DivTag $body;
/**
* Hlavička dialogu.
*/
public \Ease\Html\DivTag $header;
/**
* Vlastnosti dialogu.
*/
private array $properties;
/**
* Vytvoří modální dialogs.
*
* @param string $name
* @param mixed $title
* @param mixed $content
* @param array $properties
*/
public function __construct($name, $title, $content = null, $properties = [])
{
parent::__construct(
null,
['class' => 'modal fade', 'id' => $name, 'tabindex' => '-1', 'role' => 'dialog',
'aria-labelledby' => $title.'ID',
'aria-hidden' => 'true',
],
);
$this->properties = $properties;
$this->name = $name;
$this->title = $title;
$this->header = new \Ease\Html\DivTag(null, ['class' => 'modal-header']);
$this->header->addItem(new \Ease\Html\ButtonTag(
'×',
['class' => 'close', 'data-dismiss' => 'modal', 'aria-hidden' => 'true'],
));
$this->body = new \Ease\Html\DivTag(
$content,
['class' => 'modal-body'],
);
$this->footer = new \Ease\Html\DivTag(null, ['class' => 'modal-footer']);
$this->footer->addItem(new \Ease\Html\ButtonTag(
_('Close'),
['id' => $name.'ko', 'type' => 'button', 'class' => 'btn btn-default',
'data-dismiss' => 'modal',
],
));
$this->footer->addItem(new \Ease\Html\ButtonTag(
_('Save'),
['id' => $name.'ok', 'type' => 'button', 'class' => 'btn btn-primary'],
));
}
/**
* Finalize modal.
*/
public function finalize(): void
{
Part::twBootstrapize();
$modalDialog = $this->addItem(new \Ease\Html\DivTag(
null,
['class' => 'modal-dialog', 'role' => 'document'],
));
$modalContent = $modalDialog->addItem(new \Ease\Html\DivTag(
null,
['class' => 'modal-content'],
));
$this->header->addItem(new \Ease\Html\H4Tag(
$this->title,
['class' => 'modal-title', 'id' => $this->title.'ID'],
));
$modalContent->addItem($this->header);
$modalContent->addItem($this->body);
$modalContent->addItem($this->footer);
if (\is_array($this->properties)) {
\Ease\Shared::webPage()->addJavaScript(
<<<'EOD'
$(function ()
{
$("#
EOD.$this->name.'").modal( {'.Part::partPropertiesToString($this->properties).<<<'EOD'
});
});
EOD,
null,
true,
);
} else {
\Ease\Shared::webPage()->addJavaScript(
<<<'EOD'
$(function ()
{
$("#
EOD.$this->name.'").modal( '.$this->properties.<<<'EOD'
);
});
EOD,
null,
true,
);
}
}
}