-
Notifications
You must be signed in to change notification settings - Fork 3
/
user_rights.js
59 lines (54 loc) · 2.25 KB
/
user_rights.js
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
/**
* REDCap External Module: DAG Switcher
* @author Luke Stevens, Murdoch Children's Research Institute
* Project page JavaScript for switching user DAG
*/
'use strict';
var MCRI_DAG_Switcher_User_Rights = (function(window, document, $, JSON, undefined) {
var allDagNames;
var makePopovers = function(userDags, dagNames) {
allDagNames = dagNames;
// get the dag name links for each user
$('div.dagNameLinkDiv').each(function(){
var dagLink = $(this).children('a:first');
var gid = (dagLink.attr('gid')==='') ? 0 : dagLink.attr('gid');
var uid = dagLink.attr('uid');
// does this user currently have any other dags enabled?
var otherDags = [];
if (userDags[uid]) {
userDags[uid].forEach(function(enabledDagId) {
if (gid!=enabledDagId) { otherDags.push(enabledDagId);}
});
if (otherDags.length>0) { appendDagInfo(dagLink, uid, otherDags); }
}
});
};
function appendDagInfo(appendAfter, user, dagIdList) {
var dagNames = [];
dagIdList.forEach(function(dagId) {
dagNames.push(allDagNames[dagId]);
});
dagNames.sort()
var content = '<div style=\'font-size:75%;padding:5px;\'>User <span class=\'text-primary\'>'+user+'</span> may switch to DAGs:<ul style=\'padding-left:10px;\'>';
dagNames.forEach(function(el) {
content += '<li><span class=\'text-info\'>'+el+'</span></li>';
});
content += '</ul>';
appendAfter.after(' <a href="#" class="dag-switcher-em-popover" data-toggle="popover" data-content="'+content+'" style="font-size:75%;color:gray;">(+'+dagIdList.length+')</a>');
};
var activatePopovers = function() {
$('[data-toggle="popover"]').popover({
title: '<i class="fas fa-cube mr-1"></i>DAG Switcher',
html: true,
trigger: 'hover',
container: 'body',
placement: 'right'
});
};
return {
makePopovers: function (userDags, dagNames) {
makePopovers(userDags, dagNames);
},
activatePopovers: activatePopovers
};
})(window, document, jQuery, JSON);