ActivityUserSelectDialog.js
7.54 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
/// <reference path="../jquery-1.11.1.js" />
/// <reference path="../jquery-easyui-1.4.1/jquery.easyui.min.js" />
/// <reference path="../jquery-easyui-ext.js" />
/// <reference path="../global.js" />
/// <reference path="../global.modelctls.js" />
/// <reference path="../global.enums.js" />
/// <reference path="../global.extension.js" />
global = global || {};
global.ui = global.ui || {};
function ActivityUserSelectDialog(url, queryParams, callback, options) {
this._options = options || {};
this._url = url || this._options.url || '';
this._queryParams = queryParams || this._options.queryParams || {};
this._callback = callback || this._options.callback;
this._task = this._options.task || {};
this._sendType = this._options.sendType || global.enums.sendType.SActivitySUser;
this._dialog = null;
this._tree = null;
this.showDialog = function (data) {
var thispd = this;
if (data) {
thispd._showDialog(data);
} else if (url) {
$.post(url, thispd._queryParams, function (result) {
var d = thispd.buildData(result);
thispd._showDialog(d);
});
}
};
this.buildData = function (data) {
data = data || [];
result = [];
for (var i = 0; i < data.length; i++) {
var activity = data[i].activity;
activity.flowObjectType = activity.flowObjectType || '';
var text = activity.flowObjectName;
if (!text && activity.flowObjectType.toLowerCase() == 'endevent') {
text = '结束';
}
var activityNode = {
id: activity.flowObjectId, text: text, type: 'activity', flowRevisionId: activity.flowRevisionId,
activityId: activity.id, flowObjectName: activity.flowObjectName, flowObjectType: activity.flowObjectType
};
result.push(activityNode);
var users = data[i].users;
if (!users || users.length <= 0) continue;
activityNode.children = [];
for (var j = 0; j < users.length; j++) {
var user = users[j];
var userNode = { id: user.id, text: user.realname, type: 'user', parentId: activityNode.id, loginname: user.loginname };
activityNode.children.push(userNode);
}
}
return result;
};
this.checkedUsers = function () {
var data = $(this._tree).tree('getRoots');
var result = [];
for (var i = 0; i < data.length; i++) {
var node = data[i];
var select = { activityId: node.activityId, flowObjectId: node.id, flowObjectName: node.flowObjectName, users: '' };
var childs = $(this._tree).tree('getChildren', node.target);
for (var j = 0; j < childs.length; j++) {
var child = childs[j];
if (child.checked) {
select.users += child.loginname + ',';
}
}
if (select.users || node.checked) {
result.push(select);
}
}
return result;
};
this._showDialog = function (data) {
var thispd = this;
var tree = thispd._tree = $('<ul/>');
var dialog = this._dialog = $('<div style="padding-left:0px;padding-top:0px;"/>').append(tree).dialog({
title: '选择发送人员', width: 300, height: 400, modal: true, onOpen: function () {
var sendType = global.enums.sendType;
$(tree).tree({
data: data, checkbox: true, onBeforeCheck: function (node, checked) {
if (!checked) return true;
if (node.type == 'activity') {
if (node.flowObjectType.toLowerCase() == 'endevent') {
thispd.uncheckTree($(this), function (fn) { return fn.parentId == node.id; });
} else {
thispd.uncheckEndNode($(this));
if (thispd._sendType == sendType.SActivitySUser) {
return false;
} else if (thispd._sendType == sendType.SActivityMUser) {
thispd.uncheckTree($(this), function (fn) { return fn.parentId == node.id; });
} else if (thispd._sendType == sendType.MActivitySUser) {
return false;
} else if (thispd._sendType == sendType.MActivityMUser) {
}
}
} else if (node.type == 'user') {
thispd.uncheckEndNode($(this));
if (thispd._sendType == sendType.SActivitySUser) {
thispd.uncheckTree($(this), function (fn) { return fn.id == node.id; });
} else if (thispd._sendType == sendType.SActivityMUser) {
thispd.uncheckTree($(this), function (fn) { return fn.parentId == node.parentId; });
} else if (thispd._sendType == sendType.MActivitySUser) {
thispd.uncheckTree($(this), function (fn) { return (fn.parentId != node.parentId || fn.id == node.id); });
} else if (thispd._sendType == sendType.MActivityMUser) {
}
}
}, onClick: function (node) {
if (node.checked) {
$(tree).tree('uncheck', node.target);
} else {
$(tree).tree('check', node.target);
}
}
});
}, buttons: [{
text: '发送', iconCls: 'icon-ok', handler: function () {
var checkedUsers = thispd.checkedUsers();
if (checkedUsers.length == 0) {
$.messager.alert('提示', '请选择人员!');
return;
} else {
if (thispd._callback) {
thispd._callback(checkedUsers);
}
$(dialog).dialog('close');
}
}
}, {
text: '取消', iconCls: 'icon-cancel', handler: function () {
$(dialog).dialog('close');
}
}],
onClose: function () {
thispd._tree = null;
thispd._dialog = null;
$(this).dialog('destroy');
}
});
};
this.uncheckTree = function (tree, filter) {
var roots = $(tree).tree('getRoots');
for (var i = 0; i < roots.length; i++) {
var root = roots[i];
var chidren = $(tree).tree('getChildren', root.target);
for (var j = 0; j < chidren.length; j++) {
var child = chidren[j];
if (filter && filter(child)) continue;
if (child.checked)
$(tree).tree('uncheck', child.target);
}
}
};
this.uncheckEndNode = function (tree) {
var roots = $(tree).tree('getRoots');
for (var i = 0; i < roots.length; i++) {
var root = roots[i];
if (root.flowObjectType.toLowerCase() == 'endevent') {
$(tree).tree('uncheck', root.target);
break;
}
}
};
};