diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-01-31 08:38:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 13:38:30 +0000 |
commit | 87ed7c8affd3ade9d3cd2d9ed1a61dd5f224e473 (patch) | |
tree | be727294e31ef21e8a3f634734610e69e4a155ac /ext/js/pages/settings/anki-controller.js | |
parent | 3e419aa562aab03ca20421aaf7e4d1a39194a5b4 (diff) |
Module refactoring (#588)
* Convert PronunciationGenerator into static functions
* Convert DictionaryDataUtil into static functions
* Convert AnkiNoteDataCreator into static functions
* Convert MediaUtil into static functions
* Convert RegexUtil into static functions
* Convert StringUtil into static functions
* Convert ArrayBufferUtil into static functions
* Convert AnkiUtil into static functions
* Convert PermissionsUtil into static functions
* Convert ProfileConditionsUtil into static functions
Diffstat (limited to 'ext/js/pages/settings/anki-controller.js')
-rw-r--r-- | ext/js/pages/settings/anki-controller.js | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/ext/js/pages/settings/anki-controller.js b/ext/js/pages/settings/anki-controller.js index d1faf491..09ab3c03 100644 --- a/ext/js/pages/settings/anki-controller.js +++ b/ext/js/pages/settings/anki-controller.js @@ -21,7 +21,8 @@ import {EventListenerCollection} from '../../core/event-listener-collection.js'; import {ExtensionError} from '../../core/extension-error.js'; import {log} from '../../core/logger.js'; import {toError} from '../../core/to-error.js'; -import {AnkiUtil} from '../../data/anki-util.js'; +import {stringContainsAnyFieldMarker} from '../../data/anki-util.js'; +import {getRequiredPermissionsForAnkiFieldValue, hasPermissions, setPermissionsGranted} from '../../data/permissions-util.js'; import {querySelectorNotNull} from '../../dom/query-selector.js'; import {SelectorObserver} from '../../dom/selector-observer.js'; import {ObjectPropertyAccessor} from '../../general/object-property-accessor.js'; @@ -211,7 +212,7 @@ export class AnkiController { * @returns {string[]} */ getRequiredPermissions(fieldValue) { - return this._settingsController.permissionsUtil.getRequiredPermissionsForAnkiFieldValue(fieldValue); + return getRequiredPermissionsForAnkiFieldValue(fieldValue); } // Private @@ -738,7 +739,7 @@ class AnkiCardController { */ _validateField(node, index) { let valid = (node.dataset.hasPermissions !== 'false'); - if (valid && index === 0 && !AnkiUtil.stringContainsAnyFieldMarker(node.value)) { + if (valid && index === 0 && !stringContainsAnyFieldMarker(node.value)) { valid = false; } node.dataset.invalid = `${!valid}`; @@ -936,7 +937,7 @@ class AnkiCardController { */ async _requestPermissions(permissions) { try { - await this._settingsController.permissionsUtil.setPermissionsGranted({permissions}, true); + await setPermissionsGranted({permissions}, true); } catch (e) { log.error(e); } @@ -952,12 +953,12 @@ class AnkiCardController { const permissions = this._ankiController.getRequiredPermissions(fieldValue); if (permissions.length > 0) { node.dataset.requiredPermission = permissions.join(' '); - const hasPermissions = await ( + const hasPermissions2 = await ( request ? - this._settingsController.permissionsUtil.setPermissionsGranted({permissions}, true) : - this._settingsController.permissionsUtil.hasPermissions({permissions}) + setPermissionsGranted({permissions}, true) : + hasPermissions({permissions}) ); - node.dataset.hasPermissions = `${hasPermissions}`; + node.dataset.hasPermissions = `${hasPermissions2}`; } else { delete node.dataset.requiredPermission; delete node.dataset.hasPermissions; @@ -977,15 +978,15 @@ class AnkiCardController { if (typeof requiredPermission !== 'string') { continue; } const requiredPermissionArray = (requiredPermission.length === 0 ? [] : requiredPermission.split(' ')); - let hasPermissions = true; + let hasPermissions2 = true; for (const permission of requiredPermissionArray) { if (!permissionsSet.has(permission)) { - hasPermissions = false; + hasPermissions2 = false; break; } } - inputField.dataset.hasPermissions = `${hasPermissions}`; + inputField.dataset.hasPermissions = `${hasPermissions2}`; this._validateField(inputField, i); } } |