|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
|
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
|
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
|
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
|
8
|
|
|
* @link https://vistart.me/ |
|
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
|
10
|
|
|
* @license https://vistart.me/license/ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace rhosocial\user\grid; |
|
14
|
|
|
|
|
15
|
|
|
use Yii; |
|
16
|
|
|
use yii\helpers\Html; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class ActionColumn |
|
20
|
|
|
* @package rhosocial\user\grid |
|
21
|
|
|
* @version 1.0 |
|
22
|
|
|
* @author vistart <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class ActionColumn extends \yii\grid\ActionColumn |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var bool Indicate whether the default buttons use icon or not. |
|
28
|
|
|
*/ |
|
29
|
|
|
public $useIcon = true; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Initializes the default button rendering callbacks. |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function initDefaultButtons() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->initDefaultButton('view', $this->useIcon ? 'eye-open' : false); |
|
|
|
|
|
|
37
|
|
|
$this->initDefaultButton('update', $this->useIcon ? 'pencil' : false); |
|
|
|
|
|
|
38
|
|
|
$this->initDefaultButton('delete', $this->useIcon ? 'trash' : false, [ |
|
|
|
|
|
|
39
|
|
|
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), |
|
40
|
|
|
'data-method' => 'post', |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Initializes the default button rendering callback for single button |
|
46
|
|
|
* @param string $name Button name as it's written in template |
|
47
|
|
|
* @param string $iconName The part of Bootstrap glyphicon class that makes it unique |
|
48
|
|
|
* @param array $additionalOptions Array of additional options |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function initDefaultButton($name, $iconName, $additionalOptions = []) |
|
51
|
|
|
{ |
|
52
|
|
|
if (!isset($this->buttons[$name]) && strpos($this->template, '{' . $name . '}') !== false) { |
|
53
|
|
|
$this->buttons[$name] = function ($url, $model, $key) use ($name, $iconName, $additionalOptions) { |
|
|
|
|
|
|
54
|
|
|
switch ($name) { |
|
55
|
|
|
case 'view': |
|
56
|
|
|
$title = Yii::t('yii', 'View'); |
|
57
|
|
|
break; |
|
58
|
|
|
case 'update': |
|
59
|
|
|
$title = Yii::t('yii', 'Update'); |
|
60
|
|
|
break; |
|
61
|
|
|
case 'delete': |
|
62
|
|
|
$title = Yii::t('yii', 'Delete'); |
|
63
|
|
|
break; |
|
64
|
|
|
default: |
|
65
|
|
|
$title = ucfirst($name); |
|
66
|
|
|
} |
|
67
|
|
|
$options = array_merge([ |
|
68
|
|
|
'title' => $title, |
|
69
|
|
|
'aria-label' => $title, |
|
70
|
|
|
'data-pjax' => '0', |
|
71
|
|
|
], $additionalOptions, $this->buttonOptions); |
|
72
|
|
|
if ($iconName == false) { |
|
|
|
|
|
|
73
|
|
|
$icon = $options['title']; |
|
74
|
|
|
} else { |
|
75
|
|
|
$icon = Html::tag('span', '', ['class' => "glyphicon glyphicon-$iconName"]); |
|
76
|
|
|
} |
|
77
|
|
|
return Html::a($icon, $url, $options); |
|
78
|
|
|
}; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|