From 6c7b63abae7b51c12f75e6ea5e6ea2b9cf8e5346 Mon Sep 17 00:00:00 2001 From: Jeremy Press Date: Wed, 20 Sep 2017 10:35:01 -0700 Subject: [PATCH] Fix: Hookup cancel button (#404) * Fix: Hookup cancel button --- src/lib/annotations/drawing/DrawingModeController.js | 11 +++++++++++ .../drawing/__tests__/DrawingModeController-test.js | 12 ++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/lib/annotations/drawing/DrawingModeController.js b/src/lib/annotations/drawing/DrawingModeController.js index d2319403f..6dc47d5c9 100644 --- a/src/lib/annotations/drawing/DrawingModeController.js +++ b/src/lib/annotations/drawing/DrawingModeController.js @@ -4,6 +4,7 @@ import * as annotatorUtil from '../annotatorUtil'; import { TYPES, STATES, + SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL, SELECTOR_ANNOTATION_BUTTON_DRAW_POST, SELECTOR_ANNOTATION_BUTTON_DRAW_UNDO, SELECTOR_ANNOTATION_BUTTON_DRAW_REDO, @@ -19,6 +20,9 @@ class DrawingModeController extends AnnotationModeController { /** @property {DrawingThread} - The currently selected DrawingThread */ selectedThread; + /** @property {HTMLElement} - The button to cancel the pending drawing thread */ + cancelButtonEl; + /** @property {HTMLElement} - The button to commit the pending drawing thread */ postButtonEl; @@ -39,6 +43,7 @@ class DrawingModeController extends AnnotationModeController { registerAnnotator(annotator) { super.registerAnnotator(annotator); + this.cancelButtonEl = annotator.getAnnotateButton(SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL); this.postButtonEl = annotator.getAnnotateButton(SELECTOR_ANNOTATION_BUTTON_DRAW_POST); this.undoButtonEl = annotator.getAnnotateButton(SELECTOR_ANNOTATION_BUTTON_DRAW_UNDO); this.redoButtonEl = annotator.getAnnotateButton(SELECTOR_ANNOTATION_BUTTON_DRAW_REDO); @@ -158,6 +163,12 @@ class DrawingModeController extends AnnotationModeController { ['mouseup', 'touchcancel', 'touchend'], annotatorUtil.eventToLocationHandler(locationFunction, this.currentThread.handleStop) ); + + this.pushElementHandler(this.cancelButtonEl, 'click', () => { + this.currentThread.cancelUnsavedAnnotation(); + this.annotator.toggleAnnotationHandler(TYPES.draw); + }); + this.pushElementHandler(this.postButtonEl, 'click', () => { this.currentThread.saveAnnotation(TYPES.draw); this.annotator.toggleAnnotationHandler(TYPES.draw); diff --git a/src/lib/annotations/drawing/__tests__/DrawingModeController-test.js b/src/lib/annotations/drawing/__tests__/DrawingModeController-test.js index 95266ef58..e4eb1ad30 100644 --- a/src/lib/annotations/drawing/__tests__/DrawingModeController-test.js +++ b/src/lib/annotations/drawing/__tests__/DrawingModeController-test.js @@ -23,15 +23,17 @@ describe('lib/annotations/drawing/DrawingModeController', () => { const annotator = { getAnnotateButton: sandbox.stub() }; - annotator.getAnnotateButton.onCall(0).returns('postButton'); - annotator.getAnnotateButton.onCall(1).returns('undoButton'); - annotator.getAnnotateButton.onCall(2).returns('redoButton'); + annotator.getAnnotateButton.onCall(0).returns('cancelButton'); + annotator.getAnnotateButton.onCall(1).returns('postButton'); + annotator.getAnnotateButton.onCall(2).returns('undoButton'); + annotator.getAnnotateButton.onCall(3).returns('redoButton'); expect(drawingModeController.postButtonEl).to.be.undefined; expect(drawingModeController.undoButtonEl).to.be.undefined; expect(drawingModeController.redoButtonEl).to.be.undefined; drawingModeController.registerAnnotator(annotator); + annotator.getAnnotateButton.onCall(0).returns('cancelButton'); expect(drawingModeController.postButtonEl).to.equal('postButton'); expect(drawingModeController.redoButtonEl).to.equal('redoButton'); expect(drawingModeController.undoButtonEl).to.equal('undoButton'); @@ -139,11 +141,13 @@ describe('lib/annotations/drawing/DrawingModeController', () => { drawingModeController.postButtonEl = 'not undefined'; drawingModeController.undoButtonEl = 'also not undefined'; drawingModeController.redoButtonEl = 'additionally not undefined'; + drawingModeController.cancelButtonEl = 'definitely not undefined'; + drawingModeController.setupHandlers(); expect(stubs.createThread).to.be.called; expect(stubs.bindCustomListenersOnThread).to.be.called; - expect(drawingModeController.handlers.length).to.equal(6); + expect(drawingModeController.handlers.length).to.equal(7); }); });