template.js
9.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'dinghorn/template/index' + location.search,
add_url: 'dinghorn/template/add',
edit_url: 'dinghorn/template/edit',
del_url: 'dinghorn/template/del',
multi_url: 'dinghorn/template/multi',
table: 'dinghorn_template',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'code', title: __('Code')},
{field: 'name', title: __('Name'), operate: 'LIKE', placeholder: '模糊查找'},
{field: 'robot_names', title: __('Robot_ids'), formatter: Controller.api.formatter.robot_names, operate: false},
{field: 'typelist', title: __('Typelist'), searchList: {"text": __('Typelist text'), "link": __('Typelist link'), "markdown": __('Typelist markdown'), "actionCard": __('Typelist actioncard'), "actionCard_whole": __('Typelist actioncard_whole'), "feedCard": __('Typelist feedcard')}, formatter: Table.api.formatter.normal},
{field: 'content', title: __('Content'), operate: 'LIKE', placeholder: '模糊查找', formatter: Controller.api.formatter.content_names},
{field: 'title', title: __('Title'), operate: 'LIKE', placeholder: '模糊查找'},
// {field: 'msg_url', title: __('Msg_url'), formatter: Table.api.formatter.url},
// {field: 'picurl_image', title: __('Picurl_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
// {field: 'single_title', title: __('Single_title')},
// {field: 'btn_orientation', title: __('Btn_orientation'), searchList: {"0":__('Btn_orientation 0'),"1":__('Btn_orientation 1')}, formatter: Table.api.formatter.normal},
// {field: 'hide_avatar', title: __('Hide_avatar'), searchList: {"0":__('Hide_avatar 0'),"1":__('Hide_avatar 1')}, events: Table.api.events.image, formatter: Table.api.formatter.image},
// {field: 'btns', title: __('Btns')},
{field: 'at_mobiles', title: __('At_mobiles'), operate: 'LIKE', placeholder: '模糊查找'},
{field: 'is_atall', title: __('Is_atall'), searchList: {"0": __('Is_atall 0'), "1": __('Is_atall 1')}, formatter: Table.api.formatter.normal},
{field: 'openswitch', title: __('Openswitch'), searchList: {"0": __('Openswitch 0'), "1": __('Openswitch 1')}, formatter: Table.api.formatter.toggle},
{field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
{
field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
buttons: [
{
name: 'test_msg',
title: __('发送通知消息'),
classname: 'btn btn-xs btn-success btn-magic btn-ajax',
icon: 'fa fa-send-o',
url: 'dinghorn/template/msg_test',
confirm: '确认发送?',
success: function (data, ret) {
Fast.api.msg(ret.msg);
},
error: function (data, ret) {
Fast.api.msg(ret.msg);
return false;
}
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
recyclebin: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
'dragsort_url': ''
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: 'dinghorn/template/recyclebin' + location.search,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'name', title: __('Name'), operate: 'LIKE', placeholder: '模糊查找'},
{
field: 'deletetime',
title: __('Deletetime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
width: '130px',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'Restore',
text: __('Restore'),
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
icon: 'fa fa-rotate-left',
url: 'dinghorn/template/restore',
refresh: true
},
{
name: 'Destroy',
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
icon: 'fa fa-times',
url: 'dinghorn/template/destroy',
refresh: true
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function (e) {
Form.api.bindevent($("form[role=form]"));
function need_show(value) {
$('.msg_group').hide();
if (value == 'text') {
$('.msg_content,.msg_at').show(200);
}
else if (value == 'link') {
$('.msg_title,.msg_content,.msg_picurl_image,.msg_url').show(200);
}
else if (value == 'markdown') {
$('.msg_title,.msg_content,.msg_at,.markdown_help').show(200);
}
else if (value == 'actionCard') {
$('.msg_title,.msg_content,.markdown_help,.msg_btns,.msg_btn_orientation,.msg_hide_avatar').show(200);
}
else if (value == 'actionCard_whole') {
$('.msg_title,.msg_content,.markdown_help,.msg_single_title,.msg_url,.msg_btn_orientation,.msg_hide_avatar').show(200);
}
else if (value == 'feedCard') {
$('.msg_links').show(200);
}
}
need_show($('#c-typelist')[0].value);
// 切换消息类型时,显示不同的输入框,变化太多,直接每项都来个class
$('#c-typelist').on('change', function () {
need_show(this.value);
})
$('#show_grammar').on('click', function () {
$('.markdown_grammar').show(200);
$('.markdown_help').hide();
})
},
formatter: {
robot_names: function (value, row) {
var value = value.split(',');
var btn_html = '';
for (let i in value) {
btn_html += ' <a href="javascript:;" title="' + value[i] + '" class="btn btn-xs btn-info robot_names">' + value[i] + '</a> ';
}
return btn_html;
},
content_names: function (value, row) {
if (value.length > 30) {
return value.substring(0, 30) + '...';
}
return value;
}
}
}
};
return Controller;
});