define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mobile/topic/topic/index' + location.search,
                    add_url: 'mobile/topic/topic/add',
                    edit_url: 'mobile/topic/topic/edit',
                    del_url: 'mobile/topic/topic/del',
                    multi_url: 'mobile/topic/topic/multi',
					examine_url: 'mobile/topic/topic/examine',
                    table: 'mobile_topic',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'category.name', title: __('所属分类')},
                        {field: 'user.mobile', title: __('发布者')},
                        {field: 'title', title: __('Title')},
                        {field: 'cover', title: __('Cover'), events: Table.api.events.image, formatter: Table.api.formatter.image, searchable: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'is_recommend', title: __('Is_recommend'), searchList: {"0":__('Is_recommend 0'),"1":__('Is_recommend 1')}, formatter: Table.api.formatter.toggle},
                        {field: 'agree_num', title: __('Agree_num')},
                        {field: 'download_num', title: __('Download_num')},
                        {field: 'hot_num', title: __('Hot_num')},
						{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
						    buttons: [
						        {
						            name: 'examine',
						            text: '通过',
						            title: '通过',
						            classname: 'btn btn-xs btn-primary btn-ajax',
						            icon: '',
						            url: $.fn.bootstrapTable.defaults.extend.examine_url+'/status/1',
						            confirm: '是否确认通过审核?',
						            visible:function (row) {
						                if(row.status == 0){
						                    return true;
						                }else{
						                    return false;
						                }
						            },
						            success: function (data) {
						                table.bootstrapTable('refresh');
						            }
						        },
						    ], formatter: Table.api.formatter.operate,
						}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});