openmedialibrary/static/js/annotation.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-01-23 20:44:59 +05:30
'use strict';
2019-01-24 18:19:21 +05:30
oml.ui.annotation = function(annotation, $iframe) {
2019-01-25 15:56:45 +05:30
var $quote = Ox.Element().addClass('OxSelectable OMLQuote').css({
padding: '8px'
2019-01-29 16:12:46 +05:30
}).html(Ox.encodeHTMLEntities(annotation.text).replace(/\n/g, '<br/>')).on({
2019-01-25 15:56:45 +05:30
click: function(event) {
that.select()
$iframe.postMessage('selectAnnotation', {
2019-01-29 16:12:46 +05:30
id: annotation.id
2019-01-25 15:56:45 +05:30
})
}
})
2019-01-31 12:37:49 +05:30
var notes = annotation.notes.length ? annotation.notes.map(function(note) {
note.editable = note.user == ''
return note
}) : [{
id: 'A',
placeholder: 'Add Note',
value: '',
editable: true
}];
console.log(annotation.notes)
2019-01-29 16:12:46 +05:30
var $note = Ox.ArrayEditable({
2019-01-24 14:50:25 +05:30
editing: true,
2019-01-31 12:37:49 +05:30
items: notes,
2019-01-24 14:50:25 +05:30
type: 'textarea'
}).css({
2019-01-25 15:56:45 +05:30
margin: '2px',
minHeight: '12px'
2019-01-24 18:19:21 +05:30
}).bindEvent({
submit: function(data) {
2019-01-31 12:37:49 +05:30
var note = Ox.getObjectById(annotation.notes, data.id)
if (note) {
note.value = data.value
note.modified = (new Date).toISOString()
2019-01-24 18:19:21 +05:30
} else {
2019-01-31 12:37:49 +05:30
annotation.notes.push({
2019-01-24 18:19:21 +05:30
created: data.created || (new Date).toISOString(),
modified: (new Date).toISOString(),
id: data.id,
2019-01-31 12:37:49 +05:30
user: '',
2019-01-24 18:19:21 +05:30
value: data.value
})
}
that.triggerEvent('change')
}
2019-01-24 14:50:25 +05:30
});
2019-01-23 20:44:59 +05:30
var that = Ox.Element().attr({
2019-01-24 18:19:21 +05:30
id: 'a-' + annotation.id
2019-01-24 11:09:09 +05:30
}).addClass(
2019-01-25 15:56:45 +05:30
'OxSelectable OMLAnnotation'
2019-01-24 11:09:09 +05:30
).css({
borderBottom: '1px solid rgb(208, 208, 208)',
2019-01-31 11:52:19 +05:30
}).bindEvent({
key_delete: function() {
that.triggerEvent('delete', {
id: annotation.id
})
}
2019-01-25 15:56:45 +05:30
}).append($quote).append($note);
2019-01-29 16:12:46 +05:30
2019-01-24 14:50:25 +05:30
that.annotate = function() {
var item = {
id: 'note', value: '', editable: true
}
2019-01-25 15:56:45 +05:30
}
that.deselect = function() {
that.removeClass('selected')
2019-01-31 12:37:49 +05:30
that.loseFocus()
2019-01-25 15:56:45 +05:30
}
that.select = function () {
let selected = document.querySelector('.OMLAnnotation.selected')
selected && selected.classList.remove('selected')
that.addClass('selected')
2019-01-31 11:52:19 +05:30
that.gainFocus()
2019-01-24 14:50:25 +05:30
}
2019-01-23 20:44:59 +05:30
return that;
};