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 Users = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var users = {}; |
7604 |
25 Feb 19 |
nicklas |
var extendedProperties; |
7604 |
25 Feb 19 |
nicklas |
30 |
|
7604 |
25 Feb 19 |
nicklas |
31 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
33 |
*/ |
7604 |
25 Feb 19 |
nicklas |
users.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
35 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId == 'edit-page') |
7604 |
25 Feb 19 |
nicklas |
38 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Save + Close buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', users.save); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
42 |
|
7604 |
25 Feb 19 |
nicklas |
// Tab validation |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.info', users.validateUser); |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.extended', users.validateExtendedProperties); |
7604 |
25 Feb 19 |
nicklas |
46 |
|
7604 |
25 Feb 19 |
nicklas |
// Extended properties |
7604 |
25 Feb 19 |
nicklas |
extendedProperties = Data.json('page-data', 'extended-properties'); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < extendedProperties.length; i++) |
7604 |
25 Feb 19 |
nicklas |
50 |
{ |
7604 |
25 Feb 19 |
nicklas |
var ep = extendedProperties[i]; |
7604 |
25 Feb 19 |
nicklas |
var valueType = ep.valueType; |
7604 |
25 Feb 19 |
nicklas |
var fieldName = 'ep.'+ep.name; |
7604 |
25 Feb 19 |
nicklas |
54 |
|
7604 |
25 Feb 19 |
nicklas |
if (valueType == 'INT' || valueType == 'LONG') |
7604 |
25 Feb 19 |
nicklas |
56 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Block non-numeric keys from INT and LONG fields |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(fieldName, 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
59 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (valueType == 'FLOAT' || valueType == 'DOUBLE') |
7604 |
25 Feb 19 |
nicklas |
61 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Block non-numeric keys from FLOAT and DOUBLE fields |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(fieldName, 'keypress', Events.numberOnly); |
7604 |
25 Feb 19 |
nicklas |
64 |
} |
7604 |
25 Feb 19 |
nicklas |
65 |
} |
7604 |
25 Feb 19 |
nicklas |
66 |
|
7604 |
25 Feb 19 |
nicklas |
67 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'view-page') |
7604 |
25 Feb 19 |
nicklas |
69 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'USER', 'item-id': itemId}; |
7604 |
25 Feb 19 |
nicklas |
72 |
|
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 |
Buttons.addClickHandler('btnClone', users.cloneUserOnClick, attributes); |
7604 |
25 Feb 19 |
nicklas |
82 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'list-page') |
7604 |
25 Feb 19 |
nicklas |
84 |
{ |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'USER'}; |
7604 |
25 Feb 19 |
nicklas |
var tableAttributes = {'table-id': 'users'}; |
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 |
Buttons.addClickHandler('btnDefaultMembership', users.defaultMembershipOnClick); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnNewGroup', users.newGroupOnClick); |
7604 |
25 Feb 19 |
nicklas |
96 |
|
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 |
99 |
} |
7604 |
25 Feb 19 |
nicklas |
100 |
} |
7604 |
25 Feb 19 |
nicklas |
101 |
|
7604 |
25 Feb 19 |
nicklas |
// Add event handlers to the 'clone' and 'impersonate' icons |
7604 |
25 Feb 19 |
nicklas |
users.initElements = function(element, autoInit) |
7604 |
25 Feb 19 |
nicklas |
104 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (autoInit == 'clone') |
7604 |
25 Feb 19 |
nicklas |
106 |
{ |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler(element, users.cloneUserOnClick); |
7604 |
25 Feb 19 |
nicklas |
108 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (autoInit == 'impersonate') |
7604 |
25 Feb 19 |
nicklas |
110 |
{ |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler(element, users.impersonateUserOnClick); |
7604 |
25 Feb 19 |
nicklas |
112 |
} |
7604 |
25 Feb 19 |
nicklas |
113 |
} |
7604 |
25 Feb 19 |
nicklas |
114 |
|
7604 |
25 Feb 19 |
nicklas |
users.validateUser = function() |
7604 |
25 Feb 19 |
nicklas |
116 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['user']; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.name.value) == '') |
7604 |
25 Feb 19 |
nicklas |
119 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.name, 'You must enter a name for the user.'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
122 |
} |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.login.value) == '') |
7604 |
25 Feb 19 |
nicklas |
124 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.login, 'You must enter a login for the user.'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
127 |
} |
7604 |
25 Feb 19 |
nicklas |
if (frm.new_password.value != frm.retype_password.value) |
7604 |
25 Feb 19 |
nicklas |
129 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.retype_password, 'The two passwords do not match!'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
132 |
} |
7604 |
25 Feb 19 |
nicklas |
133 |
|
7604 |
25 Feb 19 |
nicklas |
if (frm.item_id.value == 0) |
7604 |
25 Feb 19 |
nicklas |
135 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.new_password.value) == '') |
7604 |
25 Feb 19 |
nicklas |
137 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.new_password, 'You must enter a password for the user.'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
140 |
} |
7604 |
25 Feb 19 |
nicklas |
141 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
143 |
} |
7604 |
25 Feb 19 |
nicklas |
144 |
|
7604 |
25 Feb 19 |
nicklas |
145 |
|
7604 |
25 Feb 19 |
nicklas |
// Validate the 'Other information' tab with extended properties |
7604 |
25 Feb 19 |
nicklas |
users.validateExtendedProperties = function() |
7604 |
25 Feb 19 |
nicklas |
148 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['user']; |
7604 |
25 Feb 19 |
nicklas |
var dateFormat = Data.get('page-data', 'date-format'); |
7604 |
25 Feb 19 |
nicklas |
var dateTimeFormat = Data.get('page-data', 'datetime-format'); |
7604 |
25 Feb 19 |
nicklas |
152 |
|
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < extendedProperties.length; i++) |
7604 |
25 Feb 19 |
nicklas |
154 |
{ |
7604 |
25 Feb 19 |
nicklas |
var ep = extendedProperties[i]; |
7604 |
25 Feb 19 |
nicklas |
var valueType = ep.valueType; |
7604 |
25 Feb 19 |
nicklas |
var field = frm['ep.'+ep.name]; |
7604 |
25 Feb 19 |
nicklas |
158 |
|
7604 |
25 Feb 19 |
nicklas |
if (ep.valueType == 'DATE') |
7604 |
25 Feb 19 |
nicklas |
160 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (field.value != '' && !Dates.isDate(field.value, dateFormat)) |
7604 |
25 Feb 19 |
nicklas |
162 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(field, "'"+field.value+"' is not a valid date for '" + ep.title + "'"); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
165 |
} |
7604 |
25 Feb 19 |
nicklas |
166 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (ep.valueType == 'TIMESTAMP') |
7604 |
25 Feb 19 |
nicklas |
168 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (field.value != '' && !Dates.isDate(field.value, dateTimeFormat)) |
7604 |
25 Feb 19 |
nicklas |
170 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(field, "'"+field.value+"' is not a valid timestamp for '" + ep.title + "'"); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
173 |
} |
7604 |
25 Feb 19 |
nicklas |
174 |
} |
7604 |
25 Feb 19 |
nicklas |
if (!ep.nullable) |
7604 |
25 Feb 19 |
nicklas |
176 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (ep.valueType == 'BOOLEAN') |
7604 |
25 Feb 19 |
nicklas |
178 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (Forms.getCheckedRadio(field) == null) |
7604 |
25 Feb 19 |
nicklas |
180 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(field[0], "You must select a value for '" + ep.title + "'"); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
183 |
} |
7604 |
25 Feb 19 |
nicklas |
184 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
186 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(field.value) == '') |
7604 |
25 Feb 19 |
nicklas |
188 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(field, "You must enter a value for '" + ep.title + "'"); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
191 |
} |
7604 |
25 Feb 19 |
nicklas |
192 |
} |
7604 |
25 Feb 19 |
nicklas |
193 |
} |
7604 |
25 Feb 19 |
nicklas |
194 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
196 |
} |
7604 |
25 Feb 19 |
nicklas |
197 |
|
7604 |
25 Feb 19 |
nicklas |
198 |
|
7604 |
25 Feb 19 |
nicklas |
users.save = function() |
7604 |
25 Feb 19 |
nicklas |
200 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['user']; |
7604 |
25 Feb 19 |
nicklas |
if (TabControl.validateActiveTab('settings')) |
7604 |
25 Feb 19 |
nicklas |
203 |
{ |
7604 |
25 Feb 19 |
nicklas |
Link.exportActions('membership'); |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
206 |
} |
7604 |
25 Feb 19 |
nicklas |
207 |
} |
7604 |
25 Feb 19 |
nicklas |
208 |
|
7604 |
25 Feb 19 |
nicklas |
// Open the 'Default membership' dialog |
7604 |
25 Feb 19 |
nicklas |
users.defaultMembershipOnClick = function() |
7604 |
25 Feb 19 |
nicklas |
211 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = 'index.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=EditDefaultMembership'; |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'DefaultMembership', 600, 400); |
7604 |
25 Feb 19 |
nicklas |
215 |
} |
7604 |
25 Feb 19 |
nicklas |
216 |
|
7604 |
25 Feb 19 |
nicklas |
// Create a new group item with the selected users as members |
7604 |
25 Feb 19 |
nicklas |
users.newGroupOnClick = function() |
7604 |
25 Feb 19 |
nicklas |
219 |
{ |
7604 |
25 Feb 19 |
nicklas |
var selected = Table.getSelected('users', null, 'Please select at least one item in the list'); |
7604 |
25 Feb 19 |
nicklas |
if (selected.length == 0) return; |
7604 |
25 Feb 19 |
nicklas |
222 |
|
7604 |
25 Feb 19 |
nicklas |
var extraUrl = '&user_id='+selected.join('&user_id='); |
7604 |
25 Feb 19 |
nicklas |
Items.newItem('GROUP', extraUrl); |
7604 |
25 Feb 19 |
nicklas |
225 |
} |
7604 |
25 Feb 19 |
nicklas |
226 |
|
7604 |
25 Feb 19 |
nicklas |
// Click handler for cloning a user |
7604 |
25 Feb 19 |
nicklas |
users.cloneUserOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
229 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var userId = Data.get(target, 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
Items.newItem('USER', '&clone_id='+userId); |
7604 |
25 Feb 19 |
nicklas |
233 |
} |
7604 |
25 Feb 19 |
nicklas |
234 |
|
7604 |
25 Feb 19 |
nicklas |
// Click handler for opening the 'Impersonate login' dialog |
7604 |
25 Feb 19 |
nicklas |
users.impersonateUserOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
237 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var userId = Data.get(target, 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var url = App.getRoot()+'impersonate.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&user_id='+userId; |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'Impersonate', 450, 300); |
7604 |
25 Feb 19 |
nicklas |
243 |
} |
7604 |
25 Feb 19 |
nicklas |
244 |
|
7604 |
25 Feb 19 |
nicklas |
return users; |
7604 |
25 Feb 19 |
nicklas |
246 |
}(); |
7604 |
25 Feb 19 |
nicklas |
247 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.addElementInitializer(Users.initElements); |
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Users.initPage); |