Skip to content

Commit

Permalink
Fix: Hookup cancel button (#404)
Browse files Browse the repository at this point in the history
* Fix: Hookup cancel button
  • Loading branch information
Jeremy Press authored Sep 20, 2017
1 parent 83f8c31 commit 6c7b63a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/lib/annotations/drawing/DrawingModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 6c7b63a

Please sign in to comment.