response.js
8.4 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
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte'], function ($, undefined, Backend, Table, Form, Adminlte) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'wechat/response/index',
add_url: 'wechat/response/add',
edit_url: 'wechat/response/edit',
del_url: 'wechat/response/del',
multi_url: 'wechat/response/multi',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
sortName: 'id',
columns: [
[
{field: 'state', checkbox: true,},
{field: 'id', title: 'ID'},
{field: 'type', title: __('Type')},
{field: 'title', title: __('Resource title')},
{field: 'eventkey', title: __('Event key')},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, operate: false},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
select: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'wechat/response/index',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
sortName: 'id',
columns: [
[
{field: 'state', checkbox: true,},
{field: 'id', title: 'ID'},
{field: 'type', title: __('Type')},
{field: 'title', title: __('Title')},
{field: 'eventkey', title: __('Event key')},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, operate: false},
{
field: 'operate', title: __('Operate'), events: {
'click .btn-chooseone': function (e, value, row, index) {
Fast.api.close(row);
},
}, formatter: function () {
return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
}
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Form.api.bindevent($("form[role=form]"), function (data) {
Fast.api.close(data);
});
Controller.api.bindevent();
},
edit: function () {
Form.api.bindevent($("form[role=form]"));
Controller.api.bindevent();
},
api: {
bindevent: function () {
var getAppFileds = function (id) {
var app = apps[id];
var appConfig = app['config'];
var str = '';
for (var i in appConfig) {
var type = appConfig[i]['type'];
var field = appConfig[i]['field'];
var caption = appConfig[i]['caption'];
var defaultvalue = typeof appConfig[i]['defaultvalue'] != 'undefined' ? appConfig[i]['defaultvalue'] : '';
if (type == 'text' || type == 'textarea') {
if (type == 'textarea') {
str += '<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">' + caption + ':</label><div class="col-xs-12 col-sm-8"><textarea ' + appConfig[i]['extend'] + ' class="form-control" name="row[content][' + field + ']" data-rule="' + appConfig[i]['rule'] + '">' + defaultvalue + '</textarea> </div> </div>';
} else {
str += '<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">' + caption + ':</label><div class="col-xs-12 col-sm-8"><input ' + appConfig[i]['extend'] + ' class="form-control" name="row[content][' + field + ']" type="text" value="' + defaultvalue + '" data-rule="' + appConfig[i]['rule'] + '"> </div> </div>';
}
} else {
var options = appConfig[i]['options'];
var html = '';
if (type == 'select') {
for (var j in options) {
html += '<option value="' + j + '">' + options[j] + '</option>';
}
html = '<select ' + appConfig[i]['extend'] + ' class="form-control" name="row[content][' + field + ']">' + html + '</select>';
} else if (type == 'checkbox') {
for (var j in options) {
html += '<input type="checkbox" name="row[content][' + field + '][]" value="' + j + '"> <span>' + options[j] + '</span> ';
}
} else if (type == 'radio') {
var index = 0;
for (var j in options) {
html += '<input type="radio" name="row[content][' + field + ']" value="' + j + '" ' + (index == 0 ? 'checked' : '') + '> <span>' + options[j] + '</span> ';
index++;
}
}
str += '<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">' + caption + ':</label><div class="col-xs-12 col-sm-8">' + html + ' </div> </div>';
}
}
return str;
};
$(document).on('change', "#app", function () {
var app = $(this).val();
$("#appfields").html(getAppFileds(app));
if (datas.app == app) {
delete (datas.app);
var form = $("form.form-ajax");
$.each(datas, function (i, j) {
console.log(i, j);
form.field("row[content][" + i + "]" + ($("input[name='row[content][" + i + "][]']", form).size() > 0 ? '[]' : ''), j);
});
}
Form.api.bindevent("#appfields");
});
$(document).on('click', "input[name='row[type]']", function () {
var type = $(this).val();
if (type == 'text') {
$("#expand").html('<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">文本内容:</label><div class="col-xs-12 col-sm-8"><textarea class="form-control" name="row[content][content]" data-rule="required"></textarea></div></div>');
$("form[role='form']").field("row[content][content]", datas.content);
} else if (type == 'app') {
$("#expand").html('<div class="form-group"><label for="content" class="control-label col-xs-12 col-sm-2">应用:</label><div class="col-xs-12 col-sm-8"><select class="form-control" name="row[content][app]" id="app">' + $("select[name=applist]").html() + '</select></div></div><div id="appfields"><div>');
$("form[role='form']").field("row[content][app]", datas.app);
$("#app").trigger('change');
}
});
$("input[name='row[type]']:checked").trigger("click");
}
}
};
return Controller;
});