1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* NotyLibrary.php |
5
|
|
|
* |
6
|
|
|
* Adapter for the Noty 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\Noty; |
16
|
|
|
|
17
|
|
|
use Jaxon\App\Dialog\Library\DialogLibraryTrait; |
18
|
|
|
use Jaxon\App\Dialog\MessageInterface; |
19
|
|
|
use Jaxon\App\Dialog\QuestionInterface; |
20
|
|
|
|
21
|
|
|
class NotyLibrary implements MessageInterface, QuestionInterface |
22
|
|
|
{ |
23
|
|
|
use DialogLibraryTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @const The library name |
27
|
|
|
*/ |
28
|
|
|
const NAME = 'noty'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @inheritDoc |
32
|
|
|
*/ |
33
|
|
|
public function getName(): string |
34
|
|
|
{ |
35
|
|
|
return self::NAME; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritDoc |
40
|
|
|
*/ |
41
|
|
|
public function getSubdir(): string |
42
|
|
|
{ |
43
|
|
|
return 'noty'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritDoc |
48
|
|
|
*/ |
49
|
|
|
public function getVersion(): string |
50
|
|
|
{ |
51
|
|
|
return '2.3.11'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritDoc |
56
|
|
|
*/ |
57
|
|
|
public function getJs(): string |
58
|
|
|
{ |
59
|
|
|
return $this->helper()->getJsCode('jquery.noty.packaged.min.js'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritDoc |
64
|
|
|
*/ |
65
|
|
|
public function getScript(): string |
66
|
|
|
{ |
67
|
|
|
return $this->helper()->render('noty/alert.js'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @inheritDoc |
72
|
|
|
*/ |
73
|
|
|
public function getReadyScript(): string |
74
|
|
|
{ |
75
|
|
|
return $this->helper()->render('noty/ready.js.php'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Print an alert message. |
80
|
|
|
* |
81
|
|
|
* @param string $sMessage The text of the message |
82
|
|
|
* @param string $sTitle The title of the message |
83
|
|
|
* @param string $sType The type of the message |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
protected function alert(string $sMessage, string $sTitle, string $sType): string |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
if($this->returnCode()) |
90
|
|
|
{ |
91
|
|
|
return "noty({text:" . $sMessage . ", type:'" . $sType . "', layout: 'topCenter'})"; |
92
|
|
|
} |
93
|
|
|
$aOptions = array('text' => $sMessage, 'type' => $sType); |
94
|
|
|
// Show the alert |
95
|
|
|
$this->addCommand(array('cmd' => 'noty.alert'), $aOptions); |
96
|
|
|
return ''; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritDoc |
101
|
|
|
*/ |
102
|
|
|
public function success(string $sMessage, string $sTitle = ''): string |
103
|
|
|
{ |
104
|
|
|
return $this->alert($sMessage, $sTitle, 'success'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritDoc |
109
|
|
|
*/ |
110
|
|
|
public function info(string $sMessage, string $sTitle = ''): string |
111
|
|
|
{ |
112
|
|
|
return $this->alert($sMessage, $sTitle, 'information'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @inheritDoc |
117
|
|
|
*/ |
118
|
|
|
public function warning(string $sMessage, string $sTitle = ''): string |
119
|
|
|
{ |
120
|
|
|
return $this->alert($sMessage, $sTitle, 'warning'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @inheritDoc |
125
|
|
|
*/ |
126
|
|
|
public function error(string $sMessage, string $sTitle = ''): string |
127
|
|
|
{ |
128
|
|
|
return $this->alert($sMessage, $sTitle, 'error'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @inheritDoc |
133
|
|
|
*/ |
134
|
|
|
public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string |
135
|
|
|
{ |
136
|
|
|
// $sTitle = $this->helper()->getQuestionTitle(); |
137
|
|
|
if(!$sNoScript) |
138
|
|
|
{ |
139
|
|
|
return "jaxon.dialogs.noty.confirm(" . $sQuestion . ",'',function(){" . $sYesScript . ";})"; |
140
|
|
|
} |
141
|
|
|
return "jaxon.dialogs.noty.confirm(" . $sQuestion . ",'',function(){" . $sYesScript . |
142
|
|
|
";},function(){" . $sNoScript . ";})"; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.