summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-10-17 20:59:54 -0700
committerAlex Yatskov <alex@foosoft.net>2016-10-17 20:59:54 -0700
commitde33a19498b38dcb8254654fb94bba3b7142a153 (patch)
tree3e3afa6447cc899b4f7edae3b83384cc44a45525
parent9d1756a2a869e880457589a28d6992f5b8868c7f (diff)
WIP
-rw-r--r--ext/bg/js/ankiweb.js21
1 files changed, 20 insertions, 1 deletions
diff --git a/ext/bg/js/ankiweb.js b/ext/bg/js/ankiweb.js
index 17b5525e..35f4858e 100644
--- a/ext/bg/js/ankiweb.js
+++ b/ext/bg/js/ankiweb.js
@@ -24,7 +24,26 @@ class AnkiWeb {
}
addNote(note) {
- return Promise.resolve(true);
+ return this.retrieve().then(info => {
+ const model = info.models.find(m => m.name === note.modelName);
+ if (!model) {
+ return Promise.reject('invalid model');
+ }
+
+ const fields = [];
+ for (const field of model.fields) {
+ fields.push(note.fields[field]);
+ }
+
+ const form = new FormData();
+ form.append('data', [fields, note.tags.join(' ')]);
+ form.append('mid', model.id);
+ form.append('deck', note.deckname);
+
+ return AnkiWeb.loadAccountPage('https://ankiweb.net/edit/save', 'POST', form, this.username, this.password);
+ }).then(response => {
+ return true;
+ });
}
canAddNotes(notes) {