1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* DialogLibraryInterface.php - Adapter for the JQuery-Confirm 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\JQueryConfirm; |
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 JQueryConfirmLibrary extends AbstractDialogLibrary implements ModalInterface, MessageInterface, QuestionInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @const The library name |
24
|
|
|
*/ |
25
|
|
|
const NAME = 'jconfirm'; |
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 'jquery-confirm'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
|
public function getVersion(): string |
47
|
|
|
{ |
48
|
|
|
return '3.3.0'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritDoc |
53
|
|
|
*/ |
54
|
|
|
public function getJs(): string |
55
|
|
|
{ |
56
|
|
|
return $this->xHelper->getJsCode('jquery-confirm.min.js'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritDoc |
61
|
|
|
*/ |
62
|
|
|
public function getCss(): string |
63
|
|
|
{ |
64
|
|
|
return $this->xHelper->getCssCode('jquery-confirm.min.css') . ' |
65
|
|
|
<style> |
66
|
|
|
.jconfirm .jconfirm-box div.jconfirm-content-pane { |
67
|
|
|
margin-top: 15px; |
68
|
|
|
} |
69
|
|
|
</style> |
70
|
|
|
'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritDoc |
75
|
|
|
*/ |
76
|
|
|
public function getScript(): string |
77
|
|
|
{ |
78
|
|
|
return $this->xHelper->render('jqueryconfirm/alert.js'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritDoc |
83
|
|
|
*/ |
84
|
|
|
public function getReadyScript(): string |
85
|
|
|
{ |
86
|
|
|
return $this->xHelper->render('jqueryconfirm/ready.js.php'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @inheritDoc |
91
|
|
|
*/ |
92
|
|
|
public function show(string $sTitle, string $sMessage, array $aButtons, array $aOptions = []) |
93
|
|
|
{ |
94
|
|
|
$aOptions['title'] = $sTitle; |
95
|
|
|
$aOptions['content'] = $sMessage; |
96
|
|
|
$aOptions['buttons'] = []; |
97
|
|
|
if(!array_key_exists('boxWidth', $aOptions)) |
98
|
|
|
{ |
99
|
|
|
$aOptions['useBootstrap'] = false; |
100
|
|
|
$aOptions['boxWidth'] = '600'; |
101
|
|
|
} |
102
|
|
|
$ind = 0; |
103
|
|
|
foreach($aButtons as $button) |
104
|
|
|
{ |
105
|
|
|
$_button = [ |
106
|
|
|
'text' => $button['title'], |
107
|
|
|
'btnClass' => $button['class'], |
108
|
|
|
'action' => $button['click'], |
109
|
|
|
]; |
110
|
|
|
// Optional attributes |
111
|
|
|
foreach($button as $attr => $value) |
112
|
|
|
{ |
113
|
|
|
if(!in_array($attr, ['title', 'class', 'click'])) |
114
|
|
|
{ |
115
|
|
|
$_button[$attr] = $value; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
$aOptions['buttons']['btn' . $ind++] = $_button; |
119
|
|
|
} |
120
|
|
|
// Show dialog |
121
|
|
|
$this->addCommand(array('cmd' => 'jconfirm.show'), $aOptions); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @inheritDoc |
126
|
|
|
*/ |
127
|
|
|
public function hide() |
128
|
|
|
{ |
129
|
|
|
// Hide dialog |
130
|
|
|
$this->addCommand(array('cmd' => 'jconfirm.hide'), array()); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Print an alert message. |
135
|
|
|
* |
136
|
|
|
* @param string $sMessage The text of the message |
137
|
|
|
* @param string $sTitle The title of the message |
138
|
|
|
* @param string $sType The type of the message |
139
|
|
|
* @param string $sIcon The icon of the message |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
protected function alert(string $sMessage, string $sTitle, string $sType, string $sIcon): string |
144
|
|
|
{ |
145
|
|
|
if($this->returnCode()) |
146
|
|
|
{ |
147
|
|
|
return "$.alert({content:" . $sMessage . ", title:'" . $sTitle . |
148
|
|
|
"', type:'" . $sType . "', icon:'" . $sIcon . "'})"; |
149
|
|
|
} |
150
|
|
|
$this->addCommand(array('cmd' => 'jconfirm.alert'), |
151
|
|
|
['content' => $sMessage, 'title' => $sTitle, 'type' => $sType, 'icon' => $sIcon]); |
152
|
|
|
return ''; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @inheritDoc |
157
|
|
|
*/ |
158
|
|
|
public function success(string $sMessage, string $sTitle = ''): string |
159
|
|
|
{ |
160
|
|
|
return $this->alert($sMessage, $sTitle, 'green', 'fa fa-success'); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @inheritDoc |
165
|
|
|
*/ |
166
|
|
|
public function info(string $sMessage, string $sTitle = ''): string |
167
|
|
|
{ |
168
|
|
|
return $this->alert($sMessage, $sTitle, 'blue', 'fa fa-info'); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @inheritDoc |
173
|
|
|
*/ |
174
|
|
|
public function warning(string $sMessage, string $sTitle = ''): string |
175
|
|
|
{ |
176
|
|
|
return $this->alert($sMessage, $sTitle, 'orange', 'fa fa-warning'); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @inheritDoc |
181
|
|
|
*/ |
182
|
|
|
public function error(string $sMessage, string $sTitle = ''): string |
183
|
|
|
{ |
184
|
|
|
return $this->alert($sMessage, $sTitle, 'red', 'fa fa-error'); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @inheritDoc |
189
|
|
|
*/ |
190
|
|
|
public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string |
191
|
|
|
{ |
192
|
|
|
$sTitle = $this->xHelper->getQuestionTitle(); |
193
|
|
|
if(!$sNoScript) |
194
|
|
|
{ |
195
|
|
|
return "jaxon.dialogs.jconfirm.confirm(" . $sQuestion . ",'" . |
196
|
|
|
$sTitle . "',function(){" . $sYesScript . ";})"; |
197
|
|
|
} |
198
|
|
|
return "jaxon.dialogs.jconfirm.confirm(" . $sQuestion . ",'" . $sTitle . |
199
|
|
|
"',function(){" . $sYesScript . ";},function(){" . $sNoScript . ";})"; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
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