Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit 55433eb

Browse files
committed
Make sure the user has enabled at least one feature
1 parent b6c9f3a commit 55433eb

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

js/options.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
}).checked = true;
6767

6868
self.enableButtonToToggleWipStatusCheckbox.checked = preferences.enable_button_to_toggle_wip_status;
69+
self.enableButtonToToggleWipStatusCheckbox.dispatchEvent(new CustomEvent('change'));
6970
});
7071
}
7172

@@ -78,6 +79,10 @@
7879
this.optionsForm.addEventListener('submit', function(e) {
7980
e.preventDefault();
8081

82+
if (self.hasUserDisabledAllFeatures()) {
83+
return false;
84+
}
85+
8186
if (!self.initializeVisualFeedbackOnSubmitButton()) {
8287
return false;
8388
}
@@ -149,22 +154,26 @@
149154
* the extension (which is useless).
150155
*/
151156
forceUserToEnableAtLeastOneFeatureIfNecessarily() {
152-
let hasUserDisabledAllFeatures = !this.displaySourceAndTargetBranchesCheckbox.checked
157+
if (this.hasUserDisabledAllFeatures() && !this.submitButtonInOptionsForm.disabled) {
158+
this.submitButtonInOptionsForm.disabled = true;
159+
this.submitButtonInOptionsForm.dataset.originalTextContent = this.submitButtonInOptionsForm.textContent;
160+
this.submitButtonInOptionsForm.textContent = '⚠️ Please enable at least one feature';
161+
} else if (this.submitButtonInOptionsForm.disabled) {
162+
this.submitButtonInOptionsForm.disabled = false;
163+
this.submitButtonInOptionsForm.textContent = this.submitButtonInOptionsForm.dataset.originalTextContent;
164+
165+
delete this.submitButtonInOptionsForm.dataset.originalTextContent;
166+
}
167+
}
168+
169+
/**
170+
* Determine if the user has disabled all the features of the extension (which is useless).
171+
*/
172+
hasUserDisabledAllFeatures() {
173+
return !this.displaySourceAndTargetBranchesCheckbox.checked
153174
&& !this.enableButtonToCopyMrInfoCheckbox.checked
154175
&& !this.enableJiraTicketLinkCheckbox.checked
155176
&& !this.enableButtonToToggleWipStatusCheckbox.checked;
156-
157-
if (hasUserDisabledAllFeatures) {
158-
this.displaySourceAndTargetBranchesCheckbox.required = true;
159-
this.enableButtonToCopyMrInfoCheckbox.required = true;
160-
this.enableJiraTicketLinkCheckbox.required = true;
161-
this.enableButtonToToggleWipStatusCheckbox.required = true;
162-
} else {
163-
this.displaySourceAndTargetBranchesCheckbox.required = false;
164-
this.enableButtonToCopyMrInfoCheckbox.required = false;
165-
this.enableJiraTicketLinkCheckbox.required = false;
166-
this.enableButtonToToggleWipStatusCheckbox.required = false;
167-
}
168177
}
169178

170179
/**

0 commit comments

Comments
 (0)