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