7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2013 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Roles = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var roles = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
30 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
32 |
*/ |
7604 |
25 Feb 19 |
nicklas |
roles.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
34 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId == 'edit-page') |
7604 |
25 Feb 19 |
nicklas |
37 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Save + Close buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', roles.save); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
41 |
|
7604 |
25 Feb 19 |
nicklas |
// Permission list |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('items', 'change', roles.itemOnChange) |
7604 |
25 Feb 19 |
nicklas |
// Permission checkboxes |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('deny', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('create', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('read', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('use', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('restricted_write', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('write', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('delete', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('set_owner', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('set_permission', 'click', roles.permissionsOnClick); |
7604 |
25 Feb 19 |
nicklas |
54 |
|
7604 |
25 Feb 19 |
nicklas |
// Tab validation |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.info', roles.validateRole); |
7604 |
25 Feb 19 |
nicklas |
57 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'view-page') |
7604 |
25 Feb 19 |
nicklas |
59 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'ROLE', 'item-id': itemId}; |
7604 |
25 Feb 19 |
nicklas |
62 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnEdit', Buttons.editItem, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDelete', Buttons.deleteItem, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRestore', Buttons.restoreItem, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnUsingItems', Buttons.showUsingItems, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDeletePermanently', Buttons.deleteItemPermanently, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnExport', Buttons.runPlugin, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnImport', Buttons.runPlugin, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRunPlugin', Buttons.runPlugin, attributes); |
7604 |
25 Feb 19 |
nicklas |
71 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'list-page') |
7604 |
25 Feb 19 |
nicklas |
73 |
{ |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'ROLE'}; |
7604 |
25 Feb 19 |
nicklas |
var tableAttributes = {'table-id': 'roles'}; |
7604 |
25 Feb 19 |
nicklas |
76 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnNewItem', Buttons.newItem, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDeleteItems', Buttons.deleteItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRestoreItems', Buttons.restoreItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnColumns', Buttons.configureColumns, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnExport', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnImport', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRunPlugin', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
84 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnOk', Buttons.returnSelected, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
87 |
} |
7604 |
25 Feb 19 |
nicklas |
88 |
} |
7604 |
25 Feb 19 |
nicklas |
89 |
|
7604 |
25 Feb 19 |
nicklas |
roles.validateRole = function() |
7604 |
25 Feb 19 |
nicklas |
91 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['role']; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.name.value) == '') |
7604 |
25 Feb 19 |
nicklas |
94 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.name, 'You must enter a name'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
97 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
99 |
} |
7604 |
25 Feb 19 |
nicklas |
100 |
|
7604 |
25 Feb 19 |
nicklas |
roles.save = function() |
7604 |
25 Feb 19 |
nicklas |
102 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['role']; |
7604 |
25 Feb 19 |
nicklas |
if (TabControl.validateActiveTab('settings')) |
7604 |
25 Feb 19 |
nicklas |
105 |
{ |
7604 |
25 Feb 19 |
nicklas |
Link.exportActions('members'); |
7604 |
25 Feb 19 |
nicklas |
var systemPermission = 0; |
7604 |
25 Feb 19 |
nicklas |
if (frm.share_to_everyone.checked) systemPermission += parseInt(frm.share_to_everyone.value, 10); |
7604 |
25 Feb 19 |
nicklas |
if (frm.act_as_another_user.checked) systemPermission += parseInt(frm.act_as_another_user.value, 10); |
7604 |
25 Feb 19 |
nicklas |
if (frm.select_jobagent.checked) systemPermission += parseInt(frm.select_jobagent.value, 10); |
7604 |
25 Feb 19 |
nicklas |
frm['SYSTEM'].value = systemPermission; |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
113 |
} |
7604 |
25 Feb 19 |
nicklas |
114 |
} |
7604 |
25 Feb 19 |
nicklas |
115 |
|
7604 |
25 Feb 19 |
nicklas |
roles.itemOnChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
117 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemType = event.target.value; |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['role']; |
7604 |
25 Feb 19 |
nicklas |
if (itemType) |
7604 |
25 Feb 19 |
nicklas |
121 |
{ |
7604 |
25 Feb 19 |
nicklas |
var permissionCode = frm[itemType].value; |
7604 |
25 Feb 19 |
nicklas |
var definedPermissions = parseInt(frm[itemType+'_defined'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['deny'].checked = (permissionCode & frm['deny'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['create'].checked = (permissionCode & frm['create'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['create'].disabled = !(definedPermissions & frm['create'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['read'].checked = (permissionCode & frm['read'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['read'].disabled = !(definedPermissions & frm['read'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['use'].checked = (permissionCode & frm['use'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['use'].disabled = !(definedPermissions & frm['use'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['restricted_write'].disabled = !(definedPermissions & frm['restricted_write'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['restricted_write'].checked = (permissionCode & frm['restricted_write'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['write'].checked = (permissionCode & frm['write'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['write'].disabled = !(definedPermissions & frm['write'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['delete'].checked = (permissionCode & frm['delete'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['delete'].disabled = !(definedPermissions & frm['delete'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['set_owner'].checked = (permissionCode & frm['set_owner'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['set_owner'].disabled = !(definedPermissions & frm['set_owner'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['set_permission'].checked = (permissionCode & frm['set_permission'].value); |
7604 |
25 Feb 19 |
nicklas |
frm['set_permission'].disabled = !(definedPermissions & frm['set_permission'].value); |
7604 |
25 Feb 19 |
nicklas |
141 |
} |
7604 |
25 Feb 19 |
nicklas |
142 |
} |
7604 |
25 Feb 19 |
nicklas |
143 |
|
7604 |
25 Feb 19 |
nicklas |
roles.permissionsOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
145 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['role']; |
7604 |
25 Feb 19 |
nicklas |
roles.correctPermissions(event.target.checked, event.target.name == 'deny'); |
7604 |
25 Feb 19 |
nicklas |
var permissionCode = roles.getPermissionCode(); |
7604 |
25 Feb 19 |
nicklas |
149 |
|
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < frm.items.length; i++) |
7604 |
25 Feb 19 |
nicklas |
151 |
{ |
7604 |
25 Feb 19 |
nicklas |
var item = frm.items[i]; |
7604 |
25 Feb 19 |
nicklas |
var itemType = item.value; |
7604 |
25 Feb 19 |
nicklas |
if (item.selected && itemType) |
7604 |
25 Feb 19 |
nicklas |
155 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm[itemType].value = permissionCode; |
7604 |
25 Feb 19 |
nicklas |
var definedPermissions = parseInt(frm[itemType+'_defined'].value); |
7604 |
25 Feb 19 |
nicklas |
var status = ''; |
7604 |
25 Feb 19 |
nicklas |
if (frm['deny'].checked) |
7604 |
25 Feb 19 |
nicklas |
160 |
{ |
7604 |
25 Feb 19 |
nicklas |
status = "DENIED"; |
7604 |
25 Feb 19 |
nicklas |
162 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
164 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (definedPermissions & frm['create'].value) status += frm['create'].checked ? "C" : "-"; |
7604 |
25 Feb 19 |
nicklas |
if (definedPermissions & frm['read'].value) status += frm['read'].checked ? "R" : "-"; |
7604 |
25 Feb 19 |
nicklas |
if (definedPermissions & frm['use'].value) status += frm['use'].checked ? "U" : "-"; |
7604 |
25 Feb 19 |
nicklas |
if (definedPermissions & frm['restricted_write'].value) status += frm['restricted_write'].checked ? "A" : "-"; |
7604 |
25 Feb 19 |
nicklas |
if (definedPermissions & frm['write'].value) status += frm['write'].checked ? "W" : "-"; |
7604 |
25 Feb 19 |
nicklas |
if (definedPermissions & frm['delete'].value) status += frm['delete'].checked ? "D" : "-"; |
7604 |
25 Feb 19 |
nicklas |
if (definedPermissions & frm['set_owner'].value) status += frm['set_owner'].checked ? "O" : "-"; |
7604 |
25 Feb 19 |
nicklas |
if (definedPermissions & frm['set_permission'].value) status += frm['set_permission'].checked ? "P" : "-"; |
7604 |
25 Feb 19 |
nicklas |
173 |
} |
7604 |
25 Feb 19 |
nicklas |
var text = item.text.replace(/\[.*\]/, '['+status+']'); |
7604 |
25 Feb 19 |
nicklas |
item.text = text; |
7604 |
25 Feb 19 |
nicklas |
176 |
} |
7604 |
25 Feb 19 |
nicklas |
177 |
} |
7604 |
25 Feb 19 |
nicklas |
178 |
} |
7604 |
25 Feb 19 |
nicklas |
179 |
|
7604 |
25 Feb 19 |
nicklas |
roles.correctPermissions = function(checked, forceDeny) |
7604 |
25 Feb 19 |
nicklas |
181 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['role']; |
7604 |
25 Feb 19 |
nicklas |
if (checked) |
7604 |
25 Feb 19 |
nicklas |
184 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm['deny'].checked = frm['deny'].checked && forceDeny; |
7604 |
25 Feb 19 |
nicklas |
frm['set_permission'].checked = frm['set_permission'].checked && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['set_owner'].checked = frm['set_owner'].checked && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['delete'].checked = frm['delete'].checked && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['write'].checked = (frm['write'].checked || frm['delete'].checked || frm['set_owner'].checked || frm['set_permission'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['restricted_write'].checked = (frm['restricted_write'].checked || frm['write'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['use'].checked = (frm['use'].checked || frm['write'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['read'].checked = (frm['read'].checked || frm['use'].checked || frm['restricted_write'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['create'].checked = frm['create'].checked && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
194 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
196 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm['deny'].checked = frm['deny'].checked && !frm['create'].checked && !frm['read'].checked && !frm['use'].checked && !frm['restricted_write'].checked && !frm['write'].checked && !frm['delete'].checked && !frm['set_owner'].checked && !frm['set_permission'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['create'].checked = frm['create'].checked && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['read'].checked = frm['read'].checked && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['use'].checked = (frm['use'].checked && frm['read'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['restricted_write'].checked = (frm['restricted_write'].checked && frm['read'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['write'].checked = (frm['write'].checked && frm['use'].checked) && frm['restricted_write'].checked && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['delete'].checked = (frm['delete'].checked && frm['write'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['set_owner'].checked = (frm['set_owner'].checked && frm['write'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
frm['set_permission'].checked = (frm['set_permission'].checked && frm['write'].checked) && !frm['deny'].checked; |
7604 |
25 Feb 19 |
nicklas |
206 |
} |
7604 |
25 Feb 19 |
nicklas |
207 |
} |
7604 |
25 Feb 19 |
nicklas |
208 |
|
7604 |
25 Feb 19 |
nicklas |
roles.getPermissionCode = function() |
7604 |
25 Feb 19 |
nicklas |
210 |
{ |
7604 |
25 Feb 19 |
nicklas |
var permissionCode = 0; |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['role']; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['deny'].checked ? parseInt(frm['deny'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['create'].checked ? parseInt(frm['create'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['read'].checked ? parseInt(frm['read'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['use'].checked ? parseInt(frm['use'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['restricted_write'].checked ? parseInt(frm['restricted_write'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['write'].checked ? parseInt(frm['write'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['delete'].checked ? parseInt(frm['delete'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['set_owner'].checked ? parseInt(frm['set_owner'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
permissionCode += frm['set_permission'].checked ? parseInt(frm['set_permission'].value) : 0; |
7604 |
25 Feb 19 |
nicklas |
return permissionCode; |
7604 |
25 Feb 19 |
nicklas |
223 |
} |
7604 |
25 Feb 19 |
nicklas |
224 |
|
7604 |
25 Feb 19 |
nicklas |
225 |
|
7604 |
25 Feb 19 |
nicklas |
return roles; |
7604 |
25 Feb 19 |
nicklas |
227 |
}(); |
7604 |
25 Feb 19 |
nicklas |
228 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Roles.initPage); |