diff --git a/static/js/annotationPanel.js b/static/js/annotationPanel.js index 847ef54..0ca5c7a 100644 --- a/static/js/annotationPanel.js +++ b/static/js/annotationPanel.js @@ -31,6 +31,8 @@ oml.ui.annotationPanel = function() { {id: 'note', title: Ox._('By Note Text'), checked: false}, {id: 'date', title: Ox._('By Date Added'), checked: false} ]}, + {}, + {id: 'exportAnnotations', title: Ox._('Export Annotations')}, ], style: 'square', title: 'set', @@ -39,7 +41,20 @@ oml.ui.annotationPanel = function() { }).css({ // borderColor: 'transparent', float: 'right' - }).appendTo($bar); + }).appendTo($bar) + .bindEvent({ + click: function(data) { + var id = data.id; + if (id == 'exportAnnotations') { + oml.api.get({ + id: oml.user.ui.item, + keys: [] + }, function(result) { + oml.ui.exportAnnotationsDialog(result.data).open() + }) + } + } + }); var ui = oml.user.ui; var that = Ox.SplitPanel({ diff --git a/static/js/exportAnnotationsDialog.js b/static/js/exportAnnotationsDialog.js new file mode 100644 index 0000000..f891efa --- /dev/null +++ b/static/js/exportAnnotationsDialog.js @@ -0,0 +1,62 @@ +'use strict'; + +oml.ui.exportAnnotationsDialog = function(data) { + + var ui = oml.user.ui, + + $text = Ox.Input({ + type: 'textarea', + style: 'squared', + value: getAnnotationsText(), + width: 640, + height: 480 + }) + .css({margin: '16px'}), + + that = Ox.Dialog({ + buttons: [ + Ox.Button({ + id: 'done', + style: 'squared', + title: Ox._('Done') + }) + .bindEvent({ + click: function() { + that.close(); + } + }) + ], + closeButton: true, + content: $text, + height: 480 + 2 * 16, + keys: {enter: 'done'}, + removeOnClose: true, + title: Ox._('Export Annotations'), + width: 640 + 2* 16 + }) + .bindEvent({ + close: function() { + that.close(); + }, + open: function() { + // .. + } + }); + + function getAnnotationsText() { + var annotations = oml.$ui.viewer.getAnnotations() + var text = 'Annotations for ' + data.title + ' (' + data.author.join(', ') + ')\n\n\n\n' + text += annotations.map(function(annotation) { + var text = 'Quote:\n\n' + annotation.text + if (annotation.notes.length) { + text += '\n\nNotes:\n' + annotation.notes.map(function(note) { + return note.value + }).join('\n\n') + } + return text + }).join('\n\n\n\n') + return text + } + return that; + +}; diff --git a/static/js/viewer.js b/static/js/viewer.js index 092657a..e45c4ac 100644 --- a/static/js/viewer.js +++ b/static/js/viewer.js @@ -143,6 +143,8 @@ oml.ui.viewer = function() { that.postMessage = function(event, data) { $iframe && $iframe.postMessage(event, data) }; - + that.getAnnotations = function() { + return annotations; + } return that.updateElement(); }; diff --git a/static/json/js.json b/static/json/js.json index 5578ee0..f283185 100644 --- a/static/json/js.json +++ b/static/json/js.json @@ -19,6 +19,7 @@ "deleteListDialog.js", "editDialog.js", "errorDialog.js", + "exportAnnotationsDialog.js", "filter.js", "filtersInnerPanel.js", "filtersOuterPanel.js",