<?php
/* @var $this AlbumController */
/* @var $model Album */

$this->breadcrumbs = array(
    'Albums' => array('admin'),
    Yii::t('admin', 'Manage'),
);

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

Yii::app()->getClientScript()->registerScript('batch-operation', "
        var _grid_id = 'album-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 Albums"); ?></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' => 'album-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(
            'name' => 'image',
            'value' => 'CHtml::image(Yii::app()->params["uploadUrl"] . get_class($data) . "/" . $data->image,$data->title,array("style"=>"height:100px"))',
            'type' => 'html',
            'htmlOptions' => array("style" => "width:150px;"),
            'filter' => false,
        ),
        array(
            'name' => 'title',
            'value' => 'CHtml::link($data->title,array("update","id"=>$data->id))',
            'type' => 'raw',
        ),
//        'slug',
        array(
            'name' => 'categories',
            'value' => '$data->getCategories()',
            'filter' => Category::model()->getTabList(),
        ),
        array(
            'name' => 'create_datetime',
            'value' => 'Yii::app()->dateFormatter->formatDateTime($data->create_datetime)',
            'filter' => false,
        ),
        array(
            'name' => 'status',
            'value' => '$data->getStatusLabel($data->status)',
            'type' => 'html',
            'filter' => $model->getStatuses(),
            'htmlOptions' => array('style' => 'width:100px;'),
        ),
        array(
            'header' => Yii::t('admin', 'Images Count'),
            'name' => 'albumImagesCount',
        ),
        array(
            'header' => '',
            'value' => 'CHtml::link(Yii::t("admin", "Upload Images"), array("albumImage/upload", "album_id" => $data->id,), array("class" => "btn btn-xs btn-info"))." ".CHtml::link(Yii::t("admin", "Manage Images"), array("albumImage/admin", "album_id" => $data->id,), array("class" => "btn btn-xs"))',
            'type' => 'html',
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => '{update} {delete}',
        ),
    ),
));
?>