Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add generalized disable-when-checked controller

Oliver Günther9bb02e5867e1
diff --git a/app/views/users/_general.html.erb b/app/views/users/_general.html.erb
index 8da07090c16..fa8dd6452c9 100644
--- a/app/views/users/_general.html.erb
+++ b/app/views/users/_general.html.erb
@@ -44,11 +44,7 @@ See COPYRIGHT and LICENSE files for more details.
tab: nil },
html: {
method: :put,
- autocomplete: 'off',
- data: {
- controller: 'admin-users',
- 'application-target': 'dynamic'
- }
+ autocomplete: 'off'
},
data: {
controller: 'admin-users',
diff --git a/frontend/src/stimulus/controllers/disable-when-checked.controller.ts b/frontend/src/stimulus/controllers/disable-when-checked.controller.ts
new file mode 100644
index 00000000000..ed67ca2cdf0
--- /dev/null
+++ b/frontend/src/stimulus/controllers/disable-when-checked.controller.ts
@@ -0,0 +1,30 @@
+import { ApplicationController } from 'stimulus-use';
+
+export default class OpDisableWhenCheckedController extends ApplicationController {
+ static targets = ['cause', 'effect'];
+
+ static values = {
+ reversed: Boolean,
+ };
+
+ declare reversedValue:boolean;
+
+ declare readonly hasReversedValue:boolean;
+
+ declare readonly effectTargets:HTMLInputElement[];
+
+ causeTargetConnected(target:HTMLElement) {
+ target.addEventListener('change', this.toggleDisabled.bind(this));
+ }
+
+ causeTargetDisconnected(target:HTMLElement) {
+ target.removeEventListener('change', this.toggleDisabled.bind(this));
+ }
+
+ private toggleDisabled(evt:InputEvent):void {
+ const checked = (evt.target as HTMLInputElement).checked;
+ this.effectTargets.forEach((el) => {
+ el.disabled = (this.hasReversedValue && this.reversedValue) ? !checked : checked;
+ });
+ }
+}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
index 5a52d646213..7e9f45c2813 100644
--- a/frontend/src/stimulus/setup.ts
+++ b/frontend/src/stimulus/setup.ts
@@ -1,6 +1,7 @@
import { Application } from '@hotwired/stimulus';
import { environment } from '../environments/environment';
import { OpApplicationController } from './controllers/op-application.controller';
+import OpDisableWhenCheckedController from './controllers/disable-when-checked.controller';
declare global {
interface Window {
@@ -17,3 +18,4 @@ instance.handleError = (error, message, detail) => {
};
instance.register('application', OpApplicationController);
+instance.register('disable-when-checked', OpDisableWhenCheckedController);