1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AlertLibrary.php |
5
|
|
|
* |
6
|
|
|
* Implements the dialog message and question features using the js alert and confirm functions. |
7
|
|
|
* |
8
|
|
|
* @package jaxon-core |
|
|
|
|
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-core |
13
|
|
|
*/ |
|
|
|
|
14
|
|
|
|
15
|
|
|
namespace Jaxon\App\Dialog\Library; |
16
|
|
|
|
17
|
|
|
use Jaxon\App\Dialog\LibraryInterface; |
18
|
|
|
use Jaxon\App\Dialog\MessageInterface; |
19
|
|
|
use Jaxon\App\Dialog\QuestionInterface; |
20
|
|
|
|
21
|
|
|
class AlertLibrary implements LibraryInterface, MessageInterface, QuestionInterface |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
use DialogLibraryTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get the library name |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
|
|
public function getName(): string |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
return ''; // No name |
33
|
|
|
} |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the script which makes a call only if the user answers yes to the given question |
37
|
|
|
* |
38
|
|
|
* @param string $sQuestion |
|
|
|
|
39
|
|
|
* @param string $sYesScript |
|
|
|
|
40
|
|
|
* @param string $sNoScript |
|
|
|
|
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string |
45
|
|
|
{ |
46
|
|
|
return empty($sNoScript) ? 'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}' : |
|
|
|
|
47
|
|
|
'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}else{' . $sNoScript . ';}'; |
48
|
|
|
} |
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Print an alert message. |
52
|
|
|
* |
53
|
|
|
* @param string $sMessage The text of the message |
|
|
|
|
54
|
|
|
* @param string $sTitle The title of the message |
|
|
|
|
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
private function alert(string $sMessage, string $sTitle): string |
59
|
|
|
{ |
60
|
|
|
if(!empty($sTitle)) |
61
|
|
|
{ |
62
|
|
|
$sMessage = '<b>' . $sTitle . '</b><br/>' . $sMessage; |
63
|
|
|
} |
64
|
|
|
if($this->returnCode()) |
65
|
|
|
{ |
66
|
|
|
return 'alert(' . $sMessage . ')'; |
67
|
|
|
} |
68
|
|
|
$this->xResponse->alert($sMessage, $sTitle); |
|
|
|
|
69
|
|
|
return ''; |
70
|
|
|
} |
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Print a success message. |
74
|
|
|
* |
75
|
|
|
* @param string $sMessage The text of the message |
|
|
|
|
76
|
|
|
* @param string $sTitle The title of the message |
|
|
|
|
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function success(string $sMessage, string $sTitle = ''): string |
81
|
|
|
{ |
82
|
|
|
return $this->alert($sMessage, $sTitle); |
83
|
|
|
} |
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Print an information message. |
87
|
|
|
* |
88
|
|
|
* @param string $sMessage The text of the message |
|
|
|
|
89
|
|
|
* @param string $sTitle The title of the message |
|
|
|
|
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function info(string $sMessage, string $sTitle = ''): string |
94
|
|
|
{ |
95
|
|
|
return $this->alert($sMessage, $sTitle); |
96
|
|
|
} |
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Print a warning message. |
100
|
|
|
* |
101
|
|
|
* @param string $sMessage The text of the message |
|
|
|
|
102
|
|
|
* @param string $sTitle The title of the message |
|
|
|
|
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function warning(string $sMessage, string $sTitle = ''): string |
107
|
|
|
{ |
108
|
|
|
return $this->alert($sMessage, $sTitle); |
109
|
|
|
} |
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Print an error message. |
113
|
|
|
* |
114
|
|
|
* @param string $sMessage The text of the message |
|
|
|
|
115
|
|
|
* @param string $sTitle The title of the message |
|
|
|
|
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function error(string $sMessage, string $sTitle = ''): string |
120
|
|
|
{ |
121
|
|
|
return $this->alert($sMessage, $sTitle); |
122
|
|
|
} |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|