<?php $this->widget('admin.widgets.TableCover');?>
<h2>《<?php echo $book->bookname;?>》</h2>
<?php echo CHtml::link('完整模式', array('/admin/chapters/alist','id'=>$book->bookid));?> | <?php $this->renderPartial('_search', array('book'=>$book));?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$dataProvider,
    'itemsCssClass' => 'widefat post',
    'ajaxUpdate' => true,
    'summaryText'=>'显示{start}-{end}条 总共{count}条',
    'id' => 'chapter_grid',
    'columns' => array(
        array(
            'class' => 'CCheckBoxColumn',
            'checkBoxHtmlOptions' => array('name' => 'chapters[]'),
            'selectableRows' => 2,
            'footer' => '<button type="button" onclick="getCheckbox();" style="width:76px">批量删除</button>',
        ),
        'chapterid',
        'chaptername',
        'createdate',
        'updatedate',
        'size',
        array(
            'name' => 'display',
            'value' => '$data->isDisplay()',
        ),
        array(
            'name' => 'isimage',
            'value' => '$data->isImage()',
        ),
        array(
            'class' => 'admin.widgets.buttons.chapters.UpdateButtonColumn',
            'header' => '操作',
            'template' => '{update} {delete}',
        ),
    ),
    'afterAjaxUpdate' => "function(id,data){ $('a.update,a.create').fancybox({'titleShow':false,'scrolling':false,'mouseEnabled':false,'gallery':false}); }",
));
?>
<?php
$this->widget('application.extensions.fancybox.EFancyBox', array(
    'target'=>'a.update,a.create',
    'config'=>array(
            'titleShow' => false,
            'scrolling' => false,
            'mouseEnabled' => false,
            'gallery' => false,    
        ),
    )
);
?>
<script type="text/javascript">
/*<![CDATA[*/
var getCheckbox = function() {
    var data = new Array();
    if(!confirm('确定要删除吗?')) return false;
    $("input:checkbox[name='chapters[]']").each(function () {
        if($(this).attr("checked") == true) {
        	data.push($(this).val());
        }
    });
    if(data.length > 0){
        $.post('<?php echo CHtml::normalizeUrl(array('/admin/chapters/delall/'));?>',{'chapters[]':data}, function (data) {
        var ret = $.parseJSON(data);
        if (ret != null && ret.success != null && ret.success) {
            $.fn.yiiGridView.update('chapter_grid');
        }
    });
    } else {
        alert("请选择要删除的章节!");
    }
}
/*]]>*/
</script>