|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* BootboxLibrary.php |
|
5
|
|
|
* |
|
6
|
|
|
* Adapter for the Bootbox library. |
|
7
|
|
|
* |
|
8
|
|
|
* @package jaxon-dialogs |
|
9
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
10
|
|
|
* @copyright 2016 Thierry Feuzeu <[email protected]> |
|
11
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
12
|
|
|
* @link https://github.com/jaxon-php/jaxon-dialogs |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Jaxon\Dialogs\Bootbox; |
|
16
|
|
|
|
|
17
|
|
|
use Jaxon\App\Dialog\Library\DialogLibraryTrait; |
|
18
|
|
|
use Jaxon\App\Dialog\ModalInterface; |
|
19
|
|
|
use Jaxon\App\Dialog\MessageInterface; |
|
20
|
|
|
use Jaxon\App\Dialog\QuestionInterface; |
|
21
|
|
|
|
|
22
|
|
|
class BootboxLibrary implements ModalInterface, MessageInterface, QuestionInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use DialogLibraryTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @const The library name |
|
28
|
|
|
*/ |
|
29
|
|
|
const NAME = 'bootbox'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @inheritDoc |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getName(): string |
|
35
|
|
|
{ |
|
36
|
|
|
return self::NAME; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritDoc |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getSubdir(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return 'bootbox'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @inheritDoc |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getVersion(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return '4.3.0'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* The id of the HTML container block |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function getContainer(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->helper()->getOption('dom.container', 'bootbox-container'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @inheritDoc |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getJs(): string |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->helper()->getJsCode('bootbox.min.js'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @inheritDoc |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getScript(): string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->helper()->render('bootbox/alert.js'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @inheritDoc |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getReadyScript(): string |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->helper()->render('bootbox/ready.js.php', ['container' => $this->getContainer()]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @inheritDoc |
|
91
|
|
|
*/ |
|
92
|
|
|
public function show(string $sTitle, string $sContent, array $aButtons, array $aOptions = []) |
|
93
|
|
|
{ |
|
94
|
|
|
// ModalInterface container |
|
95
|
|
|
$sContainer = $this->getContainer(); |
|
96
|
|
|
$html = $this->helper()->render('bootbox/dialog.html', |
|
97
|
|
|
['title' => $sTitle, 'content' => $sContent, 'buttons' => $aButtons]); |
|
98
|
|
|
|
|
99
|
|
|
// Assign dialog content |
|
100
|
|
|
$this->response()->assign($sContainer, 'innerHTML', $html); |
|
101
|
|
|
if(isset($aOptions['width'])) |
|
102
|
|
|
{ |
|
103
|
|
|
// Set the value of the dialog width |
|
104
|
|
|
$width = $aOptions['width']; |
|
105
|
|
|
$this->response()->script("$('.modal-dialog').css('width', '{$width}px')"); |
|
106
|
|
|
} |
|
107
|
|
|
$this->response()->script("$('#styledModal').modal('show')"); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @inheritDoc |
|
112
|
|
|
*/ |
|
113
|
|
|
public function hide() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->response()->script("$('#styledModal').modal('hide')"); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Print an alert message. |
|
120
|
|
|
* |
|
121
|
|
|
* @param string $sContent The text of the message |
|
122
|
|
|
* @param string $sTitle The title of the message |
|
123
|
|
|
* @param string $sType The type of the message |
|
124
|
|
|
* |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
protected function alert(string $sContent, string $sTitle, string $sType): string |
|
128
|
|
|
{ |
|
129
|
|
|
if($this->returnCode()) |
|
130
|
|
|
{ |
|
131
|
|
|
return "jaxon.dialogs.bootbox.alert('" . $sType . "'," . $sContent . ",'" . $sTitle . "')"; |
|
132
|
|
|
} |
|
133
|
|
|
$this->addCommand(['cmd' => 'bootbox'], ['type' => $sType, 'content' => $sContent, 'title' => $sTitle]); |
|
134
|
|
|
return ''; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @inheritDoc |
|
139
|
|
|
*/ |
|
140
|
|
|
public function success(string $sMessage, string $sTitle = ''): string |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->alert($sMessage, $sTitle, 'success'); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @inheritDoc |
|
147
|
|
|
*/ |
|
148
|
|
|
public function info(string $sMessage, string $sTitle = ''): string |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->alert($sMessage, $sTitle, 'info'); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @inheritDoc |
|
155
|
|
|
*/ |
|
156
|
|
|
public function warning(string $sMessage, string $sTitle = ''): string |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->alert($sMessage, $sTitle, 'warning'); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @inheritDoc |
|
163
|
|
|
*/ |
|
164
|
|
|
public function error(string $sMessage, string $sTitle = ''): string |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->alert($sMessage, $sTitle, 'danger'); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @inheritDoc |
|
171
|
|
|
*/ |
|
172
|
|
|
public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string |
|
173
|
|
|
{ |
|
174
|
|
|
$sTitle = $this->helper()->getQuestionTitle(); |
|
175
|
|
|
|
|
176
|
|
|
return empty($sNoScript) ? |
|
177
|
|
|
"jaxon.dialogs.bootbox.confirm(" . $sQuestion . ",'" . $sTitle . "',function(){" . $sYesScript . ";})" : |
|
178
|
|
|
"jaxon.dialogs.bootbox.confirm(" . $sQuestion . ",'" . $sTitle . "',function(){" . $sYesScript . |
|
179
|
|
|
";},function(){" . $sNoScript . ";})"; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|