6938 |
19 Aug 15 |
nicklas |
/* $Id $ |
6938 |
19 Aug 15 |
nicklas |
2 |
------------------------------------------------------------------ |
6938 |
19 Aug 15 |
nicklas |
Copyright (C) 2012 Nicklas Nordborg |
6938 |
19 Aug 15 |
nicklas |
4 |
|
6938 |
19 Aug 15 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
6938 |
19 Aug 15 |
nicklas |
Available at http://base.thep.lu.se/ |
6938 |
19 Aug 15 |
nicklas |
7 |
|
6938 |
19 Aug 15 |
nicklas |
BASE is free software; you can redistribute it and/or |
6938 |
19 Aug 15 |
nicklas |
modify it under the terms of the GNU General Public License |
6938 |
19 Aug 15 |
nicklas |
as published by the Free Software Foundation; either version 3 |
6938 |
19 Aug 15 |
nicklas |
of the License, or (at your option) any later version. |
6938 |
19 Aug 15 |
nicklas |
12 |
|
6938 |
19 Aug 15 |
nicklas |
BASE is distributed in the hope that it will be useful, |
6938 |
19 Aug 15 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6938 |
19 Aug 15 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6938 |
19 Aug 15 |
nicklas |
GNU General Public License for more details. |
6938 |
19 Aug 15 |
nicklas |
17 |
|
6938 |
19 Aug 15 |
nicklas |
You should have received a copy of the GNU General Public License |
6938 |
19 Aug 15 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6938 |
19 Aug 15 |
nicklas |
20 |
------------------------------------------------------------------ |
6938 |
19 Aug 15 |
nicklas |
21 |
|
6938 |
19 Aug 15 |
nicklas |
@author Nicklas |
6938 |
19 Aug 15 |
nicklas |
23 |
*/ |
7429 |
07 Dec 17 |
nicklas |
'use strict'; |
6938 |
19 Aug 15 |
nicklas |
25 |
|
6938 |
19 Aug 15 |
nicklas |
var Annotate = function() |
6938 |
19 Aug 15 |
nicklas |
27 |
{ |
6938 |
19 Aug 15 |
nicklas |
var annotate = {}; |
6938 |
19 Aug 15 |
nicklas |
29 |
|
6943 |
01 Sep 15 |
nicklas |
var MODIFIED = 'MODIFIED'; |
6943 |
01 Sep 15 |
nicklas |
var SYNCED = 'SYNCED'; |
6943 |
01 Sep 15 |
nicklas |
var CONVERTED = 'CONVERTED'; |
6945 |
04 Sep 15 |
nicklas |
var DELETE = 'DELETE'; |
6947 |
08 Sep 15 |
nicklas |
var INHERITED = 'INHERITED'; |
6943 |
01 Sep 15 |
nicklas |
35 |
|
6938 |
19 Aug 15 |
nicklas |
var annotations; |
6947 |
08 Sep 15 |
nicklas |
var parents; |
6938 |
19 Aug 15 |
nicklas |
var selectedAnnotation; |
6955 |
28 Sep 15 |
nicklas |
var selectedMultiIndex; |
6938 |
19 Aug 15 |
nicklas |
40 |
|
6938 |
19 Aug 15 |
nicklas |
41 |
|
6938 |
19 Aug 15 |
nicklas |
annotate.initPage = function() |
6938 |
19 Aug 15 |
nicklas |
43 |
{ |
6938 |
19 Aug 15 |
nicklas |
// Buttons (on standalone dialog) |
6938 |
19 Aug 15 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
6938 |
19 Aug 15 |
nicklas |
Buttons.addClickHandler('btnSave', annotate.save); |
6938 |
19 Aug 15 |
nicklas |
47 |
|
6938 |
19 Aug 15 |
nicklas |
// Parse the current annotation information which contain value type, current values, etc. |
6938 |
19 Aug 15 |
nicklas |
annotations = Data.json('page-data', 'annotations'); |
6947 |
08 Sep 15 |
nicklas |
parents = Data.json('page-data', 'parents'); |
6947 |
08 Sep 15 |
nicklas |
51 |
|
6938 |
19 Aug 15 |
nicklas |
// Loop through all annotations and build the selection list |
6946 |
07 Sep 15 |
nicklas |
var numPrimary = 0; |
6938 |
19 Aug 15 |
nicklas |
for (var i = 0; i < annotations.length; i++) |
6938 |
19 Aug 15 |
nicklas |
55 |
{ |
6947 |
08 Sep 15 |
nicklas |
annotate.createAnnotationEntryInList(annotations[i], false); |
6946 |
07 Sep 15 |
nicklas |
if (annotations[i].source == 'PRIMARY') numPrimary++; |
6938 |
19 Aug 15 |
nicklas |
58 |
} |
6946 |
07 Sep 15 |
nicklas |
if (numPrimary == 0) Doc.hide('primary-list'); |
6946 |
07 Sep 15 |
nicklas |
if (numPrimary == annotations.length) Doc.hide('inherited-list'); |
6938 |
19 Aug 15 |
nicklas |
61 |
|
6938 |
19 Aug 15 |
nicklas |
// Event handlers for input fields |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('STRING-input', 'change', annotate.valueOnChange); |
6955 |
28 Sep 15 |
nicklas |
Events.addEventHandler('STRING-input', 'blur', annotate.valueOnBlur); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('TEXT-input', 'change', annotate.valueOnChange); |
6955 |
28 Sep 15 |
nicklas |
Events.addEventHandler('TEXT-input', 'blur', annotate.valueOnBlur); |
6938 |
19 Aug 15 |
nicklas |
Buttons.addClickHandler('TEXT-zoom', annotate.openTextZoom); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('INT-input', 'keypress', Events.integerOnly); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('INT-input', 'change', annotate.valueOnChange); |
6955 |
28 Sep 15 |
nicklas |
Events.addEventHandler('INT-input', 'blur', annotate.valueOnBlur); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('LONG-input', 'keypress', Events.integerOnly); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('LONG-input', 'change', annotate.valueOnChange); |
6955 |
28 Sep 15 |
nicklas |
Events.addEventHandler('LONG-input', 'blur', annotate.valueOnBlur); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('FLOAT-input', 'keypress', Events.numberOnly); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('FLOAT-input', 'change', annotate.valueOnChange); |
6955 |
28 Sep 15 |
nicklas |
Events.addEventHandler('FLOAT-input', 'blur', annotate.valueOnBlur); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('DOUBLE-input', 'keypress', Events.numberOnly); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('DOUBLE-input', 'change', annotate.valueOnChange); |
6955 |
28 Sep 15 |
nicklas |
Events.addEventHandler('DOUBLE-input', 'blur', annotate.valueOnBlur); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('DATE-input', 'change', annotate.valueOnChange); |
6955 |
28 Sep 15 |
nicklas |
Events.addEventHandler('DATE-input', 'blur', annotate.valueOnBlur); |
6938 |
19 Aug 15 |
nicklas |
Buttons.addClickHandler('DATE-calendar', annotate.openCalendar); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('TIMESTAMP-input', 'change', annotate.valueOnChange); |
6955 |
28 Sep 15 |
nicklas |
Events.addEventHandler('TIMESTAMP-input', 'blur', annotate.valueOnBlur); |
6938 |
19 Aug 15 |
nicklas |
Buttons.addClickHandler('TIMESTAMP-calendar', annotate.openCalendar); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('BOOLEAN-input-NULL', 'click', annotate.valueOnChange); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('BOOLEAN-input-TRUE', 'click', annotate.valueOnChange); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('BOOLEAN-input-FALSE', 'click', annotate.valueOnChange); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('ENUM-SINGLE-input', 'change', annotate.valueOnChange); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('ENUM-MULTIPLE-input', 'change', annotate.valueOnChange); |
6938 |
19 Aug 15 |
nicklas |
91 |
|
6938 |
19 Aug 15 |
nicklas |
// Buttons for multi-valued annotations |
6938 |
19 Aug 15 |
nicklas |
Buttons.addClickHandler('btnMultiAdd', annotate.addMultiValue); |
6938 |
19 Aug 15 |
nicklas |
Buttons.addClickHandler('btnMultiRemove', annotate.removeMultiValue); |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('multi-values', 'click', annotate.multiValueOnClick); |
6938 |
19 Aug 15 |
nicklas |
96 |
|
6938 |
19 Aug 15 |
nicklas |
97 |
|
6938 |
19 Aug 15 |
nicklas |
// The category list box is used to filter visible annotations |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('categories', 'change', annotate.categoryOnChange); |
6938 |
19 Aug 15 |
nicklas |
annotate.categoryOnChange(); |
6938 |
19 Aug 15 |
nicklas |
101 |
|
6938 |
19 Aug 15 |
nicklas |
// Unit selection |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler('unit', 'change', annotate.unitOnChange); |
6938 |
19 Aug 15 |
nicklas |
104 |
|
6946 |
07 Sep 15 |
nicklas |
// Check/uncheck all |
6946 |
07 Sep 15 |
nicklas |
Events.addEventHandler('check-all-primary', 'click', annotate.checkAllPrimary); |
6946 |
07 Sep 15 |
nicklas |
Events.addEventHandler('check-all-inherited', 'click', annotate.checkAllInherited); |
6946 |
07 Sep 15 |
nicklas |
108 |
|
6943 |
01 Sep 15 |
nicklas |
// Sync modified clone |
6945 |
04 Sep 15 |
nicklas |
Events.addEventHandler('sync-modified', 'click', annotate.syncSelectedClone); |
6945 |
04 Sep 15 |
nicklas |
Buttons.addClickHandler('btnSync', annotate.syncAllCheckedClones); |
6945 |
04 Sep 15 |
nicklas |
112 |
|
6946 |
07 Sep 15 |
nicklas |
// Convert between inherited/cloned |
6945 |
04 Sep 15 |
nicklas |
Events.addEventHandler('convert-to-cloned', 'click', annotate.convertSelectedToCloned); |
6945 |
04 Sep 15 |
nicklas |
Buttons.addClickHandler('btnClone', annotate.convertAllCheckedToCloned); |
6946 |
07 Sep 15 |
nicklas |
Buttons.addClickHandler('btnUnclone', annotate.convertAllCheckedToInherited); |
6943 |
01 Sep 15 |
nicklas |
117 |
|
6946 |
07 Sep 15 |
nicklas |
// Delete annotations |
6945 |
04 Sep 15 |
nicklas |
Buttons.addClickHandler('btnDelete', annotate.deleteAllChecked); |
6947 |
08 Sep 15 |
nicklas |
// Add inherited annotations |
6947 |
08 Sep 15 |
nicklas |
Buttons.addClickHandler('btnAdd', annotate.addInheritedAnnotations); |
6947 |
08 Sep 15 |
nicklas |
Events.addEventHandler('btnAdd', 'remove-annotation', annotate.onRemoveInheritedAnnotation); |
6947 |
08 Sep 15 |
nicklas |
Events.addEventHandler('btnAdd', 'inherit-annotation', annotate.onAddInheritedAnnotation); |
6945 |
04 Sep 15 |
nicklas |
124 |
|
6938 |
19 Aug 15 |
nicklas |
// Select the initial annotation |
6938 |
19 Aug 15 |
nicklas |
var annotationTypeId = Data.int('page-data', 'annotation-type-id'); |
6938 |
19 Aug 15 |
nicklas |
var annotationId = Data.int('page-data', 'annotation-id'); |
6938 |
19 Aug 15 |
nicklas |
if (annotationId) |
6938 |
19 Aug 15 |
nicklas |
129 |
{ |
7832 |
24 Jun 20 |
nicklas |
annotate.selectAnnotation(annotationTypeId+'-'+annotationId, true); |
6938 |
19 Aug 15 |
nicklas |
131 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (annotationTypeId) |
6938 |
19 Aug 15 |
nicklas |
133 |
{ |
7832 |
24 Jun 20 |
nicklas |
annotate.selectAnnotation(annotationTypeId, true); |
6938 |
19 Aug 15 |
nicklas |
135 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
137 |
{ |
6938 |
19 Aug 15 |
nicklas |
annotate.selectAnnotation(null); |
6938 |
19 Aug 15 |
nicklas |
139 |
} |
6938 |
19 Aug 15 |
nicklas |
140 |
} |
6938 |
19 Aug 15 |
nicklas |
141 |
|
6938 |
19 Aug 15 |
nicklas |
142 |
/** |
6938 |
19 Aug 15 |
nicklas |
Create an entry for the given annotation/annotation type |
6938 |
19 Aug 15 |
nicklas |
in the list. |
6938 |
19 Aug 15 |
nicklas |
145 |
*/ |
6947 |
08 Sep 15 |
nicklas |
annotate.createAnnotationEntryInList = function(entry, autoSort) |
6938 |
19 Aug 15 |
nicklas |
147 |
{ |
6938 |
19 Aug 15 |
nicklas |
var ann = entry.annotation; |
6938 |
19 Aug 15 |
nicklas |
var at = entry.annotationType; |
6938 |
19 Aug 15 |
nicklas |
150 |
|
6938 |
19 Aug 15 |
nicklas |
var div = document.createElement('div'); |
6938 |
19 Aug 15 |
nicklas |
div.className = 'param interactable'; |
7206 |
19 Oct 16 |
nicklas |
if (!entry.annotatePermission) div.className += ' disabled'; |
6938 |
19 Aug 15 |
nicklas |
div.id = entry.id; |
6938 |
19 Aug 15 |
nicklas |
div.title = Strings.encodeTags(at.name); |
6938 |
19 Aug 15 |
nicklas |
156 |
|
6938 |
19 Aug 15 |
nicklas |
var html = ''; |
6945 |
04 Sep 15 |
nicklas |
var icon = annotate.getIcon(entry); |
6943 |
01 Sep 15 |
nicklas |
159 |
|
7206 |
19 Oct 16 |
nicklas |
if (entry.annotatePermission) |
7206 |
19 Oct 16 |
nicklas |
161 |
{ |
7206 |
19 Oct 16 |
nicklas |
html += '<input type="checkbox" style="float: right;" id="check.'+entry.id+'">'; |
7206 |
19 Oct 16 |
nicklas |
163 |
} |
6938 |
19 Aug 15 |
nicklas |
html += '<span class="icon">'; |
6938 |
19 Aug 15 |
nicklas |
html += '<img id="icon.'+entry.id+'" src="../../images/'+icon+'">'; |
6938 |
19 Aug 15 |
nicklas |
html += '</span>'; |
6938 |
19 Aug 15 |
nicklas |
// DEBUG!! |
6938 |
19 Aug 15 |
nicklas |
//html += entry.source; |
6938 |
19 Aug 15 |
nicklas |
169 |
|
6938 |
19 Aug 15 |
nicklas |
html += '<span class="label">'; |
6938 |
19 Aug 15 |
nicklas |
if (at.removed) html += '<img src="../../images/deleted.png">'; |
6938 |
19 Aug 15 |
nicklas |
if (at.protocolParameter) html += '<img src="../../images/parameter.png">'; |
6938 |
19 Aug 15 |
nicklas |
html += Strings.encodeTags(at.name)+'</span>'; |
6938 |
19 Aug 15 |
nicklas |
html += '</div>'; |
6938 |
19 Aug 15 |
nicklas |
div.innerHTML = html; |
6938 |
19 Aug 15 |
nicklas |
176 |
|
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler(div, 'click', annotate.annotationOnClick); |
6947 |
08 Sep 15 |
nicklas |
var list = Doc.element(entry.source == 'PRIMARY' ? 'primary-list' : 'inherited-list'); |
6947 |
08 Sep 15 |
nicklas |
var beforeChild = null; |
6947 |
08 Sep 15 |
nicklas |
if (autoSort) |
6947 |
08 Sep 15 |
nicklas |
181 |
{ |
6947 |
08 Sep 15 |
nicklas |
var childNo = 0; |
6947 |
08 Sep 15 |
nicklas |
while (childNo < list.childNodes.length) |
6947 |
08 Sep 15 |
nicklas |
184 |
{ |
6947 |
08 Sep 15 |
nicklas |
var child = list.childNodes[childNo]; |
6947 |
08 Sep 15 |
nicklas |
if (child.title && child.title > div.title) |
6947 |
08 Sep 15 |
nicklas |
187 |
{ |
6947 |
08 Sep 15 |
nicklas |
beforeChild = child; |
6947 |
08 Sep 15 |
nicklas |
break; |
6947 |
08 Sep 15 |
nicklas |
190 |
} |
6947 |
08 Sep 15 |
nicklas |
childNo++; |
6947 |
08 Sep 15 |
nicklas |
192 |
} |
6947 |
08 Sep 15 |
nicklas |
193 |
} |
6947 |
08 Sep 15 |
nicklas |
list.insertBefore(div, beforeChild); |
6938 |
19 Aug 15 |
nicklas |
195 |
} |
6938 |
19 Aug 15 |
nicklas |
196 |
|
6938 |
19 Aug 15 |
nicklas |
197 |
/** |
6938 |
19 Aug 15 |
nicklas |
Event handler for the 'Categories' list. This will |
6938 |
19 Aug 15 |
nicklas |
filter the main list to only include annotations in the select |
6938 |
19 Aug 15 |
nicklas |
category. Special cases are 'all', 'protocol parameter' and 'uncategorized' |
6938 |
19 Aug 15 |
nicklas |
201 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.categoryOnChange = function() |
6938 |
19 Aug 15 |
nicklas |
203 |
{ |
6938 |
19 Aug 15 |
nicklas |
var frm = document.forms['annotations']; |
6938 |
19 Aug 15 |
nicklas |
var categoryId = parseInt(frm.categories.value); |
6938 |
19 Aug 15 |
nicklas |
206 |
|
6938 |
19 Aug 15 |
nicklas |
for (var entryNo = 0; entryNo < annotations.length; entryNo++) |
6938 |
19 Aug 15 |
nicklas |
208 |
{ |
6938 |
19 Aug 15 |
nicklas |
var entry = annotations[entryNo]; |
6938 |
19 Aug 15 |
nicklas |
var at = entry.annotationType; |
6938 |
19 Aug 15 |
nicklas |
211 |
|
6938 |
19 Aug 15 |
nicklas |
var show = false; |
6947 |
08 Sep 15 |
nicklas |
if (entry.source != 'PRIMARY') |
6947 |
08 Sep 15 |
nicklas |
214 |
{ |
6947 |
08 Sep 15 |
nicklas |
// INHERITED or CLONED annotations are visible unless DELETEd |
6947 |
08 Sep 15 |
nicklas |
show = entry.modified != 'DELETE'; |
6947 |
08 Sep 15 |
nicklas |
217 |
} |
6946 |
07 Sep 15 |
nicklas |
else if (categoryId == -1) |
6938 |
19 Aug 15 |
nicklas |
219 |
{ |
6938 |
19 Aug 15 |
nicklas |
// show all |
6938 |
19 Aug 15 |
nicklas |
show = true; |
6938 |
19 Aug 15 |
nicklas |
222 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (categoryId == -2 && at.protocolParameter) |
6938 |
19 Aug 15 |
nicklas |
224 |
{ |
6938 |
19 Aug 15 |
nicklas |
// show protocol parameters |
6938 |
19 Aug 15 |
nicklas |
show = true; |
6938 |
19 Aug 15 |
nicklas |
227 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (categoryId == 0 && at.categories.length == 0 && !at.protocolParameter) |
6938 |
19 Aug 15 |
nicklas |
229 |
{ |
6938 |
19 Aug 15 |
nicklas |
// show uncategorized |
6938 |
19 Aug 15 |
nicklas |
show = true; |
6938 |
19 Aug 15 |
nicklas |
232 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
234 |
{ |
6938 |
19 Aug 15 |
nicklas |
// show the selected category |
6938 |
19 Aug 15 |
nicklas |
for (var categoryNo = 0; categoryNo < at.categories.length; categoryNo++) |
6938 |
19 Aug 15 |
nicklas |
237 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (at.categories[categoryNo] == categoryId) |
6938 |
19 Aug 15 |
nicklas |
239 |
{ |
6938 |
19 Aug 15 |
nicklas |
show = true; |
6938 |
19 Aug 15 |
nicklas |
break; |
6938 |
19 Aug 15 |
nicklas |
242 |
} |
6938 |
19 Aug 15 |
nicklas |
243 |
} |
6938 |
19 Aug 15 |
nicklas |
244 |
} |
6938 |
19 Aug 15 |
nicklas |
245 |
|
7926 |
24 Feb 21 |
nicklas |
entry.visible = show; |
6938 |
19 Aug 15 |
nicklas |
Doc.showHide(entry.id, show); |
6938 |
19 Aug 15 |
nicklas |
248 |
} |
6938 |
19 Aug 15 |
nicklas |
249 |
} |
6938 |
19 Aug 15 |
nicklas |
250 |
|
6938 |
19 Aug 15 |
nicklas |
251 |
/** |
6938 |
19 Aug 15 |
nicklas |
Get the annotation entry for the given id. |
6938 |
19 Aug 15 |
nicklas |
Returns null if not found. |
6938 |
19 Aug 15 |
nicklas |
254 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.getEntryById = function(entryId) |
6938 |
19 Aug 15 |
nicklas |
256 |
{ |
6938 |
19 Aug 15 |
nicklas |
for (var i = 0; i < annotations.length; i++) |
6938 |
19 Aug 15 |
nicklas |
258 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (annotations[i].id == entryId) |
6938 |
19 Aug 15 |
nicklas |
260 |
{ |
6938 |
19 Aug 15 |
nicklas |
return annotations[i]; |
6938 |
19 Aug 15 |
nicklas |
262 |
} |
6938 |
19 Aug 15 |
nicklas |
263 |
} |
6938 |
19 Aug 15 |
nicklas |
return null; |
6938 |
19 Aug 15 |
nicklas |
265 |
} |
6938 |
19 Aug 15 |
nicklas |
266 |
|
6938 |
19 Aug 15 |
nicklas |
267 |
|
6938 |
19 Aug 15 |
nicklas |
268 |
/** |
6938 |
19 Aug 15 |
nicklas |
Select the given annotation entry. This will mark the annotation |
6938 |
19 Aug 15 |
nicklas |
in the main list, display the input fields associated with it |
6938 |
19 Aug 15 |
nicklas |
and populate the input fields with the current value(s). |
6938 |
19 Aug 15 |
nicklas |
272 |
*/ |
7832 |
24 Jun 20 |
nicklas |
annotate.selectAnnotation = function(entryId, scrollIntoView) |
6938 |
19 Aug 15 |
nicklas |
274 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (selectedAnnotation) |
6938 |
19 Aug 15 |
nicklas |
276 |
{ |
6938 |
19 Aug 15 |
nicklas |
Doc.removeClass(selectedAnnotation.id, 'selected'); |
6938 |
19 Aug 15 |
nicklas |
278 |
} |
6938 |
19 Aug 15 |
nicklas |
279 |
|
6938 |
19 Aug 15 |
nicklas |
var frm = document.forms['annotations']; |
6938 |
19 Aug 15 |
nicklas |
// Mark the selected annotation and make sure the |
6938 |
19 Aug 15 |
nicklas |
// category list doesn't hide it |
6938 |
19 Aug 15 |
nicklas |
selectedAnnotation = annotate.getEntryById(entryId); |
6955 |
28 Sep 15 |
nicklas |
selectedMultiIndex = -1; |
6955 |
28 Sep 15 |
nicklas |
285 |
|
6938 |
19 Aug 15 |
nicklas |
var classes = []; |
6938 |
19 Aug 15 |
nicklas |
var valueElement; |
6938 |
19 Aug 15 |
nicklas |
288 |
|
6938 |
19 Aug 15 |
nicklas |
if (selectedAnnotation == null) |
6938 |
19 Aug 15 |
nicklas |
290 |
{ |
6938 |
19 Aug 15 |
nicklas |
classes.push('none-selected'); |
6938 |
19 Aug 15 |
nicklas |
if (annotations.length == 0) |
6938 |
19 Aug 15 |
nicklas |
293 |
{ |
6938 |
19 Aug 15 |
nicklas |
classes.push('no-annotations'); |
6938 |
19 Aug 15 |
nicklas |
295 |
} |
6938 |
19 Aug 15 |
nicklas |
296 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
298 |
{ |
6938 |
19 Aug 15 |
nicklas |
299 |
|
6938 |
19 Aug 15 |
nicklas |
Doc.addClass(entryId, 'selected'); |
6938 |
19 Aug 15 |
nicklas |
if (Doc.element(entryId).style.display=='none') |
6938 |
19 Aug 15 |
nicklas |
302 |
{ |
6938 |
19 Aug 15 |
nicklas |
// Make sure the entry is not hidden because a different |
6938 |
19 Aug 15 |
nicklas |
// category is selected |
6938 |
19 Aug 15 |
nicklas |
frm.categories.selectedIndex = 0; |
6938 |
19 Aug 15 |
nicklas |
annotate.categoryOnChange(); |
6938 |
19 Aug 15 |
nicklas |
307 |
} |
7832 |
24 Jun 20 |
nicklas |
if (scrollIntoView) Doc.element(entryId).scrollIntoView({block: 'center'}); |
6938 |
19 Aug 15 |
nicklas |
309 |
|
6938 |
19 Aug 15 |
nicklas |
var at = selectedAnnotation.annotationType; |
6938 |
19 Aug 15 |
nicklas |
var ann = selectedAnnotation.annotation; |
6938 |
19 Aug 15 |
nicklas |
312 |
|
6938 |
19 Aug 15 |
nicklas |
annotate.showNameAndOtherInfo(at); |
6943 |
01 Sep 15 |
nicklas |
classes.push('has-selected'); |
6938 |
19 Aug 15 |
nicklas |
classes.push(selectedAnnotation.source); |
6938 |
19 Aug 15 |
nicklas |
if (at.description) classes.push('has-description'); |
7206 |
19 Oct 16 |
nicklas |
if (!selectedAnnotation.annotatePermission) classes.push('no-annotate-permission'); |
6938 |
19 Aug 15 |
nicklas |
318 |
|
7334 |
11 Apr 17 |
nicklas |
if (at.projectAnnotations && ann) |
7334 |
11 Apr 17 |
nicklas |
320 |
{ |
7334 |
11 Apr 17 |
nicklas |
var msg = ''; |
7334 |
11 Apr 17 |
nicklas |
var defaultValues = ''; |
8083 |
20 Oct 22 |
nicklas |
var projectId = Data.int('page-data', 'project-id'); |
8083 |
20 Oct 22 |
nicklas |
var activeProjectId = Data.int('page-data', 'active-project-id'); |
7334 |
11 Apr 17 |
nicklas |
if (ann.projectId != 0) |
7334 |
11 Apr 17 |
nicklas |
326 |
{ |
7334 |
11 Apr 17 |
nicklas |
if (ann.override) |
7334 |
11 Apr 17 |
nicklas |
328 |
{ |
7334 |
11 Apr 17 |
nicklas |
msg = 'This is a project-specific annotation that overrides the default value:<br>'; |
7334 |
11 Apr 17 |
nicklas |
var defA = selectedAnnotation.defaultValues; |
7334 |
11 Apr 17 |
nicklas |
var symbol = defA.unitSymbol ? ' ' + defA.unitSymbol : ''; |
7334 |
11 Apr 17 |
nicklas |
defaultValues = Strings.encodeTags(defA.values.join(symbol+', ')+symbol); |
7334 |
11 Apr 17 |
nicklas |
333 |
} |
7334 |
11 Apr 17 |
nicklas |
else |
7334 |
11 Apr 17 |
nicklas |
335 |
{ |
7334 |
11 Apr 17 |
nicklas |
msg = 'This is a project-specific annotation without a default value.'; |
7334 |
11 Apr 17 |
nicklas |
337 |
} |
7334 |
11 Apr 17 |
nicklas |
338 |
} |
7334 |
11 Apr 17 |
nicklas |
else |
7334 |
11 Apr 17 |
nicklas |
340 |
{ |
8083 |
20 Oct 22 |
nicklas |
msg = 'This is the default value for a project annotation.'; |
8083 |
20 Oct 22 |
nicklas |
if (projectId < 0 && activeProjectId > 0) msg += '<br>Changing it will create a project-specific value.'; |
7334 |
11 Apr 17 |
nicklas |
343 |
} |
7334 |
11 Apr 17 |
nicklas |
Doc.element('project-annotations-message').innerHTML = msg; |
7334 |
11 Apr 17 |
nicklas |
Doc.element('default-values').innerHTML = defaultValues; |
7334 |
11 Apr 17 |
nicklas |
classes.push('project-annotations'); |
7334 |
11 Apr 17 |
nicklas |
347 |
} |
7334 |
11 Apr 17 |
nicklas |
348 |
|
6938 |
19 Aug 15 |
nicklas |
if (selectedAnnotation.source != 'PRIMARY') |
6938 |
19 Aug 15 |
nicklas |
350 |
{ |
6938 |
19 Aug 15 |
nicklas |
var inherited = selectedAnnotation.inherited; |
6938 |
19 Aug 15 |
nicklas |
if (inherited) |
6938 |
19 Aug 15 |
nicklas |
353 |
{ |
6938 |
19 Aug 15 |
nicklas |
var symbol = inherited.unitSymbol ? ' ' + inherited.unitSymbol : ''; |
6943 |
01 Sep 15 |
nicklas |
355 |
|
6938 |
19 Aug 15 |
nicklas |
Doc.element('inherited-values').innerHTML = Strings.encodeTags(inherited.values.join(symbol+', ')+symbol); |
6943 |
01 Sep 15 |
nicklas |
Doc.element('inherited-item').innerHTML = (selectedAnnotation.source == 'CLONED' ? 'Cloned from ' : 'Inherited from ') + Strings.encodeTags(inherited.from.name) + ' <span class="itemsubtype">('+inherited.from.type+')</span>'; |
6943 |
01 Sep 15 |
nicklas |
358 |
|
6943 |
01 Sep 15 |
nicklas |
if (selectedAnnotation.source == 'CLONED' && inherited.lastUpdate > ann.lastUpdate) |
6943 |
01 Sep 15 |
nicklas |
360 |
{ |
6943 |
01 Sep 15 |
nicklas |
classes.push('modified'); |
6943 |
01 Sep 15 |
nicklas |
362 |
} |
6943 |
01 Sep 15 |
nicklas |
363 |
|
6938 |
19 Aug 15 |
nicklas |
364 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
366 |
{ |
6938 |
19 Aug 15 |
nicklas |
classes.push('inherited-missing'); |
6938 |
19 Aug 15 |
nicklas |
368 |
} |
6938 |
19 Aug 15 |
nicklas |
369 |
} |
6938 |
19 Aug 15 |
nicklas |
370 |
|
6938 |
19 Aug 15 |
nicklas |
if (!at.enumeration) |
6938 |
19 Aug 15 |
nicklas |
372 |
{ |
6938 |
19 Aug 15 |
nicklas |
// Just display the correct input section |
6938 |
19 Aug 15 |
nicklas |
classes.push(at.valueType); |
6938 |
19 Aug 15 |
nicklas |
valueElement = frm[at.valueType+'-input']; |
6938 |
19 Aug 15 |
nicklas |
376 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
378 |
{ |
6938 |
19 Aug 15 |
nicklas |
// We need to populate the selection list or |
6938 |
19 Aug 15 |
nicklas |
// generate radiobuttons/checkboxes |
6938 |
19 Aug 15 |
nicklas |
var symbol = at.defaultUnit ? ' ' + at.defaultSymbol : ''; |
6938 |
19 Aug 15 |
nicklas |
if (at.displayAsList) |
6938 |
19 Aug 15 |
nicklas |
383 |
{ |
6938 |
19 Aug 15 |
nicklas |
classes.push(at.multiplicity == 1 ? 'ENUM-SINGLE' : 'ENUM-MULTIPLE'); |
6938 |
19 Aug 15 |
nicklas |
var list = Doc.element(at.multiplicity == 1 ? 'ENUM-SINGLE-input' : 'ENUM-MULTIPLE-input'); |
6943 |
01 Sep 15 |
nicklas |
annotate.initEnumList(list, at.enumeration, at.multiplicity == 1 && selectedAnnotation.source == 'PRIMARY', symbol); |
6938 |
19 Aug 15 |
nicklas |
valueElement = list; |
6938 |
19 Aug 15 |
nicklas |
388 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
390 |
{ |
6938 |
19 Aug 15 |
nicklas |
classes.push('ENUM-RADIO-CHECKBOX'); |
6943 |
01 Sep 15 |
nicklas |
var tmp = annotate.initEnumCheckboxes(at.enumeration, at.multiplicity == 1, symbol, selectedAnnotation.source == 'PRIMARY'); |
6938 |
19 Aug 15 |
nicklas |
Doc.element('ENUM-RADIO-CHECKBOX').innerHTML = ''; |
6938 |
19 Aug 15 |
nicklas |
Doc.element('ENUM-RADIO-CHECKBOX').appendChild(tmp); |
6938 |
19 Aug 15 |
nicklas |
valueElement = frm['check']; |
6938 |
19 Aug 15 |
nicklas |
396 |
} |
6938 |
19 Aug 15 |
nicklas |
397 |
} |
6938 |
19 Aug 15 |
nicklas |
398 |
|
6938 |
19 Aug 15 |
nicklas |
if (at.units) |
6938 |
19 Aug 15 |
nicklas |
400 |
{ |
6938 |
19 Aug 15 |
nicklas |
classes.push('has-unit') |
6938 |
19 Aug 15 |
nicklas |
annotate.initUnitList(at.units, ann && ann.unit || at.defaultUnit); |
6938 |
19 Aug 15 |
nicklas |
403 |
} |
6938 |
19 Aug 15 |
nicklas |
404 |
|
6955 |
28 Sep 15 |
nicklas |
405 |
|
6938 |
19 Aug 15 |
nicklas |
// Fill form with current values |
6955 |
28 Sep 15 |
nicklas |
var values = ann.values.length > 0 || at.multiplicity != 1 ? ann.values : ['']; |
6938 |
19 Aug 15 |
nicklas |
if (valueElement.type && valueElement.type.indexOf('select') == 0) |
6938 |
19 Aug 15 |
nicklas |
409 |
{ |
6938 |
19 Aug 15 |
nicklas |
// selection list |
6938 |
19 Aug 15 |
nicklas |
Forms.selectListOptions(valueElement, values); |
6938 |
19 Aug 15 |
nicklas |
412 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (valueElement.length) |
6938 |
19 Aug 15 |
nicklas |
414 |
{ |
6938 |
19 Aug 15 |
nicklas |
// radio buttons or checkboxes |
6938 |
19 Aug 15 |
nicklas |
if (at.multiplicity == 1) |
6938 |
19 Aug 15 |
nicklas |
417 |
{ |
6938 |
19 Aug 15 |
nicklas |
Forms.checkRadio(valueElement, values[0]); |
6938 |
19 Aug 15 |
nicklas |
419 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
421 |
{ |
6938 |
19 Aug 15 |
nicklas |
Forms.checkCheckBoxes(valueElement, values); |
6938 |
19 Aug 15 |
nicklas |
423 |
} |
6938 |
19 Aug 15 |
nicklas |
424 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
426 |
{ |
6938 |
19 Aug 15 |
nicklas |
// regular input field |
6938 |
19 Aug 15 |
nicklas |
if (at.multiplicity == 1) |
6938 |
19 Aug 15 |
nicklas |
429 |
{ |
6938 |
19 Aug 15 |
nicklas |
valueElement.value = values[0]; |
6938 |
19 Aug 15 |
nicklas |
431 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
433 |
{ |
6955 |
28 Sep 15 |
nicklas |
classes.push('multiple'); |
6955 |
28 Sep 15 |
nicklas |
// Fill the 'multi-values' list with the current values |
6955 |
28 Sep 15 |
nicklas |
var multiValues = frm['multi-values']; |
6955 |
28 Sep 15 |
nicklas |
multiValues.length = 0; |
6955 |
28 Sep 15 |
nicklas |
for (var i = 0; i < values.length; i++) |
6955 |
28 Sep 15 |
nicklas |
439 |
{ |
6955 |
28 Sep 15 |
nicklas |
multiValues[multiValues.length] = new Option(values[i]); |
6955 |
28 Sep 15 |
nicklas |
441 |
} |
6955 |
28 Sep 15 |
nicklas |
valueElement.value = ''; |
6938 |
19 Aug 15 |
nicklas |
443 |
} |
6938 |
19 Aug 15 |
nicklas |
444 |
} |
6938 |
19 Aug 15 |
nicklas |
445 |
} |
6938 |
19 Aug 15 |
nicklas |
Doc.element('selected-container').className = classes.join(' '); |
6938 |
19 Aug 15 |
nicklas |
if (valueElement && valueElement.focus) valueElement.focus(); |
6938 |
19 Aug 15 |
nicklas |
448 |
} |
6938 |
19 Aug 15 |
nicklas |
449 |
|
6938 |
19 Aug 15 |
nicklas |
450 |
/** |
6938 |
19 Aug 15 |
nicklas |
Display information about the annotation. |
6938 |
19 Aug 15 |
nicklas |
452 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.showNameAndOtherInfo = function(at) |
6938 |
19 Aug 15 |
nicklas |
454 |
{ |
6938 |
19 Aug 15 |
nicklas |
Doc.element('selected-name').innerHTML = Strings.encodeTags(at.name); |
6938 |
19 Aug 15 |
nicklas |
Doc.element('selected-description').innerHTML = at.description || ''; |
6938 |
19 Aug 15 |
nicklas |
457 |
|
6938 |
19 Aug 15 |
nicklas |
var typeSummary = at.valueType; |
6938 |
19 Aug 15 |
nicklas |
if (at.enumeration) |
6938 |
19 Aug 15 |
nicklas |
460 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (at.multiplicity == 0) |
6938 |
19 Aug 15 |
nicklas |
462 |
{ |
6938 |
19 Aug 15 |
nicklas |
typeSummary = "Select one or more"; |
6938 |
19 Aug 15 |
nicklas |
464 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (at.multiplicity == 1) |
6938 |
19 Aug 15 |
nicklas |
466 |
{ |
6938 |
19 Aug 15 |
nicklas |
typeSummary = "Select one"; |
6938 |
19 Aug 15 |
nicklas |
468 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
470 |
{ |
6938 |
19 Aug 15 |
nicklas |
typeSummary = "Select 1‒"+at.multiplicity; |
6938 |
19 Aug 15 |
nicklas |
472 |
} |
6938 |
19 Aug 15 |
nicklas |
473 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
475 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (at.minValue != null && at.maxValue != null) |
6938 |
19 Aug 15 |
nicklas |
477 |
{ |
6938 |
19 Aug 15 |
nicklas |
typeSummary += ': '+at.minValue+'-'+at.maxValue; |
6938 |
19 Aug 15 |
nicklas |
479 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (at.minValue != null) |
6938 |
19 Aug 15 |
nicklas |
481 |
{ |
6938 |
19 Aug 15 |
nicklas |
typeSummary += ' >= '+at.minValue; |
6938 |
19 Aug 15 |
nicklas |
483 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (at.maxValue != null) |
6938 |
19 Aug 15 |
nicklas |
485 |
{ |
6938 |
19 Aug 15 |
nicklas |
typeSummary += ' <= '+at.maxValue; |
6938 |
19 Aug 15 |
nicklas |
487 |
} |
6955 |
28 Sep 15 |
nicklas |
if (at.multiplicity > 1) |
6955 |
28 Sep 15 |
nicklas |
489 |
{ |
6955 |
28 Sep 15 |
nicklas |
typeSummary += '; max '+at.multiplicity+' values'; |
6955 |
28 Sep 15 |
nicklas |
491 |
} |
6938 |
19 Aug 15 |
nicklas |
492 |
} |
6938 |
19 Aug 15 |
nicklas |
Doc.element('selected-type').innerHTML = typeSummary; |
6938 |
19 Aug 15 |
nicklas |
494 |
} |
6938 |
19 Aug 15 |
nicklas |
495 |
|
6938 |
19 Aug 15 |
nicklas |
496 |
/** |
6938 |
19 Aug 15 |
nicklas |
Initialize the units list with the given units. |
6938 |
19 Aug 15 |
nicklas |
'selected' is the id of the unit that should be |
6938 |
19 Aug 15 |
nicklas |
selected. |
6938 |
19 Aug 15 |
nicklas |
500 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.initUnitList = function(units, selected) |
6938 |
19 Aug 15 |
nicklas |
502 |
{ |
6938 |
19 Aug 15 |
nicklas |
var unitList = Doc.element('unit'); |
6938 |
19 Aug 15 |
nicklas |
unitList.length = 0; |
6938 |
19 Aug 15 |
nicklas |
for (var unitNo = 0; unitNo < units.length; unitNo++) |
6938 |
19 Aug 15 |
nicklas |
506 |
{ |
6938 |
19 Aug 15 |
nicklas |
var unit = units[unitNo]; |
6981 |
08 Oct 15 |
nicklas |
var option = new Option(unit.symbol, unit.id, false, selected == unit.id); |
6938 |
19 Aug 15 |
nicklas |
option.title = unit.description; |
6938 |
19 Aug 15 |
nicklas |
unitList[unitList.length] = option; |
6938 |
19 Aug 15 |
nicklas |
511 |
} |
6938 |
19 Aug 15 |
nicklas |
512 |
} |
6938 |
19 Aug 15 |
nicklas |
513 |
|
6938 |
19 Aug 15 |
nicklas |
514 |
/** |
6938 |
19 Aug 15 |
nicklas |
Fill the given <select> list with the given |
6938 |
19 Aug 15 |
nicklas |
options. If 'notSpecified' is set, the first |
6938 |
19 Aug 15 |
nicklas |
option will be 'not specified'. |
6938 |
19 Aug 15 |
nicklas |
518 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.initEnumList = function(list, values, notSpecified, unit) |
6938 |
19 Aug 15 |
nicklas |
520 |
{ |
6938 |
19 Aug 15 |
nicklas |
list.length = 0; |
6938 |
19 Aug 15 |
nicklas |
if (notSpecified) |
6938 |
19 Aug 15 |
nicklas |
523 |
{ |
6938 |
19 Aug 15 |
nicklas |
list[0] = new Option('- not specified -', ''); |
6938 |
19 Aug 15 |
nicklas |
list[0].className = 'not-specified'; |
6938 |
19 Aug 15 |
nicklas |
526 |
} |
6938 |
19 Aug 15 |
nicklas |
for (var valueNo = 0; valueNo < values.length; valueNo++) |
6938 |
19 Aug 15 |
nicklas |
528 |
{ |
6938 |
19 Aug 15 |
nicklas |
var value = values[valueNo]; |
6938 |
19 Aug 15 |
nicklas |
list[list.length] = new Option(value+unit, value); |
6938 |
19 Aug 15 |
nicklas |
531 |
} |
6938 |
19 Aug 15 |
nicklas |
532 |
} |
6938 |
19 Aug 15 |
nicklas |
533 |
|
6938 |
19 Aug 15 |
nicklas |
534 |
/** |
6938 |
19 Aug 15 |
nicklas |
Generate checkboxes or radiobuttons for an enumeration |
6938 |
19 Aug 15 |
nicklas |
annotation. |
6938 |
19 Aug 15 |
nicklas |
537 |
*/ |
6943 |
01 Sep 15 |
nicklas |
annotate.initEnumCheckboxes = function(values, radio, unit, includeNotSpecified) |
6938 |
19 Aug 15 |
nicklas |
539 |
{ |
6938 |
19 Aug 15 |
nicklas |
var tmp = document.createDocumentFragment(); |
6938 |
19 Aug 15 |
nicklas |
var ctlType = radio ? 'radio' : 'checkbox'; |
6955 |
28 Sep 15 |
nicklas |
if (includeNotSpecified && radio) |
6938 |
19 Aug 15 |
nicklas |
543 |
{ |
6938 |
19 Aug 15 |
nicklas |
var noop = annotate.createRadioOrCheckBox(ctlType, '', '- not specified -'); |
6938 |
19 Aug 15 |
nicklas |
noop.className = 'not-specified'; |
6938 |
19 Aug 15 |
nicklas |
tmp.appendChild(noop); |
6938 |
19 Aug 15 |
nicklas |
547 |
} |
6938 |
19 Aug 15 |
nicklas |
for (var valueNo = 0; valueNo < values.length; valueNo++) |
6938 |
19 Aug 15 |
nicklas |
549 |
{ |
6938 |
19 Aug 15 |
nicklas |
var value = values[valueNo]; |
6938 |
19 Aug 15 |
nicklas |
tmp.appendChild(annotate.createRadioOrCheckBox(ctlType, value, value+unit)); |
6938 |
19 Aug 15 |
nicklas |
552 |
} |
6938 |
19 Aug 15 |
nicklas |
return tmp; |
6938 |
19 Aug 15 |
nicklas |
554 |
} |
6938 |
19 Aug 15 |
nicklas |
555 |
|
6938 |
19 Aug 15 |
nicklas |
556 |
/** |
6938 |
19 Aug 15 |
nicklas |
Create a <input> element that is either a radio och checkbox. |
6938 |
19 Aug 15 |
nicklas |
558 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.createRadioOrCheckBox = function(type, value, text) |
6938 |
19 Aug 15 |
nicklas |
560 |
{ |
6938 |
19 Aug 15 |
nicklas |
var ctl = document.createElement('input'); |
6938 |
19 Aug 15 |
nicklas |
ctl.type = type; |
6938 |
19 Aug 15 |
nicklas |
ctl.name = 'check'; |
6938 |
19 Aug 15 |
nicklas |
ctl.value = value; |
6938 |
19 Aug 15 |
nicklas |
Events.addEventHandler(ctl, 'click', annotate.valueOnChange); |
6938 |
19 Aug 15 |
nicklas |
var lbl = document.createElement('label'); |
6938 |
19 Aug 15 |
nicklas |
lbl.appendChild(ctl); |
6938 |
19 Aug 15 |
nicklas |
lbl.appendChild(document.createTextNode(text)); |
6938 |
19 Aug 15 |
nicklas |
lbl.appendChild(document.createElement('br')); |
6938 |
19 Aug 15 |
nicklas |
return lbl; |
6938 |
19 Aug 15 |
nicklas |
571 |
} |
6938 |
19 Aug 15 |
nicklas |
572 |
|
6938 |
19 Aug 15 |
nicklas |
573 |
/** |
6938 |
19 Aug 15 |
nicklas |
Event handler for selecting annotations from the main list. |
6938 |
19 Aug 15 |
nicklas |
575 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.annotationOnClick = function(event) |
6938 |
19 Aug 15 |
nicklas |
577 |
{ |
6938 |
19 Aug 15 |
nicklas |
annotate.selectAnnotation(event.currentTarget.id); |
6938 |
19 Aug 15 |
nicklas |
579 |
} |
6938 |
19 Aug 15 |
nicklas |
580 |
|
6938 |
19 Aug 15 |
nicklas |
581 |
/** |
6938 |
19 Aug 15 |
nicklas |
Update the given annotation with a single value. All existing |
6938 |
19 Aug 15 |
nicklas |
values are overwritten. If the value is not accepted an |
6938 |
19 Aug 15 |
nicklas |
exception is thrown. |
6938 |
19 Aug 15 |
nicklas |
585 |
*/ |
6955 |
28 Sep 15 |
nicklas |
annotate.setSingleValue = function(entry, value) |
6938 |
19 Aug 15 |
nicklas |
587 |
{ |
6938 |
19 Aug 15 |
nicklas |
var values = []; |
6938 |
19 Aug 15 |
nicklas |
if (value != null && value != '') |
6938 |
19 Aug 15 |
nicklas |
590 |
{ |
6938 |
19 Aug 15 |
nicklas |
values[0] = value; |
6938 |
19 Aug 15 |
nicklas |
592 |
} |
6955 |
28 Sep 15 |
nicklas |
annotate.setMultipleValues(entry, values); |
6938 |
19 Aug 15 |
nicklas |
594 |
} |
6938 |
19 Aug 15 |
nicklas |
595 |
|
6938 |
19 Aug 15 |
nicklas |
596 |
/** |
6938 |
19 Aug 15 |
nicklas |
Update the given annotation with multiple values. All existing |
6938 |
19 Aug 15 |
nicklas |
values are overwritten. If the values are not accepted an |
6938 |
19 Aug 15 |
nicklas |
exception is thrown. |
6938 |
19 Aug 15 |
nicklas |
600 |
*/ |
6955 |
28 Sep 15 |
nicklas |
annotate.setMultipleValues = function(entry, values) |
6938 |
19 Aug 15 |
nicklas |
602 |
{ |
6955 |
28 Sep 15 |
nicklas |
var at = entry.annotationType; |
6955 |
28 Sep 15 |
nicklas |
var ann = entry.annotation; |
6938 |
19 Aug 15 |
nicklas |
605 |
|
6938 |
19 Aug 15 |
nicklas |
if (at.multiplicity > 0 && values.length > at.multiplicity) |
6938 |
19 Aug 15 |
nicklas |
607 |
{ |
6938 |
19 Aug 15 |
nicklas |
throw 'Max '+at.multiplicity+' values allowed'; |
6938 |
19 Aug 15 |
nicklas |
609 |
} |
6938 |
19 Aug 15 |
nicklas |
ann.values = values; |
6955 |
28 Sep 15 |
nicklas |
entry.modified = MODIFIED; |
6955 |
28 Sep 15 |
nicklas |
annotate.updateIcon(entry); |
6938 |
19 Aug 15 |
nicklas |
613 |
} |
6938 |
19 Aug 15 |
nicklas |
614 |
|
6938 |
19 Aug 15 |
nicklas |
615 |
/** |
6938 |
19 Aug 15 |
nicklas |
Update/add/remove a single value in a multi-valued annotation. If the value |
6938 |
19 Aug 15 |
nicklas |
is not accepted an exception is thrown. |
6938 |
19 Aug 15 |
nicklas |
618 |
*/ |
6955 |
28 Sep 15 |
nicklas |
annotate.setIndexedValue = function(entry, index, value) |
6938 |
19 Aug 15 |
nicklas |
620 |
{ |
6955 |
28 Sep 15 |
nicklas |
var ann = entry.annotation; |
6955 |
28 Sep 15 |
nicklas |
var at = entry.annotationType; |
6955 |
28 Sep 15 |
nicklas |
623 |
|
6938 |
19 Aug 15 |
nicklas |
if (!value) |
6938 |
19 Aug 15 |
nicklas |
625 |
{ |
6955 |
28 Sep 15 |
nicklas |
if (index < ann.values.length) |
6938 |
19 Aug 15 |
nicklas |
627 |
{ |
6955 |
28 Sep 15 |
nicklas |
ann.values.splice(index, 1); |
6938 |
19 Aug 15 |
nicklas |
629 |
} |
6938 |
19 Aug 15 |
nicklas |
630 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
632 |
{ |
6955 |
28 Sep 15 |
nicklas |
if (index >= ann.values.length) |
6938 |
19 Aug 15 |
nicklas |
634 |
{ |
6938 |
19 Aug 15 |
nicklas |
// Add a new value |
6955 |
28 Sep 15 |
nicklas |
if (at.multiplicity > 0 && ann.values.length >= at.multiplicity) |
6938 |
19 Aug 15 |
nicklas |
637 |
{ |
6955 |
28 Sep 15 |
nicklas |
throw 'Max '+at.multiplicity+' values allowed'; |
6938 |
19 Aug 15 |
nicklas |
639 |
} |
6955 |
28 Sep 15 |
nicklas |
index = ann.values.length; |
6938 |
19 Aug 15 |
nicklas |
641 |
} |
6955 |
28 Sep 15 |
nicklas |
ann.values[index] = value; |
6938 |
19 Aug 15 |
nicklas |
643 |
} |
6955 |
28 Sep 15 |
nicklas |
entry.modified = MODIFIED; |
6955 |
28 Sep 15 |
nicklas |
annotate.updateIcon(entry); |
6938 |
19 Aug 15 |
nicklas |
646 |
} |
6938 |
19 Aug 15 |
nicklas |
647 |
|
6938 |
19 Aug 15 |
nicklas |
648 |
/** |
6938 |
19 Aug 15 |
nicklas |
Change the unit of the given annotation. |
6938 |
19 Aug 15 |
nicklas |
650 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.setUnit = function(annotation, unit) |
6938 |
19 Aug 15 |
nicklas |
652 |
{ |
6938 |
19 Aug 15 |
nicklas |
annotation.annotation.unit = unit; |
6943 |
01 Sep 15 |
nicklas |
annotation.modified = MODIFIED; |
6938 |
19 Aug 15 |
nicklas |
655 |
} |
6938 |
19 Aug 15 |
nicklas |
656 |
|
6938 |
19 Aug 15 |
nicklas |
657 |
/** |
6938 |
19 Aug 15 |
nicklas |
Event handler that is executed when an annotation values has changed. |
6938 |
19 Aug 15 |
nicklas |
This new value should be stored back into the 'annotations' array. |
6938 |
19 Aug 15 |
nicklas |
The exact procedure depends on the type of value. |
6938 |
19 Aug 15 |
nicklas |
661 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.valueOnChange = function(event) |
6938 |
19 Aug 15 |
nicklas |
663 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (!selectedAnnotation) return; |
6938 |
19 Aug 15 |
nicklas |
665 |
|
6938 |
19 Aug 15 |
nicklas |
var at = selectedAnnotation.annotationType; |
6938 |
19 Aug 15 |
nicklas |
var frm = document.forms['annotations']; |
6938 |
19 Aug 15 |
nicklas |
var target = event.currentTarget; |
6938 |
19 Aug 15 |
nicklas |
try |
6938 |
19 Aug 15 |
nicklas |
670 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (at.multiplicity == 1) |
6938 |
19 Aug 15 |
nicklas |
672 |
{ |
6938 |
19 Aug 15 |
nicklas |
// If only a single value is accepted the event target holds the new value |
6938 |
19 Aug 15 |
nicklas |
annotate.setSingleValue(selectedAnnotation, target.value); |
6938 |
19 Aug 15 |
nicklas |
675 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (at.enumeration) |
6938 |
19 Aug 15 |
nicklas |
677 |
{ |
6938 |
19 Aug 15 |
nicklas |
// If the annotation is a multi-valued enumeration the input fields can be either a |
6938 |
19 Aug 15 |
nicklas |
// group of checkboxes or a select control allowing multiple selections. |
6938 |
19 Aug 15 |
nicklas |
if (target.type == 'checkbox') target = frm[target.name]; // An array of all checkboxes in the group |
6938 |
19 Aug 15 |
nicklas |
var values = []; |
6938 |
19 Aug 15 |
nicklas |
for (var i = 0; i < target.length; i++) |
6938 |
19 Aug 15 |
nicklas |
683 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (target[i].checked || target[i].selected) |
6938 |
19 Aug 15 |
nicklas |
685 |
{ |
6938 |
19 Aug 15 |
nicklas |
values[values.length] = target[i].value; |
6938 |
19 Aug 15 |
nicklas |
687 |
} |
6938 |
19 Aug 15 |
nicklas |
688 |
} |
6938 |
19 Aug 15 |
nicklas |
annotate.setMultipleValues(selectedAnnotation, values); |
6938 |
19 Aug 15 |
nicklas |
690 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
692 |
{ |
6938 |
19 Aug 15 |
nicklas |
// Otherwise we use the 'multi-values' control and update the currently |
6955 |
28 Sep 15 |
nicklas |
// selected option (but note that we can't use 'selectedIndex' property of the |
6955 |
28 Sep 15 |
nicklas |
// list control, since it may already point to the future selection |
6955 |
28 Sep 15 |
nicklas |
var selectedIndex = frm['multi-values'].selectedIndex; |
6955 |
28 Sep 15 |
nicklas |
if (selectedMultiIndex >= 0) |
6938 |
19 Aug 15 |
nicklas |
698 |
{ |
6955 |
28 Sep 15 |
nicklas |
annotate.setIndexedValue(selectedAnnotation, selectedMultiIndex, target.value); |
6938 |
19 Aug 15 |
nicklas |
var multiValues = frm['multi-values']; |
6938 |
19 Aug 15 |
nicklas |
if (!target.value) |
6938 |
19 Aug 15 |
nicklas |
702 |
{ |
6955 |
28 Sep 15 |
nicklas |
multiValues[selectedMultiIndex] = null; |
6955 |
28 Sep 15 |
nicklas |
selectedMultiIndex = -1; |
6938 |
19 Aug 15 |
nicklas |
705 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
707 |
{ |
6955 |
28 Sep 15 |
nicklas |
multiValues[selectedMultiIndex].text = target.value; |
6938 |
19 Aug 15 |
nicklas |
709 |
} |
6938 |
19 Aug 15 |
nicklas |
710 |
} |
6938 |
19 Aug 15 |
nicklas |
711 |
} |
6938 |
19 Aug 15 |
nicklas |
712 |
} |
6938 |
19 Aug 15 |
nicklas |
catch (errorMessage) |
6938 |
19 Aug 15 |
nicklas |
714 |
{ |
6938 |
19 Aug 15 |
nicklas |
event.preventDefault(); |
6938 |
19 Aug 15 |
nicklas |
Forms.showNotification(event.currentTarget, errorMessage); |
6938 |
19 Aug 15 |
nicklas |
717 |
} |
6938 |
19 Aug 15 |
nicklas |
718 |
} |
6938 |
19 Aug 15 |
nicklas |
719 |
|
6955 |
28 Sep 15 |
nicklas |
// To catch the case if 'new' was clicked but no value was entered |
6955 |
28 Sep 15 |
nicklas |
annotate.valueOnBlur = function(event) |
6955 |
28 Sep 15 |
nicklas |
722 |
{ |
6981 |
08 Oct 15 |
nicklas |
if (!selectedAnnotation || selectedMultiIndex < 0) return; |
6955 |
28 Sep 15 |
nicklas |
724 |
|
6955 |
28 Sep 15 |
nicklas |
var frm = document.forms['annotations']; |
6955 |
28 Sep 15 |
nicklas |
726 |
|
6955 |
28 Sep 15 |
nicklas |
if (event.currentTarget.value == '' && frm['multi-values'][selectedMultiIndex].isNewValue) |
6955 |
28 Sep 15 |
nicklas |
728 |
{ |
6955 |
28 Sep 15 |
nicklas |
// This will remove the new but empty value |
6955 |
28 Sep 15 |
nicklas |
Events.sendChangeEvent(event.currentTarget); |
6955 |
28 Sep 15 |
nicklas |
731 |
} |
6955 |
28 Sep 15 |
nicklas |
else |
6955 |
28 Sep 15 |
nicklas |
733 |
{ |
6955 |
28 Sep 15 |
nicklas |
frm['multi-values'][selectedMultiIndex].isNewValue = false; |
6955 |
28 Sep 15 |
nicklas |
735 |
} |
6955 |
28 Sep 15 |
nicklas |
736 |
} |
6955 |
28 Sep 15 |
nicklas |
737 |
|
6938 |
19 Aug 15 |
nicklas |
738 |
/** |
6938 |
19 Aug 15 |
nicklas |
Event handler that handle changes to the selected unit. |
6938 |
19 Aug 15 |
nicklas |
740 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.unitOnChange = function(event) |
6938 |
19 Aug 15 |
nicklas |
742 |
{ |
6942 |
31 Aug 15 |
nicklas |
annotate.setUnit(selectedAnnotation, parseInt(event.currentTarget.value)); |
6938 |
19 Aug 15 |
nicklas |
744 |
} |
6938 |
19 Aug 15 |
nicklas |
745 |
|
6943 |
01 Sep 15 |
nicklas |
746 |
/** |
6946 |
07 Sep 15 |
nicklas |
Toggle the checkbox for all primary annotations. Holding down |
6946 |
07 Sep 15 |
nicklas |
CTRL/SHIFT/ALT will selected or deselect all. |
6946 |
07 Sep 15 |
nicklas |
749 |
*/ |
6946 |
07 Sep 15 |
nicklas |
annotate.checkAllPrimary = function(event) |
6946 |
07 Sep 15 |
nicklas |
751 |
{ |
6946 |
07 Sep 15 |
nicklas |
var specialKey = event.altKey || event.ctrlKey || event.shiftKey; |
6946 |
07 Sep 15 |
nicklas |
var first = null; |
6946 |
07 Sep 15 |
nicklas |
for (var i = 0; i < annotations.length; i++) |
6946 |
07 Sep 15 |
nicklas |
755 |
{ |
6946 |
07 Sep 15 |
nicklas |
var entry = annotations[i]; |
7926 |
24 Feb 21 |
nicklas |
if (entry.visible && entry.source == 'PRIMARY') |
6946 |
07 Sep 15 |
nicklas |
758 |
{ |
6946 |
07 Sep 15 |
nicklas |
var checkbox = Doc.element('check.'+entry.id); |
7206 |
19 Oct 16 |
nicklas |
if (checkbox) |
7206 |
19 Oct 16 |
nicklas |
761 |
{ |
7206 |
19 Oct 16 |
nicklas |
if (first == null) first = checkbox.checked; |
7206 |
19 Oct 16 |
nicklas |
checkbox.checked = specialKey ? !first : !checkbox.checked; |
7206 |
19 Oct 16 |
nicklas |
764 |
} |
6946 |
07 Sep 15 |
nicklas |
765 |
} |
6946 |
07 Sep 15 |
nicklas |
766 |
} |
6946 |
07 Sep 15 |
nicklas |
767 |
} |
6946 |
07 Sep 15 |
nicklas |
768 |
|
6946 |
07 Sep 15 |
nicklas |
769 |
/** |
6946 |
07 Sep 15 |
nicklas |
Toggle the checkbox for all inherited/cloned annotations. Holding down |
6946 |
07 Sep 15 |
nicklas |
CTRL/SHIFT/ALT will selected or deselect all. |
6946 |
07 Sep 15 |
nicklas |
772 |
*/ |
6946 |
07 Sep 15 |
nicklas |
annotate.checkAllInherited = function(event) |
6946 |
07 Sep 15 |
nicklas |
774 |
{ |
6946 |
07 Sep 15 |
nicklas |
var specialKey = event.altKey || event.ctrlKey || event.shiftKey; |
6946 |
07 Sep 15 |
nicklas |
var first = null; |
6946 |
07 Sep 15 |
nicklas |
for (var i = 0; i < annotations.length; i++) |
6946 |
07 Sep 15 |
nicklas |
778 |
{ |
6946 |
07 Sep 15 |
nicklas |
var entry = annotations[i]; |
7926 |
24 Feb 21 |
nicklas |
if (entry.visible && entry.source != 'PRIMARY') |
6946 |
07 Sep 15 |
nicklas |
781 |
{ |
6946 |
07 Sep 15 |
nicklas |
var checkbox = Doc.element('check.'+entry.id); |
7206 |
19 Oct 16 |
nicklas |
if (checkbox) |
7206 |
19 Oct 16 |
nicklas |
784 |
{ |
7206 |
19 Oct 16 |
nicklas |
if (first == null) first = checkbox.checked; |
7206 |
19 Oct 16 |
nicklas |
checkbox.checked = specialKey ? !first : !checkbox.checked; |
7206 |
19 Oct 16 |
nicklas |
787 |
} |
6946 |
07 Sep 15 |
nicklas |
788 |
} |
6946 |
07 Sep 15 |
nicklas |
789 |
} |
6946 |
07 Sep 15 |
nicklas |
790 |
} |
6946 |
07 Sep 15 |
nicklas |
791 |
|
6946 |
07 Sep 15 |
nicklas |
792 |
/** |
6945 |
04 Sep 15 |
nicklas |
Call the given method for all annotations that |
6945 |
04 Sep 15 |
nicklas |
have been checked. The method must take a single |
6945 |
04 Sep 15 |
nicklas |
parameter which is the entry object with the |
6945 |
04 Sep 15 |
nicklas |
annotation information. |
6945 |
04 Sep 15 |
nicklas |
@return The return value of the method when called |
6945 |
04 Sep 15 |
nicklas |
on the current selected annotation or null if the |
6945 |
04 Sep 15 |
nicklas |
selected annotation is not checked |
6945 |
04 Sep 15 |
nicklas |
800 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.forAllChecked = function(method) |
6945 |
04 Sep 15 |
nicklas |
802 |
{ |
6945 |
04 Sep 15 |
nicklas |
var returnValue = null; |
6945 |
04 Sep 15 |
nicklas |
var numChecked = 0; |
6945 |
04 Sep 15 |
nicklas |
for (var i = 0; i < annotations.length; i++) |
6945 |
04 Sep 15 |
nicklas |
806 |
{ |
6945 |
04 Sep 15 |
nicklas |
var entry = annotations[i]; |
7206 |
19 Oct 16 |
nicklas |
var checkbox = Doc.element('check.'+entry.id); |
7206 |
19 Oct 16 |
nicklas |
if (checkbox && checkbox.checked) |
6945 |
04 Sep 15 |
nicklas |
810 |
{ |
6945 |
04 Sep 15 |
nicklas |
numChecked++; |
6945 |
04 Sep 15 |
nicklas |
var rv = method.call(null, entry); |
6945 |
04 Sep 15 |
nicklas |
if (entry == selectedAnnotation) returnValue = rv; |
6945 |
04 Sep 15 |
nicklas |
814 |
} |
6945 |
04 Sep 15 |
nicklas |
815 |
} |
6945 |
04 Sep 15 |
nicklas |
if (numChecked == 0) |
6945 |
04 Sep 15 |
nicklas |
817 |
{ |
6945 |
04 Sep 15 |
nicklas |
Forms.showNotification('annotation-list', 'Please select annotations first...', null, 'pointer-left'); |
6945 |
04 Sep 15 |
nicklas |
819 |
} |
6945 |
04 Sep 15 |
nicklas |
return returnValue; |
6945 |
04 Sep 15 |
nicklas |
821 |
} |
6945 |
04 Sep 15 |
nicklas |
822 |
|
6945 |
04 Sep 15 |
nicklas |
823 |
/** |
6945 |
04 Sep 15 |
nicklas |
Synchronizes checked CLONED annotations. |
6945 |
04 Sep 15 |
nicklas |
825 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.syncAllCheckedClones = function() |
6945 |
04 Sep 15 |
nicklas |
827 |
{ |
6945 |
04 Sep 15 |
nicklas |
if (annotate.forAllChecked(annotate.syncClone)) |
6945 |
04 Sep 15 |
nicklas |
829 |
{ |
6945 |
04 Sep 15 |
nicklas |
annotate.selectAnnotation(selectedAnnotation.id); |
6945 |
04 Sep 15 |
nicklas |
831 |
} |
6945 |
04 Sep 15 |
nicklas |
832 |
} |
6945 |
04 Sep 15 |
nicklas |
833 |
|
6945 |
04 Sep 15 |
nicklas |
834 |
/** |
6945 |
04 Sep 15 |
nicklas |
Synchronizes the currently selected CLONED annotation |
6945 |
04 Sep 15 |
nicklas |
836 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.syncSelectedClone = function() |
6945 |
04 Sep 15 |
nicklas |
838 |
{ |
6945 |
04 Sep 15 |
nicklas |
annotate.syncClone(selectedAnnotation); |
6945 |
04 Sep 15 |
nicklas |
annotate.selectAnnotation(selectedAnnotation.id); |
6945 |
04 Sep 15 |
nicklas |
841 |
} |
6945 |
04 Sep 15 |
nicklas |
842 |
|
6945 |
04 Sep 15 |
nicklas |
843 |
/** |
6943 |
01 Sep 15 |
nicklas |
Syncs a cloned value with the parent items value. |
6945 |
04 Sep 15 |
nicklas |
@returns TRUE if the entry was synced, FALSE if not. |
6943 |
01 Sep 15 |
nicklas |
846 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.syncClone = function(entry) |
6943 |
01 Sep 15 |
nicklas |
848 |
{ |
6945 |
04 Sep 15 |
nicklas |
if (entry.source != 'CLONED') return false; |
6945 |
04 Sep 15 |
nicklas |
if (!entry.inherited) return false; |
6943 |
01 Sep 15 |
nicklas |
851 |
|
6945 |
04 Sep 15 |
nicklas |
annotate.setMultipleValues(entry, entry.inherited.values); |
6945 |
04 Sep 15 |
nicklas |
annotate.setUnit(entry, entry.inherited.unit); |
6945 |
04 Sep 15 |
nicklas |
entry.annotation.lastUpdate = entry.inherited.lastUpdate; |
6945 |
04 Sep 15 |
nicklas |
entry.modified = SYNCED; |
6945 |
04 Sep 15 |
nicklas |
annotate.updateIcon(entry); |
6943 |
01 Sep 15 |
nicklas |
857 |
|
6945 |
04 Sep 15 |
nicklas |
return true; |
6943 |
01 Sep 15 |
nicklas |
859 |
} |
6943 |
01 Sep 15 |
nicklas |
860 |
|
6945 |
04 Sep 15 |
nicklas |
861 |
|
6943 |
01 Sep 15 |
nicklas |
862 |
/** |
6945 |
04 Sep 15 |
nicklas |
Converts checked INHERITED annotations to CLONED annotations. |
6945 |
04 Sep 15 |
nicklas |
864 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.convertAllCheckedToCloned = function() |
6945 |
04 Sep 15 |
nicklas |
866 |
{ |
6945 |
04 Sep 15 |
nicklas |
if (annotate.forAllChecked(annotate.convertToCloned)) |
6945 |
04 Sep 15 |
nicklas |
868 |
{ |
6945 |
04 Sep 15 |
nicklas |
annotate.selectAnnotation(selectedAnnotation.id); |
6945 |
04 Sep 15 |
nicklas |
870 |
} |
6945 |
04 Sep 15 |
nicklas |
871 |
} |
6945 |
04 Sep 15 |
nicklas |
872 |
|
6945 |
04 Sep 15 |
nicklas |
873 |
/** |
6945 |
04 Sep 15 |
nicklas |
Converts the selected annotation to a CLONED annotation. |
6945 |
04 Sep 15 |
nicklas |
875 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.convertSelectedToCloned = function() |
6945 |
04 Sep 15 |
nicklas |
877 |
{ |
6945 |
04 Sep 15 |
nicklas |
annotate.convertToCloned(selectedAnnotation); |
6945 |
04 Sep 15 |
nicklas |
annotate.selectAnnotation(selectedAnnotation.id); |
6945 |
04 Sep 15 |
nicklas |
880 |
} |
6945 |
04 Sep 15 |
nicklas |
881 |
|
6945 |
04 Sep 15 |
nicklas |
882 |
/** |
6943 |
01 Sep 15 |
nicklas |
Converts an INHERITED annotation to a CLONED annotation. |
6943 |
01 Sep 15 |
nicklas |
884 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.convertToCloned = function(entry) |
6943 |
01 Sep 15 |
nicklas |
886 |
{ |
6945 |
04 Sep 15 |
nicklas |
if (entry.source != 'INHERITED') return false; |
6943 |
01 Sep 15 |
nicklas |
888 |
|
6945 |
04 Sep 15 |
nicklas |
var ann = entry.annotation; |
6945 |
04 Sep 15 |
nicklas |
var inherited = entry.inherited; |
6943 |
01 Sep 15 |
nicklas |
891 |
|
6945 |
04 Sep 15 |
nicklas |
entry.source = 'CLONED'; |
6945 |
04 Sep 15 |
nicklas |
entry.modified = CONVERTED; |
6943 |
01 Sep 15 |
nicklas |
ann.values = inherited.values; |
6943 |
01 Sep 15 |
nicklas |
ann.unit = inherited.unit; |
6945 |
04 Sep 15 |
nicklas |
annotate.updateIcon(entry); |
6945 |
04 Sep 15 |
nicklas |
897 |
|
6945 |
04 Sep 15 |
nicklas |
return true; |
6943 |
01 Sep 15 |
nicklas |
899 |
} |
6943 |
01 Sep 15 |
nicklas |
900 |
|
6943 |
01 Sep 15 |
nicklas |
901 |
/** |
6945 |
04 Sep 15 |
nicklas |
Converts checked CLONED annotations to INHERITED annotations. |
6945 |
04 Sep 15 |
nicklas |
903 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.convertAllCheckedToInherited = function() |
6945 |
04 Sep 15 |
nicklas |
905 |
{ |
6945 |
04 Sep 15 |
nicklas |
if (annotate.forAllChecked(annotate.convertToInherited)) |
6945 |
04 Sep 15 |
nicklas |
907 |
{ |
6945 |
04 Sep 15 |
nicklas |
annotate.selectAnnotation(selectedAnnotation.id); |
6945 |
04 Sep 15 |
nicklas |
909 |
} |
6945 |
04 Sep 15 |
nicklas |
910 |
} |
6945 |
04 Sep 15 |
nicklas |
911 |
|
6945 |
04 Sep 15 |
nicklas |
912 |
/** |
6943 |
01 Sep 15 |
nicklas |
Converts a CLONED annotation to an INHERITED annotation. |
6946 |
07 Sep 15 |
nicklas |
If the annotation is not CLONED or if the parent item |
6946 |
07 Sep 15 |
nicklas |
is unknown, nothing is done. |
6943 |
01 Sep 15 |
nicklas |
916 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.convertToInherited = function(entry) |
6943 |
01 Sep 15 |
nicklas |
918 |
{ |
6945 |
04 Sep 15 |
nicklas |
if (entry.source != 'CLONED') return false; |
6943 |
01 Sep 15 |
nicklas |
920 |
|
6945 |
04 Sep 15 |
nicklas |
var ann = entry.annotation; |
6945 |
04 Sep 15 |
nicklas |
var inherited = entry.inherited; |
6946 |
07 Sep 15 |
nicklas |
if (!inherited) return false; |
6943 |
01 Sep 15 |
nicklas |
924 |
|
6945 |
04 Sep 15 |
nicklas |
entry.source = 'INHERITED'; |
6945 |
04 Sep 15 |
nicklas |
entry.modified = CONVERTED; |
6943 |
01 Sep 15 |
nicklas |
ann.values = []; |
6943 |
01 Sep 15 |
nicklas |
ann.unit = null; |
6945 |
04 Sep 15 |
nicklas |
annotate.updateIcon(entry); |
6945 |
04 Sep 15 |
nicklas |
return true; |
6943 |
01 Sep 15 |
nicklas |
931 |
} |
6943 |
01 Sep 15 |
nicklas |
932 |
|
6946 |
07 Sep 15 |
nicklas |
933 |
/** |
6946 |
07 Sep 15 |
nicklas |
Delete all checked annotations. |
6946 |
07 Sep 15 |
nicklas |
935 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.deleteAllChecked = function() |
6945 |
04 Sep 15 |
nicklas |
937 |
{ |
6945 |
04 Sep 15 |
nicklas |
if (annotate.forAllChecked(annotate.deleteAnnotation)) |
6945 |
04 Sep 15 |
nicklas |
939 |
{ |
6945 |
04 Sep 15 |
nicklas |
annotate.selectAnnotation(selectedAnnotation.source == 'PRIMARY' ? selectedAnnotation.id : null); |
6945 |
04 Sep 15 |
nicklas |
941 |
} |
6945 |
04 Sep 15 |
nicklas |
942 |
} |
6943 |
01 Sep 15 |
nicklas |
943 |
|
6946 |
07 Sep 15 |
nicklas |
944 |
/** |
6946 |
07 Sep 15 |
nicklas |
Delete an annotation. PRIMARY annotations have all their values removed. |
6946 |
07 Sep 15 |
nicklas |
INHERITED/CLONED annotations are deleted. |
6946 |
07 Sep 15 |
nicklas |
947 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.deleteAnnotation = function(entry) |
6945 |
04 Sep 15 |
nicklas |
949 |
{ |
6945 |
04 Sep 15 |
nicklas |
if (entry.source == 'PRIMARY') |
6945 |
04 Sep 15 |
nicklas |
951 |
{ |
6946 |
07 Sep 15 |
nicklas |
entry.modified = MODIFIED; |
6945 |
04 Sep 15 |
nicklas |
entry.annotation.values = []; |
6945 |
04 Sep 15 |
nicklas |
entry.annotation.unit = null; |
6945 |
04 Sep 15 |
nicklas |
annotate.updateIcon(entry); |
6945 |
04 Sep 15 |
nicklas |
956 |
} |
6945 |
04 Sep 15 |
nicklas |
else |
6945 |
04 Sep 15 |
nicklas |
958 |
{ |
6946 |
07 Sep 15 |
nicklas |
entry.modified = DELETE; |
6945 |
04 Sep 15 |
nicklas |
Doc.hide(entry.id); |
6945 |
04 Sep 15 |
nicklas |
961 |
} |
6945 |
04 Sep 15 |
nicklas |
return true; |
6945 |
04 Sep 15 |
nicklas |
963 |
} |
6945 |
04 Sep 15 |
nicklas |
964 |
|
6947 |
08 Sep 15 |
nicklas |
965 |
/** |
6947 |
08 Sep 15 |
nicklas |
Open a popup dialog for selecting parent annotations |
6947 |
08 Sep 15 |
nicklas |
that should be inherited. |
6947 |
08 Sep 15 |
nicklas |
968 |
*/ |
6947 |
08 Sep 15 |
nicklas |
annotate.addInheritedAnnotations = function(event) |
6947 |
08 Sep 15 |
nicklas |
970 |
{ |
6947 |
08 Sep 15 |
nicklas |
var url = 'inherit.jsp?ID='+App.getSessionId(); |
6947 |
08 Sep 15 |
nicklas |
url += '&item_type='+Data.get('page-data', 'item-type'); |
6947 |
08 Sep 15 |
nicklas |
url += '&item_id='+Data.get('page-data', 'item-id'); |
6947 |
08 Sep 15 |
nicklas |
url += '&callback='+event.currentTarget.id; |
6947 |
08 Sep 15 |
nicklas |
975 |
|
6947 |
08 Sep 15 |
nicklas |
// Items marked for DELETE should show up in the dialog |
6947 |
08 Sep 15 |
nicklas |
var deleted = []; |
6947 |
08 Sep 15 |
nicklas |
for (var i = 0; i < annotations.length; i++) |
6947 |
08 Sep 15 |
nicklas |
979 |
{ |
6947 |
08 Sep 15 |
nicklas |
var entry = annotations[i]; |
6947 |
08 Sep 15 |
nicklas |
if (entry.source != 'PRIMARY' && entry.modified == DELETE && entry.annotation.id) |
6947 |
08 Sep 15 |
nicklas |
982 |
{ |
6947 |
08 Sep 15 |
nicklas |
deleted[deleted.length] = entry.annotation.id; |
6947 |
08 Sep 15 |
nicklas |
984 |
} |
6947 |
08 Sep 15 |
nicklas |
985 |
} |
6947 |
08 Sep 15 |
nicklas |
url += '&deleted='+deleted.join(','); |
6947 |
08 Sep 15 |
nicklas |
987 |
|
6947 |
08 Sep 15 |
nicklas |
if (parents.length) |
6947 |
08 Sep 15 |
nicklas |
989 |
{ |
6947 |
08 Sep 15 |
nicklas |
url += '&parents='+parents.join('&parents='); |
6947 |
08 Sep 15 |
nicklas |
991 |
} |
6947 |
08 Sep 15 |
nicklas |
992 |
|
6947 |
08 Sep 15 |
nicklas |
Dialogs.openPopup(url, 'InheritAnnotations', 750, 500); |
6947 |
08 Sep 15 |
nicklas |
994 |
} |
6947 |
08 Sep 15 |
nicklas |
995 |
|
6947 |
08 Sep 15 |
nicklas |
annotate.setParents = function(newParents) |
6947 |
08 Sep 15 |
nicklas |
997 |
{ |
6947 |
08 Sep 15 |
nicklas |
parents = newParents; |
6947 |
08 Sep 15 |
nicklas |
999 |
} |
6947 |
08 Sep 15 |
nicklas |
1000 |
|
6947 |
08 Sep 15 |
nicklas |
1001 |
/** |
6947 |
08 Sep 15 |
nicklas |
Event handler for removing an inherited annotation. |
6947 |
08 Sep 15 |
nicklas |
1003 |
*/ |
6947 |
08 Sep 15 |
nicklas |
annotate.onRemoveInheritedAnnotation = function(event) |
6947 |
08 Sep 15 |
nicklas |
1005 |
{ |
6947 |
08 Sep 15 |
nicklas |
var inheritedId = event.detail.id; |
6947 |
08 Sep 15 |
nicklas |
for (var i = 0; i < annotations.length; i++) |
6947 |
08 Sep 15 |
nicklas |
1008 |
{ |
6947 |
08 Sep 15 |
nicklas |
var entry = annotations[i]; |
6947 |
08 Sep 15 |
nicklas |
if (entry.inherited && entry.inherited.id == inheritedId) |
6947 |
08 Sep 15 |
nicklas |
1011 |
{ |
6947 |
08 Sep 15 |
nicklas |
annotate.deleteAnnotation(entry); |
6947 |
08 Sep 15 |
nicklas |
return; |
6947 |
08 Sep 15 |
nicklas |
1014 |
} |
6947 |
08 Sep 15 |
nicklas |
1015 |
} |
6947 |
08 Sep 15 |
nicklas |
1016 |
} |
6947 |
08 Sep 15 |
nicklas |
1017 |
|
6947 |
08 Sep 15 |
nicklas |
1018 |
/** |
6947 |
08 Sep 15 |
nicklas |
Event handler for adding an inherited annotation. Note |
6947 |
08 Sep 15 |
nicklas |
that the annotation may be an annotation that is already |
6947 |
08 Sep 15 |
nicklas |
inherited but has been marked for DELETE. In this case the |
6947 |
08 Sep 15 |
nicklas |
DELETE should be cancelled. |
6947 |
08 Sep 15 |
nicklas |
1023 |
*/ |
6947 |
08 Sep 15 |
nicklas |
annotate.onAddInheritedAnnotation = function(event) |
6947 |
08 Sep 15 |
nicklas |
1025 |
{ |
6947 |
08 Sep 15 |
nicklas |
Doc.show('inherited-list'); |
6947 |
08 Sep 15 |
nicklas |
var inheritedId = event.detail.id; |
6981 |
08 Oct 15 |
nicklas |
var clone = event.detail.clone; |
6947 |
08 Sep 15 |
nicklas |
1029 |
|
6947 |
08 Sep 15 |
nicklas |
// Check if we have info about this annotation already |
6947 |
08 Sep 15 |
nicklas |
for (var i = 0; i < annotations.length; i++) |
6947 |
08 Sep 15 |
nicklas |
1032 |
{ |
6947 |
08 Sep 15 |
nicklas |
var entry = annotations[i]; |
6947 |
08 Sep 15 |
nicklas |
if (entry.inherited && entry.inherited.id == inheritedId) |
6947 |
08 Sep 15 |
nicklas |
1035 |
{ |
6947 |
08 Sep 15 |
nicklas |
entry.modified = INHERITED; |
6981 |
08 Oct 15 |
nicklas |
if (clone && entry.source != 'CLONED') |
6981 |
08 Oct 15 |
nicklas |
1038 |
{ |
6981 |
08 Oct 15 |
nicklas |
annotate.convertToCloned(entry); |
6981 |
08 Oct 15 |
nicklas |
1040 |
} |
6981 |
08 Oct 15 |
nicklas |
else if (!clone && entry.source != 'INHERITED') |
6981 |
08 Oct 15 |
nicklas |
1042 |
{ |
6981 |
08 Oct 15 |
nicklas |
annotate.convertToInherited(entry); |
6981 |
08 Oct 15 |
nicklas |
1044 |
} |
6947 |
08 Sep 15 |
nicklas |
Doc.show(entry.id); |
6947 |
08 Sep 15 |
nicklas |
return; |
6947 |
08 Sep 15 |
nicklas |
1047 |
} |
6947 |
08 Sep 15 |
nicklas |
1048 |
} |
6947 |
08 Sep 15 |
nicklas |
1049 |
|
6947 |
08 Sep 15 |
nicklas |
// Load info about this annotation |
6947 |
08 Sep 15 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
6947 |
08 Sep 15 |
nicklas |
url += '&cmd=GetAnnotationInfoForInherit'; |
6947 |
08 Sep 15 |
nicklas |
url += '&item_id='+inheritedId; |
6947 |
08 Sep 15 |
nicklas |
1054 |
|
6947 |
08 Sep 15 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
6947 |
08 Sep 15 |
nicklas |
request.open("GET", url, true); |
6947 |
08 Sep 15 |
nicklas |
request.send(null); |
6981 |
08 Oct 15 |
nicklas |
var callback = clone ? annotate.inheritInfoLoadedAndClone : annotate.inheritInfoLoaded; |
6981 |
08 Oct 15 |
nicklas |
Ajax.setReadyStateHandler(request, callback, callback); |
6947 |
08 Sep 15 |
nicklas |
1060 |
} |
6947 |
08 Sep 15 |
nicklas |
1061 |
|
6947 |
08 Sep 15 |
nicklas |
1062 |
/** |
6981 |
08 Oct 15 |
nicklas |
Callback that converts the inherited annotation to a cloned |
6981 |
08 Oct 15 |
nicklas |
annotation. |
6981 |
08 Oct 15 |
nicklas |
1065 |
*/ |
6981 |
08 Oct 15 |
nicklas |
annotate.inheritInfoLoadedAndClone = function(request) |
6981 |
08 Oct 15 |
nicklas |
1067 |
{ |
6981 |
08 Oct 15 |
nicklas |
var entry = annotate.inheritInfoLoaded(request); |
6981 |
08 Oct 15 |
nicklas |
annotate.convertToCloned(entry); |
6981 |
08 Oct 15 |
nicklas |
1070 |
} |
6981 |
08 Oct 15 |
nicklas |
1071 |
|
6981 |
08 Oct 15 |
nicklas |
1072 |
/** |
6947 |
08 Sep 15 |
nicklas |
Callback after we have got information about an annotation |
6947 |
08 Sep 15 |
nicklas |
that we should inherit. |
6947 |
08 Sep 15 |
nicklas |
1075 |
*/ |
6947 |
08 Sep 15 |
nicklas |
annotate.inheritInfoLoaded = function(request) |
6947 |
08 Sep 15 |
nicklas |
1077 |
{ |
6947 |
08 Sep 15 |
nicklas |
var response = JSON.parse(request.responseText); |
6947 |
08 Sep 15 |
nicklas |
if (response.status != 'ok') |
6947 |
08 Sep 15 |
nicklas |
1080 |
{ |
6947 |
08 Sep 15 |
nicklas |
App.debug(request.responseText); |
6947 |
08 Sep 15 |
nicklas |
return; |
6947 |
08 Sep 15 |
nicklas |
1083 |
} |
6947 |
08 Sep 15 |
nicklas |
1084 |
|
6947 |
08 Sep 15 |
nicklas |
var entry = response.info; |
6947 |
08 Sep 15 |
nicklas |
entry.modified = INHERITED; |
6947 |
08 Sep 15 |
nicklas |
1087 |
|
6947 |
08 Sep 15 |
nicklas |
annotations[annotations.length] = entry; |
6947 |
08 Sep 15 |
nicklas |
annotate.createAnnotationEntryInList(entry, true); |
6981 |
08 Oct 15 |
nicklas |
return entry; |
6947 |
08 Sep 15 |
nicklas |
1091 |
} |
6947 |
08 Sep 15 |
nicklas |
1092 |
|
6938 |
19 Aug 15 |
nicklas |
annotate.addMultiValue = function(event) |
6938 |
19 Aug 15 |
nicklas |
1094 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (!selectedAnnotation) return; |
6938 |
19 Aug 15 |
nicklas |
1096 |
|
6955 |
28 Sep 15 |
nicklas |
var at = selectedAnnotation.annotationType; |
6955 |
28 Sep 15 |
nicklas |
1098 |
|
6938 |
19 Aug 15 |
nicklas |
var frm = document.forms['annotations']; |
6955 |
28 Sep 15 |
nicklas |
var valueElement = frm[at.valueType+'-input']; |
6955 |
28 Sep 15 |
nicklas |
1101 |
|
6938 |
19 Aug 15 |
nicklas |
var multiValues = frm['multi-values']; |
6938 |
19 Aug 15 |
nicklas |
var errorMessage = null; |
6938 |
19 Aug 15 |
nicklas |
try |
6938 |
19 Aug 15 |
nicklas |
1105 |
{ |
6955 |
28 Sep 15 |
nicklas |
// If one item is already selected, we create a new entry |
6955 |
28 Sep 15 |
nicklas |
if (selectedMultiIndex >= 0) |
6938 |
19 Aug 15 |
nicklas |
1108 |
{ |
6938 |
19 Aug 15 |
nicklas |
// Add a new option |
6938 |
19 Aug 15 |
nicklas |
errorMessage = annotate.setIndexedValue(selectedAnnotation, multiValues.length, ''); |
6938 |
19 Aug 15 |
nicklas |
if (!errorMessage) |
6938 |
19 Aug 15 |
nicklas |
1112 |
{ |
6955 |
28 Sep 15 |
nicklas |
var opt = new Option('<new>', '', false, true); |
6955 |
28 Sep 15 |
nicklas |
opt.isNewValue = true; |
6955 |
28 Sep 15 |
nicklas |
multiValues[multiValues.length] = opt; |
6955 |
28 Sep 15 |
nicklas |
selectedMultiIndex = multiValues.length-1; |
6938 |
19 Aug 15 |
nicklas |
valueElement.value = ''; |
6938 |
19 Aug 15 |
nicklas |
1118 |
} |
6938 |
19 Aug 15 |
nicklas |
1119 |
} |
6938 |
19 Aug 15 |
nicklas |
else if (valueElement.value != '') |
6938 |
19 Aug 15 |
nicklas |
1121 |
{ |
6938 |
19 Aug 15 |
nicklas |
// Add the current value |
6938 |
19 Aug 15 |
nicklas |
errorMessage = annotate.setIndexedValue(selectedAnnotation, multiValues.length, valueElement.value); |
6938 |
19 Aug 15 |
nicklas |
if (!errorMessage) |
6938 |
19 Aug 15 |
nicklas |
1125 |
{ |
6938 |
19 Aug 15 |
nicklas |
multiValues[multiValues.length] = new Option(valueElement.value, '', false, false); |
6938 |
19 Aug 15 |
nicklas |
valueElement.value = ''; |
6938 |
19 Aug 15 |
nicklas |
1128 |
} |
6938 |
19 Aug 15 |
nicklas |
1129 |
} |
6938 |
19 Aug 15 |
nicklas |
valueElement.focus(); |
6938 |
19 Aug 15 |
nicklas |
1131 |
} |
6938 |
19 Aug 15 |
nicklas |
catch (errorMessage) |
6938 |
19 Aug 15 |
nicklas |
1133 |
{ |
6938 |
19 Aug 15 |
nicklas |
Forms.showNotification('btnMultiAdd', errorMessage, null, 'pointer-left'); |
6938 |
19 Aug 15 |
nicklas |
1135 |
} |
6938 |
19 Aug 15 |
nicklas |
1136 |
} |
6938 |
19 Aug 15 |
nicklas |
1137 |
|
6938 |
19 Aug 15 |
nicklas |
annotate.removeMultiValue = function() |
6938 |
19 Aug 15 |
nicklas |
1139 |
{ |
6955 |
28 Sep 15 |
nicklas |
if (!selectedAnnotation) return; |
6955 |
28 Sep 15 |
nicklas |
1141 |
|
6938 |
19 Aug 15 |
nicklas |
var frm = document.forms['annotations']; |
6955 |
28 Sep 15 |
nicklas |
var selectedIndex = frm['multi-values'].selectedIndex; |
6938 |
19 Aug 15 |
nicklas |
1144 |
|
6955 |
28 Sep 15 |
nicklas |
if (selectedIndex >= 0) |
6955 |
28 Sep 15 |
nicklas |
1146 |
{ |
6955 |
28 Sep 15 |
nicklas |
// Clear the current value, and send a 'change' event to let the |
6955 |
28 Sep 15 |
nicklas |
// regular event handlers take care of the removal |
6955 |
28 Sep 15 |
nicklas |
var at = selectedAnnotation.annotationType; |
6955 |
28 Sep 15 |
nicklas |
var valueElement = frm[at.valueType+'-input']; |
6955 |
28 Sep 15 |
nicklas |
valueElement.value = ''; |
6955 |
28 Sep 15 |
nicklas |
Events.sendChangeEvent(valueElement); |
6955 |
28 Sep 15 |
nicklas |
1153 |
} |
6938 |
19 Aug 15 |
nicklas |
1154 |
} |
6955 |
28 Sep 15 |
nicklas |
1155 |
|
6938 |
19 Aug 15 |
nicklas |
1156 |
/** |
6938 |
19 Aug 15 |
nicklas |
Event handler for the 'multi-values' selection list. This should change |
6938 |
19 Aug 15 |
nicklas |
the value that is currently being edited to the selected option. |
6938 |
19 Aug 15 |
nicklas |
1159 |
*/ |
6955 |
28 Sep 15 |
nicklas |
annotate.multiValueOnClick = function(event) |
6938 |
19 Aug 15 |
nicklas |
1161 |
{ |
6938 |
19 Aug 15 |
nicklas |
if (!selectedAnnotation) return; |
6955 |
28 Sep 15 |
nicklas |
1163 |
|
6955 |
28 Sep 15 |
nicklas |
var at = selectedAnnotation.annotationType; |
6955 |
28 Sep 15 |
nicklas |
var ann = selectedAnnotation.annotation; |
6955 |
28 Sep 15 |
nicklas |
1166 |
|
6938 |
19 Aug 15 |
nicklas |
var frm = document.forms['annotations']; |
6955 |
28 Sep 15 |
nicklas |
selectedMultiIndex = event.currentTarget.selectedIndex; |
6955 |
28 Sep 15 |
nicklas |
if (selectedMultiIndex >= 0) |
6938 |
19 Aug 15 |
nicklas |
1170 |
{ |
6955 |
28 Sep 15 |
nicklas |
var valueElement = frm[at.valueType+'-input']; |
6955 |
28 Sep 15 |
nicklas |
valueElement.value = ann.values[selectedMultiIndex]; |
6955 |
28 Sep 15 |
nicklas |
valueElement.focus(); |
6938 |
19 Aug 15 |
nicklas |
1174 |
} |
6938 |
19 Aug 15 |
nicklas |
1175 |
} |
6938 |
19 Aug 15 |
nicklas |
1176 |
|
6945 |
04 Sep 15 |
nicklas |
1177 |
|
6945 |
04 Sep 15 |
nicklas |
annotate.getIcon = function(entry) |
6938 |
19 Aug 15 |
nicklas |
1179 |
{ |
6938 |
19 Aug 15 |
nicklas |
var icon; |
6938 |
19 Aug 15 |
nicklas |
var ann = entry.annotation; |
6938 |
19 Aug 15 |
nicklas |
1182 |
|
6945 |
04 Sep 15 |
nicklas |
if (entry.source == 'PRIMARY') |
6938 |
19 Aug 15 |
nicklas |
1184 |
{ |
6945 |
04 Sep 15 |
nicklas |
// 'x' for has values, empty otherwise |
6945 |
04 Sep 15 |
nicklas |
icon = (ann && ann.values.length > 0) ? 'notrequired_values.png' : 'notrequired_novalues.png'; |
6938 |
19 Aug 15 |
nicklas |
1187 |
} |
6945 |
04 Sep 15 |
nicklas |
else if (entry.source == 'INHERITED') |
6945 |
04 Sep 15 |
nicklas |
1189 |
{ |
6945 |
04 Sep 15 |
nicklas |
// Always the same 'x' with an anchor |
6945 |
04 Sep 15 |
nicklas |
icon = 'inherited.png' |
6945 |
04 Sep 15 |
nicklas |
1192 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
1194 |
{ |
6945 |
04 Sep 15 |
nicklas |
// Cloned annotations |
6945 |
04 Sep 15 |
nicklas |
if (!entry.inherited) |
6945 |
04 Sep 15 |
nicklas |
1197 |
{ |
6945 |
04 Sep 15 |
nicklas |
// No parent item |
6945 |
04 Sep 15 |
nicklas |
icon = 'cloned-noparent.png'; |
6945 |
04 Sep 15 |
nicklas |
1200 |
} |
6945 |
04 Sep 15 |
nicklas |
else if (entry.inherited.lastUpdate > ann.lastUpdate) |
6945 |
04 Sep 15 |
nicklas |
1202 |
{ |
6945 |
04 Sep 15 |
nicklas |
// The parent annotation has been updated |
6945 |
04 Sep 15 |
nicklas |
icon = 'cloned-outofsync.png'; |
6945 |
04 Sep 15 |
nicklas |
1205 |
} |
6945 |
04 Sep 15 |
nicklas |
else |
6945 |
04 Sep 15 |
nicklas |
1207 |
{ |
6945 |
04 Sep 15 |
nicklas |
icon = 'cloned.png'; |
6945 |
04 Sep 15 |
nicklas |
1209 |
} |
6938 |
19 Aug 15 |
nicklas |
1210 |
} |
6945 |
04 Sep 15 |
nicklas |
return icon; |
6945 |
04 Sep 15 |
nicklas |
1212 |
} |
6945 |
04 Sep 15 |
nicklas |
1213 |
|
6945 |
04 Sep 15 |
nicklas |
1214 |
/** |
6945 |
04 Sep 15 |
nicklas |
Update the icon for the annotation. The icon is different depending on if |
6945 |
04 Sep 15 |
nicklas |
there are values or not for the annotation. |
6945 |
04 Sep 15 |
nicklas |
1217 |
*/ |
6945 |
04 Sep 15 |
nicklas |
annotate.updateIcon = function(entry) |
6945 |
04 Sep 15 |
nicklas |
1219 |
{ |
6945 |
04 Sep 15 |
nicklas |
var icon = annotate.getIcon(entry); |
6938 |
19 Aug 15 |
nicklas |
var img = Doc.element('icon.'+entry.id); |
6938 |
19 Aug 15 |
nicklas |
img.src = App.getRoot()+'images/'+icon; |
6938 |
19 Aug 15 |
nicklas |
1223 |
} |
6938 |
19 Aug 15 |
nicklas |
1224 |
|
6938 |
19 Aug 15 |
nicklas |
1225 |
/** |
6938 |
19 Aug 15 |
nicklas |
Open the calendar dialog for the selected annotation. |
6938 |
19 Aug 15 |
nicklas |
1227 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.openCalendar = function(event) |
6938 |
19 Aug 15 |
nicklas |
1229 |
{ |
6938 |
19 Aug 15 |
nicklas |
var at = selectedAnnotation.annotationType; |
6938 |
19 Aug 15 |
nicklas |
var title = at.name; |
6938 |
19 Aug 15 |
nicklas |
var useTime = at.valueType == 'TIMESTAMP'; |
6938 |
19 Aug 15 |
nicklas |
var format = Data.get('page-data', useTime ? 'datetime-format' : 'date-format'); |
6938 |
19 Aug 15 |
nicklas |
Dialogs.openCalendar(at.valueType+'-input', title, format, useTime); |
6938 |
19 Aug 15 |
nicklas |
1235 |
} |
6938 |
19 Aug 15 |
nicklas |
1236 |
|
6938 |
19 Aug 15 |
nicklas |
1237 |
/** |
6938 |
19 Aug 15 |
nicklas |
Open the text zoom dialog for the selected annotation. |
6938 |
19 Aug 15 |
nicklas |
1239 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.openTextZoom = function(event) |
6938 |
19 Aug 15 |
nicklas |
1241 |
{ |
6938 |
19 Aug 15 |
nicklas |
var at = selectedAnnotation.annotationType; |
6938 |
19 Aug 15 |
nicklas |
var title = at.name; |
6938 |
19 Aug 15 |
nicklas |
Dialogs.openZoom(at.valueType+'-input', title); |
6938 |
19 Aug 15 |
nicklas |
1245 |
} |
6938 |
19 Aug 15 |
nicklas |
1246 |
|
6938 |
19 Aug 15 |
nicklas |
1247 |
/** |
6938 |
19 Aug 15 |
nicklas |
Copy all modified annotation values to the given form as hidden fields. |
6938 |
19 Aug 15 |
nicklas |
1249 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.saveModifiedAnnotationToForm = function(frm) |
6938 |
19 Aug 15 |
nicklas |
1251 |
{ |
6938 |
19 Aug 15 |
nicklas |
var modified = []; |
6938 |
19 Aug 15 |
nicklas |
for (var entryNo = 0; entryNo < annotations.length; entryNo++) |
6938 |
19 Aug 15 |
nicklas |
1254 |
{ |
6938 |
19 Aug 15 |
nicklas |
var entry = annotations[entryNo]; |
7206 |
19 Oct 16 |
nicklas |
if (entry.annotatePermission && entry.modified) |
6938 |
19 Aug 15 |
nicklas |
1257 |
{ |
6938 |
19 Aug 15 |
nicklas |
var tmp = {}; |
6938 |
19 Aug 15 |
nicklas |
modified[modified.length] = tmp; |
6943 |
01 Sep 15 |
nicklas |
tmp.source = entry.source; |
6943 |
01 Sep 15 |
nicklas |
tmp.modified = entry.modified; |
6938 |
19 Aug 15 |
nicklas |
tmp.annotationTypeId = entry.annotationType.id; |
6947 |
08 Sep 15 |
nicklas |
if (entry.annotation) |
6947 |
08 Sep 15 |
nicklas |
1264 |
{ |
6947 |
08 Sep 15 |
nicklas |
tmp.values = entry.annotation.values; |
6947 |
08 Sep 15 |
nicklas |
tmp.annotationId = entry.annotation.id; |
6947 |
08 Sep 15 |
nicklas |
tmp.unitId = entry.annotation.unit; |
6955 |
28 Sep 15 |
nicklas |
if (tmp.modified == MODIFIED && tmp.values.length == 0) |
6955 |
28 Sep 15 |
nicklas |
1269 |
{ |
6955 |
28 Sep 15 |
nicklas |
tmp.modified = DELETE; |
6955 |
28 Sep 15 |
nicklas |
1271 |
} |
6947 |
08 Sep 15 |
nicklas |
1272 |
} |
6947 |
08 Sep 15 |
nicklas |
if (entry.inherited) |
6947 |
08 Sep 15 |
nicklas |
1274 |
{ |
6947 |
08 Sep 15 |
nicklas |
tmp.inheritedId = entry.inherited.id; |
6947 |
08 Sep 15 |
nicklas |
1276 |
} |
6938 |
19 Aug 15 |
nicklas |
1277 |
} |
6938 |
19 Aug 15 |
nicklas |
1278 |
} |
6938 |
19 Aug 15 |
nicklas |
1279 |
|
6955 |
28 Sep 15 |
nicklas |
//alert(JSON.stringify(modified)); |
6943 |
01 Sep 15 |
nicklas |
1281 |
|
6938 |
19 Aug 15 |
nicklas |
if (frm.modifiedAnnotations) |
6938 |
19 Aug 15 |
nicklas |
1283 |
{ |
6938 |
19 Aug 15 |
nicklas |
frm.modifiedAnnotations.value = JSON.stringify(modified); |
6938 |
19 Aug 15 |
nicklas |
1285 |
} |
6938 |
19 Aug 15 |
nicklas |
else |
6938 |
19 Aug 15 |
nicklas |
1287 |
{ |
6938 |
19 Aug 15 |
nicklas |
Forms.addHidden(frm, 'modifiedAnnotations', JSON.stringify(modified)); |
6938 |
19 Aug 15 |
nicklas |
1289 |
} |
6938 |
19 Aug 15 |
nicklas |
1290 |
|
6938 |
19 Aug 15 |
nicklas |
1291 |
} |
6938 |
19 Aug 15 |
nicklas |
1292 |
|
6938 |
19 Aug 15 |
nicklas |
1293 |
/** |
6938 |
19 Aug 15 |
nicklas |
Save the annotations in standalone mode. |
6938 |
19 Aug 15 |
nicklas |
1295 |
*/ |
6938 |
19 Aug 15 |
nicklas |
annotate.save = function() |
6938 |
19 Aug 15 |
nicklas |
1297 |
{ |
6938 |
19 Aug 15 |
nicklas |
var frm = document.forms['modified']; |
6938 |
19 Aug 15 |
nicklas |
annotate.saveModifiedAnnotationToForm(frm); |
6938 |
19 Aug 15 |
nicklas |
frm.submit(); |
6938 |
19 Aug 15 |
nicklas |
1301 |
} |
6938 |
19 Aug 15 |
nicklas |
1302 |
|
6938 |
19 Aug 15 |
nicklas |
return annotate; |
6938 |
19 Aug 15 |
nicklas |
1304 |
}(); |
6938 |
19 Aug 15 |
nicklas |
1305 |
|
6938 |
19 Aug 15 |
nicklas |
Doc.onLoad(Annotate.initPage); |
6938 |
19 Aug 15 |
nicklas |
1307 |
|
6938 |
19 Aug 15 |
nicklas |
1308 |
|