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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix event listener binding
Oliver Günther8fa690be7204
diff --git a/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.ts b/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.tsindex b0a946d02b7..b11f1c1bd05 100644--- a/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.ts+++ b/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.ts@@ -43,6 +43,8 @@ export class WorkPackageReminderModalComponent extends OpModalComponent implemenpublic title$:Observable<string>;+ private boundListener = this.turboSubmitEndListener.bind(this);+constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,readonly cdRef:ChangeDetectorRef,@@ -69,13 +71,13 @@ export class WorkPackageReminderModalComponent extends OpModalComponent implemenngAfterViewInit() {// Use event delegation on a parent element that won't be re-rendered- this.elementRef.nativeElement.addEventListener('turbo:submit-end', this.turboSubmitEndListener.bind(this));+ this.elementRef.nativeElement.addEventListener('turbo:submit-end', this.boundListener);}ngOnDestroy() {super.ngOnDestroy();- this.elementRef.nativeElement.removeEventListener('turbo:submit-end', this.turboSubmitEndListener.bind(this));+ this.elementRef.nativeElement.removeEventListener('turbo:submit-end', this.boundListener);}onClose():boolean {diff --git a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.tsindex 8abf179696e..bfe9678b209 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts+++ b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts@@ -79,6 +79,8 @@ export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponenopened = false;+ private boundListener = this.contextBasedListener.bind(this);+constructor(readonly I18n:I18nService,readonly elementRef:ElementRef,@@ -111,7 +113,7 @@ export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponenthis.frameElement.nativeElement- .addEventListener('turbo:submit-end', this.contextBasedListener.bind(this));+ .addEventListener('turbo:submit-end', this.boundListener);}ngOnDestroy() {@@ -120,7 +122,7 @@ export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponenthis.frameElement.nativeElement- .removeEventListener('turbo:submit-end', this.contextBasedListener.bind(this));+ .removeEventListener('turbo:submit-end', this.boundListener);}public get asHoursOrPercent():string {diff --git a/frontend/src/stimulus/controllers/disable-when-checked.controller.ts b/frontend/src/stimulus/controllers/disable-when-checked.controller.tsindex ed67ca2cdf0..716047e7a1f 100644--- a/frontend/src/stimulus/controllers/disable-when-checked.controller.ts+++ b/frontend/src/stimulus/controllers/disable-when-checked.controller.ts@@ -13,12 +13,14 @@ export default class OpDisableWhenCheckedController extends ApplicationControlledeclare readonly effectTargets:HTMLInputElement[];+ private boundListener = this.toggleDisabled.bind(this);+causeTargetConnected(target:HTMLElement) {- target.addEventListener('change', this.toggleDisabled.bind(this));+ target.addEventListener('change', this.boundListener);}causeTargetDisconnected(target:HTMLElement) {- target.removeEventListener('change', this.toggleDisabled.bind(this));+ target.removeEventListener('change', this.boundListener);}private toggleDisabled(evt:InputEvent):void {diff --git a/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.tsindex 661600cbf03..fb3705db770 100644--- a/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts@@ -88,9 +88,11 @@ export default class FiltersFormController extends Controller {declare performTurboRequestsValue:boolean;declare readonly clearButtonIdValue:string;+ private boundListener = this.sendForm.bind(this);+initialize() {// Initialize runs anytime an element with a controller connected to the DOM for the first time- this.sendForm = debounce(this.sendForm.bind(this), 300);+ this.sendForm = debounce(this.boundListener, 300);this.autoReloadTargets = [...this.simpleValueTargets,...this.operatorTargets,@@ -113,9 +115,9 @@ export default class FiltersFormController extends Controller {if (this.performTurboRequestsValue) {this.autoReloadTargets.forEach((target) => {if (target instanceof HTMLInputElement) {- target.addEventListener('input', this.sendForm.bind(this));+ target.addEventListener('input', this.boundListener);} else {- target.addEventListener('change', this.sendForm.bind(this));+ target.addEventListener('change', this.boundListener);}});}@@ -130,9 +132,9 @@ export default class FiltersFormController extends Controller {if (this.performTurboRequestsValue) {this.autoReloadTargets.forEach((target) => {if (target instanceof HTMLInputElement) {- target.removeEventListener('input', this.sendForm.bind(this));+ target.removeEventListener('input', this.boundListener);} else {- target.removeEventListener('change', this.sendForm.bind(this));+ target.removeEventListener('change', this.boundListener);}});}diff --git a/frontend/src/stimulus/controllers/dynamic/projects/zen-mode.controller.ts b/frontend/src/stimulus/controllers/dynamic/projects/zen-mode.controller.tsindex b512dbc6b20..049063aaac5 100644--- a/frontend/src/stimulus/controllers/dynamic/projects/zen-mode.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/projects/zen-mode.controller.ts@@ -6,13 +6,15 @@ export default class OpProjectsZenModeController extends ApplicationController {declare readonly buttonTarget:HTMLElement;+ private boundHandler = this.fullscreenChangeEventHandler.bind(this);+connect() {- document.addEventListener('fullscreenchange', this.fullscreenChangeEventHandler.bind(this));+ document.addEventListener('fullscreenchange', this.boundHandler);}disconnect() {super.disconnect();- document.removeEventListener('fullscreenchange', this.fullscreenChangeEventHandler.bind(this));+ document.removeEventListener('fullscreenchange', this.boundHandler);}fullscreenChangeEventHandler() {diff --git a/frontend/src/stimulus/controllers/dynamic/shares/user-selected.controller.ts b/frontend/src/stimulus/controllers/dynamic/shares/user-selected.controller.tsindex c1a0e088775..92394ac557a 100644--- a/frontend/src/stimulus/controllers/dynamic/shares/user-selected.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/shares/user-selected.controller.ts@@ -43,12 +43,14 @@ export default class UserSelectedController extends Controller {private selectedValues:IUserAutocompleteItem[] = [];+ private boundListener = this.handleValueSelected.bind(this);+connect() {- this.autocompleterElement.addEventListener('change', this.handleValueSelected.bind(this));+ this.autocompleterElement.addEventListener('change', this.boundListener);}disconnect() {- this.autocompleterElement.removeEventListener('change', this.handleValueSelected.bind(this));+ this.autocompleterElement.removeEventListener('change', this.boundListener);}ensureUsersSelected(evt:CustomEvent):void {diff --git a/frontend/src/stimulus/controllers/show-when-checked.controller.ts b/frontend/src/stimulus/controllers/show-when-checked.controller.tsindex 1674cc7a527..4646bbd20ea 100644--- a/frontend/src/stimulus/controllers/show-when-checked.controller.ts+++ b/frontend/src/stimulus/controllers/show-when-checked.controller.ts@@ -13,12 +13,14 @@ export default class OpShowWhenCheckedController extends ApplicationController {declare readonly effectTargets:HTMLInputElement[];+ private boundListener = this.toggleDisabled.bind(this);+causeTargetConnected(target:HTMLElement) {- target.addEventListener('change', this.toggleDisabled.bind(this));+ target.addEventListener('change', this.boundListener);}causeTargetDisconnected(target:HTMLElement) {- target.removeEventListener('change', this.toggleDisabled.bind(this));+ target.removeEventListener('change', this.boundListener);}private toggleDisabled(evt:InputEvent):void {diff --git a/frontend/src/stimulus/controllers/show-when-value-selected.controller.ts b/frontend/src/stimulus/controllers/show-when-value-selected.controller.tsindex d29ae2c9c33..821f07e42ee 100644--- a/frontend/src/stimulus/controllers/show-when-value-selected.controller.ts+++ b/frontend/src/stimulus/controllers/show-when-value-selected.controller.ts@@ -5,12 +5,14 @@ export default class OpShowWhenValueSelectedController extends ApplicationControdeclare readonly effectTargets:HTMLInputElement[];+ private boundListener = this.toggleDisabled.bind(this);+causeTargetConnected(target:HTMLElement) {- target.addEventListener('change', this.toggleDisabled.bind(this));+ target.addEventListener('change', this.boundListener);}causeTargetDisconnected(target:HTMLElement) {- target.removeEventListener('change', this.toggleDisabled.bind(this));+ target.removeEventListener('change', this.boundListener);}private toggleDisabled(evt:InputEvent):void {