add renderAnnotation method

This commit is contained in:
rlx 2019-02-04 14:23:42 +05:30
parent 5f5ebc3b7a
commit ef2b56e0a9
4 changed files with 30 additions and 19 deletions

View File

@ -64,7 +64,6 @@ oml.ui.annotation = function(annotation, $iframe) {
} }
}).append($quote).append($notes); }).append($quote).append($notes);
function addNote() { function addNote() {
if (!$notes.options('items').length) { if (!$notes.options('items').length) {
that.select() that.select()
@ -78,7 +77,6 @@ oml.ui.annotation = function(annotation, $iframe) {
} }
} }
that.annotate = function() { that.annotate = function() {
if (oml.user.ui.showAnnotations) { if (oml.user.ui.showAnnotations) {
addNote() addNote()

View File

@ -1,10 +1,9 @@
oml.ui.annotationFolder = function() { oml.ui.annotationFolder = function() {
var ui = oml.user.ui, var that = Ox.Element().addClass('OxAnnotationFolder').css({
that = Ox.Element().addClass('OxAnnotationFolder').css({ overflowY: 'auto',
overflowY: 'auto', overflowX: 'hidden',
overflowX: 'hidden', });
});
return that; return that;

View File

@ -23,14 +23,14 @@ oml.ui.annotationPanel = function() {
{id: 'addAnnotation', title: 'Add Annotation', disabled: true}, {id: 'addAnnotation', title: 'Add Annotation', disabled: true},
{id: 'removeAnnotation', title: 'Remove Annotation', disabled: true}, {id: 'removeAnnotation', title: 'Remove Annotation', disabled: true},
{}, {},
{id: 'showAnnotationUsers', title: Ox._('Show Annotations'), disabled: true}, {id: 'show', title: Ox._('Show Annotations'), disabled: true},
{group: 'show', min: 1, max: 1, items: [ {group: 'showAnnotationUsers', min: 1, max: 1, items: [
{id: 'all', title: Ox._('All Annotations'), checked: ui.showAnnotationUsers == 'all'}, {id: 'all', title: Ox._('All Annotations'), checked: ui.showAnnotationUsers == 'all'},
{id: 'me', title: Ox._('My Annotations'), checked: ui.showAnnotationUsers == 'me'}, {id: 'me', title: Ox._('My Annotations'), checked: ui.showAnnotationUsers == 'me'},
]}, ]},
{}, {},
{id: 'sortAnnotations', title: Ox._('Sort Annotations'), disabled: true}, {id: 'sort', title: Ox._('Sort Annotations'), disabled: true},
{group: 'sort', min: 1, max: 1, items: [ {group: 'sortAnnotations', min: 1, max: 1, items: [
{id: 'position', title: Ox._('By Position'), checked: ui.sortAnnotations == 'position'}, {id: 'position', title: Ox._('By Position'), checked: ui.sortAnnotations == 'position'},
{id: 'quote', title: Ox._('By Quote Text'), checked: ui.sortAnnotations == 'quote'}, {id: 'quote', title: Ox._('By Quote Text'), checked: ui.sortAnnotations == 'quote'},
{id: 'note', title: Ox._('By Note Text'), checked: ui.sortAnnotations == 'note'}, {id: 'note', title: Ox._('By Note Text'), checked: ui.sortAnnotations == 'note'},
@ -46,8 +46,18 @@ oml.ui.annotationPanel = function() {
}).css({ }).css({
// borderColor: 'transparent', // borderColor: 'transparent',
float: 'right' float: 'right'
}).appendTo($bar) }).bindEvent({
.bindEvent({ change: function(data) {
if (data.id == 'showAnnotationUsers') {
var value = data.checked[0].id;
oml.UI.set('showAnnotationUsers', value);
oml.$ui.viewer.renderAnnotations();
} else if (data.id == 'sortAnnotations') {
var value = data.checked[0].id;
oml.UI.set('sortAnnotations', value);
oml.$ui.viewer.renderAnnotations();
}
},
click: function(data) { click: function(data) {
var id = data.id; var id = data.id;
if (id == 'exportAnnotations') { if (id == 'exportAnnotations') {
@ -59,7 +69,7 @@ oml.ui.annotationPanel = function() {
}) })
} }
} }
}); }).appendTo($bar);
var ui = oml.user.ui; var ui = oml.user.ui;
var that = Ox.SplitPanel({ var that = Ox.SplitPanel({

View File

@ -115,14 +115,10 @@ oml.ui.viewer = function() {
console.log('got', event, data) console.log('got', event, data)
that.triggerEvent(event, data); that.triggerEvent(event, data);
} }
}).bindEvent({ }).bindEvent({
init: function() { init: function() {
loadAnnotations(function(annotations) { loadAnnotations(function(annotations) {
annotations.forEach(function(data) { that.renderAnnotations()
var $annotation = oml.ui.annotation(data, $iframe).bindEvent(annotationEvents)
oml.$ui.annotationFolder.append($annotation);
})
// fixme: trigger loaded event from reader instead? // fixme: trigger loaded event from reader instead?
setTimeout(function() { setTimeout(function() {
that.postMessage('addAnnotations', { that.postMessage('addAnnotations', {
@ -146,5 +142,13 @@ oml.ui.viewer = function() {
that.getAnnotations = function() { that.getAnnotations = function() {
return annotations; return annotations;
} }
that.renderAnnotations = function() {
oml.$ui.annotationFolder.empty();
Ox.sortBy(annotations, ui.sortAnnotations);
annotations.forEach(function(data) {
var $annotation = oml.ui.annotation(data, $iframe).bindEvent(annotationEvents)
oml.$ui.annotationFolder.append($annotation);
})
}
return that.updateElement(); return that.updateElement();
}; };