1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.writesdown.com/ |
4
|
|
|
* @author Agiel K. Saputra <[email protected]> |
5
|
|
|
* @copyright Copyright (c) 2015 WritesDown |
6
|
|
|
* @license http://www.writesdown.com/license/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use yii\grid\GridView; |
10
|
|
|
use yii\helpers\ArrayHelper; |
11
|
|
|
use yii\helpers\Html; |
12
|
|
|
use yii\helpers\Url; |
13
|
|
|
use yii\widgets\Pjax; |
14
|
|
|
|
15
|
|
|
/* @var $this yii\web\View */ |
16
|
|
|
/* @var $searchModel common\models\search\MediaComment */ |
17
|
|
|
/* @var $dataProvider yii\data\ActiveDataProvider */ |
18
|
|
|
/* @var $media common\models\Media|null */ |
19
|
|
|
|
20
|
|
|
$this->title = Yii::t('writesdown', 'Media Comments'); |
21
|
|
|
$this->params['breadcrumbs'][] = [ |
22
|
|
|
'label' => Yii::t('writesdown', 'Media'), |
23
|
|
|
'url' => ['index'], |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
View Code Duplication |
if ($media) { |
|
|
|
|
27
|
|
|
$this->params['breadcrumbs'][] = $media->id; |
28
|
|
|
$this->title = Yii::t('writesdown', 'Media {media} Comments', [ |
29
|
|
|
'media' => $media->id, |
30
|
|
|
]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$this->params['breadcrumbs'][] = Yii::t('writesdown', 'Comments'); |
34
|
|
|
?> |
35
|
|
|
<div class="media-comment-index"> |
36
|
|
|
<div class="form-inline grid-nav" role="form"> |
37
|
|
|
<div class="form-group"> |
38
|
|
|
<?= Html::dropDownList( |
39
|
|
|
'bulk-action', |
40
|
|
|
null, |
41
|
|
|
ArrayHelper::merge($searchModel->getStatuses(), ['delete' => 'Delete']), [ |
42
|
|
|
'class' => 'bulk-action form-control', |
43
|
|
|
'prompt' => Yii::t('writesdown', 'Bulk Action'), |
44
|
|
|
]) ?> |
45
|
|
|
|
46
|
|
|
<?= Html::button(Yii::t('writesdown', 'Apply'), ['class' => 'btn btn-flat btn-warning bulk-button']) ?> |
47
|
|
|
|
48
|
|
|
<?= Html::button(Html::tag('i', '', ['class' => 'fa fa-search']), [ |
49
|
|
|
'class' => 'btn btn-flat btn-info', |
50
|
|
|
'data-toggle' => 'collapse', |
51
|
|
|
'data-target' => '#media-comment-search', |
52
|
|
|
]) ?> |
53
|
|
|
|
54
|
|
|
</div> |
55
|
|
|
</div> |
56
|
|
|
<?php Pjax::begin() ?> |
57
|
|
|
<?= $this->render('_search', ['model' => $searchModel, 'media' => $media]) ?> |
58
|
|
|
<?= GridView::widget([ |
59
|
|
|
'dataProvider' => $dataProvider, |
60
|
|
|
'filterModel' => $searchModel, |
61
|
|
|
'id' => 'media-comment-grid-view', |
62
|
|
|
'columns' => [ |
63
|
|
|
['class' => 'yii\grid\CheckboxColumn'], |
64
|
|
|
|
65
|
|
|
'author:ntext', |
66
|
|
|
'email:email', |
67
|
|
|
[ |
68
|
|
|
'attribute' => 'content', |
69
|
|
|
'format' => 'html', |
70
|
|
|
'value' => function ($model) { |
71
|
|
|
return substr(strip_tags($model->content), 0, 150) . '...'; |
72
|
|
|
}, |
73
|
|
|
], |
74
|
|
|
[ |
75
|
|
|
'attribute' => 'status', |
76
|
|
|
'filter' => $searchModel->getStatuses(), |
77
|
|
|
], |
78
|
|
|
|
79
|
|
|
[ |
80
|
|
|
'class' => 'yii\grid\ActionColumn', |
81
|
|
|
'template' => Yii::$app->user->can('editor') ? '{view} {update} {delete} {reply}' : '{view}', |
82
|
|
|
'buttons' => [ |
83
|
|
View Code Duplication |
'view' => function ($url, $model) { |
|
|
|
|
84
|
|
|
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', |
85
|
|
|
$model->commentMedia->url . '#comment' . $model->id, [ |
86
|
|
|
'title' => Yii::t('yii', 'View'), |
87
|
|
|
'data-pjax' => '0', |
88
|
|
|
]); |
89
|
|
|
}, |
90
|
|
|
'reply' => function ($url, $model) { |
91
|
|
|
return Html::a('<span class="glyphicon glyphicon-share-alt"></span>', [ |
92
|
|
|
'reply', |
93
|
|
|
'id' => $model->id, |
94
|
|
|
], [ |
95
|
|
|
'title' => Yii::t('writesdown', 'Reply'), |
96
|
|
|
'data-pjax' => '0', |
97
|
|
|
]); |
98
|
|
|
}, |
99
|
|
|
], |
100
|
|
|
], |
101
|
|
|
], |
102
|
|
|
]) ?> |
103
|
|
|
|
104
|
|
|
<?php Pjax::end() ?> |
105
|
|
|
|
106
|
|
|
</div> |
107
|
|
|
<?php $this->registerJs(str_replace(["\r", "\n"], "", 'jQuery(".bulk-button").click(function(e){ |
108
|
|
|
e.preventDefault(); |
109
|
|
|
if(confirm("' . Yii::t("app", "Are you sure?") . '")){ |
110
|
|
|
var ids = $("#media-comment-grid-view").yiiGridView("getSelectedRows"); |
111
|
|
|
var action = $(this).parents(".form-group").find(".bulk-action").val(); |
112
|
|
|
$.ajax({ |
113
|
|
|
url: "' . Url::to(["bulk-action"]) . '", |
114
|
|
|
data: { ids: ids, action: action, _csrf: yii.getCsrfToken() }, |
115
|
|
|
type:"POST", |
116
|
|
|
success: function(data){ |
117
|
|
|
$.pjax.reload({container:"#media-comment-grid-view"}); |
118
|
|
|
} |
119
|
|
|
}); |
120
|
|
|
} |
121
|
|
|
});')) ?> |
122
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.