-
Notifications
You must be signed in to change notification settings - Fork 87
/
user.html
416 lines (380 loc) · 14.7 KB
/
user.html
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
<div class="user">
<h1></h1>
<div class="buttonBar well well-sm">
<button class="btn btn-default editButton">Edit</button>
<button class="btn btn-primary saveButton initialhide">Save</button>
<button class="btn btn-default cancelButton initialhide">Cancel</button>
<button class="btn btn-default sendPasswordResetLinkButton initialhide">Send password reset link</button>
</div>
<ul class="nav nav-tabs">
<li class="detailsLink active"><a>Details</a></li>
<li class="revisionsLink"><a>Revisions</a></li>
<li class="checkoutsLink"><a>Checkouts</a></li>
<li class="projectsLink"><a>Projects</a></li>
</ul>
<div class="content">
<div class="details tab-pane">
<table class="table detailsTable">
<thead></thead>
<tbody></tbody>
</table>
</div>
<div class="revisions tab-pane initialhide">
<div class="well well-sm norevisions">No revisions</div>
<table class="revisionsTable initialhide table table-striped table-hover">
<thead>
<tr>
<th>Id</th>
<th>Date</th>
<th>Project</th>
<th>Comment</th>
<th>Size</th>
<th>Actions</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div class="tab-pane checkouts initialhide">
<div class="well well-sm nocheckouts">No checkouts</div>
<table class="checkoutsTable initialhide table table-striped table-hover">
<thead>
<tr>
<th>Id</th>
<th>Date</th>
<th>User</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="projects tab-pane initialhide">
<div class="well well-sm noprojects">No projects</div>
<div class="linkspacer">
<a class="addProjectLink">Add project</a>
</div>
<div class="well well-sm noProjectsMessage initialhide"></div>
<div class="addProjectToUserDiv initialhide">
<form class="form-inline">
<div class="form-group">
<select class="form-control"></select>
</div>
<button class="btn btn-default">Add</button>
</form>
</div>
<table class="projectsTable initialhide table table-striped table-hover">
<thead>
<tr><th>Name</th><th>Sub Projects</th><th>Revisions</th><th>Actions</th></tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div class="initialhide tab-pane dropdowntemplate">
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown">
Actions
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a>Download/Checkout</a></li>
</ul>
</div>
</div>
</div>
<script>
function User(containerDiv, main, user) {
var othis = this;
othis.user = user;
this.close = function() {
};
this.show = function(){
if (typeof user == "number" || typeof user == "string") {
othis.reloadUser(user);
} else {
othis.user = user;
othis.updateUser();
}
};
this.reloadUser = function(uoid) {
if (uoid == null) {
uoid = othis.user.oid;
}
Global.bimServerApi.call("ServiceInterface", "getUserByUoid", {uoid: uoid}, function(user){
othis.user = user;
othis.updateUser();
});
};
this.updateUser = function() {
$(".user h1").html(othis.user.name);
// $(".user .revisionsLink a").html("Revisions" + (othis.user.revisions.length == 0 ? "" : (" (" + othis.user.revisions.length + ")")));
$(".user .checkoutsLink a").html("Checkouts" + (othis.user.checkouts == null || othis.user.checkouts.length == 0 ? "" : (" (" + othis.user.checkouts.length + ")")));
$(".user .projectsLink a").html("Projects" + (othis.user.hasRightsOn.length == 0 ? "" : (" (" + othis.user.hasRightsOn.length + ")")));
containerDiv.find(".detailsTable tbody").empty();
containerDiv.find(".detailsTable").append("<tr><td>Username</td><td>" + othis.user.username + "</td></tr>");
containerDiv.find(".detailsTable").append("<tr><td>Name</td><td>" + othis.user.name + "</td></tr>");
containerDiv.find(".detailsTable").append("<tr><td>UUID</td><td>" + othis.user.uuid + "</td></tr>");
containerDiv.find(".detailsTable").append("<tr><td>Created on</td><td>" + formatDateTime(new Date(othis.user.createdOn)) + " (by <span class=\"createdBy\"></span>)</td></tr>");
containerDiv.find(".createdBy").append(createUserLink(main, othis.user.createdById));
containerDiv.find(".detailsTable").append("<tr><td>Type</td><td><div class=\"ro\">" + formatUserType(othis.user.userType) + "</div><div class=\"w\"><select class=\"form-control usertypeSelect\"><option value=\"ADMIN\">Administrator</option><option value=\"USER\">User</option><option value=\"READ_ONLY\">Read only</option></select></div></td></tr>");
containerDiv.find(".usertypeSelect").val(othis.user.userType);
containerDiv.find(".detailsTable").append("<tr><td>State</td><td>" + othis.user.state + "</td></tr>");
containerDiv.find(".detailsTable").append("<tr><td>Service Token</td><td>" + othis.user.token + "</td></tr>");
Global.bimServerApi.call("ServiceInterface", "getAllCheckoutsByUser", {uoid: othis.user.oid}, function(checkouts){
$(".user .checkoutsLink a").html("Checkouts" + (checkouts == null || checkouts.length == 0 ? "" : (" (" + checkouts.length + ")")));
});
$(".user .w").hide();
var history = History.getState().data;
if (history.tab == "details") {
othis.showDetails();
} else if (history.tab == "revisions") {
othis.showRevisions();
} else if (history.tab == "checkouts") {
othis.showCheckouts();
} else if (history.tab == "projects") {
othis.showProjects();
} else {
othis.showDetails();
}
};
this.showDetails = function() {
pushHistory({page: "User", uoid: othis.user.oid, tab: "details"}, "User " + othis.user.name);
$(".user .nav li").removeClass("active");
$(".user .detailsLink").addClass("active");
$(".user .content > div").hide();
$(".user .details").show();
};
this.projectClick = function() {
main.showProject($(this).data("project"), null, true);
othis.close();
};
this.revisionClick = function(event) {
if (!$(event.target).is("a, button, span.caret")) {
main.showRevision($(this).parents("tr").andSelf().data("revision"), null, true);
othis.close();
}
};
this.addRevision = function(revision) {
$(".user .norevisions").hide();
$(".user .revisionsTable").show();
var revisionRow = $("<tr class=\"revision\">");
revisionRow.data("revision", revision);
revisionRow.click(othis.revisionClick);
revisionRow.append("<td>" + revision.id + "</td>");
revisionRow.append("<td><span title=\"" + formatDateTime(new Date(revision.date)) + "\" class=\"timespan\" datetime=\"" + revision.date + "\">" + formatTimeSpan(new Date().getTime() - revision.date, false) + "</span></td>");
var projectTd = $("<td></td>");
var projectA = $("<a>loading...</a>");
projectA.attr("poid", revision.projectId);
loadProject(projectA);
projectA.click(othis.projectClick);
projectTd.append(projectA);
revisionRow.append(projectTd);
revisionRow.append("<td>" + revision.comment + "</td>");
revisionRow.append("<td>" + revision.size + "</td>");
var actions = $("<td></td>");
var dd = $(".dropdowntemplaterevision").clone();
dd.removeClass("dropdowntemplaterevision");
dd.find(".downloadCheckoutRevisionButton").click(othis.downloadCheckoutClick);
dd.show();
actions.append(dd);
revisionRow.append(actions);
$(".revisionsTable tbody").append(revisionRow);
};
this.downloadCheckoutClick = function(event) {
event.preventDefault();
othis.showDownloadCheckoutPopup($(this).parents("tr").andSelf().data("revision"));
};
this.showDownloadCheckoutPopup = function(revision) {
var div = $("<div class=\"modal fade\">");
$(document.body).append(div);
var params = {
downloadType: "single",
allowCheckouts: true,
poid: revision.projectId,
roid: revision.oid
};
div.load(Global.baseDir + "download.html", function(){
new Download($(this), params);
}).modal({keyboard:true});
};
this.showRevisions = function() {
pushHistoryAppend({tab: "revisions"}, "User " + othis.user.name);
$(".user .nav li").removeClass("active");
$(".user .revisionsLink").addClass("active");
$(".user .content > div").hide();
$(".user .revisions").show();
Global.bimServerApi.call("ServiceInterface", "getAllRevisionsByUser", {uoid: othis.user.oid}, function(data){
$(".revisionsTable tr.revision").remove();
data.forEach(function(revision){
othis.addRevision(revision);
});
});
};
this.addCheckout = function(checkout) {
$(".user .nocheckouts").hide();
$(".user .checkoutsTable").show();
var checkoutRow = $("<tr>");
checkoutRow.data("checkout", checkout);
checkoutRow.data("revision", checkout.revision);
checkoutRow.click(othis.checkoutClick);
checkoutRow.append("<td>" + checkout.revision.id + "</td>");
checkoutRow.append("<td><span title=\"" + formatDateTime(new Date(checkout.date)) + "\" class=\"timespan\" datetime=\"" + checkout.date + "\">" + formatTimeSpan(new Date().getTime() - checkout.date, false) + "</span></td>");
var userTd = $("<td></td>");
var userA = $("<a>loading...</a>");
userA.attr("uoid", checkout.userId);
userA.click(othis.userClick);
userTd.append(userA);
loadUser(userA);
checkoutRow.append(userTd);
var actions = newSplitDropDownTd("Download", othis.downloadCheckoutClick);
checkoutRow.append(actions);
$(".user .checkoutsTable tbody").prepend(checkoutRow);
};
this.showCheckouts = function() {
pushHistoryAppend({tab: "checkouts"}, "User " + othis.user.name);
$(".user .nav li").removeClass("active");
$(".user .checkoutsLink").addClass("active");
$(".user .content > div").hide();
$(".user .checkouts").show();
Global.bimServerApi.call("ServiceInterface", "getAllCheckoutsByUser", {uoid: othis.user.oid}, function(data){
$(".user .checkoutsTable tbody tr").remove();
data.forEach(function(checkout){
othis.addCheckout(checkout);
});
});
};
this.addProject = function(project) {
$(".user .noprojects").hide();
$(".user .projectsTable").show();
$(".projects .projectsTable").show();
$(".projects .noprojects").hide();
var projectRow = $("<tr class=\"project\">");
projectRow.data("project", project);
var nameTd = $("<td></td>");
var nameLink = $("<a>" + project.name + "</a>");
nameLink.data("project", project);
nameLink.click(othis.projectClick);
nameTd.append(nameLink);
projectRow.append(nameTd);
projectRow.append("<td>" + project.subProjects.length + "</td>");
projectRow.append("<td>" + project.revisions.length + "</td>");
if (main.user.userType == "ADMIN") {
projectRow.append(newButtonTd("Revoke", othis.revokeProject));
} else {
projectRow.append("<td></td>");
}
$(".projectsTable tbody").append(projectRow);
};
this.revokeProject = function(){
var project = $(this).parents("tr").data("project");
Global.bimServerApi.callWithFullIndication("ServiceInterface", "removeUserFromProject", {
uoid: othis.user.oid,
poid: project.oid
}, function(data){
othis.showProjects();
});
};
this.showProjects = function() {
pushHistoryAppend({tab: "projects"}, "User " + othis.user.name);
$(".user .nav li").removeClass("active");
$(".user .projectsLink").addClass("active");
$(".user .content > div").hide();
$(".user .projects").show();
Global.bimServerApi.call("ServiceInterface", "getUsersProjects", {uoid: othis.user.oid}, function(data){
$(".projectsTable tr.project").remove();
data.forEach(function(project){
othis.addProject(project);
});
});
if (main.user.userType == "ADMIN") {
Global.bimServerApi.call("ServiceInterface", "getAllNonAuthorizedProjectsOfUser", {uoid: othis.user.oid}, function(data){
if (data.length == 0) {
containerDiv.find(".noProjectsMessage").html("No projects available to add").show();
containerDiv.find(".addProjectLink").hide();
containerDiv.find(".addProjectToUserDiv").hide();
} else {
containerDiv.find(".noProjectsMessage").hide();
containerDiv.find(".addProjectLink").show();
}
});
} else {
containerDiv.find(".addProjectLink").hide();
}
};
this.editButtonClick = function(){
$(".user .w").show();
$(".user .ro").hide();
$(".user .editButton").hide();
$(".user .cancelButton").show();
$(".user .saveButton").show();
};
this.cancelButtonClick = function(){
$(".user .editButton").show();
$(".user .cancelButton").hide();
$(".user .saveButton").hide();
$(".user .ro").show();
$(".user .w").hide();
containerDiv.find(".usertypeSelect").val(othis.user.userType);
};
this.saveButtonClick = function(){
Global.bimServerApi.callWithFullIndication("ServiceInterface", "changeUserType", {
uoid: othis.user.oid,
userType: $(".user .usertypeSelect").val()
}, function(){
othis.reloadUser();
$(".user .editButton").show();
$(".user .cancelButton").hide();
$(".user .saveButton").hide();
$(".user .ro").show();
$(".user .w").hide();
});
};
this.sendPasswordResetLink = function(){
Global.bimServerApi.callWithFullIndication("AuthInterface", "requestPasswordChange", {username: othis.user.username, resetUrl: Global.baseDir + "?page=ResetPassword", includeSiteAddress: false}, function(){
});
};
if (main.user.userType == "ADMIN") {
$(".sendPasswordResetLinkButton").show();
}
this.addProjectLinkClick = function() {
Global.bimServerApi.call("ServiceInterface", "getAllNonAuthorizedProjectsOfUser", {uoid: othis.user.oid}, function(data){
containerDiv.find(".addProjectToUserDiv select option").remove();
if (data.length == 0) {
containerDiv.find(".noProjectsMessage").html("No projects available to add").show();
containerDiv.find(".addProjectLink").hide();
containerDiv.find(".addProjectToUserDiv").hide();
} else {
data.forEach(function(project){
var option = $("<option value=\"" + project.oid + "\">" + project.name + "</option>");
containerDiv.find(".addProjectToUserDiv select").append(option);
});
containerDiv.find(".addProjectLink").hide();
containerDiv.find(".addProjectToUserDiv").show();
}
});
};
this.addProjectToUser = function(event){
event.preventDefault();
Global.bimServerApi.callWithFullIndication("ServiceInterface", "addUserToProject", {
uoid: othis.user.oid,
poid: containerDiv.find(".addProjectToUserDiv select option:selected").val()
}, function(data){
othis.showProjects();
othis.addProjectLinkClick();
});
};
containerDiv.find(".addProjectToUserDiv button").click(othis.addProjectToUser);
containerDiv.find(".addProjectLink").click(othis.addProjectLinkClick);
$(".user .sendPasswordResetLinkButton").click(othis.sendPasswordResetLink);
$(".user .saveButton").click(othis.saveButtonClick);
$(".user .cancelButton").click(othis.cancelButtonClick);
$(".user .detailsLink").click(othis.showDetails);
$(".user .revisionsLink").click(othis.showRevisions);
$(".user .checkoutsLink").click(othis.showCheckouts);
$(".user .projectsLink").click(othis.showProjects);
$(".user .editButton").click(othis.editButtonClick);
}
</script>