fields.js
7.8 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
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'facrm/fields/index' + Config.params,
add_url: 'facrm/fields/add' + Config.params,
edit_url: 'facrm/fields/edit' + Config.params,
del_url: 'facrm/fields/del' + Config.params,
multi_url: 'facrm/fields/multi' + Config.params,
table: 'facrm_fields',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'weigh',
pagination: false,
search: false,
commonSearch: false,
columns: [
[
{
field: 'state', checkbox: true, formatter: function (value, row, index) {
if (row.state === false) {
return {
disabled: true,
}
} else {
return {
disabled: false,
}
}
}
},
{
field: 'id', sortable: true, title: __('Id'), formatter: function (value, row, index) {
return isNaN(value) ? '-' : value;
}
},
{field: 'source', visible: false, operate: false, title: __('Source')},
{
field: 'name', title: __('Name'), formatter: function (value, row, index) {
return row.issystem ? "<span class='text-muted'>" + value + "</span>" : value;
}
},
{
field: 'type', title: __('Type'), formatter: function (value, row, index) {
return row.issystem ? "<span class='text-muted'>" + value + "</span>" : value;
}
},
{
field: 'title', title: __('Title'), formatter: function (value, row, index) {
return row.issystem ? "<span class='text-muted'>" + value + "</span>" : value;
}
},
{
field: 'isfilter',
title: __('列表搜索'),
searchList: {"1": __('Yes'), "0": __('No')},
formatter: function (value, row, index) {
return row.issystem ? "-" : Table.api.formatter.toggle.call(this, value, row, index);
}
},
{
field: 'islist',
title: __('显示列表'),
searchList: {"1": __('Yes'), "0": __('No')},
formatter: function (value, row, index) {
return row.issystem ? "-" : Table.api.formatter.toggle.call(this, value, row, index);
}
},
{field: 'weigh', title: __('Weigh'), visible: false},
{
field: 'createtime',
title: __('Createtime'),
visible: false,
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime,
extend: 'autocomplete="off"'
},
{
field: 'updatetime',
title: __('Updatetime'),
visible: false,
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime,
extend: 'autocomplete="off"'
},
{
field: 'status', title: __('Status'), formatter: function (value, row, index) {
return row.issystem ? "-" : Table.api.formatter.status.call(this, value, row, index);
}
},
{
field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
formatter: function (value, row, index) {
return row.issystem ? "<div style='height:26px;line-height:26px;'>-</div>" : Table.api.formatter.operate.call(this, value, row, index);
}
}
]
],
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
//渲染关联显示字段和存储字段
var renderselect = function (id, data, defaultvalue) {
var html = [];
for (var i = 0; i < data.length; i++) {
html.push("<option value='" + data[i].name + "' " + (defaultvalue == data[i].name ? "selected" : "") + " data-subtext='" + data[i].title + "'>" + data[i].name + "</option>");
}
var select = $(id);
$(select).html(html.join(""));
select.trigger("change");
if (select.data("selectpicker")) {
select.selectpicker('refresh');
}
};
//关联表切换
$(document).on('change', "#c-selectpage-table", function (e, first) {
var that = this;
Fast.api.ajax({
url: "facrm/fields/gettablefields",
data: {table: $(that).val()},
}, function (data, ret) {
renderselect("#c-selectpage-primarykey", data.fieldList, first ? $("#c-selectpage-primarykey").data("value") : '');
renderselect("#c-selectpage-field", data.fieldList, first ? $("#c-selectpage-field").data("value") : '');
return false;
});
return false;
});
//如果编辑模式则渲染已知数据
if (['selectpage', 'selectpages'].indexOf($("#c-type").val()) > -1) {
$("#c-selectpage-table").trigger("change", true);
}
//不可见的元素不验证
$("form#add-form").data("validator-options", {ignore: ':hidden'});
$(document).on("change", "#c-type", function () {
$(".tf").addClass("hidden");
$(".tf.tf-" + $(this).val()).removeClass("hidden");
});
Form.api.bindevent($("form[role=form]"));
$("#c-type").trigger("change");
}
}
};
return Controller;
});