# HG changeset patch # User hertzhaft # Date 1480702408 -3600 # Node ID 817a5c42cb1ba4599978d8d5b431e4b9ef25ea90 # Parent a07a557b6e395e583aa9d845adca3858d12293da annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id) diff -r a07a557b6e39 -r 817a5c42cb1b webapp/src/main/webapp/jquery/jquery.digilib.annotator.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.annotator.js Fri Dec 02 18:13:05 2016 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.annotator.js Fri Dec 02 19:13:28 2016 +0100 @@ -307,7 +307,7 @@ /** - * Show editor and save annotation. + * Show editor, edit and save new annotation. */ var addAnnotationContent = function (data, shape, screenPos) { var annotator = data.annotator; @@ -316,23 +316,32 @@ var annotation = annotator.createAnnotation(); annotation.editing = true; var cleanup = function () { + annotator.unsubscribe('annotationStore', store); annotator.unsubscribe('annotationEditorSubmit', save); annotator.unsubscribe('annotationEditorHidden', cancel); delete annotation.editing; }; var save = function () { - console.log("annotation save."); - cleanup(); - annotator.setupAnnotation(annotation); + console.log("annotation save"); // Fire annotationCreated events so that plugins can react to them annotator.publish('annotationCreated', [annotation]); + }; + var store = function (orig, stored) { + if (stored == null) { + console.warn('Annotation Store did not return the stored annotation'); + stored = annotation; + } + console.debug("annotation stored", stored); + cleanup(); renderAnnotations(data); + annotator.setupAnnotation(stored); }; var cancel = function () { - console.log("annotation cancel."); + console.log("annotation cancel"); cleanup(); renderAnnotations(data); }; + annotator.subscribe('annotationStored', store); annotator.subscribe('annotationEditorSubmit', save); annotator.subscribe('annotationEditorHidden', cancel); annotator.showEditor(annotation, screenPos.getAsCss()); diff -r a07a557b6e39 -r 817a5c42cb1b webapp/src/main/webapp/jquery/jquery.digilib.vector.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Fri Dec 02 18:13:05 2016 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Fri Dec 02 19:13:28 2016 +0100 @@ -217,9 +217,9 @@ svgElement: svgElement, svgAttr: svgAttr, createScreenCoords: createScreenCoords, - startEditShape: startEditShape, - undoEditShape: undoEditShape, - finishEditShape: finishEditShape, + startShapeEdit: startShapeEdit, + undoShapeEdit: undoShapeEdit, + finishShapeEdit: finishShapeEdit, redrawShape: redrawShape }); }; @@ -608,7 +608,7 @@ * @param data * @param shape */ - var startEditShape = function (data, shape) { + var startShapeEdit = function (data, shape) { shape.properties.editable = true; shape.savecoords = shape.geometry.coordinates.slice(0); // clone coords redrawShape(data, shape); @@ -620,7 +620,7 @@ * @param data * @param shape */ - var finishEditShape = function (data, shape) { + var finishShapeEdit = function (data, shape) { shape.properties.editable = false; redrawShape(data, shape); }; @@ -631,9 +631,9 @@ * @param data * @param shape */ - var undoEditShape = function (data, shape) { + var undoShapeEdit = function (data, shape) { shape.geometry.coordinates = shape.savecoords; - finishEditShape(data, shape); + finishShapeEdit(data, shape); }; /**