Use apiOptionsGet instead of optionsLoad

This commit is contained in:
toasted-nutbread 2019-09-07 15:59:10 -04:00
parent 99cec1d23f
commit 4686a31a0a
2 changed files with 22 additions and 8 deletions

View File

@ -22,7 +22,8 @@ $(document).ready(utilAsync(() => {
$('#open-options').click(() => apiCommandExec('options')); $('#open-options').click(() => apiCommandExec('options'));
$('#open-help').click(() => apiCommandExec('help')); $('#open-help').click(() => apiCommandExec('help'));
optionsLoad().then(options => { const optionsContext = {depth: 0};
apiOptionsGet(optionsContext).then(options => {
const toggle = $('#enable-search'); const toggle = $('#enable-search');
toggle.prop('checked', options.general.enable).change(); toggle.prop('checked', options.general.enable).change();
toggle.bootstrapToggle(); toggle.bootstrapToggle();

View File

@ -16,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
function getOptionsContext() {
return {
depth: 0
};
}
async function formRead(options) { async function formRead(options) {
options.general.showGuide = $('#show-usage-guide').prop('checked'); options.general.showGuide = $('#show-usage-guide').prop('checked');
@ -137,7 +142,8 @@ async function onFormOptionsChanged(e) {
return; return;
} }
const options = await optionsLoad(); const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
const optionsAnkiEnableOld = options.anki.enable; const optionsAnkiEnableOld = options.anki.enable;
const optionsAnkiServerOld = options.anki.server; const optionsAnkiServerOld = options.anki.server;
@ -163,7 +169,8 @@ async function onFormOptionsChanged(e) {
} }
async function onReady() { async function onReady() {
const options = await optionsLoad(); const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
$('#show-usage-guide').prop('checked', options.general.showGuide); $('#show-usage-guide').prop('checked', options.general.showGuide);
$('#compact-tags').prop('checked', options.general.compactTags); $('#compact-tags').prop('checked', options.general.compactTags);
@ -374,7 +381,8 @@ async function onDictionaryPurge(e) {
dictionarySpinnerShow(true); dictionarySpinnerShow(true);
await utilDatabasePurge(); await utilDatabasePurge();
const options = await optionsLoad(); const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
options.dictionaries = {}; options.dictionaries = {};
options.general.mainDictionary = ''; options.general.mainDictionary = '';
await optionsSave(options); await optionsSave(options);
@ -414,8 +422,9 @@ async function onDictionaryImport(e) {
setProgress(0.0); setProgress(0.0);
const exceptions = []; const exceptions = [];
const options = await optionsLoad();
const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions); const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions);
const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
options.dictionaries[summary.title] = {enabled: true, priority: 0, allowSecondarySearches: false}; options.dictionaries[summary.title] = {enabled: true, priority: 0, allowSecondarySearches: false};
if (summary.sequenced && options.general.mainDictionary === '') { if (summary.sequenced && options.general.mainDictionary === '') {
options.general.mainDictionary = summary.title; options.general.mainDictionary = summary.title;
@ -566,7 +575,8 @@ async function onAnkiModelChanged(e) {
const tab = element.closest('.tab-pane'); const tab = element.closest('.tab-pane');
const tabId = tab.attr('id'); const tabId = tab.attr('id');
const options = await optionsLoad(); const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
await formRead(options); await formRead(options);
options.anki[tabId].fields = {}; options.anki[tabId].fields = {};
await optionsSave(options); await optionsSave(options);
@ -584,8 +594,11 @@ async function onAnkiModelChanged(e) {
async function onAnkiFieldTemplatesReset(e) { async function onAnkiFieldTemplatesReset(e) {
try { try {
e.preventDefault(); e.preventDefault();
const options = await optionsLoad(); const optionsContext = getOptionsContext();
$('#field-templates').val(options.anki.fieldTemplates = optionsFieldTemplates()); const options = await apiOptionsGet(optionsContext);
const fieldTemplates = optionsFieldTemplates();
options.anki.fieldTemplates = fieldTemplates;
$('#field-templates').val(fieldTemplates);
await optionsSave(options); await optionsSave(options);
} catch (e) { } catch (e) {
ankiErrorShow(e); ankiErrorShow(e);