-
Notifications
You must be signed in to change notification settings - Fork 1
/
Modal.php
108 lines (92 loc) · 3.41 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
<?php
namespace iutbay\yii2bootstrap;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
/**
* Modal widget
* @author Kevin LEVRON <[email protected]>
*/
class Modal extends \yii\bootstrap\Modal
{
/**
* @var string the header content in the modal window.
*/
var $header = '<h4 class="modal-title">Modal title</h4>';
/**
* @var array|false the options for rendering the cancel button.
* The cancel button is displayed in the footer of the modal window. Clicking
* on the button will hide the modal window. If this is false, no cancel button will be rendered.
*/
public $cancelButton = [
'label' => 'Annuler',
'options' => [
'data-dismiss' => 'modal',
],
];
/**
* @var array|false the options for rendering the submit button.
* The submit button is displayed in the footer of the modal window. Clicking
* on the button will submit the modal form. If this is false, no submit button will be rendered.
*/
public $submitButton = [
'label' => 'OK',
'type' => 'submit',
];
/**
* Renders the close button.
* This will use the latest markup from http://getbootstrap.com/javascript/#modals
* @return string the rendering result
*/
protected function renderCloseButton()
{
if ($this->closeButton !== false) {
$tag = ArrayHelper::remove($this->closeButton, 'tag', 'button');
$label = ArrayHelper::remove($this->closeButton, 'label', '×');
$label = Html::tag('span', $label, ['aria-hidden' => 'true']);
if ($tag === 'button' && !isset($this->closeButton['type'])) {
$this->closeButton['type'] = 'button';
}
ArrayHelper::remove($this->closeButton, 'aria-hidden');
$this->closeButton['aria-label'] = Yii::t('app', 'Close');
return Html::tag($tag, $label, $this->closeButton);
} else {
return null;
}
}
/**
* Renders the HTML markup for the footer of the modal.
* This will also render buttons.
* @return string the rendering result
*/
public function renderFooter()
{
$footer = parent::renderFooter();
if (empty($footer) && (isset($this->cancelButton) || isset($this->submitButton))) {
if ($this->cancelButton)
$footer.= Button::widget($this->cancelButton);
if ($this->submitButton)
$footer.= Button::widget($this->submitButton);
Html::addCssClass($this->footerOptions, 'modal-footer');
$footer = Html::tag('div', "\n" .$footer . "\n", $this->footerOptions);
}
return $footer;
}
/**
* Registers a specific Bootstrap plugin and the related events
* @param string $name the name of the Bootstrap plugin
*/
protected function registerPlugin($name)
{
$view = $this->getView();
ModalAsset::register($view);
$id = $this->options['id'];
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
$js = "jQuery('#$id').myModal($options);";
$view->registerJs($js);
}
$this->registerClientEvents();
}
}