<?php
/* @var $this MemberController */
/* @var $dataProvider CActiveDataProvider */
$this->breadcrumbs = array(
    'Members',
);
$this->pageTitle = 'Kelola TIM';
?>


<?php

$total = Member::model()->getCountMember();

if ($total < 3) :
    echo CHtml::link(
        '<i class="fa fa-plus"></i> Tambah',
        array(
            'create'
        ),
        array('class' => 'btn btn-info btn-flat', 'title' => 'Tambah Anggota')
    );

endif;
?>

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'member-grid',
    'dataProvider' => $dataProvider,
    //'filter'=>$model,
    'itemsCssClass' => 'table-responsive table table-striped table-hover table-vcenter',
    'columns' => array(

        // array(
        //     'header'=>'No',
        //     'value'=>'$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1',
        //     'htmlOptions'=>array('width'=>'10px',
        //         'style' => 'text-align: center;')),

        // 'id_member',
        // 'create_time',
        // 'update_time',
        // 'visit_time',
        'code',
        'fullname',
        'phone',
        'email',

        array(
            'header' => 'KTP',
            'class' => 'CButtonColumn',
            'template' => '{KTP}',
            'buttons' => array(
                'KTP' =>
                array(
                    'url' => 'Yii::app()->createUrl("main/member/upload", array("id"=>$data->id_member,"type"=>1))',
                    'options' => array(
                        'ajax' => array(
                            'type' => 'POST',
                            'url' => "js:$(this).attr('href')",
                            'success' => 'function(data) { $("#viewModal .modal-body p").html(data); $("#viewModal").modal(); }'
                        ),
                    ),
                ),
            ),
        ),


        array(
            'header' => 'Pas Foto',
            'class' => 'CButtonColumn',
            'template' => '{Pas Foto}',
            'buttons' => array(
                'Pas Foto' =>
                array(
                    'url' => 'Yii::app()->createUrl("main/member/upload", array("id"=>$data->id_member,"type"=>2))',
                    'options' => array(
                        'ajax' => array(
                            'type' => 'POST',
                            'url' => "js:$(this).attr('href')",
                            'success' => 'function(data) { $("#viewModal .modal-body p").html(data); $("#viewModal").modal(); }'
                        ),
                    ),
                ),
            ),
        ),


        array(
            'header' => 'Follow Sosmed',
            'class' => 'CButtonColumn',
            'template' => '{Follow Sosmed}',
            'buttons' => array(
                'Follow Sosmed' =>
                array(
                    'url' => 'Yii::app()->createUrl("main/member/upload", array("id"=>$data->id_member,"type"=>3))',
                    'options' => array(
                        'ajax' => array(
                            'type' => 'POST',
                            'url' => "js:$(this).attr('href')",
                            'success' => 'function(data) { $("#viewModal .modal-body p").html(data); $("#viewModal").modal(); }'
                        ),
                    ),
                ),
            ),
        ),



        array(
            'class' => 'CButtonColumn',
            'template' => '{update}{delete}',
            'afterDelete'=>'function(link,success,data){ if(success) location.reload(); }',

            'buttons' => array(
                'update' =>
                array(
                    'url' => 'Yii::app()->createUrl("main/member/update", array("id"=>$data->id_member))',
                    'options' => array(
                        'ajax' => array(
                            'type' => 'POST',
                            'url' => "js:$(this).attr('href')",
                            'success' => 'function(data) { $("#viewModal .modal-body p").html(data); $("#viewModal").modal(); }'
                        ),
                    ),
                ),

                'delete' =>
                array(
                    'url' => 'Yii::app()->createUrl("main/member/delete", array("id"=>$data->id_member))',
                    'imageUrl' => YII::app()->baseUrl . '/image/setting/delete.png',
                ),

            ),
        ),


    ),
)); ?>



<!-- Modal -->
<div class="modal fade" id="viewModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- Popup Header -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title"><strong>Update </strong> </h4>
            </div>
            <!-- Popup Content -->
            <div class="modal-body">
                <p>Data</p>
            </div>
        </div>
    </div>
</div>