7773 |
17 Feb 20 |
nicklas |
/* $Id $ |
7773 |
17 Feb 20 |
nicklas |
2 |
------------------------------------------------------------------ |
7773 |
17 Feb 20 |
nicklas |
Copyright (C) 2020 Nicklas Nordborg |
7773 |
17 Feb 20 |
nicklas |
4 |
|
7773 |
17 Feb 20 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7773 |
17 Feb 20 |
nicklas |
Available at http://base.thep.lu.se/ |
7773 |
17 Feb 20 |
nicklas |
7 |
|
7773 |
17 Feb 20 |
nicklas |
BASE is free software; you can redistribute it and/or |
7773 |
17 Feb 20 |
nicklas |
modify it under the terms of the GNU General Public License |
7773 |
17 Feb 20 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7773 |
17 Feb 20 |
nicklas |
of the License, or (at your option) any later version. |
7773 |
17 Feb 20 |
nicklas |
12 |
|
7773 |
17 Feb 20 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7773 |
17 Feb 20 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7773 |
17 Feb 20 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7773 |
17 Feb 20 |
nicklas |
GNU General Public License for more details. |
7773 |
17 Feb 20 |
nicklas |
17 |
|
7773 |
17 Feb 20 |
nicklas |
You should have received a copy of the GNU General Public License |
7773 |
17 Feb 20 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7773 |
17 Feb 20 |
nicklas |
20 |
------------------------------------------------------------------ |
7773 |
17 Feb 20 |
nicklas |
21 |
|
7773 |
17 Feb 20 |
nicklas |
@author Nicklas |
7773 |
17 Feb 20 |
nicklas |
23 |
*/ |
7773 |
17 Feb 20 |
nicklas |
'use strict'; |
7773 |
17 Feb 20 |
nicklas |
25 |
|
7773 |
17 Feb 20 |
nicklas |
var Configure = function() |
7773 |
17 Feb 20 |
nicklas |
27 |
{ |
7773 |
17 Feb 20 |
nicklas |
var configure = {}; |
7773 |
17 Feb 20 |
nicklas |
29 |
|
8083 |
20 Oct 22 |
nicklas |
var currentTargetSubtypes; |
8083 |
20 Oct 22 |
nicklas |
var currentTargetAnnotationTypesAll; |
8083 |
20 Oct 22 |
nicklas |
var currentTargetAnnotationTypesCategory; |
8083 |
20 Oct 22 |
nicklas |
var currentTargetExtensionColumns; |
7773 |
17 Feb 20 |
nicklas |
34 |
|
8083 |
20 Oct 22 |
nicklas |
var currentChildItemTypes; |
8083 |
20 Oct 22 |
nicklas |
var currentChildSubtypes; |
8083 |
20 Oct 22 |
nicklas |
var currentChildAnnotationTypesAll; |
8083 |
20 Oct 22 |
nicklas |
var currentChildAnnotationTypesCategory; |
8083 |
20 Oct 22 |
nicklas |
var currentChildExtensionColumns; |
8083 |
20 Oct 22 |
nicklas |
40 |
|
7842 |
01 Sep 20 |
nicklas |
// See also net.sf.basedb.clients.web.extensions.list.RelatedItemColumn.pathTitles |
7779 |
28 Feb 20 |
nicklas |
var nameCol = {'id': '.', 'text': 'Name'}; |
7779 |
28 Feb 20 |
nicklas |
var externalIdCol = {'id': 'externalId', 'text': 'External ID'}; |
7779 |
28 Feb 20 |
nicklas |
var bioPlateCol = {'id': 'bioWell.bioPlate', 'text': 'Bioplate'}; |
7779 |
28 Feb 20 |
nicklas |
var entryDateCol = {'id': 'entryDate', 'text': 'Registered'}; |
7779 |
28 Feb 20 |
nicklas |
var remainingQCol = {'id': 'remainingQuantity', 'text': 'Remaining quantity'}; |
7845 |
04 Sep 20 |
nicklas |
var originalQCol = {'id': 'originalQuantity', 'text': 'Original quantity'}; |
7885 |
04 Dec 20 |
nicklas |
var itemListCol = {'id': '§itemLists', 'text': 'Item list'}; |
7779 |
28 Feb 20 |
nicklas |
49 |
|
7845 |
04 Sep 20 |
nicklas |
var creationRegistredCol = {'id': 'creationEvent.entryDate', 'text': 'Registration date'}; |
7845 |
04 Sep 20 |
nicklas |
var creationEventdateCol = {'id': 'creationEvent.eventDate', 'text': 'Creation date'}; |
7779 |
28 Feb 20 |
nicklas |
var creationProtocolCol = {'id': 'creationEvent.protocol', 'text': 'Protocol'}; |
7779 |
28 Feb 20 |
nicklas |
var creationHardwareCol = {'id': 'creationEvent.hardware', 'text': 'Hardware'}; |
7779 |
28 Feb 20 |
nicklas |
54 |
|
7779 |
28 Feb 20 |
nicklas |
var protocolCol = {'id': 'protocol', 'text': 'Protocol'}; |
7779 |
28 Feb 20 |
nicklas |
var hardwareCol = {'id': 'hardware', 'text': 'Hardware'}; |
7779 |
28 Feb 20 |
nicklas |
var softwareCol = {'id': 'software', 'text': 'Software'}; |
7845 |
04 Sep 20 |
nicklas |
var tagCol = {'id': 'tag', 'text': 'Tag'}; |
7845 |
04 Sep 20 |
nicklas |
var jobTypeCol = {'id': 'job.itemSubtype', 'text': 'Job type'}; |
7779 |
28 Feb 20 |
nicklas |
60 |
|
7779 |
28 Feb 20 |
nicklas |
var staticColumns = { |
7885 |
04 Dec 20 |
nicklas |
'BIOSOURCE': [nameCol, externalIdCol, itemListCol, entryDateCol], |
7885 |
04 Dec 20 |
nicklas |
'SAMPLE': [nameCol, externalIdCol, itemListCol, bioPlateCol, creationEventdateCol, creationRegistredCol, creationProtocolCol, remainingQCol, originalQCol], |
7885 |
04 Dec 20 |
nicklas |
'EXTRACT': [nameCol, externalIdCol, itemListCol, bioPlateCol, creationEventdateCol, creationRegistredCol, creationProtocolCol, remainingQCol, originalQCol, tagCol], |
7885 |
04 Dec 20 |
nicklas |
'PHYSICALBIOASSAY': [nameCol, itemListCol, creationEventdateCol, creationRegistredCol, creationProtocolCol, creationHardwareCol], |
7885 |
04 Dec 20 |
nicklas |
'DERIVEDBIOASSAY': [nameCol, itemListCol, entryDateCol, protocolCol, softwareCol, hardwareCol, jobTypeCol], |
7885 |
04 Dec 20 |
nicklas |
'RAWBIOASSAY': [nameCol, itemListCol, entryDateCol, protocolCol, softwareCol, jobTypeCol] |
7779 |
28 Feb 20 |
nicklas |
68 |
} |
7779 |
28 Feb 20 |
nicklas |
69 |
|
7773 |
17 Feb 20 |
nicklas |
70 |
/** |
7773 |
17 Feb 20 |
nicklas |
Initialize the page. |
7773 |
17 Feb 20 |
nicklas |
72 |
*/ |
7773 |
17 Feb 20 |
nicklas |
configure.initPage = function() |
7773 |
17 Feb 20 |
nicklas |
74 |
{ |
7842 |
01 Sep 20 |
nicklas |
Events.addEventHandler('targetItemType', 'change', configure.targetItemTypeOnChange); |
8083 |
20 Oct 22 |
nicklas |
Events.addEventHandler('targetSubtype', 'change', configure.targetSubtypeOnChange); |
8083 |
20 Oct 22 |
nicklas |
Events.addEventHandler('childItemType', 'change', configure.childItemTypeOnChange); |
8083 |
20 Oct 22 |
nicklas |
Events.addEventHandler('childSubtype', 'change', configure.childSubtypeOnChange); |
7773 |
17 Feb 20 |
nicklas |
Events.addEventHandler('showAllAnnotationTypes', 'change', configure.updateColumnsList); |
7813 |
19 May 20 |
nicklas |
Events.addEventHandler(document.body, 'click', configure.hideMessage); |
7773 |
17 Feb 20 |
nicklas |
81 |
|
7773 |
17 Feb 20 |
nicklas |
// Buttons |
7773 |
17 Feb 20 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7773 |
17 Feb 20 |
nicklas |
Buttons.addClickHandler('btnAdd', configure.addColumn); |
7773 |
17 Feb 20 |
nicklas |
85 |
} |
7773 |
17 Feb 20 |
nicklas |
86 |
|
8083 |
20 Oct 22 |
nicklas |
// Clear existing columns |
8083 |
20 Oct 22 |
nicklas |
configure.clearColumns = function() |
7773 |
17 Feb 20 |
nicklas |
89 |
{ |
8083 |
20 Oct 22 |
nicklas |
Doc.element('columns').innerHTML = ''; |
8083 |
20 Oct 22 |
nicklas |
Doc.element('annotations').innerHTML = ''; |
8083 |
20 Oct 22 |
nicklas |
Doc.element('extensions').innerHTML = ''; |
8083 |
20 Oct 22 |
nicklas |
Doc.hide('targetPath'); |
8083 |
20 Oct 22 |
nicklas |
Doc.hide('childPath'); |
8083 |
20 Oct 22 |
nicklas |
95 |
} |
8083 |
20 Oct 22 |
nicklas |
// Clear the list and disable it |
8083 |
20 Oct 22 |
nicklas |
configure.clearList = function(listOrId) |
8083 |
20 Oct 22 |
nicklas |
98 |
{ |
8083 |
20 Oct 22 |
nicklas |
var list = Doc.element(listOrId); |
8083 |
20 Oct 22 |
nicklas |
list.disabled = true; |
8083 |
20 Oct 22 |
nicklas |
list.length = 1; |
8083 |
20 Oct 22 |
nicklas |
102 |
} |
8083 |
20 Oct 22 |
nicklas |
103 |
|
8083 |
20 Oct 22 |
nicklas |
configure.targetItemTypeOnChange = function(event) |
8083 |
20 Oct 22 |
nicklas |
105 |
{ |
8083 |
20 Oct 22 |
nicklas |
// Reset everything that depends on the target item type |
8083 |
20 Oct 22 |
nicklas |
configure.clearColumns(); |
8083 |
20 Oct 22 |
nicklas |
configure.clearList('targetSubtype'); |
8083 |
20 Oct 22 |
nicklas |
configure.clearList('childItemType'); |
8083 |
20 Oct 22 |
nicklas |
configure.clearList('childSubtype'); |
8094 |
04 Nov 22 |
nicklas |
Doc.element('allowDoublingBack').disabled = true; |
8083 |
20 Oct 22 |
nicklas |
112 |
|
7842 |
01 Sep 20 |
nicklas |
var frm = document.forms['relatedItems']; |
8083 |
20 Oct 22 |
nicklas |
var sourceItemType = frm.item_type.value; |
7842 |
01 Sep 20 |
nicklas |
var targetItemType = frm.targetItemType.value; |
8083 |
20 Oct 22 |
nicklas |
var direction = Data.get(frm.targetItemType[frm.targetItemType.selectedIndex], 'direction'); |
8083 |
20 Oct 22 |
nicklas |
117 |
|
8083 |
20 Oct 22 |
nicklas |
if (targetItemType) |
8083 |
20 Oct 22 |
nicklas |
119 |
{ |
8083 |
20 Oct 22 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
8083 |
20 Oct 22 |
nicklas |
url += '&cmd=GetSubtypesAndAnnotationTypes&itemType='+encodeURIComponent(targetItemType); |
8083 |
20 Oct 22 |
nicklas |
url += '&sourceItemType='+encodeURIComponent(sourceItemType); |
8083 |
20 Oct 22 |
nicklas |
url += '&direction='+encodeURIComponent(direction); |
8083 |
20 Oct 22 |
nicklas |
124 |
|
8083 |
20 Oct 22 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
8083 |
20 Oct 22 |
nicklas |
request.open("GET", url, true); |
8083 |
20 Oct 22 |
nicklas |
request.send(null); |
8083 |
20 Oct 22 |
nicklas |
Ajax.setReadyStateHandler(request, configure.targetTypeInfoLoaded, configure.targetTypeInfoLoaded); |
8083 |
20 Oct 22 |
nicklas |
129 |
} |
8083 |
20 Oct 22 |
nicklas |
130 |
} |
8083 |
20 Oct 22 |
nicklas |
131 |
|
8083 |
20 Oct 22 |
nicklas |
configure.targetSubtypeOnChange = function(event) |
8083 |
20 Oct 22 |
nicklas |
133 |
{ |
8083 |
20 Oct 22 |
nicklas |
// Reset everything that depends on the target subtype |
8083 |
20 Oct 22 |
nicklas |
configure.clearColumns(); |
8083 |
20 Oct 22 |
nicklas |
136 |
|
8083 |
20 Oct 22 |
nicklas |
var frm = document.forms['relatedItems']; |
8083 |
20 Oct 22 |
nicklas |
var targetItemType = frm.targetItemType.value; |
8083 |
20 Oct 22 |
nicklas |
var sourceItemType = frm.item_type.value; |
8083 |
20 Oct 22 |
nicklas |
var category = frm.targetSubtype.selectedIndex > 0 ? frm.targetSubtype[frm.targetSubtype.selectedIndex].text : null; |
7842 |
01 Sep 20 |
nicklas |
if (targetItemType && category) |
7773 |
17 Feb 20 |
nicklas |
142 |
{ |
7773 |
17 Feb 20 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
7842 |
01 Sep 20 |
nicklas |
url += '&cmd=GetAnnotationTypesForCategory&itemType='+encodeURIComponent(targetItemType); |
8083 |
20 Oct 22 |
nicklas |
url += '&sourceItemType='+encodeURIComponent(sourceItemType); |
7773 |
17 Feb 20 |
nicklas |
url += '&category='+encodeURIComponent(category); |
7773 |
17 Feb 20 |
nicklas |
147 |
|
7773 |
17 Feb 20 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
7773 |
17 Feb 20 |
nicklas |
request.open("GET", url, true); |
7773 |
17 Feb 20 |
nicklas |
request.send(null); |
8083 |
20 Oct 22 |
nicklas |
Ajax.setReadyStateHandler(request, configure.targetTypeInfoLoaded, configure.targetTypeInfoLoaded); |
7773 |
17 Feb 20 |
nicklas |
152 |
} |
7773 |
17 Feb 20 |
nicklas |
153 |
} |
7773 |
17 Feb 20 |
nicklas |
154 |
|
8083 |
20 Oct 22 |
nicklas |
configure.targetTypeInfoLoaded = function(request) |
7773 |
17 Feb 20 |
nicklas |
156 |
{ |
8083 |
20 Oct 22 |
nicklas |
var response = JSON.parse(request.responseText); |
8083 |
20 Oct 22 |
nicklas |
if (response.status != 'ok') |
7773 |
17 Feb 20 |
nicklas |
159 |
{ |
8083 |
20 Oct 22 |
nicklas |
App.debug(request.responseText); |
8083 |
20 Oct 22 |
nicklas |
return; |
8083 |
20 Oct 22 |
nicklas |
162 |
} |
8083 |
20 Oct 22 |
nicklas |
var frm = document.forms['relatedItems']; |
8083 |
20 Oct 22 |
nicklas |
164 |
|
8083 |
20 Oct 22 |
nicklas |
if (response.childTypes) |
8083 |
20 Oct 22 |
nicklas |
166 |
{ |
8083 |
20 Oct 22 |
nicklas |
frm.childItemType.length = 1; |
8083 |
20 Oct 22 |
nicklas |
currentChildItemTypes = response.childTypes; |
8083 |
20 Oct 22 |
nicklas |
for (var i = 0; i < currentChildItemTypes.length; i++) |
8083 |
20 Oct 22 |
nicklas |
170 |
{ |
8083 |
20 Oct 22 |
nicklas |
var st = currentChildItemTypes[i]; |
8083 |
20 Oct 22 |
nicklas |
frm.childItemType[frm.childItemType.length] = new Option('Child: '+st.name, st.id); |
8083 |
20 Oct 22 |
nicklas |
173 |
} |
8083 |
20 Oct 22 |
nicklas |
frm.childItemType.selectedIndex = 0; |
8083 |
20 Oct 22 |
nicklas |
frm.childItemType.disabled = currentChildItemTypes.length == 0; |
8083 |
20 Oct 22 |
nicklas |
176 |
} |
8083 |
20 Oct 22 |
nicklas |
177 |
|
8083 |
20 Oct 22 |
nicklas |
if (response.subtypes) |
8083 |
20 Oct 22 |
nicklas |
179 |
{ |
8083 |
20 Oct 22 |
nicklas |
currentTargetSubtypes = response.subtypes; |
8083 |
20 Oct 22 |
nicklas |
frm.targetSubtype.length = 1; |
8083 |
20 Oct 22 |
nicklas |
for (var i = 0; i < currentTargetSubtypes.length; i++) |
8083 |
20 Oct 22 |
nicklas |
183 |
{ |
8083 |
20 Oct 22 |
nicklas |
var st = currentTargetSubtypes[i]; |
8083 |
20 Oct 22 |
nicklas |
frm.targetSubtype[frm.targetSubtype.length] = new Option(st.name, st.id); |
8083 |
20 Oct 22 |
nicklas |
186 |
} |
8083 |
20 Oct 22 |
nicklas |
frm.targetSubtype.selectedIndex = 0; |
8083 |
20 Oct 22 |
nicklas |
frm.targetSubtype.disabled = currentTargetSubtypes.length == 0; |
8083 |
20 Oct 22 |
nicklas |
189 |
} |
8083 |
20 Oct 22 |
nicklas |
190 |
|
8083 |
20 Oct 22 |
nicklas |
if (response.annotationTypes) currentTargetAnnotationTypesAll = response.annotationTypes; |
8083 |
20 Oct 22 |
nicklas |
if (response.annotationTypesCategory) currentTargetAnnotationTypesCategory = response.annotationTypesCategory; |
8083 |
20 Oct 22 |
nicklas |
if (response.extensionColumns) currentTargetExtensionColumns = response.extensionColumns; |
8083 |
20 Oct 22 |
nicklas |
194 |
|
8083 |
20 Oct 22 |
nicklas |
configure.updateColumnsList(); |
8083 |
20 Oct 22 |
nicklas |
196 |
} |
8083 |
20 Oct 22 |
nicklas |
197 |
|
8083 |
20 Oct 22 |
nicklas |
configure.childItemTypeOnChange = function(event) |
8083 |
20 Oct 22 |
nicklas |
199 |
{ |
8083 |
20 Oct 22 |
nicklas |
// Reset everything that depends on the child item type |
8083 |
20 Oct 22 |
nicklas |
configure.clearColumns(); |
8083 |
20 Oct 22 |
nicklas |
configure.clearList('childSubtype'); |
8094 |
04 Nov 22 |
nicklas |
Doc.element('allowDoublingBack').disabled = true; |
8083 |
20 Oct 22 |
nicklas |
204 |
|
8083 |
20 Oct 22 |
nicklas |
var frm = document.forms['relatedItems']; |
8083 |
20 Oct 22 |
nicklas |
var targetItemType = frm.targetItemType.value; |
8083 |
20 Oct 22 |
nicklas |
var childItemType = frm.childItemType.value; |
8083 |
20 Oct 22 |
nicklas |
208 |
|
8083 |
20 Oct 22 |
nicklas |
if (targetItemType && childItemType) |
8083 |
20 Oct 22 |
nicklas |
210 |
{ |
7773 |
17 Feb 20 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
8083 |
20 Oct 22 |
nicklas |
url += '&cmd=GetSubtypesAndAnnotationTypes&itemType='+encodeURIComponent(childItemType); |
8083 |
20 Oct 22 |
nicklas |
url += '&sourceItemType='+encodeURIComponent(targetItemType); |
8083 |
20 Oct 22 |
nicklas |
url += '&direction=CHILD'; |
7773 |
17 Feb 20 |
nicklas |
215 |
|
7773 |
17 Feb 20 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
7773 |
17 Feb 20 |
nicklas |
request.open("GET", url, true); |
7773 |
17 Feb 20 |
nicklas |
request.send(null); |
8083 |
20 Oct 22 |
nicklas |
Ajax.setReadyStateHandler(request, configure.childTypeInfoLoaded, configure.childTypeInfoLoaded); |
7773 |
17 Feb 20 |
nicklas |
220 |
} |
8083 |
20 Oct 22 |
nicklas |
else |
8083 |
20 Oct 22 |
nicklas |
222 |
{ |
8083 |
20 Oct 22 |
nicklas |
configure.updateColumnsList(); |
8083 |
20 Oct 22 |
nicklas |
224 |
} |
7773 |
17 Feb 20 |
nicklas |
225 |
} |
8083 |
20 Oct 22 |
nicklas |
226 |
|
8083 |
20 Oct 22 |
nicklas |
configure.childSubtypeOnChange = function(event) |
7773 |
17 Feb 20 |
nicklas |
228 |
{ |
8083 |
20 Oct 22 |
nicklas |
// Reset everything that depends on the child subtype |
8083 |
20 Oct 22 |
nicklas |
configure.clearColumns(); |
8083 |
20 Oct 22 |
nicklas |
231 |
|
8083 |
20 Oct 22 |
nicklas |
var frm = document.forms['relatedItems']; |
8083 |
20 Oct 22 |
nicklas |
var targetItemType = frm.targetItemType.value; |
8083 |
20 Oct 22 |
nicklas |
var childItemType = frm.childItemType.value; |
8083 |
20 Oct 22 |
nicklas |
var category = frm.childSubtype.selectedIndex > 0 ? frm.childSubtype[frm.childSubtype.selectedIndex].text : null; |
8083 |
20 Oct 22 |
nicklas |
if (targetItemType && childItemType && category) |
8083 |
20 Oct 22 |
nicklas |
237 |
{ |
8083 |
20 Oct 22 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
8083 |
20 Oct 22 |
nicklas |
url += '&cmd=GetAnnotationTypesForCategory&itemType='+encodeURIComponent(childItemType); |
8083 |
20 Oct 22 |
nicklas |
url += '&sourceItemType='+encodeURIComponent(targetItemType); |
8083 |
20 Oct 22 |
nicklas |
url += '&category='+encodeURIComponent(category); |
8083 |
20 Oct 22 |
nicklas |
242 |
|
8083 |
20 Oct 22 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
8083 |
20 Oct 22 |
nicklas |
request.open("GET", url, true); |
8083 |
20 Oct 22 |
nicklas |
request.send(null); |
8083 |
20 Oct 22 |
nicklas |
Ajax.setReadyStateHandler(request, configure.childTypeInfoLoaded, configure.childTypeInfoLoaded); |
8083 |
20 Oct 22 |
nicklas |
247 |
} |
8083 |
20 Oct 22 |
nicklas |
248 |
} |
8083 |
20 Oct 22 |
nicklas |
249 |
|
8083 |
20 Oct 22 |
nicklas |
configure.childTypeInfoLoaded = function(request) |
8083 |
20 Oct 22 |
nicklas |
251 |
{ |
7773 |
17 Feb 20 |
nicklas |
var response = JSON.parse(request.responseText); |
7773 |
17 Feb 20 |
nicklas |
if (response.status != 'ok') |
7773 |
17 Feb 20 |
nicklas |
254 |
{ |
7773 |
17 Feb 20 |
nicklas |
App.debug(request.responseText); |
7773 |
17 Feb 20 |
nicklas |
return; |
7773 |
17 Feb 20 |
nicklas |
257 |
} |
7842 |
01 Sep 20 |
nicklas |
var frm = document.forms['relatedItems']; |
8083 |
20 Oct 22 |
nicklas |
259 |
|
7773 |
17 Feb 20 |
nicklas |
if (response.subtypes) |
7773 |
17 Feb 20 |
nicklas |
261 |
{ |
8083 |
20 Oct 22 |
nicklas |
currentChildSubtypes = response.subtypes; |
8083 |
20 Oct 22 |
nicklas |
frm.childSubtype.length = 1; |
8083 |
20 Oct 22 |
nicklas |
for (var i = 0; i < currentChildSubtypes.length; i++) |
7773 |
17 Feb 20 |
nicklas |
265 |
{ |
8083 |
20 Oct 22 |
nicklas |
var st = currentChildSubtypes[i]; |
8083 |
20 Oct 22 |
nicklas |
frm.childSubtype[frm.childSubtype.length] = new Option(st.name, st.id); |
7773 |
17 Feb 20 |
nicklas |
268 |
} |
8083 |
20 Oct 22 |
nicklas |
frm.childSubtype.selectedIndex = 0; |
8083 |
20 Oct 22 |
nicklas |
frm.childSubtype.disabled = currentChildSubtypes.length == 0; |
8094 |
04 Nov 22 |
nicklas |
frm.allowDoublingBack.disabled = currentChildSubtypes.length == 0; |
8083 |
20 Oct 22 |
nicklas |
272 |
} |
8083 |
20 Oct 22 |
nicklas |
273 |
|
8083 |
20 Oct 22 |
nicklas |
if (response.annotationTypes) currentChildAnnotationTypesAll = response.annotationTypes; |
8083 |
20 Oct 22 |
nicklas |
if (response.annotationTypesCategory) currentChildAnnotationTypesCategory = response.annotationTypesCategory; |
8083 |
20 Oct 22 |
nicklas |
if (response.extensionColumns) currentChildExtensionColumns = response.extensionColumns; |
8083 |
20 Oct 22 |
nicklas |
277 |
|
7773 |
17 Feb 20 |
nicklas |
configure.updateColumnsList(); |
7773 |
17 Feb 20 |
nicklas |
279 |
} |
8083 |
20 Oct 22 |
nicklas |
280 |
|
7773 |
17 Feb 20 |
nicklas |
281 |
|
7773 |
17 Feb 20 |
nicklas |
configure.updateColumnsList = function() |
7773 |
17 Feb 20 |
nicklas |
283 |
{ |
7842 |
01 Sep 20 |
nicklas |
var frm = document.forms['relatedItems']; |
7773 |
17 Feb 20 |
nicklas |
285 |
|
7842 |
01 Sep 20 |
nicklas |
var targetItemType = frm.targetItemType.value; |
8083 |
20 Oct 22 |
nicklas |
var targetSubtype = frm.targetSubtype.value; |
8083 |
20 Oct 22 |
nicklas |
var childItemType = frm.childItemType.value; |
8083 |
20 Oct 22 |
nicklas |
var childSubtype = frm.childSubtype.value; |
7773 |
17 Feb 20 |
nicklas |
290 |
|
8083 |
20 Oct 22 |
nicklas |
// At least a target item type and a subtype must be selected |
8083 |
20 Oct 22 |
nicklas |
if (!targetItemType || !targetSubtype) return; |
8083 |
20 Oct 22 |
nicklas |
// If a child item type is selected, so must a child subtype |
8083 |
20 Oct 22 |
nicklas |
if (childItemType && !childSubtype) return; |
8083 |
20 Oct 22 |
nicklas |
295 |
|
8083 |
20 Oct 22 |
nicklas |
var targetDirection = Data.get(frm.targetItemType[frm.targetItemType.selectedIndex], 'direction'); |
8083 |
20 Oct 22 |
nicklas |
var targetText = frm.targetSubtype[frm.targetSubtype.selectedIndex].text; |
8083 |
20 Oct 22 |
nicklas |
if (targetDirection == 'PARENT') |
7773 |
17 Feb 20 |
nicklas |
299 |
{ |
8083 |
20 Oct 22 |
nicklas |
Doc.element('targetPath').innerHTML = 'Parent('+targetText+')'; |
8083 |
20 Oct 22 |
nicklas |
Doc.element('targetPath').className = 'parentitem'; |
7773 |
17 Feb 20 |
nicklas |
302 |
} |
8083 |
20 Oct 22 |
nicklas |
else |
8083 |
20 Oct 22 |
nicklas |
304 |
{ |
8083 |
20 Oct 22 |
nicklas |
Doc.element('targetPath').innerHTML = 'Child('+targetText+')'; |
8083 |
20 Oct 22 |
nicklas |
Doc.element('targetPath').className = 'childitem'; |
8083 |
20 Oct 22 |
nicklas |
307 |
} |
8083 |
20 Oct 22 |
nicklas |
Doc.show('targetPath', 'inline'); |
8083 |
20 Oct 22 |
nicklas |
309 |
|
8083 |
20 Oct 22 |
nicklas |
var staticCols = staticColumns[targetItemType] || []; |
8083 |
20 Oct 22 |
nicklas |
var annotationCols = frm.showAllAnnotationTypes.checked ? currentTargetAnnotationTypesAll : currentTargetAnnotationTypesCategory; |
8083 |
20 Oct 22 |
nicklas |
var xtCols = currentTargetExtensionColumns; |
7773 |
17 Feb 20 |
nicklas |
313 |
|
8083 |
20 Oct 22 |
nicklas |
if (childItemType && childSubtype) |
8083 |
20 Oct 22 |
nicklas |
315 |
{ |
8083 |
20 Oct 22 |
nicklas |
staticCols = staticColumns[childItemType] || []; |
8083 |
20 Oct 22 |
nicklas |
annotationCols = frm.showAllAnnotationTypes.checked ? currentChildAnnotationTypesAll : currentChildAnnotationTypesCategory; |
8083 |
20 Oct 22 |
nicklas |
xtCols = currentChildExtensionColumns; |
8083 |
20 Oct 22 |
nicklas |
var childText = frm.childSubtype[frm.childSubtype.selectedIndex].text; |
8083 |
20 Oct 22 |
nicklas |
Doc.element('childPath').innerHTML = 'Child: '+childText; |
8083 |
20 Oct 22 |
nicklas |
Doc.show('childPath', 'inline'); |
8083 |
20 Oct 22 |
nicklas |
322 |
} |
7779 |
28 Feb 20 |
nicklas |
323 |
|
8083 |
20 Oct 22 |
nicklas |
var html = ''; |
7779 |
28 Feb 20 |
nicklas |
// Add static property columns depending on itemtype |
8083 |
20 Oct 22 |
nicklas |
for (var i = 0; i < staticCols.length; i++) |
7779 |
28 Feb 20 |
nicklas |
327 |
{ |
8083 |
20 Oct 22 |
nicklas |
var c = staticCols[i]; |
8083 |
20 Oct 22 |
nicklas |
var text = Strings.encodeTags(c.text); |
8083 |
20 Oct 22 |
nicklas |
html += '<div><label><input type="checkbox" data-column-id="'+c.id+'" data-column-title="'+text+'">'; |
8083 |
20 Oct 22 |
nicklas |
html += text + '</label></div>'; |
7779 |
28 Feb 20 |
nicklas |
332 |
} |
8083 |
20 Oct 22 |
nicklas |
Doc.element('columns').innerHTML = html; |
8083 |
20 Oct 22 |
nicklas |
334 |
|
7779 |
28 Feb 20 |
nicklas |
// Add annotation columns |
8083 |
20 Oct 22 |
nicklas |
html = ''; |
8083 |
20 Oct 22 |
nicklas |
for (var i = 0; i < annotationCols.length; i++) |
7773 |
17 Feb 20 |
nicklas |
338 |
{ |
8083 |
20 Oct 22 |
nicklas |
var at = annotationCols[i]; |
8083 |
20 Oct 22 |
nicklas |
var text = Strings.encodeTags(at.name); |
8083 |
20 Oct 22 |
nicklas |
html += '<div><label><input type="checkbox" data-column-id="#+'+at.id+'" data-column-title="'+text+'">'; |
8083 |
20 Oct 22 |
nicklas |
html += text + '</label></div>'; |
7773 |
17 Feb 20 |
nicklas |
343 |
} |
8083 |
20 Oct 22 |
nicklas |
Doc.element('annotations').innerHTML = html; |
8083 |
20 Oct 22 |
nicklas |
345 |
|
8083 |
20 Oct 22 |
nicklas |
// Extension columns |
8083 |
20 Oct 22 |
nicklas |
html = ''; |
8083 |
20 Oct 22 |
nicklas |
for (var i = 0; i < xtCols.length; i++) |
8083 |
20 Oct 22 |
nicklas |
349 |
{ |
8083 |
20 Oct 22 |
nicklas |
var xtCol = xtCols[i]; |
8083 |
20 Oct 22 |
nicklas |
var id = "!"+xtCol.id+"#"+xtCol.columnId; |
8083 |
20 Oct 22 |
nicklas |
var text = Strings.encodeTags(xtCol.name); |
8083 |
20 Oct 22 |
nicklas |
if (xtCol.id.indexOf('net.sf.basedb.clients.web.related-item-columns') == 0) |
8083 |
20 Oct 22 |
nicklas |
354 |
{ |
8083 |
20 Oct 22 |
nicklas |
// Special case when the extension is the related-item extionsion |
8083 |
20 Oct 22 |
nicklas |
// It has built-in support for two hops and doen't have to use the |
8083 |
20 Oct 22 |
nicklas |
// extension mechanism recursively |
8083 |
20 Oct 22 |
nicklas |
id = xtCol.columnId; |
8083 |
20 Oct 22 |
nicklas |
359 |
} |
8083 |
20 Oct 22 |
nicklas |
html += '<div title="'+Strings.encodeTags(xtCol.tooltip)+'">'; |
8083 |
20 Oct 22 |
nicklas |
html += '<label><input type="checkbox" data-column-id="'+id+'" data-column-title="'+text+'">'; |
8083 |
20 Oct 22 |
nicklas |
html += (xtCol.nameHTML || text) + '</label></div>'; |
8083 |
20 Oct 22 |
nicklas |
363 |
} |
8083 |
20 Oct 22 |
nicklas |
Doc.element('extensions').innerHTML = html; |
7773 |
17 Feb 20 |
nicklas |
365 |
} |
7773 |
17 Feb 20 |
nicklas |
366 |
|
7813 |
19 May 20 |
nicklas |
configure.addColumn = function(event) |
7773 |
17 Feb 20 |
nicklas |
368 |
{ |
7842 |
01 Sep 20 |
nicklas |
var frm = document.forms['relatedItems']; |
7773 |
17 Feb 20 |
nicklas |
370 |
|
7773 |
17 Feb 20 |
nicklas |
var data = {}; |
7842 |
01 Sep 20 |
nicklas |
data.targetItemType = frm.targetItemType.value; |
8083 |
20 Oct 22 |
nicklas |
data.targetSubtype = frm.targetSubtype.value; |
8083 |
20 Oct 22 |
nicklas |
data.childItemType = frm.childItemType.value; |
8083 |
20 Oct 22 |
nicklas |
data.childSubtype = frm.childSubtype.value; |
8094 |
04 Nov 22 |
nicklas |
data.allowDoublingBack = frm.allowDoublingBack.checked?1:0; |
7773 |
17 Feb 20 |
nicklas |
377 |
|
7842 |
01 Sep 20 |
nicklas |
if (!data.targetItemType) |
7773 |
17 Feb 20 |
nicklas |
379 |
{ |
7842 |
01 Sep 20 |
nicklas |
Forms.showNotification('targetItemType', 'Please select a parent or child item type!'); |
7773 |
17 Feb 20 |
nicklas |
return; |
7773 |
17 Feb 20 |
nicklas |
382 |
} |
8083 |
20 Oct 22 |
nicklas |
if (!data.targetSubtype) |
7773 |
17 Feb 20 |
nicklas |
384 |
{ |
8083 |
20 Oct 22 |
nicklas |
Forms.showNotification('targetSubtype', 'Please select a subtype!'); |
7773 |
17 Feb 20 |
nicklas |
return; |
7773 |
17 Feb 20 |
nicklas |
387 |
} |
8083 |
20 Oct 22 |
nicklas |
if (data.childItemType && !data.childSubtype) |
8083 |
20 Oct 22 |
nicklas |
389 |
{ |
8083 |
20 Oct 22 |
nicklas |
Forms.showNotification('childSubtype', 'Please select a subtype!'); |
8083 |
20 Oct 22 |
nicklas |
return; |
8083 |
20 Oct 22 |
nicklas |
392 |
} |
8083 |
20 Oct 22 |
nicklas |
393 |
|
8083 |
20 Oct 22 |
nicklas |
data.targetSubtypeName = frm.targetSubtype[frm.targetSubtype.selectedIndex].text; |
7842 |
01 Sep 20 |
nicklas |
data.direction = Data.get(frm.targetItemType[frm.targetItemType.selectedIndex], 'direction'); |
7773 |
17 Feb 20 |
nicklas |
396 |
|
8083 |
20 Oct 22 |
nicklas |
var propertyPrefix = '/'+data.direction+'/'+data.targetItemType+'/'+data.targetSubtype+'/'; |
8083 |
20 Oct 22 |
nicklas |
var titlePrefix = data.targetSubtypeName; |
8083 |
20 Oct 22 |
nicklas |
if (data.childItemType) |
8083 |
20 Oct 22 |
nicklas |
400 |
{ |
8083 |
20 Oct 22 |
nicklas |
data.childSubtypeName = frm.childSubtype[frm.childSubtype.selectedIndex].text; |
8094 |
04 Nov 22 |
nicklas |
propertyPrefix += (data.allowDoublingBack?'/CHILD+/':'/CHILD/')+data.childItemType+'/'+data.childSubtype+'/'; |
8083 |
20 Oct 22 |
nicklas |
titlePrefix += '.'+data.childSubtypeName; |
8083 |
20 Oct 22 |
nicklas |
404 |
} |
8083 |
20 Oct 22 |
nicklas |
405 |
|
7773 |
17 Feb 20 |
nicklas |
var numSelected = 0; |
8083 |
20 Oct 22 |
nicklas |
var allColumns = document.querySelectorAll("input[data-column-id]"); |
8083 |
20 Oct 22 |
nicklas |
for (var i = 0; i < allColumns.length; i++) |
7773 |
17 Feb 20 |
nicklas |
409 |
{ |
8083 |
20 Oct 22 |
nicklas |
if (allColumns[i].checked) |
7773 |
17 Feb 20 |
nicklas |
411 |
{ |
8083 |
20 Oct 22 |
nicklas |
var col = allColumns[i]; |
8083 |
20 Oct 22 |
nicklas |
data.column = Data.get(col, 'column-id'); |
8083 |
20 Oct 22 |
nicklas |
data.property = propertyPrefix+data.column; |
8083 |
20 Oct 22 |
nicklas |
data.title = titlePrefix + (data.column == '.' ? '' : '.'+Data.get(col, 'column-title')); |
7842 |
01 Sep 20 |
nicklas |
Events.sendCustomEvent(window.opener.Doc.element('selectRelatedItemColumn'), 'base-selected', data); |
7773 |
17 Feb 20 |
nicklas |
numSelected++; |
8083 |
20 Oct 22 |
nicklas |
// Remove the column from the list |
8083 |
20 Oct 22 |
nicklas |
var div = col.parentNode.parentNode; |
8083 |
20 Oct 22 |
nicklas |
div.parentNode.removeChild(div); |
7773 |
17 Feb 20 |
nicklas |
421 |
} |
7773 |
17 Feb 20 |
nicklas |
422 |
} |
7773 |
17 Feb 20 |
nicklas |
423 |
|
7773 |
17 Feb 20 |
nicklas |
if (numSelected == 0) |
7773 |
17 Feb 20 |
nicklas |
425 |
{ |
8083 |
20 Oct 22 |
nicklas |
Forms.showNotification('columnstable', 'Please select at least one column!', null, 'pointer-below'); |
7773 |
17 Feb 20 |
nicklas |
return; |
7773 |
17 Feb 20 |
nicklas |
428 |
} |
7813 |
19 May 20 |
nicklas |
Doc.element('added-column-msg').innerHTML = numSelected == 1 ? |
7813 |
19 May 20 |
nicklas |
'1 column has been added to the table.' : numSelected + ' columns have been added to the table.'; |
8083 |
20 Oct 22 |
nicklas |
Doc.show('added-column-msg', 'table'); |
7813 |
19 May 20 |
nicklas |
event.stopPropagation(); // To prevent the hideMessage() method from executing |
8083 |
20 Oct 22 |
nicklas |
setTimeout(configure.hideMessage, 2000); |
7773 |
17 Feb 20 |
nicklas |
434 |
} |
7773 |
17 Feb 20 |
nicklas |
435 |
|
7813 |
19 May 20 |
nicklas |
configure.hideMessage = function(event) |
7813 |
19 May 20 |
nicklas |
437 |
{ |
7813 |
19 May 20 |
nicklas |
Doc.hide('added-column-msg'); |
7813 |
19 May 20 |
nicklas |
439 |
} |
7813 |
19 May 20 |
nicklas |
440 |
|
7773 |
17 Feb 20 |
nicklas |
return configure; |
7773 |
17 Feb 20 |
nicklas |
442 |
}(); |
7773 |
17 Feb 20 |
nicklas |
443 |
|
7773 |
17 Feb 20 |
nicklas |
Doc.onLoad(Configure.initPage); |