forked from YL20181120/yii2-dwz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alert.php
49 lines (44 loc) · 1.24 KB
/
Alert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace yii\dwz;
use yii\helpers\Html;
use \yii\base\InvalidParamException;
/**
*
*/
class Alert extends Widget
{
public $message;
public $type = 'info';
public $content;
private $CLASS_RANGE = ['info','warning','success','error','javascript'];
public function init(){
parent::init();
if(!in_array($this->type, $this->CLASS_RANGE))
throw new InvalidParamException("Param type must in range '".implode(' ', $this->CLASS_RANGE)."'",1);
if($this->content == null || $this->content == "")
throw new InvalidParamException("content can not be null",1);
}
public function run(){
return $this->renderAlert();
}
protected function renderAlert() {
switch ($this->type) {
case 'warning':
$this->options['onclick'] = "alertMsg.warn('".$this->message."')";
break;
case 'success':
$this->options['onclick'] = "alertMsg.correct('".$this->message."')";
break;
case 'error':
$this->options['onclick'] = "alertMsg.error('".$this->message."')";
break;
case 'javascript':
$this->options['onclick'] = $this->message;
break;
case 'info':
$this->options['onclick'] = "alertMsg.info('".$this->message."')";
break;
}
return Html::a($this->content,'javascript:;',$this->options);;
}
}