store comments
This commit is contained in:
parent
2dcf358eb5
commit
57692665a4
2 changed files with 35 additions and 6 deletions
|
@ -1,14 +1,34 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
oml.ui.annotation = function(data, $iframe) {
|
oml.ui.annotation = function(annotation, $iframe) {
|
||||||
var $arrayEditable = Ox.ArrayEditable({
|
var $arrayEditable = Ox.ArrayEditable({
|
||||||
editing: true,
|
editing: true,
|
||||||
|
items: (annotation.comments || []).map(function(comment) {
|
||||||
|
comment.editable = true
|
||||||
|
return comment
|
||||||
|
}),
|
||||||
type: 'textarea'
|
type: 'textarea'
|
||||||
}).css({
|
}).css({
|
||||||
minHeight: '16px'
|
minHeight: '16px'
|
||||||
|
}).bindEvent({
|
||||||
|
submit: function(data) {
|
||||||
|
var comment = Ox.getObjectById(annotation.comments, data.id)
|
||||||
|
if (comment) {
|
||||||
|
comment.value = data.value
|
||||||
|
comment.modified = (new Date).toISOString()
|
||||||
|
} else {
|
||||||
|
annotation.comments.push({
|
||||||
|
created: data.created || (new Date).toISOString(),
|
||||||
|
modified: (new Date).toISOString(),
|
||||||
|
id: data.id,
|
||||||
|
value: data.value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
that.triggerEvent('change')
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var that = Ox.Element().attr({
|
var that = Ox.Element().attr({
|
||||||
id: 'a-' + data.id
|
id: 'a-' + annotation.id
|
||||||
}).addClass(
|
}).addClass(
|
||||||
'OxSelectable'
|
'OxSelectable'
|
||||||
).css({
|
).css({
|
||||||
|
@ -21,10 +41,10 @@ oml.ui.annotation = function(data, $iframe) {
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
lineHeight: '21px',
|
lineHeight: '21px',
|
||||||
padding: '8px'
|
padding: '8px'
|
||||||
}).html(Ox.encodeHTMLEntities(data.text).replace(/\n/g, '<br/>')).on({
|
}).html(Ox.encodeHTMLEntities(annotation.text).replace(/\n/g, '<br/>')).on({
|
||||||
click: function(event) {
|
click: function(event) {
|
||||||
$iframe.postMessage('selectAnnotation', {
|
$iframe.postMessage('selectAnnotation', {
|
||||||
id: data.id
|
id: annotation.id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -46,6 +46,7 @@ oml.ui.viewer = function() {
|
||||||
function saveAnnotations(data) {
|
function saveAnnotations(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
data.created = data.created || (new Date).toISOString();
|
data.created = data.created || (new Date).toISOString();
|
||||||
|
data.comments = data.comments || [];
|
||||||
annotations.push(data);
|
annotations.push(data);
|
||||||
}
|
}
|
||||||
localStorage[item + '.annotations'] = JSON.stringify(annotations)
|
localStorage[item + '.annotations'] = JSON.stringify(annotations)
|
||||||
|
@ -57,6 +58,14 @@ oml.ui.viewer = function() {
|
||||||
saveAnnotations()
|
saveAnnotations()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var annotationEvents = {
|
||||||
|
change: function() {
|
||||||
|
console.log('change...')
|
||||||
|
console.log(annotations)
|
||||||
|
saveAnnotations()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
that.updateElement = function() {
|
that.updateElement = function() {
|
||||||
item = ui.item;
|
item = ui.item;
|
||||||
if (item && item.length) {
|
if (item && item.length) {
|
||||||
|
@ -75,7 +84,7 @@ oml.ui.viewer = function() {
|
||||||
if (event == 'addAnnotation') {
|
if (event == 'addAnnotation') {
|
||||||
console.log('adding', data.id)
|
console.log('adding', data.id)
|
||||||
saveAnnotations(data);
|
saveAnnotations(data);
|
||||||
var $annotation = oml.ui.annotation(data, $iframe)
|
var $annotation = oml.ui.annotation(data, $iframe).bindEvent(annotationEvents)
|
||||||
oml.$ui.annotationFolder.append($annotation);
|
oml.$ui.annotationFolder.append($annotation);
|
||||||
$annotation.annotate();
|
$annotation.annotate();
|
||||||
} else if (event == 'removeAnnotation') {
|
} else if (event == 'removeAnnotation') {
|
||||||
|
@ -93,7 +102,7 @@ oml.ui.viewer = function() {
|
||||||
init: function() {
|
init: function() {
|
||||||
loadAnnotations(function(annotations) {
|
loadAnnotations(function(annotations) {
|
||||||
annotations.forEach(function(data) {
|
annotations.forEach(function(data) {
|
||||||
var $annotation = oml.ui.annotation(data, $iframe)
|
var $annotation = oml.ui.annotation(data, $iframe).bindEvent(annotationEvents)
|
||||||
oml.$ui.annotationFolder.append($annotation);
|
oml.$ui.annotationFolder.append($annotation);
|
||||||
})
|
})
|
||||||
// fixme: trigger loaded event from reader instead?
|
// fixme: trigger loaded event from reader instead?
|
||||||
|
|
Loading…
Reference in a new issue