|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var CommentsPane = function CommentsPane($element, opts) { |
|
|
|
var $header = $element.children('h1'), |
|
$body = $element.children('div'), |
|
$comments_container = $("#comments_container"), |
|
objects = opts.selected; |
|
var self = this; |
|
|
|
var tmplText = $('#comments_template').html(); |
|
var commentsTempl = _.template(tmplText); |
|
|
|
|
|
var initEvents = (function initEvents() { |
|
|
|
$header.on('click', function(){ |
|
$header.toggleClass('closed'); |
|
$body.slideToggle(); |
|
|
|
var expanded = !$header.hasClass('closed'); |
|
OME.setPaneExpanded('comments', expanded); |
|
|
|
if (expanded && $comments_container.is(":empty")) { |
|
this.render(); |
|
} |
|
}.bind(this)); |
|
}).bind(this); |
|
|
|
|
|
$("#add_comment_wrapper label").inFieldLabels(); |
|
$("#id_comment") |
|
.on('blur', function(event){ |
|
setTimeout(function(){ |
|
$("#add_comment_form input[type='submit']").hide(); |
|
}, 200); |
|
}) |
|
.on('focus', function(){ |
|
$("#add_comment_form input[type='submit']").show(); |
|
}); |
|
|
|
|
|
$("#comments_container").on("click", ".removeComment", function(event){ |
|
var url = $(this).attr('url'); |
|
var objId = objects.join("|"); |
|
OME.removeItem(event, ".ann_comment_wrapper", url, objId); |
|
return false; |
|
}); |
|
|
|
|
|
$("#add_comment_form").ajaxForm({ |
|
beforeSubmit: function(data, $form, options) { |
|
var textArea = $('#add_comment_form textarea'); |
|
if (textArea.val().trim().length === 0) return false; |
|
|
|
objects.forEach(function(o){ |
|
var dtypeId = o.split("-"); |
|
data.push({"name": dtypeId[0], "value": dtypeId[1]}); |
|
}); |
|
}, |
|
success: function(html) { |
|
$("#id_comment").val(""); |
|
self.render(); |
|
}, |
|
}); |
|
|
|
|
|
this.render = function render() { |
|
|
|
if ($comments_container.is(":visible")) { |
|
|
|
if ($comments_container.is(":empty")) { |
|
$comments_container.html("Loading comments..."); |
|
} |
|
|
|
var request = objects.map(function(o){ |
|
return o.replace("-", "="); |
|
}); |
|
request = request.join("&"); |
|
|
|
$.getJSON(WEBCLIENT.URLS.webindex + "api/annotations/?type=comment&" + request, function(data){ |
|
|
|
|
|
|
|
|
|
var experimenters = data.experimenters.reduce(function(prev, exp){ |
|
prev[exp.id + ""] = exp; |
|
return prev; |
|
}, {}); |
|
|
|
|
|
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]; |
|
} |
|
ann.addedBy = [ann.link.owner.id]; |
|
|
|
|
|
|
|
return ann; |
|
}); |
|
|
|
|
|
anns.sort(function(a, b) { |
|
return a.date < b.date ? 1 : -1; |
|
}); |
|
|
|
|
|
anns = anns.filter(function(ann, idx){ |
|
|
|
return (idx === 0 || anns[idx - 1].id !== ann.id); |
|
}); |
|
|
|
|
|
var html = ""; |
|
if (anns.length > 0) { |
|
html = commentsTempl({'anns': anns, |
|
'static': WEBCLIENT.URLS.static_webclient, |
|
'webindex': WEBCLIENT.URLS.webindex}); |
|
} |
|
$comments_container.html(html); |
|
|
|
|
|
OME.linkify_element($( ".commentText" )); |
|
OME.filterAnnotationsAddedBy(); |
|
$(".tooltip", $comments_container).tooltip_init(); |
|
}); |
|
} |
|
}; |
|
|
|
|
|
initEvents(); |
|
|
|
if (OME.getPaneExpanded('comments')) { |
|
$header.toggleClass('closed'); |
|
$body.show(); |
|
} |
|
|
|
this.render(); |
|
}; |