[scrobbles] Fix adding comments to webpages
This commit is contained in:
@ -17,9 +17,7 @@
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var latestScrobbleUuid = "{{ latest_scrobble_uuid|default:'' }}";
|
||||
console.log('DEBUG: latestScrobbleUuid =', latestScrobbleUuid);
|
||||
if (!latestScrobbleUuid) {
|
||||
console.log('No latest scrobble UUID available');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -48,6 +46,7 @@
|
||||
return {
|
||||
"@context": "http://www.w3.org/ns/anno.jsonld",
|
||||
"@type": "Annotation",
|
||||
"id": "note-{{ forloop.counter }}",
|
||||
"body": [{"@type": "TextualBody", "value": parsed.text}],
|
||||
"target": {"selector": [{"type": "TextPositionSelector", "start": parsed.position.start, "end": parsed.position.end}]}
|
||||
};
|
||||
@ -57,16 +56,12 @@
|
||||
{% endfor %}
|
||||
].filter(function(n) { return n !== null; });
|
||||
|
||||
console.log("existing:", existingNotes);
|
||||
if (existingNotes.length > 0) {
|
||||
r.setAnnotations(existingNotes);
|
||||
}
|
||||
|
||||
r.on('createAnnotation', function(annotation) {
|
||||
var note = annotation.body && annotation.body[0] ? annotation.body[0].value : null;
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
|
||||
function getPositionFromAnnotation(annotation) {
|
||||
var position = null;
|
||||
if (annotation.target && annotation.target.selector) {
|
||||
var selector = annotation.target.selector;
|
||||
@ -77,9 +72,19 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
var currentAnnotation = null;
|
||||
|
||||
r.on('createAnnotation', function(annotation) {
|
||||
var note = annotation.body && annotation.body[0] ? annotation.body[0].value : null;
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
|
||||
var position = getPositionFromAnnotation(annotation);
|
||||
|
||||
console.log('Sending fetch to:', '/api/v1/scrobbles/' + latestScrobbleUuid + '/');
|
||||
console.log('CSRF token:', '{{ csrf_token }}');
|
||||
fetch('/api/v1/scrobbles/' + latestScrobbleUuid + '/', {
|
||||
method: 'PATCH',
|
||||
credentials: 'same-origin',
|
||||
@ -98,6 +103,14 @@
|
||||
console.error('Error saving note:', error);
|
||||
});
|
||||
});
|
||||
|
||||
r.on('selectAnnotation', function(annotation, element) {
|
||||
currentAnnotation = annotation;
|
||||
});
|
||||
|
||||
r.on('deleteAnnotation', function(annotation) {
|
||||
console.log('Deleted annotation:', annotation);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@ -131,7 +144,7 @@
|
||||
{% for scrobble in scrobbles.all %}
|
||||
<tr>
|
||||
<td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td>
|
||||
<td>{% for note in scrobble.logdata.notes %}{{note}}{% if not forloop.last %}; {% endif%}{% endfor %}
|
||||
<td>{% if scrobble.logdata.notes %}{% for note in scrobble.logdata.notes %}{{note}}{% if not forloop.last %}; {% endif%}{% endfor %}{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user