File size: 5,045 Bytes
eb67da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
// Copyright (C) 2016 University of Dundee & Open Microscopy Environment.
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
var CustomAnnsPane = function CustomAnnsPane($element, opts) {
var $header = $element.children('h1'),
$body = $element.children('div'),
$custom_annotations = $("#custom_annotations"),
objects = opts.selected;
var tmplText = $('#customanns_template').html();
var customannsTempl = _.template(tmplText);
var initEvents = (function initEvents() {
$header.on('click', function(){
$header.toggleClass('closed');
$body.slideToggle();
var expanded = !$header.hasClass('closed');
OME.setPaneExpanded('others', expanded);
if (expanded && $custom_annotations.is(":empty")) {
this.render();
}
}.bind(this));
}).bind(this);
// display xml in a new window
$body.on( "click", ".show_xml", function(event) {
var xml = $(event.target).next().html();
var newWindow=window.open('','','height=500,width=500,scrollbars=yes, top=50, left=100');
newWindow.document.write(xml);
newWindow.document.close();
return false;
});
this.render = function render() {
if ($custom_annotations.is(":visible")) {
if ($custom_annotations.is(":empty")) {
$custom_annotations.html("Loading other annotations...");
}
var request = objects.map(function(o){
return o.replace("-", "=");
});
request = request.join("&");
$.getJSON(WEBCLIENT.URLS.webindex + "api/annotations/?type=custom&" + request, function(data){
// manipulate data...
// make an object of eid: experimenter
var experimenters = data.experimenters.reduce(function(prev, exp){
prev[exp.id + ""] = exp;
return prev;
}, {});
// Populate experimenters within anns
var anns = data.annotations.map(function(ann){
ann.owner = experimenters[ann.owner.id];
if (ann.link && ann.link.owner) {
ann.link.owner = experimenters[ann.link.owner.id];
}
// AddedBy IDs for filtering
ann.addedBy = [ann.link.owner.id];
// convert 'class' to 'type' E.g. XmlAnnotationI to Xml
ann.type = ann.class.replace('AnnotationI', '');
var attrs = ['textValue', 'timeValue', 'termValue', 'longValue', 'doubleValue', 'boolValue'];
attrs.forEach(function(a){
if (ann[a] !== undefined){
// BUG: CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
// ann.value = _.escape(ann[a]);
// FIXED:
ann.value = ann[a];
}
});
if (objects.length > 1) {
ann.parent = {
'class': ann.link.parent.class.slice(0, -1), // slice parent class 'ProjectI' > 'Project'
'id': ann.link.parent.id
};
}
return ann;
});
// Show most recent annotations at the top
anns.sort(function(a, b) {
return a.date < b.date;
});
// Update html...
var html = "";
if (anns.length > 0) {
html = customannsTempl({'anns': anns,
'static': WEBCLIENT.URLS.static_webclient,
'webindex': WEBCLIENT.URLS.webindex});
}
$custom_annotations.html(html);
// Finish up...
OME.filterAnnotationsAddedBy();
$(".tooltip", $custom_annotations).tooltip_init();
});
}
};
initEvents();
if (OME.getPaneExpanded('others')) {
$header.toggleClass('closed');
$body.show();
}
this.render();
}; |