diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-05-30 09:33:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-30 09:33:13 -0400 |
commit | 63a3e56367b95f7ea64a5701d17179de60ed8718 (patch) | |
tree | fc811028b127abf9c1ff1dbdbb4663ba70b60649 /ext/bg/js/settings/generic-setting-controller.js | |
parent | 1a5a37c9e47dc4d1f1e1b3ffaf990e792140b912 (diff) |
Use SettingsController (#576)
* Use settingsController internally in settings/main.js
* Replace modifyingProfileChange with SettingsController.optionsContextChanged
* Update ClipboardPopupsController to use SettingsController
* Store reference to checkbox
* Use this._settingsController for everything
* Change where current profile is initially assigned from
* Remove some unnecessary async calls
* Move setup calls
* Update AnkiTemplatesController to use SettingsController
* Cache default field templates
* Update AnkiController to use SettingsController
* Update AudioController to use SettingsController
* Update SettingsBackup to use SettingsController
* Update DictionaryController to use SettingsController
* Update GenericSettingController to use SettingsController
* Update ProfileController to use SettingsController
* Remove unused
* Remove unused
* Replace some uses of api.options* functions
* Fix missing awaits
* Fix invalid function
Diffstat (limited to 'ext/bg/js/settings/generic-setting-controller.js')
-rw-r--r-- | ext/bg/js/settings/generic-setting-controller.js | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/ext/bg/js/settings/generic-setting-controller.js b/ext/bg/js/settings/generic-setting-controller.js index 4a20bf65..d7d40c5d 100644 --- a/ext/bg/js/settings/generic-setting-controller.js +++ b/ext/bg/js/settings/generic-setting-controller.js @@ -16,24 +16,26 @@ */ /* globals - * getOptionsContext - * getOptionsMutable - * settingsSaveOptions * utilBackgroundIsolate */ class GenericSettingController { - prepare() { - $('input, select, textarea').not('.anki-model').not('.ignore-form-changes *').change(this._onFormOptionsChanged.bind(this)); + constructor(settingsController) { + this._settingsController = settingsController; } - optionsChanged(options) { - this._formWrite(options); + async prepare() { + $('input, select, textarea').not('.anki-model').not('.ignore-form-changes *').change(this._onFormOptionsChanged.bind(this)); + + this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); + + const options = await this._settingsController.getOptions(); + this._onOptionsChanged({options}); } // Private - async _formWrite(options) { + _onOptionsChanged({options}) { $('#enable').prop('checked', options.general.enable); $('#show-usage-guide').prop('checked', options.general.showGuide); $('#compact-tags').prop('checked', options.general.compactTags); @@ -107,7 +109,7 @@ class GenericSettingController { this._formUpdateVisibility(options); } - async _formRead(options) { + _formRead(options) { options.general.enable = $('#enable').prop('checked'); options.general.showGuide = $('#show-usage-guide').prop('checked'); options.general.compactTags = $('#compact-tags').prop('checked'); @@ -180,12 +182,10 @@ class GenericSettingController { } async _onFormOptionsChanged() { - const optionsContext = getOptionsContext(); - const options = await getOptionsMutable(optionsContext); - - await this._formRead(options); - await settingsSaveOptions(); + const options = await this._settingsController.getOptionsMutable(); + this._formRead(options); this._formUpdateVisibility(options); + await this._settingsController.save(); } _formUpdateVisibility(options) { |