comments!="Y") return "";
/** @var yii\web\View $this */
/** @var yii\data\ActiveDataProvider $dataProvider */
$query = $model->hasMany(Comments::class,['news_id'=>"id"])->orderBy(['created_at'=>SORT_ASC]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 0
],
]);
echo "comments";
?>
$manager = \Yii::$app->getUrlManager()->createUrl('/manager/comments/ajaxtoggle');
$script = <<< JS
$('.mtoggle').on('click', function(e) {
console.log($(this).attr("id"));
console.log($(this).attr("data-value"));
$.ajax({
url: "$manager",
method: "POST",
data: {id: $(this).attr("id"), value: $(this).attr("data-value")},
success: function(data) {
let obj = JSON.parse(data);
if( obj['stat'] == 'ok' ){
let id = obj['id'];
let val = obj['value'];
if( val=="Y" ){
$('#'+id).toggleClass("btn-success");
$('#'+id).addClass('btn-danger');
$('#'+id).text("Скрыть");
$('#'+id).attr("data-value", 'N');
}else{
$('#'+id).toggleClass('btn-danger');
$('#'+id).addClass("btn-success");
$('#'+id).text("Пропустить");
$('#'+id).attr("data-value", 'Y');
}
}
}
});
});
JS;
$this->registerJs($script, View::POS_READY);