Note adding now possible
This commit is contained in:
parent
4a6055d781
commit
80f5699d86
@ -48,3 +48,7 @@ function bgGetState(callback) {
|
|||||||
function bgCanAddNotes(definitions, modes, callback) {
|
function bgCanAddNotes(definitions, modes, callback) {
|
||||||
bgSendMessage('canAddNotes', {definitions, modes}, callback);
|
bgSendMessage('canAddNotes', {definitions, modes}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bgAddNote(definition, mode, callback) {
|
||||||
|
bgSendMessage('addNote', {definition: definition, mode: mode}, callback);
|
||||||
|
}
|
||||||
|
@ -81,7 +81,7 @@ class Client {
|
|||||||
|
|
||||||
onFrameMessage(e) {
|
onFrameMessage(e) {
|
||||||
const {action, params} = e.data, handlers = {
|
const {action, params} = e.data, handlers = {
|
||||||
addNote: ({mode, index}) => this.actionAddNote(mode, index, (data) => e.source.postMessage(data, e.origin)),
|
addNote: ({mode, index}) => this.actionAddNote(index, mode, (data) => e.source.postMessage(data, e.origin)),
|
||||||
displayKanji: this.actionDisplayKanji
|
displayKanji: this.actionDisplayKanji
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,10 +117,7 @@ class Client {
|
|||||||
|
|
||||||
bgCanAddNotes(definitions, ['vocabExp', 'vocabReading'], (states) => {
|
bgCanAddNotes(definitions, ['vocabExp', 'vocabReading'], (states) => {
|
||||||
if (states !== null) {
|
if (states !== null) {
|
||||||
states.forEach((state, index) => this.popup.sendMessage(
|
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index: index, state: state, sequence: sequence}));
|
||||||
'setActionState',
|
|
||||||
{index: index, state: state, sequence: sequence}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -129,14 +126,18 @@ class Client {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
actionAddNote(mode, index, callback) {
|
actionAddNote(index, mode, callback) {
|
||||||
const state = {};
|
const state = {};
|
||||||
state[mode] = false;
|
state[mode] = false;
|
||||||
|
|
||||||
this.popup.sendMessage(
|
bgAddNote(this.definitions[index], mode, (success) => {
|
||||||
'setActionState',
|
if (success) {
|
||||||
{index: index, state: state, sequence: this.sequence}
|
this.popup.sendMessage('setActionState', {index: index, state: state, sequence: this.sequence});
|
||||||
);
|
} else {
|
||||||
|
alert('Note could not be added');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actionDisplayKanji(kanji) {
|
actionDisplayKanji(kanji) {
|
||||||
@ -151,10 +152,7 @@ class Client {
|
|||||||
|
|
||||||
bgCanAddNotes(definitions, ['kanji'], (states) => {
|
bgCanAddNotes(definitions, ['kanji'], (states) => {
|
||||||
if (states !== null) {
|
if (states !== null) {
|
||||||
states.forEach((state, index) => this.popup.sendMessage(
|
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index: index, state: state, sequence: sequence}));
|
||||||
'setActionState',
|
|
||||||
{index: index, state: state, sequence: sequence}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user