<?php
/* @var $this ArticleController */
/* @var $model Article */
$this->breadcrumbs = array(
    'Articles' => array('admin'),
    'Manage',
);
$this->menu = array(
    array('label' => 'List Article', 'url' => array('admin')),
    array('label' => 'Create Article', 'url' => array('create')),
);

Yii::app()->getClientScript()->registerScript('batch-operation', "
        var _grid_id = 'article-grid';
        var _confirm = '" . Yii::t('zii', 'Are you sure you want to perform this action?') . "'; 
        jQuery('a.batch-operation').on('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>Manage Articles</h1></div>
<div class="batch-operations pull-left">
    <div class="btn-group">
        <button data-toggle="dropdown" type="button" 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->renderPartial('admin.components.actions.views.export',array('criteria'=>null,'columns'=>NULL)); ?>
<?php
$this->widget('ext.widgets.FGridView', array(
    'id' => 'article-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' => 'title',
            'value' => 'CHtml::link($data->title,array("update","id"=>$data->id))',
            'type' => 'raw',
        ),
        array(
            'name' => 'hits',
            'value' => 'number_format($data->hits)',
            'htmlOptions' => array('style' => 'width:100px;'),
        ),
        array(
            'name' => 'create_datetime',
            'value' => 'date("d-m-Y",$data->create_datetime)',
            'filter' => false,
        ),
        array(
            'name' => 'status',
            'value' => '$data->getStatusLabel($data->status)',
            'type' => 'html',
            'filter' => $model->getStatuses(),
            'htmlOptions' => array('style' => 'width:100px;'),
        ),
        // array(
        //     'class' => 'editable.EditableColumn',
        //     'name' => 'featured',
        //     'value' => '$data->getFeaturedLabel($data->featured)',
        //     'filter' => $model->getFeaturedOptions(),
        //     'htmlOptions' => array('style' => 'width:80px;'),
        //     'editable' => array(
        //         'type' => 'select',
        //         'url' => $this->createUrl('quickUpdate'),
        //         'source' => $model->getFeaturedOptions(),
        //     )
        // ),
        array(
            'name' => 'categories',
            'value' => '$data->getCategories()',
            'filter' => Category::model()->getTabList(),
        ),
//	'update_datetime',
//	'language',
        array(
            'class' => 'CButtonColumn',
            'template' => '{update}{delete}{delete_pdf}{delete_flash}{delete_image}',

            'buttons'=>array(
			
				'delete_pdf'=>array(
					'label'=>'',
                    
					'click'=>'function(){return confirm("are you sure to delete pdf ?");}',
					'url'=>'Yii::app()->createUrl("admin/article/delete_pdf", array("id"=>$data->id))',
					'visible'=>'$data->attachment_title != NULL ',
                    'options'=>array( 'class'=>'icon-trash','title'=>'Delete pdf' ),
				),
				'delete_image'=>array(
					'label'=>'',
                    
					'click'=>'function(){return confirm("are you sure to delete the article image ?");}',
					'url'=>'Yii::app()->createUrl("admin/article/deleteImage", array("id"=>$data->id))',
					'visible'=>'$data->image != NULL ',
                    'options'=>array( 'class'=>'icon-remove','title'=>'Delete Image' ),
				),

                'delete_flash'=>array(
					'label'=>'',
                    
					'click'=>'function(){return confirm("are you sure to delete flash file ?");}',
					'url'=>'Yii::app()->createUrl("admin/article/delete_flash", array("id"=>$data->id))',
					'visible'=>'$data->flash_file != NULL ',
                    'options'=>array( 'class'=>'icon-remove-circle','title'=>'Delete Flash' ),
				),
				
				
				
			)


        ),
    ),
));
