7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2015 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 Inherit = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var inherit = {}; |
7604 |
25 Feb 19 |
nicklas |
var noneSelectedRow; |
7604 |
25 Feb 19 |
nicklas |
30 |
|
7604 |
25 Feb 19 |
nicklas |
var selectedAnnotationTypes = []; |
7604 |
25 Feb 19 |
nicklas |
var allowedAnnotationTypes = []; |
7604 |
25 Feb 19 |
nicklas |
33 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
35 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', inherit.save); |
7604 |
25 Feb 19 |
nicklas |
39 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSelectAnnotationTypes', inherit.selectAnnotationTypes); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('btnSelectAnnotationTypes', 'base-selected', inherit.annotationTypeSelected); |
7604 |
25 Feb 19 |
nicklas |
42 |
|
7604 |
25 Feb 19 |
nicklas |
noneSelectedRow = Doc.element('none-selected').parentNode.parentNode; |
7604 |
25 Feb 19 |
nicklas |
44 |
|
7604 |
25 Feb 19 |
nicklas |
var annotationTypes = Data.json('page-data', 'annotation-types'); |
7604 |
25 Feb 19 |
nicklas |
if (annotationTypes) |
7604 |
25 Feb 19 |
nicklas |
47 |
{ |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < annotationTypes.length; i++) |
7604 |
25 Feb 19 |
nicklas |
49 |
{ |
7604 |
25 Feb 19 |
nicklas |
var at = annotationTypes[i]; |
7604 |
25 Feb 19 |
nicklas |
inherit.addAnnotationType(at); |
7604 |
25 Feb 19 |
nicklas |
inherit.addMoreAnnotationTypeInfo(at); |
7604 |
25 Feb 19 |
nicklas |
53 |
} |
7604 |
25 Feb 19 |
nicklas |
54 |
} |
7604 |
25 Feb 19 |
nicklas |
55 |
} |
7604 |
25 Feb 19 |
nicklas |
56 |
|
7604 |
25 Feb 19 |
nicklas |
57 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.selectAnnotationTypes = function(event) |
7604 |
25 Feb 19 |
nicklas |
59 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = '&resetTemporary=1&tmpfilter:BOOLEAN:disableInheritance=false'; |
7604 |
25 Feb 19 |
nicklas |
url += '&exclude='+selectedAnnotationTypes.join(','); |
7604 |
25 Feb 19 |
nicklas |
Dialogs.selectItem('ANNOTATIONTYPE', event.currentTarget.id, 1, url); |
7604 |
25 Feb 19 |
nicklas |
63 |
} |
7604 |
25 Feb 19 |
nicklas |
64 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.annotationTypeSelected = function(event) |
7604 |
25 Feb 19 |
nicklas |
66 |
{ |
7604 |
25 Feb 19 |
nicklas |
var item = event.detail; |
7604 |
25 Feb 19 |
nicklas |
if (Doc.element('at-'+item.id)) return; |
7604 |
25 Feb 19 |
nicklas |
69 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.addAnnotationType(item); |
7604 |
25 Feb 19 |
nicklas |
71 |
|
7604 |
25 Feb 19 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
7604 |
25 Feb 19 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=GetAnnotationTypeInfo&item_id=' + item.id; |
7604 |
25 Feb 19 |
nicklas |
request.open("GET", url, true); |
7604 |
25 Feb 19 |
nicklas |
request.send(null); |
7604 |
25 Feb 19 |
nicklas |
Ajax.setReadyStateHandler(request, inherit.annotationTypeInfoLoaded, inherit.annotationTypeInfoLoaded); |
7604 |
25 Feb 19 |
nicklas |
78 |
} |
7604 |
25 Feb 19 |
nicklas |
79 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.annotationTypeInfoLoaded = function(request) |
7604 |
25 Feb 19 |
nicklas |
81 |
{ |
7604 |
25 Feb 19 |
nicklas |
var response = JSON.parse(request.responseText); |
7604 |
25 Feb 19 |
nicklas |
if (response.status != 'ok') |
7604 |
25 Feb 19 |
nicklas |
84 |
{ |
7604 |
25 Feb 19 |
nicklas |
App.debug(request.responseText); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
87 |
} |
7604 |
25 Feb 19 |
nicklas |
88 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.addMoreAnnotationTypeInfo(response.annotationType); |
7604 |
25 Feb 19 |
nicklas |
90 |
} |
7604 |
25 Feb 19 |
nicklas |
91 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.addAnnotationType = function(item) |
7604 |
25 Feb 19 |
nicklas |
93 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotations']; |
7604 |
25 Feb 19 |
nicklas |
selectedAnnotationTypes[selectedAnnotationTypes.length] = item.id; |
7604 |
25 Feb 19 |
nicklas |
96 |
|
7604 |
25 Feb 19 |
nicklas |
var tr = document.createElement('tr'); |
8013 |
13 Aug 21 |
nicklas |
tr.className = 'row highlight ' + (selectedAnnotationTypes.length % 2 == 0 ? 'bg-evenrow' : 'bg-oddrow'); |
7604 |
25 Feb 19 |
nicklas |
tr.id = 'at-'+item.id; |
7604 |
25 Feb 19 |
nicklas |
100 |
|
7604 |
25 Feb 19 |
nicklas |
var html = '<td class="cell">'+Strings.encodeTags(item.name)+'</td>'; |
7604 |
25 Feb 19 |
nicklas |
html += '<td class="cell">'; |
7604 |
25 Feb 19 |
nicklas |
html += '<select name="action_'+item.id+'" data-item-id="'+item.id+'">'; |
7604 |
25 Feb 19 |
nicklas |
html += '<option value="inherit" selected>Inherit from: '; |
7604 |
25 Feb 19 |
nicklas |
html += '<option value="clone">Clone from: '; |
7604 |
25 Feb 19 |
nicklas |
html += '<option value="resync">Re-sync cloned'; |
7604 |
25 Feb 19 |
nicklas |
html += '<option value="remove">Remove'; |
7604 |
25 Feb 19 |
nicklas |
html += '</select>'; |
7604 |
25 Feb 19 |
nicklas |
html += '</td>'; |
7604 |
25 Feb 19 |
nicklas |
html += '<td class="cell">'; |
7604 |
25 Feb 19 |
nicklas |
html += '<select name="from_'+item.id+'" id="from_'+item.id+'">'; |
7604 |
25 Feb 19 |
nicklas |
html += '<option value="">- any parent -'; |
7604 |
25 Feb 19 |
nicklas |
html += '</select>'; |
7604 |
25 Feb 19 |
nicklas |
html += '</td>' |
7604 |
25 Feb 19 |
nicklas |
html += '<td class="cell">'; |
7604 |
25 Feb 19 |
nicklas |
html += '<label><input type="checkbox" name="nodup_'+item.id+'" checked>No duplicates</label> '; |
7604 |
25 Feb 19 |
nicklas |
html += '<label><input type="checkbox" name="replace_'+item.id+'" checked>Replace existing</label>'; |
7604 |
25 Feb 19 |
nicklas |
html += '</td>'; |
7604 |
25 Feb 19 |
nicklas |
tr.innerHTML = html; |
7604 |
25 Feb 19 |
nicklas |
120 |
|
7604 |
25 Feb 19 |
nicklas |
var section = Doc.element('selectedAnnotationTypes'); |
7604 |
25 Feb 19 |
nicklas |
section.insertBefore(tr, noneSelectedRow); |
7604 |
25 Feb 19 |
nicklas |
Doc.hide(noneSelectedRow); |
7604 |
25 Feb 19 |
nicklas |
124 |
|
7604 |
25 Feb 19 |
nicklas |
Forms.linkCheckboxesWithLabels(tr); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(frm['action_'+item.id], 'change', inherit.actionOnChange); |
7604 |
25 Feb 19 |
nicklas |
127 |
} |
7604 |
25 Feb 19 |
nicklas |
128 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.addMoreAnnotationTypeInfo = function(item) |
7604 |
25 Feb 19 |
nicklas |
130 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (item.disableInheritance) |
7604 |
25 Feb 19 |
nicklas |
132 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotations']; |
7604 |
25 Feb 19 |
nicklas |
var action = frm['action_'+item.id]; |
7604 |
25 Feb 19 |
nicklas |
action.length = 0; |
7604 |
25 Feb 19 |
nicklas |
action[0] = new Option('Inheritance disabled'); |
7604 |
25 Feb 19 |
nicklas |
action.disabled = true; |
7604 |
25 Feb 19 |
nicklas |
frm['from_'+item.id].disabled = true; |
7604 |
25 Feb 19 |
nicklas |
frm['nodup_'+item.id].disabled = true; |
7604 |
25 Feb 19 |
nicklas |
frm['replace_'+item.id].disabled = true; |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
142 |
} |
7604 |
25 Feb 19 |
nicklas |
143 |
|
7604 |
25 Feb 19 |
nicklas |
allowedAnnotationTypes[allowedAnnotationTypes.length] = item.id; |
7604 |
25 Feb 19 |
nicklas |
var selection = Doc.element('from_'+item.id); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < item.subtypes.length; i++) |
7604 |
25 Feb 19 |
nicklas |
147 |
{ |
7604 |
25 Feb 19 |
nicklas |
var subtype = item.subtypes[i]; |
7604 |
25 Feb 19 |
nicklas |
selection[selection.length] = new Option(subtype.name + ' ('+subtype.itemType.toLowerCase()+')', subtype.id, false, subtype.selected); |
7604 |
25 Feb 19 |
nicklas |
150 |
} |
7604 |
25 Feb 19 |
nicklas |
151 |
|
7604 |
25 Feb 19 |
nicklas |
if (item.plateTypes) |
7604 |
25 Feb 19 |
nicklas |
153 |
{ |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < item.plateTypes.length; i++) |
7604 |
25 Feb 19 |
nicklas |
155 |
{ |
7604 |
25 Feb 19 |
nicklas |
var plateType = atInfo.plateTypes[i]; |
7604 |
25 Feb 19 |
nicklas |
selection[selection.length] = new Option(plateType.name + ' (bioplate)', plateType.subtype.id); |
7604 |
25 Feb 19 |
nicklas |
158 |
} |
7604 |
25 Feb 19 |
nicklas |
if (selection.selectedIndex == 0) selection.selectedIndex = 1; |
7604 |
25 Feb 19 |
nicklas |
160 |
} |
7604 |
25 Feb 19 |
nicklas |
161 |
} |
7604 |
25 Feb 19 |
nicklas |
162 |
|
7604 |
25 Feb 19 |
nicklas |
163 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.actionOnChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
165 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotations']; |
7604 |
25 Feb 19 |
nicklas |
167 |
|
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get(target, 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var disabled = target.value == 'remove' || target.value == 'resync'; |
7604 |
25 Feb 19 |
nicklas |
171 |
|
7604 |
25 Feb 19 |
nicklas |
frm['from_'+itemId].disabled = disabled; |
7604 |
25 Feb 19 |
nicklas |
frm['nodup_'+itemId].disabled = disabled; |
7604 |
25 Feb 19 |
nicklas |
frm['replace_'+itemId].disabled = disabled; |
7604 |
25 Feb 19 |
nicklas |
175 |
} |
7604 |
25 Feb 19 |
nicklas |
176 |
|
7604 |
25 Feb 19 |
nicklas |
inherit.save = function() |
7604 |
25 Feb 19 |
nicklas |
178 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (allowedAnnotationTypes.length == 0) |
7604 |
25 Feb 19 |
nicklas |
180 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification('btnSelectAnnotationTypes', 'Please select annotation types to inherit!'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
183 |
} |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotations']; |
7604 |
25 Feb 19 |
nicklas |
frm.cmd.value = 'BatchInherit'; |
7604 |
25 Feb 19 |
nicklas |
Forms.addHidden(frm, 'annotationTypes', allowedAnnotationTypes.join(',')); |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
188 |
} |
7604 |
25 Feb 19 |
nicklas |
189 |
|
7604 |
25 Feb 19 |
nicklas |
return inherit; |
7604 |
25 Feb 19 |
nicklas |
191 |
}(); |
7604 |
25 Feb 19 |
nicklas |
192 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Inherit.initPage); |
7604 |
25 Feb 19 |
nicklas |
194 |
|
7604 |
25 Feb 19 |
nicklas |
195 |
|