diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-07-01 18:27:49 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-07-01 18:27:49 -0700 |
commit | d57c5530b7ad56a7cc89782b4d186d8fddb55d86 (patch) | |
tree | 09cce1fded053b04ea716c2d4d44fb4676b24800 /ext/mixed/js | |
parent | 390cb12896607144fcd1046950f3a2aa680db71b (diff) |
view added notes
Diffstat (limited to 'ext/mixed/js')
-rw-r--r-- | ext/mixed/js/display.js | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 7982c69f..da0cd351 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -40,6 +40,10 @@ class Display { throw 'override me'; } + noteView(noteId) { + throw 'override me'; + } + templateRender(template, data) { throw 'override me'; } @@ -88,6 +92,7 @@ class Display { this.entryScroll(context && context.index || 0); $('.action-add-note').click(this.onAddNote.bind(this)); + $('.action-view-note').click(this.onViewNote.bind(this)); $('.action-play-audio').click(this.onPlayAudio.bind(this)); $('.kanji-link').click(this.onKanjiLookup.bind(this)); @@ -134,7 +139,7 @@ class Display { adderButtonsUpdate(modes, sequence) { return this.definitionsAddable(this.definitions, modes).then(states => { - if (states === null || sequence !== this.sequence) { + if (!states || sequence !== this.sequence) { return; } @@ -211,6 +216,13 @@ class Display { this.noteAdd(this.definitions[index], link.data('mode')); } + onViewNote(e) { + e.preventDefault(); + const link = $(e.currentTarget); + const index = Display.entryIndexFind(link); + this.noteView(link.data('noteId')); + } + onKeyDown(e) { const noteTryAdd = mode => { const button = Display.adderButtonFind(this.index, mode); @@ -219,6 +231,13 @@ class Display { } }; + const noteTryView = mode => { + const button = Display.viewerButtonFind(this.index); + if (button.length !== 0 && !button.hasClass('disabled')) { + this.noteView(button.data('noteId')); + } + }; + const handlers = { 27: /* escape */ () => { this.clearSearch(); @@ -303,6 +322,12 @@ class Display { return true; } + }, + + 86: /* v */ () => { + if (e.altKey) { + noteTryView(); + } } }; @@ -326,10 +351,11 @@ class Display { noteAdd(definition, mode) { this.spinner.show(); - return this.definitionAdd(definition, mode).then(success => { - if (success) { + return this.definitionAdd(definition, mode).then(noteId => { + if (noteId) { const index = this.definitions.indexOf(definition); Display.adderButtonFind(index, mode).addClass('disabled'); + Display.viewerButtonFind(index).removeClass('pending disabled').data('noteId', noteId); } else { this.handleError('note could not be added'); } @@ -375,4 +401,8 @@ class Display { static adderButtonFind(index, mode) { return $('.entry').eq(index).find(`.action-add-note[data-mode="${mode}"]`); } + + static viewerButtonFind(index) { + return $('.entry').eq(index).find('.action-view-note'); + } } |