diff options
author | Alex Yatskov <FooSoft@users.noreply.github.com> | 2019-09-16 18:32:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-16 18:32:01 -0700 |
commit | e3fb9603e22c5cbdc7cdf00b60e8ccbf1c7e2116 (patch) | |
tree | 912db53d6c496d8b2f26178db091aaaaaba729b4 /ext/bg/js/settings.js | |
parent | ae696c32eb572b3824cadcf3ab8852725c793191 (diff) | |
parent | 9fb89d8f7d77dd70b2493f730d8b224c994a6e98 (diff) |
Merge pull request #209 from toasted-nutbread/settings-profiles
Settings profiles
Diffstat (limited to 'ext/bg/js/settings.js')
-rw-r--r-- | ext/bg/js/settings.js | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 3d581ba5..cb3ddd4e 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -16,10 +16,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -function getOptionsContext() { - return { - depth: 0 - }; +async function getOptionsArray() { + const optionsFull = await apiOptionsGetFull(); + return optionsFull.profiles.map(profile => profile.options); } async function formRead(options) { @@ -239,11 +238,8 @@ async function onFormOptionsChanged(e) { } async function onReady() { - const optionsContext = getOptionsContext(); - const options = await apiOptionsGet(optionsContext); - formSetupEventListeners(); - await formWrite(options); + await profileOptionsSetup(); storageInfoInitialize(); @@ -424,12 +420,14 @@ async function onDictionaryPurge(e) { dictionarySpinnerShow(true); await utilDatabasePurge(); - const optionsContext = getOptionsContext(); - const options = await apiOptionsGet(optionsContext); - options.dictionaries = utilBackgroundIsolate({}); - options.general.mainDictionary = ''; + for (const options of await getOptionsArray()) { + options.dictionaries = utilBackgroundIsolate({}); + options.general.mainDictionary = ''; + } await settingsSaveOptions(); + const optionsContext = getOptionsContext(); + const options = await apiOptionsGet(optionsContext); await dictionaryGroupsPopulate(options); await formMainDictionaryOptionsPopulate(options); } catch (e) { @@ -466,24 +464,25 @@ async function onDictionaryImport(e) { const exceptions = []; const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions); - const optionsContext = getOptionsContext(); - const options = await apiOptionsGet(optionsContext); - options.dictionaries[summary.title] = utilBackgroundIsolate({ - enabled: true, - priority: 0, - allowSecondarySearches: false - }); - if (summary.sequenced && options.general.mainDictionary === '') { - options.general.mainDictionary = summary.title; + for (const options of await getOptionsArray()) { + options.dictionaries[summary.title] = utilBackgroundIsolate({ + enabled: true, + priority: 0, + allowSecondarySearches: false + }); + if (summary.sequenced && options.general.mainDictionary === '') { + options.general.mainDictionary = summary.title; + } } + await settingsSaveOptions(); if (exceptions.length > 0) { exceptions.push(`Dictionary may not have been imported properly: ${exceptions.length} error${exceptions.length === 1 ? '' : 's'} reported.`); dictionaryErrorsShow(exceptions); } - await settingsSaveOptions(); - + const optionsContext = getOptionsContext(); + const options = await apiOptionsGet(optionsContext); await dictionaryGroupsPopulate(options); await formMainDictionaryOptionsPopulate(options); } catch (e) { @@ -643,7 +642,7 @@ async function onAnkiFieldTemplatesReset(e) { e.preventDefault(); const optionsContext = getOptionsContext(); const options = await apiOptionsGet(optionsContext); - const fieldTemplates = optionsFieldTemplates(); + const fieldTemplates = profileOptionsGetDefaultFieldTemplates(); options.anki.fieldTemplates = fieldTemplates; $('#field-templates').val(fieldTemplates); await settingsSaveOptions(); |