1
|
|
|
<?php |
2
|
|
|
use yii\helpers\Html; |
3
|
|
|
use yii\helpers\Url; |
4
|
|
|
use yii\grid\GridView; |
5
|
|
|
use zacksleo\yii2\post\assets\ClipboardAsset; |
6
|
|
|
use zacksleo\yii2\post\assets\ToastrAsset; |
7
|
|
|
use zacksleo\yii2\post\Module; |
8
|
|
|
use zacksleo\yii2\post\models\Post; |
9
|
|
|
use yii\web\View; |
10
|
|
|
|
11
|
|
|
/* @var $this yii\web\View */ |
12
|
|
|
/* @var $dataProvider yii\data\ActiveDataProvider */ |
13
|
|
|
$this->title = Module::t('post', 'Posts'); |
14
|
|
|
$this->params['breadcrumbs'][] = Module::t('post', 'Posts'); |
15
|
|
|
ClipboardAsset::register($this); |
16
|
|
|
ToastrAsset::register($this); |
17
|
|
|
?> |
18
|
|
|
<style type="text/css"> |
19
|
|
|
.color-blue { |
20
|
|
|
color: #337ab7; |
21
|
|
|
} |
22
|
|
|
</style> |
23
|
|
|
<div class="post-index"> |
24
|
|
|
<p> |
25
|
|
|
<?= Html::a(Module::t('post', 'Create'), ['create'], ['class' => 'btn btn-success']) ?> |
26
|
|
|
</p> |
27
|
|
|
<?= GridView::widget([ |
28
|
|
|
'dataProvider' => $dataProvider, |
29
|
|
|
'columns' => [ |
30
|
|
|
['class' => 'yii\grid\SerialColumn'], |
31
|
|
|
[ |
32
|
|
|
'label' => '缩略图', |
33
|
|
|
'format' => [ |
34
|
|
|
"image", |
35
|
|
|
[ |
36
|
|
|
"width" => "84", |
37
|
|
|
"height" => "84", |
38
|
|
|
] |
39
|
|
|
], |
40
|
|
|
'value' => function ($model) { |
41
|
|
|
return $model->getImgUrl(); |
42
|
|
|
} |
43
|
|
|
], |
44
|
|
|
'title', |
45
|
|
|
'order', |
46
|
|
|
'updated_at:date', |
47
|
|
|
['class' => 'yii\grid\ActionColumn', |
48
|
|
|
'template' => '{view} {update} {delete} {up} {url}', |
49
|
|
|
'buttons' => [ |
50
|
|
|
'up' => function ($url, $model, $key) { |
|
|
|
|
51
|
|
|
if ($model->status == Post::STATUS_ACTIVE) { |
52
|
|
|
$span = Html::tag('a id="status_' . $model->id . '" class="glyphicon glyphicon-remove color-blue" title="' . Module::t('post', 'offline') . '" onclick="setStatus(' . $model->id . ',0)"></a'); |
53
|
|
|
return Html::a($span, '#'); |
54
|
|
|
} else { |
55
|
|
|
$span = Html::tag('a id="status_' . $model->id . '" class="glyphicon glyphicon-ok color-blue" title="' . Module::t('post', 'online') . '" onclick="setStatus(' . $model->id . ',1)"></a'); |
56
|
|
|
return Html::a($span, '#'); |
57
|
|
|
} |
58
|
|
|
}, |
59
|
|
|
'url' => function ($url, $model, $key) { |
|
|
|
|
60
|
|
|
$span = Html::tag('a class="glyphicon glyphicon-link color-blue cp" title="复制链接" data-clipboard-text="' . $model->url . '"></a'); |
61
|
|
|
return Html::a($span, '#'); |
62
|
|
|
} |
63
|
|
|
] |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
]); ?> |
67
|
|
|
</div> |
68
|
|
|
<script type="text/javascript"> |
69
|
|
|
/** |
70
|
|
|
* @brief 修改文章的状态是否显示 |
71
|
|
|
* @param id |
72
|
|
|
* @param status 是否显示(1:显示0:不显示) |
73
|
|
|
* @return |
74
|
|
|
*/ |
75
|
|
|
function setStatus(id, status) { |
76
|
|
|
$.ajax({ |
77
|
|
|
type: "GET", |
78
|
|
|
url: "<?= Url::to(['status'])?>", |
79
|
|
|
data: {id: id, status: status}, |
80
|
|
|
success: function (rep) { |
81
|
|
|
if (rep.status === 1) { |
82
|
|
|
if (status === 1) { |
83
|
|
|
$("#status_" + id).removeClass("glyphicon-ok").addClass("glyphicon-remove"); |
84
|
|
|
$("#status_" + id).attr("onclick", "setStatus(" + id + ",0)"); |
85
|
|
|
} else { |
86
|
|
|
$("#status_" + id).removeClass("glyphicon-remove").addClass("glyphicon-ok"); |
87
|
|
|
$("#status_" + id).attr("onclick", "setStatus(" + id + ",1)"); |
88
|
|
|
} |
89
|
|
|
toastr.success('设置成功'); |
90
|
|
|
} else { |
91
|
|
|
toastr.error('修改失败'); |
92
|
|
|
} |
93
|
|
|
}, |
94
|
|
|
error: function (rep) { |
95
|
|
|
toastr.error('网络错误'); |
96
|
|
|
} |
97
|
|
|
}); |
98
|
|
|
} |
99
|
|
|
</script> |
100
|
|
|
<?php |
101
|
|
|
$js = <<<JS |
102
|
|
|
var clipboard = new Clipboard('.cp'); |
103
|
|
|
toastr.options = { |
104
|
|
|
"closeButton": true, |
105
|
|
|
"debug": false, |
106
|
|
|
"positionClass": "toast-top-right", |
107
|
|
|
"onclick": null, |
108
|
|
|
"showDuration": "1000", |
109
|
|
|
"hideDuration": "1000", |
110
|
|
|
"timeOut": "5000", |
111
|
|
|
"extendedTimeOut": "1000", |
112
|
|
|
"showEasing": "swing", |
113
|
|
|
"hideEasing": "linear", |
114
|
|
|
"showMethod": "fadeIn", |
115
|
|
|
"hideMethod": "fadeOut" |
116
|
|
|
} |
117
|
|
|
clipboard.on('success', function(e) { |
118
|
|
|
toastr.success('复制成功'); |
119
|
|
|
e.clearSelection(); |
120
|
|
|
}); |
121
|
|
|
|
122
|
|
|
clipboard.on('error', function(e) { |
123
|
|
|
toastr.error('复制失败'); |
124
|
|
|
}); |
125
|
|
|
JS; |
126
|
|
|
$this->registerJs($js, View::POS_END); |
127
|
|
|
?> |
128
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.