define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'dynamic/dynamic/index' + location.search,
// add_url: 'dynamic/dynamic/add',
edit_url: 'dynamic/dynamic/edit',
del_url: 'dynamic/dynamic/del',
multi_url: 'dynamic/dynamic/multi',
// import_url: 'dynamic/dynamic/import',
table: 'dynamic',
}
});
var table = $("#table");
//修改 data-value="0" 和 name="status"
table.on('post-common-search.bs.table', function (event, table) {
$('ul.nav-tabs li a[data-value="0"]').trigger('click');
$('select[name="status"]').val('0');
$(".btn-success").trigger('click');
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'user.u_id', title: __('User.u_id')},
{field: 'user.nickname', title: __('User.nickname')},
{
field: 'content', title: __('Content'), operate: 'LIKE',
formatter: function (value, row, index, field) {
return "" + value + "";
},
cellStyle: function (value, row, index, field) {
return {
css: {
"white-space": "nowrap",
"text-overflow": "ellipsis",
"overflow": "hidden",
"max-width": "250px"
}
};
}
},
{field: 'res_type', title: __('Res_type'), searchList: {"1":__('Res_type 1'),"2":__('Res_type 2'),"3":__('Res_type 3')}, formatter: Table.api.formatter.normal},
{
field: 'image', title: __('Image'), operate: false, events: Table.api.events.image,
formatter: function (value, row, index) {
if (row.res_type == 1) {
value = value === null ? '' : value.toString();
var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
var arr = value.split(',');
var html = [];
$.each(arr, function (i, value) {
value = value ? value : '/assets/img/blank.gif';
html.push('
');
});
return html.join(' ');
} else if (row.res_type == 2) {
return "
";
} else if (row.res_type == 3) {
return "";
}
}
},
// {field: 'image_thumb', title: __('Image_thumb'), operate: 'LIKE'},
{
field: 'commit',
title: __('Commit'),
operate: false,
formatter: Controller.api.formatter.commitsearch
},
{field: 'likes', title: __('Likes'), operate: false},
{field: 'is_online', title: __('Is_online'), searchList: {"-1":__('Is_online -1'),"1":__('Is_online 1')}, formatter: Table.api.formatter.normal},
{field: 'is_recommend', title: __('Is_recommend'), searchList: {"0":__('Is_recommend 0'),"1":__('Is_recommend 1')}, formatter: Table.api.formatter.normal},
{field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
// {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
// 更多操作
$(document).on("click", ".nav-tabs li", function () {
datavalue = $(this).find('a').data('value');
if(datavalue === 0){
$(".dropdown").show();
}else{
$(".dropdown").hide();
}
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
formatter: {
commitsearch: function (value, row, index) {
//这里手动构造URL
url = "dynamic/commit?dynamic_id=" + row.id;
//方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容
//return '' + __('Search %s', value) + '';
//方式二,直接调用Table.api.formatter.addtabs
this.url = url;
this.atitle = '动态评论列表';
return Table.api.formatter.dialog.call(this, value, row, index);
}
}
}
};
return Controller;
});