<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\bootstrap\Modal;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel app\models\MVotingSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Voting';
$this->params['breadcrumbs'][] = $this->title;
?>

<?php
        
    Modal::begin([
        'header' => '<center><h4>DATA VOTING</h4></center>',
        'id' => 'modal-data',
        'size' => 'modal-lg',
        'options' => [
              'tabindex' => false, 
          ],
    ]);

    echo '<div id="content-modal-data"></div>';
    Modal::end();
?>

<div class="mvoting-index">

    <center><h3><b class="text-danger">MASTER DATA VOTING</b></h3></center>

    <p align="right">

       

        <?= Html::button('<span class="glyphicon glyphicon-plus"></span> TAMBAH DATA VOTING', ['id' => 'modalButton', 'value' => \yii\helpers\Url::to(['create']), 'class' => 'btn btn-success']) ?>
    </p>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'nama_voting',
            'periode_awal',
            'periode_tutup',
            'status_aktif',

            [
                'attribute' => 'status_aktif',
                'format' =>'raw',
                'value' => function ($model){
                    if ($model->status_aktif==1) {
                        return '<b><span class="label label-primary">AKTIF</span></b>';
                    }else{
                        return '<b><span class="label label-danger">TIDAK AKTIF</span></b>';
                    }
                }
            ],

           /* [
                'options' => [
                    'width' => '80px',
                ],
                'class' => 'yii\grid\ActionColumn'
            ],*/

            [
                'options' => [
                    'width' => '150px',
                ],
                'header' => 'AKSI',

                'class' => 'yii\grid\ActionColumn',
                    'template' => '{view} {update} {delete}',
                    'buttons' => [
                        'view' => function($url, $model) {
                            return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', '#', [
                                        'class' => 'btn btn-info',
                                        'title' => 'VIEW DATA',
                                        'onclick' => "
                          $.ajax({
                            url: '$url',
                            success:function(data){
                              $('#title').html('Detail Organisasi');
                              $('#content-modal-data').html(data);
                              $('#modal-data').modal('show');
                            },
                            error:function(xhr, ajaxOptions, throwError){
                              alert(xhr.responseText);
                            }
                          })
                          ",
                                    ]);
                        },

                        'update' => function($url, $model) {
                            return Html::a('<span class="glyphicon glyphicon-pencil"></span>', '#', [
                                        'class' => 'btn btn-warning',
                                        'title' => 'EDIT DATA',
                                        'id' => 'modalButton',
                                        'onclick' => "
                          $.ajax({
                            url: '$url',
                            success:function(data){
                              $('#title').html('Detail Organisasi');
                              $('#content-modal-data').html(data);
                              $('#modal-data').modal('show');
                            },
                            error:function(xhr, ajaxOptions, throwError){
                              alert(xhr.responseText);
                            }
                          })
                          ",
                                    ]);
                        },
                        'delete' => function ($url, $model) {
                            return  Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
                                        'class' => 'btn btn-danger',
                                        'title' => 'HAPUS DATA',
                                        'data-toggle' => 'tooltip',
                                        'data-method' => 'post',
                                        'data-confirm' => 'Apakah anda yakin ingin menghapus data ini?'
                                    ]);
                        },
                    ]
            ],

            [
                'header' => 'KANDIDAT',
                
                'format' =>'raw',
                'value' => function ($model){
                    if ($model->id_voting!=NULL) {
                        return Html::a('<span class="glyphicon glyphicon-list-alt"></span> LIHAT KANDIDAT VOTING',Url::to(['kandidat/index','id_voting'=>$model->id_voting]),['data-pjax' => 0, 'class' => 'btn btn-default btn-sm',
                                        'title' => 'LIHAT KANDIDAT VOTING',]);
                    }else{
                        return "-";
                    }
                }

                
            ],


        ],
    ]); ?>

   


</div>

<?php
 
$script = <<< JS
    $(function () {
        $('#modalButton').click(function () {
            $('#modal-data').modal('show')
                .find('#content-modal-data')
                .load($(this).attr('value'));
        });
        
    });
    
    
    
JS;
$this->registerJs($script)
?>
