From de2029fb7aca268bc21116703c79119012550368 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 11 Aug 2016 20:56:49 -0700 Subject: [PATCH] WIP --- ext/bg/js/options-form.js | 53 ++++++++++++++++++++++++++++++--------- ext/bg/options.html | 4 --- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index bb9f762b..979f5377 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -31,7 +31,17 @@ function fieldsToDict(selection) { } function modelIdToFieldOptKey(id) { - return {'anki-term-model': 'ankiTermFields', 'anki-kanji-model': 'ankiKanjiFields'}[id]; + return { + 'anki-term-model': 'ankiTermFields', + 'anki-kanji-model': 'ankiKanjiFields' + }[id]; +} + +function modelIdToTags(id) { + return { + 'anki-term-model': ['audio', 'expression', 'glossary', 'glossary-list', 'reading', 'sentence', 'tags', 'url'], + 'anki-kanji-model': ['character', 'glossary', 'glossary-list', 'kunyomi', 'onyomi', 'url'], + }[id]; } function formToOptions(section, callback) { @@ -111,33 +121,50 @@ function populateAnkiFields(element, opts) { return; } - const optKey = modelIdToFieldOptKey(element.attr('id')); + const modelId = element.attr('id'); + const optKey = modelIdToFieldOptKey(modelId); + const tags = modelIdToTags(modelId); + yomichan().api_getModelFieldNames({modelName, callback: (names) => { const table = element.closest('.tab-pane').find('.anki-fields'); table.find('tbody').remove(); - const body = $(''); + const tbody = $(''); names.forEach((name) => { + const button = $('