summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-14 21:18:22 -0500
committerGitHub <noreply@github.com>2021-01-14 21:18:22 -0500
commita97fbcde83dbafb147e936ff1ca720afab3bdc0a (patch)
tree2726672f75969916bf04d770593eb44f3cd42ffd /ext/bg/js
parent84d3af0f8d26e06efb01e47a504d510f22caa970 (diff)
Add reset input to profile condition (#1237)
* Add _setType and _setOperator * Add reset value menu option
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/settings/profile-conditions-ui.js61
1 files changed, 40 insertions, 21 deletions
diff --git a/ext/bg/js/settings/profile-conditions-ui.js b/ext/bg/js/settings/profile-conditions-ui.js
index 77c9db77..5db823af 100644
--- a/ext/bg/js/settings/profile-conditions-ui.js
+++ b/ext/bg/js/settings/profile-conditions-ui.js
@@ -485,32 +485,13 @@ class ProfileConditionUI {
_onTypeChange(e) {
const type = e.currentTarget.value;
- const operators = this._getDescriptorOperators(type);
- const operator = operators.length > 0 ? operators[0].name : '';
- const operatorDetails = this._getOperatorDetails(type, operator);
- const {defaultValue} = operatorDetails;
- this._updateSelect(this._operatorInput, this._operatorOptionContainer, operators, operator);
- this._updateValueInput(defaultValue, operatorDetails);
- this.settingsController.modifyGlobalSettings([
- {action: 'set', path: this.getPath('type'), value: type},
- {action: 'set', path: this.getPath('operator'), value: operator},
- {action: 'set', path: this.getPath('value'), value: defaultValue}
- ]);
+ this._setType(type);
}
_onOperatorChange(e) {
const type = this._typeInput.value;
const operator = e.currentTarget.value;
- const operatorDetails = this._getOperatorDetails(type, operator);
- const settingsModifications = [{action: 'set', path: this.getPath('operator'), value: operator}];
- if (operatorDetails.resetDefaultOnChange) {
- const {defaultValue} = operatorDetails;
- const okay = this._updateValueInput(defaultValue, operatorDetails);
- if (okay) {
- settingsModifications.push({action: 'set', path: this.getPath('value'), value: defaultValue});
- }
- }
- this.settingsController.modifyGlobalSettings(settingsModifications);
+ this._setOperator(type, operator);
}
_onValueInputChange({validate, normalize}, e) {
@@ -544,6 +525,9 @@ class ProfileConditionUI {
case 'delete':
this._removeSelf();
break;
+ case 'resetValue':
+ this._resetValue();
+ break;
}
}
@@ -654,4 +638,39 @@ class ProfileConditionUI {
_joinModifiers(modifiersArray) {
return modifiersArray.join(', ');
}
+
+ async _setType(type, operator) {
+ const operators = this._getDescriptorOperators(type);
+ if (typeof operator === 'undefined') {
+ operator = operators.length > 0 ? operators[0].name : '';
+ }
+ const operatorDetails = this._getOperatorDetails(type, operator);
+ const {defaultValue} = operatorDetails;
+ this._updateSelect(this._operatorInput, this._operatorOptionContainer, operators, operator);
+ this._updateValueInput(defaultValue, operatorDetails);
+ await this.settingsController.modifyGlobalSettings([
+ {action: 'set', path: this.getPath('type'), value: type},
+ {action: 'set', path: this.getPath('operator'), value: operator},
+ {action: 'set', path: this.getPath('value'), value: defaultValue}
+ ]);
+ }
+
+ async _setOperator(type, operator) {
+ const operatorDetails = this._getOperatorDetails(type, operator);
+ const settingsModifications = [{action: 'set', path: this.getPath('operator'), value: operator}];
+ if (operatorDetails.resetDefaultOnChange) {
+ const {defaultValue} = operatorDetails;
+ const okay = this._updateValueInput(defaultValue, operatorDetails);
+ if (okay) {
+ settingsModifications.push({action: 'set', path: this.getPath('value'), value: defaultValue});
+ }
+ }
+ await this.settingsController.modifyGlobalSettings(settingsModifications);
+ }
+
+ async _resetValue() {
+ const type = this._typeInput.value;
+ const operator = this._operatorInput.value;
+ await this._setType(type, operator);
+ }
}