<?php
/* @var $this CommentController */
/* @var $model Comment */
$cs = Yii::app()->clientScript;
$this->breadcrumbs = array(
    'Comments' => array('admin'),
    Yii::t('admin', 'Manage'),
);

$this->menu = array(
    array('label' => 'Manage Comment', 'url' => array('admin')),
    array('label' => 'Create Comment', 'url' => array('create')),
);

$cs->registerScript('batch-operation', "
        var _grid_id = 'comment-grid';
        var _confirm = '" . Yii::t('zii', 'Are you sure you want to perform this action?') . "'; 
        jQuery('a.batch-operation').live('click', function(e) {        
                e.preventDefault();
                var _items = $.fn.yiiGridView.getChecked(_grid_id, 'item-check-box');
                if(_items.length===0){jQuery('.batch-operations .errorMessage').removeClass('hidden');return false}
                jQuery('.batch-operations .errorMessage').addClass('hidden');
                
                if (confirm(_confirm)) {
                        jQuery.ajax({
                                'type': 'POST',
                                'data': {'items': _items,},
                                'success': function(data) {jQuery.fn.yiiGridView.update(_grid_id);},
                                'error': function(jqXHR, textStatus, errorThrown) {jQuery.fn.yiiGridView.update(_grid_id);},
                                'url': $(this).attr('href'),
                                'cache': false,
                        });
                        return false;
                } else return false;
        });        
");
?>
<div class="page-header">
    <h1><?php echo Yii::t("admin", "Manage Comments"); ?></h1>
</div>

<div class="batch-operations">
    <div class="btn-group">
        <button data-toggle="dropdown" class="btn btn-info btn-sm dropdown-toggle"><i class="icon-white icon-cog"></i><?php echo Yii::t('admin', 'Options'); ?><span class="icon-caret-down icon-on-right"></span></button>
        <ul class="dropdown-menu">
            <li><a href="<?php echo $this->createUrl('batchOperation', array('operation' => 'delete', 'ajax' => TRUE)); ?>" class="batch-operation batch-delete"><i class="icon icon-trash"></i>&nbsp;&nbsp;<?php echo Yii::t('site', 'Delete'); ?></a></li>
            <li><a href="<?php echo $this->createUrl('batchOperation', array('operation' => 'approve', 'ajax' => TRUE)); ?>" class="batch-operation batch-approve"><i class="icon icon-ok-circle"></i>&nbsp;<?php echo Yii::t('site', 'Approve'); ?></a></li>
            <li><a href="<?php echo $this->createUrl('batchOperation', array('operation' => 'draft', 'ajax' => TRUE)); ?>" class="batch-operation batch-approve"><i class="icon icon-ban-circle"></i>&nbsp;<?php echo Yii::t('site', 'Draft'); ?></a></li>
        </ul>
    </div><!-- /btn-group -->
    <span class="errorMessage hidden" ><?php echo Yii::t('site', 'Please select at least one item to delete.'); ?></span>
</div>




<?php
$this->widget('ext.widgets.FGridView', array(
    'id' => 'comment-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        array(
            'class' => 'CCheckBoxColumn',
            'selectableRows' => 10000,
            'id' => 'item-check-box', // need this id for use with $.fn.yiiGridView.getChecked(containerID,columnID)
            'htmlOptions' => array('style' => 'width:20px;'),
        ),
        array(
            'name' => 'id',
            'htmlOptions' => array('style' => 'width:50px;'),
        ),
        array(
            'header' => Yii::t('admin', 'Sender Informations'),
            'value' => '$data->sender_name."<br/>".$data->sender_email."<br/>".$data->sender_homepage."<br/>"',
            'type' => 'html',
        ),
//        'sender_name',
//        'sender_email',
//        'sender_homepage',
        array(
            'name' => 'body',
            'type' => 'text',
        ),
//        'user_agent',
        array(
            'name' => 'create_datetime',
            'value' => 'Yii::app()->dateFormatter->formatDateTime($data->create_datetime)',
            'filter' => false,
        ),
        array(
            'class' => 'editable.EditableColumn',
            'name' => 'status',
            'value' => '$data->getStatusLabel()',
            'filter' => Locale::getStatues(),
            'headerHtmlOptions' => array('style' => 'width: 150px'),
            'editable' => array(
                'type' => 'select',
                'url' => $this->createUrl('quickUpdate'),
                'source' => Comment::getStatuses(),
            )
        ),
        array(
            'name' => 'ip_address',
            'value' => '(strlen($data->country)? CHtml::image(Yii::app()->baseUrl."/images/admin/flags/".strtolower($data->country).".png",$data->country,array("title"=>$data->country)):"")."<span>".long2ip($data->ip_address)."</span>"',
            'type' => 'html',
            'htmlOptions' => array('id' => 'cell-ip_address', 'width' => '100px'),
            'filter' => false,
        ),
//        'update_datetime',
//        'owner_route',
//        'owner_params',
//        'parent_id',
        array(
            'class' => 'CButtonColumn',
        ),
    ),
));
?>