# HG changeset patch
# User hertzhaft
# Date 1474023489 -7200
# Node ID c1a390b47e07ae29c3a182261d5b464546182d6d
# Parent 70e1225fe08cc85d10648c4e1f9767c9b26f4b79
monkey-patch annotator-dl for maps (add fields for editor/viewer)
diff -r 70e1225fe08c -r c1a390b47e07 webapp/src/main/webapp/jquery/digilib-map.html
--- a/webapp/src/main/webapp/jquery/digilib-map.html Thu Sep 08 19:54:38 2016 +0200
+++ b/webapp/src/main/webapp/jquery/digilib-map.html Fri Sep 16 12:58:09 2016 +0200
@@ -26,7 +26,7 @@
-
+
@@ -47,42 +47,117 @@
},
},
// are annotations read-only?
+ // URL of annotation server
+ 'annotationServerUrl' : 'http://localhost:3000/map',
+ // are annotations read-only?
'annotationsReadOnly' : false,
// URL of annotation server
'annotationServerUrl' : 'http://hertz-test64.biblhertz.it:3000/map',
// URL of authentication token server
- 'annotationTokenUrl' : 'http://hertz-test64.biblhertz.it:3000/token',
+ 'annotationTokenUrl' : 'http://localhost:3000/token',
// list of Annotator plugins
- 'annotatorPlugins' : ['Auth', 'DigilibIntegrator', 'Markdown', 'Store', 'Tags']
- // annotationPageUri
- // 'annotationPageUri' : function() { return window.location.href }
+ 'annotatorPlugins' : ['Auth', 'Markdown', 'DigilibIntegrator', 'Store', 'Tags']
};
- // store additional data (apart from 'rows') from loadAnnotationsFromSearch
- var _onLoadAnnotationsFromSearch = function (data) {
- if (data == null) {
- data = {};
+ var _setupEditor = function() {
+ var e = new Annotator.Editor();
+ var _t = Annotator._t;
+ this.editor = e;
+ e.hide().on('hide', this.onEditorHide).on('save', this.onEditorSubmit);
+ e.addField({
+ id: 'map_name',
+ type: 'input',
+ label: _t('normal name') + '\u2026',
+ load: function(field, annotation) {
+ return $(field).find('#map_name').val(annotation.name || '');
+ },
+ submit: function(field, annotation) {
+ return annotation.name = $(field).find('#map_name').val();
+ }
+ });
+ e.addField({
+ id: 'map_nr',
+ type: 'input',
+ label: _t('nr') + '\u2026',
+ load: function(field, annotation) {
+ return $(field).find('#map_nr').val(annotation.nr || '');
+ },
+ submit: function(field, annotation) {
+ return annotation.nr = $(field).find('#map_nr').val();
+ }
+ });
+ e.addField({
+ id: 'map_legend',
+ type: 'input',
+ label: _t('legend') + '\u2026',
+ load: function(field, annotation) {
+ return $(field).find('#map_legend').val(annotation.legend || '');
+ },
+ submit: function(field, annotation) {
+ return annotation.legend = $(field).find('#map_legend').val();
}
- this.annotator.data = data;
- console.log('maps: data', data);
+ });
+ e.addField({
+ id: 'map_desc',
+ type: 'textarea',
+ label: _t('description') + '\u2026',
+ load: function(field, annotation) {
+ return $(field).find('#map_desc').val(annotation.desc || '');
+ },
+ submit: function(field, annotation) {
+ return annotation.desc = $(field).find('#map_desc').val();
+ }
+ });
+ e.addField({
+ id: 'map_fmid',
+ type: 'input',
+ label: _t('zuccaro (fm) id') + '\u2026',
+ load: function(field, annotation) {
+ return $(field).find('#map_fmid').val(annotation.fmid || '');
+ },
+ submit: function(field, annotation) {
+ return annotation.fmid = $(field).find('#map_fmid').val();
+ }
+ });
+ e.addField({
+ id: 'map_layer',
+ type: 'select',
+ label: _t('layer') + '\u2026',
+ load: function(field, annotation) {
+ return $(field).find('#map_layer').val(annotation.layer || '');
+ },
+ submit: function(field, annotation) {
+ return annotation.layer = $(field).find('#map_layer').val();
+ }
+ });
+ e.element.appendTo(this.wrapper);
+ return this;
+ };
+
+ var _onLoadAnnotationsFromSearch = function(data) {
+ if (data == null) {
+ data = {};
+ }
+ this.element.data('digilib').annotationdata = data;
+ console.debug("_onloadAnnotationsFromSearch", data);
return this._onLoadAnnotations(data.rows || []);
};
- // monkey patch the annotator Store plugin
- var handleSetup = function (evt) {
- console.log('maps: handleSetup');
- this.annotator.plugins.Store._onLoadAnnotationsFromSearch = _onLoadAnnotationsFromSearch;
- }
- // add zoom area params to loadAnnotationsFromSearch url
+
var getZoomArea = function (data) {
return data.zoomArea.toString();
};
- // monkey patches for annotator_dl.js
+ var getFn = function (data) {
+ return data.settings.fn;
+ };
var hook = function (data) {
- data.settings.annotatorPluginSettings.Store.loadFromSearch.za = getZoomArea;
- $(data).on('setup', handleSetup); // too late, annotations have already been loaded
+ var loadParams = data.settings.annotatorPluginSettings.Store.loadFromSearch;
+ loadParams.za = getZoomArea;
+ loadParams.fn = getFn;
};
+ // monkey patch Store plugin
+ Annotator.prototype._setupEditor = _setupEditor;
+ Annotator.Plugin.Store.prototype._onLoadAnnotationsFromSearch = _onLoadAnnotationsFromSearch;
var $div = $('div#digilib');
$div.digilib(settings, hook);
-
});