remove annotations and other annotation menu options
This commit is contained in:
parent
8169d8e720
commit
b4b66f9bd5
4 changed files with 88 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
oml.ui.annotationPanel = function() {
|
oml.ui.annotationPanel = function(options, self) {
|
||||||
|
self = self || {};
|
||||||
var ui = oml.user.ui;
|
var ui = oml.user.ui;
|
||||||
|
|
||||||
var ui = oml.user.ui;
|
var ui = oml.user.ui;
|
||||||
|
@ -29,14 +30,15 @@ oml.ui.annotationPanel = function() {
|
||||||
click: function() {
|
click: function() {
|
||||||
var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
|
var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
|
||||||
$annotation.length && $annotation.delete()
|
$annotation.length && $annotation.delete()
|
||||||
$deleteQuote.options({disabled: true})
|
that.updateSelection()
|
||||||
}
|
}
|
||||||
}).appendTo($bar);
|
}).appendTo($bar);
|
||||||
|
|
||||||
var $menuButton = Ox.MenuButton({
|
var $menuButton = Ox.MenuButton({
|
||||||
items: [
|
items: [
|
||||||
{id: 'addAnnotation', title: 'Add Annotation', disabled: true},
|
{id: 'addAnnotation', title: 'Add Annotation', disabled: true, keyboard: 'return'},
|
||||||
{id: 'removeAnnotation', title: 'Remove Annotation', disabled: true},
|
{id: 'removeAnnotation', title: 'Remove Annotation', disabled: true, keyboard: 'delete'},
|
||||||
|
{id: 'removeAnnotations', title: 'Remove All Annotation', disabled: true},
|
||||||
{},
|
{},
|
||||||
{id: 'show', title: Ox._('Show Annotations'), disabled: true},
|
{id: 'show', title: Ox._('Show Annotations'), disabled: true},
|
||||||
{group: 'showAnnotationUsers', min: 1, max: 1, items: [
|
{group: 'showAnnotationUsers', min: 1, max: 1, items: [
|
||||||
|
@ -82,6 +84,14 @@ oml.ui.annotationPanel = function() {
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
oml.ui.exportAnnotationsDialog(result.data).open()
|
oml.ui.exportAnnotationsDialog(result.data).open()
|
||||||
})
|
})
|
||||||
|
} else if (id =='addAnnotation') {
|
||||||
|
oml.$ui.viewer.postMessage('addAnnotation', {})
|
||||||
|
} else if (id =='removeAnnotation') {
|
||||||
|
var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
|
||||||
|
$annotation.length && $annotation.delete()
|
||||||
|
that.updateSelection()
|
||||||
|
} else if (id =='removeAnnotations') {
|
||||||
|
oml.ui.removeAnnotationsDialog().open()
|
||||||
} else {
|
} else {
|
||||||
console.log('click', id, data)
|
console.log('click', id, data)
|
||||||
}
|
}
|
||||||
|
@ -113,16 +123,18 @@ oml.ui.annotationPanel = function() {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
|
}, self).update({
|
||||||
|
hasAnnotations: function() {
|
||||||
|
$menuButton[self.options.hasAnnotations ? 'enableItem' : 'disableItem']('removeAnnotations')
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
that.updateSelection = function(selection) {
|
that.updateSelection = function(selection) {
|
||||||
$addQuote.options({
|
|
||||||
disabled: !selection
|
|
||||||
})
|
|
||||||
var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
|
var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
|
||||||
$deleteQuote.options({
|
$addQuote.options({disabled: !selection})
|
||||||
disabled: !$annotation.length
|
$deleteQuote.options({disabled: !$annotation.length})
|
||||||
})
|
$menuButton[selection ? 'enableItem' : 'disableItem']('addAnnotation')
|
||||||
|
$menuButton[$annotation.length ? 'enableItem' : 'disableItem']('removeAnnotation')
|
||||||
}
|
}
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
48
static/js/removeAnnotations.js
Normal file
48
static/js/removeAnnotations.js
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
oml.ui.removeAnnotationsDialog = function() {
|
||||||
|
|
||||||
|
var ui = oml.user.ui,
|
||||||
|
|
||||||
|
annotations = oml.$ui.viewer.getAnnotations().filter(function(a) {
|
||||||
|
return a.user == oml.user.id
|
||||||
|
}),
|
||||||
|
annotationsName = Ox._(annotations.length == 1 ? 'Annotation' : 'Annotations'),
|
||||||
|
theseAnnotationsName = annotations.length == 1
|
||||||
|
? Ox._('this annotation')
|
||||||
|
: Ox._('these {0} annotations', [Ox.formatNumber(annotations.length)]),
|
||||||
|
|
||||||
|
that = oml.ui.confirmDialog({
|
||||||
|
buttons: [
|
||||||
|
Ox.Button({
|
||||||
|
style: 'squared',
|
||||||
|
title: Ox._('No, Keep {0}', [annotationsName])
|
||||||
|
}),
|
||||||
|
Ox.Button({
|
||||||
|
style: 'squared',
|
||||||
|
title: Ox._('Yes, Delete {0}', [annotationsName])
|
||||||
|
})
|
||||||
|
],
|
||||||
|
content: Ox._(
|
||||||
|
'Are you sure that you want to permanently delete {0}?',
|
||||||
|
[theseAnnotationsName]
|
||||||
|
),
|
||||||
|
title: Ox._('Delete {0}', [annotationsName])
|
||||||
|
}, function() {
|
||||||
|
Ox.serialForEach(annotations, function(a, index, annotations, next) {
|
||||||
|
oml.api.removeAnnotation({
|
||||||
|
item: ui.item,
|
||||||
|
annotation: a.id
|
||||||
|
}, function(result) {
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
}, function() {
|
||||||
|
Ox.Request.clearCache();
|
||||||
|
oml.$ui.viewer.renderAnnotations(true);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
return that;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
|
@ -111,6 +111,7 @@ oml.ui.viewer = function() {
|
||||||
if (save !== false) {
|
if (save !== false) {
|
||||||
oml.api.addAnnotation(a)
|
oml.api.addAnnotation(a)
|
||||||
}
|
}
|
||||||
|
data.user = a.user || oml.user.id
|
||||||
data.notes = data.notes || [];
|
data.notes = data.notes || [];
|
||||||
annotations.push(data);
|
annotations.push(data);
|
||||||
}
|
}
|
||||||
|
@ -157,9 +158,13 @@ oml.ui.viewer = function() {
|
||||||
oml.$ui.annotationFolder.append($annotation);
|
oml.$ui.annotationFolder.append($annotation);
|
||||||
$annotation.annotate();
|
$annotation.annotate();
|
||||||
oml.$ui.annotationPanel.updateSelection(false)
|
oml.$ui.annotationPanel.updateSelection(false)
|
||||||
|
oml.$ui.annotationPanel.options({hasAnnotations: true})
|
||||||
} else if (event == 'removeAnnotation') {
|
} else if (event == 'removeAnnotation') {
|
||||||
oml.$ui.annotationFolder.find('#a-' + data.id).remove()
|
oml.$ui.annotationFolder.find('#a-' + data.id).remove()
|
||||||
data.id && removeAnnotation(data.id)
|
data.id && removeAnnotation(data.id)
|
||||||
|
oml.$ui.annotationPanel.options({hasAnnotations: annotations.filter(function(a) {
|
||||||
|
return a.user == oml.user.id
|
||||||
|
}).length > 0})
|
||||||
} else if (event == 'selectAnnotation') {
|
} else if (event == 'selectAnnotation') {
|
||||||
if (data.id) {
|
if (data.id) {
|
||||||
var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id)
|
var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id)
|
||||||
|
@ -196,7 +201,7 @@ oml.ui.viewer = function() {
|
||||||
that.getAnnotations = function() {
|
that.getAnnotations = function() {
|
||||||
return annotations;
|
return annotations;
|
||||||
}
|
}
|
||||||
that.renderAnnotations = function() {
|
that.renderAnnotations = function(load=false) {
|
||||||
var sortKey = ui.sortAnnotations
|
var sortKey = ui.sortAnnotations
|
||||||
if (sortKey == 'date') {
|
if (sortKey == 'date') {
|
||||||
sortKey = 'created'
|
sortKey = 'created'
|
||||||
|
@ -207,9 +212,15 @@ oml.ui.viewer = function() {
|
||||||
if (sortKey == 'quote') {
|
if (sortKey == 'quote') {
|
||||||
sortKey = 'text'
|
sortKey = 'text'
|
||||||
}
|
}
|
||||||
|
if (load) {
|
||||||
|
loadAnnotations(function() {
|
||||||
|
that.renderAnnotations()
|
||||||
|
})
|
||||||
|
}
|
||||||
annotations = Ox.sortBy(annotations, sortKey)
|
annotations = Ox.sortBy(annotations, sortKey)
|
||||||
oml.$ui.annotationFolder.empty();
|
oml.$ui.annotationFolder.empty();
|
||||||
var visibleAnnotations = [];
|
var visibleAnnotations = [];
|
||||||
|
var hasAnnotations = false;
|
||||||
annotations.forEach(function(data) {
|
annotations.forEach(function(data) {
|
||||||
//that.postMessage('removeAnnotation', {id: data.id})
|
//that.postMessage('removeAnnotation', {id: data.id})
|
||||||
if (ui.showAnnotationUsers == 'all' || data.user == oml.user.id) {
|
if (ui.showAnnotationUsers == 'all' || data.user == oml.user.id) {
|
||||||
|
@ -217,7 +228,11 @@ oml.ui.viewer = function() {
|
||||||
oml.$ui.annotationFolder.append($annotation);
|
oml.$ui.annotationFolder.append($annotation);
|
||||||
visibleAnnotations.push(data)
|
visibleAnnotations.push(data)
|
||||||
}
|
}
|
||||||
|
if (data.user == oml.user.id) {
|
||||||
|
hasAnnotations = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
oml.$ui.annotationPanel.options({hasAnnotations: hasAnnotations})
|
||||||
// fixme: trigger loaded event from reader instead?
|
// fixme: trigger loaded event from reader instead?
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
that.postMessage('addAnnotations', {
|
that.postMessage('addAnnotations', {
|
||||||
|
@ -225,6 +240,7 @@ oml.ui.viewer = function() {
|
||||||
replace: true
|
replace: true
|
||||||
})
|
})
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
||||||
}
|
}
|
||||||
return that.updateElement();
|
return that.updateElement();
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
"preferencesPanel.js",
|
"preferencesPanel.js",
|
||||||
"previewButton.js",
|
"previewButton.js",
|
||||||
"previewDialog.js",
|
"previewDialog.js",
|
||||||
|
"removeAnnotations.js",
|
||||||
"resetUIDialog.js",
|
"resetUIDialog.js",
|
||||||
"rightPanel.js",
|
"rightPanel.js",
|
||||||
"sectionButtons.js",
|
"sectionButtons.js",
|
||||||
|
|
Loading…
Reference in a new issue