archives.js
20.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'cms/archives/index',
add_url: 'cms/archives/add',
edit_url: 'cms/archives/edit',
del_url: 'cms/archives/del',
multi_url: 'cms/archives/multi',
dragsort_url: '',
table: 'archives',
}
});
var table = $("#table");
//在表格内容渲染完成后回调的事件
table.on('post-body.bs.table', function (e, settings, json, xhr) {
//当为新选项卡中打开时
if (Config.cms.archiveseditmode == 'addtabs') {
$(".btn-editone", this)
.off("click")
.removeClass("btn-editone")
.addClass("btn-addtabs")
.prop("title", __('Edit'));
}
});
//当双击单元格时
table.on('dbl-click-row.bs.table', function (e, row, element, field) {
$(".btn-addtabs", element).trigger("click");
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'weigh',
searchFormVisible: Fast.api.query("model_id") ? true : false,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id'), sortable: true},
{
field: 'user_id',
title: __('User_id'),
visible: false,
addclass: 'selectpage',
extend: 'data-source="user/user/index" data-field="nickname"',
operate: '=',
formatter: Table.api.formatter.search
},
{
field: 'channel_id',
title: __('Channel_id'),
visible: false,
operate: false,
formatter: Table.api.formatter.search
},
{
field: 'channel.name',
title: __('Channel'),
operate: false,
formatter: function (value, row, index) {
return '<a href="javascript:;" class="searchit" data-field="channel_id" data-value="' + row.channel_id + '">' + value + '</a>';
}
},
{
field: 'model_id', title: __('Model'), visible: false, align: 'left', addclass:"selectpage", extend:"data-source='cms/modelx/index' data-field='name'"
},
{
field: 'title', title: __('Title'), align: 'left', formatter: function (value, row, index) {
return '<div class="tdtitle"><a href="' + row.url + '" target="_blank">' + value + '</a></div>' + Table.api.formatter.flag.call(this, row['flag'], row, index);
}
},
{field: 'image', title: __('Image'), operate: false, formatter: Table.api.formatter.image},
{field: 'views', title: __('Views'), operate: 'BETWEEN', sortable: true},
{field: 'comments', title: __('Comments'), operate: 'BETWEEN', sortable: true},
{field: 'weigh', title: __('Weigh'), operate: false},
{
field: 'createtime',
title: __('Createtime'),
visible: false,
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'updatetime',
title: __('Updatetime'),
sortable: true,
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{field: 'status', title: __('Status'), searchList: {"normal": __('Status normal'), "hidden": __('Status hidden'), "rejected": __('Status rejected'), "pulloff": __('Status pulloff')}, formatter: Table.api.formatter.status},
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
//当为新选项卡中打开时
if (Config.cms.archiveseditmode == 'addtabs') {
$(".btn-add").off("click").on("click", function () {
Fast.api.addtabs('cms/archives/add', __('Add'));
return false;
});
}
$(document).on("click", "a.btn-channel", function () {
$("#archivespanel").toggleClass("col-md-9", $("#channelbar").hasClass("hidden"));
$("#channelbar").toggleClass("hidden");
});
require(['jstree'], function () {
//全选和展开
$(document).on("click", "#checkall", function () {
$("#channeltree").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
});
$(document).on("click", "#expandall", function () {
$("#channeltree").jstree($(this).prop("checked") ? "open_all" : "close_all");
});
$('#channeltree').on("changed.jstree", function (e, data) {
var options = table.bootstrapTable('getOptions');
options.pageNumber = 1;
options.queryParams = function (params) {
params.filter = JSON.stringify(data.selected.length > 0 ? {channel_id: data.selected.join(",")} : {});
params.op = JSON.stringify(data.selected.length > 0 ? {channel_id: 'in'} : {});
return params;
};
table.bootstrapTable('refresh', {});
return false;
});
$('#channeltree').jstree({
"themes": {
"stripes": true
},
"checkbox": {
"keep_selected_style": false,
},
"types": {
"channel": {
"icon": "fa fa-th",
},
"list": {
"icon": "fa fa-list",
},
"link": {
"icon": "fa fa-link",
},
"disabled": {
"check_node": false,
"uncheck_node": false
}
},
'plugins': ["types", "checkbox"],
"core": {
"multiple": true,
'check_callback': true,
"data": Config.channelList
}
});
});
$(document).on('click', '.btn-move', function () {
var ids = Table.api.selectedids(table);
Layer.open({
title: __('Move'),
content: Template("channeltpl", {}),
btn: [__('Move')],
yes: function (index, layero) {
var channel_id = $("select[name='channel']", layero).val();
if (channel_id == 0) {
Toastr.error(__('Please select channel'));
return;
}
Fast.api.ajax({
url: "cms/archives/move/ids/" + ids.join(","),
type: "post",
data: {channel_id: channel_id},
}, function () {
table.bootstrapTable('refresh', {});
Layer.close(index);
});
},
success: function (layero, index) {
}
});
});
},
content: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'cms/archives/content/model_id/' + Config.model_id,
add_url: '',
edit_url: 'cms/archives/edit',
del_url: 'cms/archives/del',
multi_url: '',
table: '',
}
});
var table = $("#table");
//在表格内容渲染完成后回调的事件
table.on('post-body.bs.table', function (e, settings, json, xhr) {
$(".btn-editone", this)
.off("click")
.removeClass("btn-editone")
.addClass("btn-addtabs")
.prop("title", __('Edit'));
});
//默认字段
var columns = [
{checkbox: true},
//这里因为涉及到关联多个表,因为用了两个字段来操作,一个隐藏,一个搜索
{field: 'main.id', title: __('Id'), visible: false},
{field: 'id', title: __('Id'), operate: false},
{
field: 'channel_id',
title: __('Channel_id'),
addclass: 'selectpage',
extend: 'data-source="cms/channel/index"',
formatter: Table.api.formatter.search
},
{field: 'channel_name', title: __('Channel_name'), operate: false}
];
//动态追加字段
$.each(Config.fields, function (i, j) {
var data = {field: j.field, title: j.title, operate: 'like'};
//如果是图片,加上formatter
if (j.type == 'image') {
data.formatter = Table.api.formatter.image;
} else if (j.type == 'images') {
data.formatter = Table.api.formatter.images;
} else if (j.type == 'radio' || j.type == 'check' || j.type == 'select' || j.type == 'selects') {
data.formatter = Controller.api.formatter.content;
data.extend = j.content;
}
columns.push(data);
});
//追加操作字段
columns.push({
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: columns
});
// 为表格绑定事件
Table.api.bindevent(table);
},
diyform: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'cms/archives/diyform/diyform_id/' + Config.diyform_id,
add_url: '',
edit_url: 'cms/archives/edit',
del_url: 'cms/archives/del',
multi_url: '',
table: '',
}
});
var table = $("#table");
//在表格内容渲染完成后回调的事件
table.on('post-body.bs.table', function (e, settings, json, xhr) {
$(".btn-editone", this)
.off("click")
.removeClass("btn-editone")
.addClass("btn-addtabs")
.prop("title", __('Edit'));
});
//默认字段
var columns = [
{checkbox: true},
{field: 'id', title: __('Id'), operate: false},
];
//动态追加字段
$.each(Config.fields, function (i, j) {
var data = {field: j.field, title: j.title, operate: 'like'};
//如果是图片,加上formatter
if (j.type == 'image') {
data.formatter = Table.api.formatter.image;
} else if (j.type == 'images') {
data.formatter = Table.api.formatter.images;
} else if (j.type == 'radio' || j.type == 'check' || j.type == 'select' || j.type == 'selects') {
data.formatter = Controller.api.formatter.content;
data.extend = j.content;
}
columns.push(data);
});
//追加操作字段
columns.push({
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: columns
})
;
// 为表格绑定事件
Table.api.bindevent(table);
},
recyclebin: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
'dragsort_url': ''
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: 'cms/archives/recyclebin',
pk: 'id',
sortName: 'weigh',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'title', title: __('Title'), align: 'left'},
{field: 'image', title: __('Image'), operate: false, formatter: Table.api.formatter.image},
{
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-restoreit',
icon: 'fa fa-rotate-left',
url: 'cms/archives/restore'
},
{
name: 'Destroy',
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-destroyit',
icon: 'fa fa-times',
url: 'cms/archives/destroy'
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
$(document).on('click', '.btn-destroyall', function () {
var that = this;
Layer.confirm(__('Are you sure you want to truncate?'), function () {
Fast.api.ajax($(that).attr("href"), function () {
Layer.closeAll();
table.bootstrapTable('refresh');
}, function () {
Layer.closeAll();
});
});
return false;
});
$(document).on('click', '.btn-restoreall,.btn-restoreit,.btn-destroyit', function () {
Fast.api.ajax($(this).attr("href"), function () {
table.bootstrapTable('refresh');
});
return false;
});
},
add: function () {
$(document).on('change', '#c-channel_id', function () {
Fast.api.ajax({
url: 'cms/archives/get_channel_fields',
data: {channel_id: $(this).val()}
}, function (data) {
$("#extend").html(data.html);
Form.api.bindevent($("#extend"));
return false;
});
localStorage.setItem('last_channel_id', $(this).val());
});
var last_channel_id = localStorage.getItem('last_channel_id');
if (last_channel_id) {
$("#c-channel_id option[value='" + last_channel_id + "']").prop("selected", true);
}
$("#c-channel_id").trigger("change");
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
Fast.api.ajax({
url: 'cms/archives/get_channel_fields',
data: {channel_id: $("#c-channel_id").val(), archives_id: $("#archive-id").val()}
}, function (data) {
$("#extend").html(data.html);
Form.api.bindevent($("#extend"));
return false;
});
},
api: {
formatter: {
content: function (value, row, index) {
var extend = this.extend;
if (!value) {
return '';
}
var valueArr = value.toString().split(/,/);
var result = [];
$.each(valueArr, function (i, j) {
result.push(typeof extend[j] !== 'undefined' ? extend[j] : j);
});
return result.join(',');
}
},
bindevent: function () {
$.validator.config({
rules: {
diyname: function (element) {
if (element.value.toString().match(/^\d+$/)) {
return __('Can not be digital');
}
return $.ajax({
url: 'cms/archives/check_element_available',
type: 'POST',
data: {id: $("#archive-id").val(), name: element.name, value: element.value},
dataType: 'json'
});
}
}
});
Form.api.bindevent($("form[role=form]"), function () {
if (Config.cms.archiveseditmode == 'addtabs') {
var obj = top.window.$("ul.nav-addtabs li.active");
top.window.Toastr.success(__('Operation completed'));
top.window.$(".sidebar-menu a[url$='/cms/archives'][addtabs]").click();
top.window.$(".sidebar-menu a[url$='/cms/archives'][addtabs]").dblclick();
obj.find(".fa-remove").trigger("click");
}
});
}
}
};
return Controller;
});