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
dedicated controller for permanent attribute on focus
ulferts69979b35366f
diff --git a/app/forms/work_packages/progress_form.rb b/app/forms/work_packages/progress_form.rbindex 36cfd5d5ba4..f16bc6bced4 100644--- a/app/forms/work_packages/progress_form.rb+++ b/app/forms/work_packages/progress_form.rb@@ -168,13 +168,20 @@ class WorkPackages::ProgressForm < ApplicationFormenddef default_field_options(name)- data = { "work-packages--progress--preview-progress-target": "progressInput",- "work-packages--progress--touched-field-marker-target": "progressInput",- action: "input->work-packages--progress--touched-field-marker#markFieldAsTouched" }+ data = {+ "work-packages--progress--preview-progress-target": "progressInput",+ "work-packages--progress--touched-field-marker-target": "progressInput",+ "application-target": "dynamic",+ controller: "permanent-on-focus",+ action: "input->work-packages--progress--touched-field-marker#markFieldAsTouched " \+ "focus->permanent-on-focus#togglePermanentAttribute " \+ "blur->permanent-on-focus#togglePermanentAttribute"+ }+if @focused_field == namedata[:"work-packages--progress--focus-field-target"] = "fieldToFocus"# Prevent changes being morphed into the input that is currently focused.- # After this initial rendering, the preview-progress.controller takes over in maintaining+ # After this initial rendering, the permanent-on-focus.controller takes over maintaining# the attribute on the input currently focused.data["turbo-permanent"] = trueenddiff --git a/frontend/src/stimulus/controllers/dynamic/permanent-on-focus.controller.ts b/frontend/src/stimulus/controllers/dynamic/permanent-on-focus.controller.tsindex e69de29bb2d..a68fb9b69d0 100644--- a/frontend/src/stimulus/controllers/dynamic/permanent-on-focus.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/permanent-on-focus.controller.ts@@ -0,0 +1,39 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) 2024 the OpenProject GmbH+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License version 3.+ *+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+ * Copyright (C) 2006-2013 Jean-Philippe Lang+ * Copyright (C) 2010-2013 the ChiliProject Team+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License+ * as published by the Free Software Foundation; either version 2+ * of the License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+ *+ * See COPYRIGHT and LICENSE files for more details.+ * +++ */++import { Controller } from '@hotwired/stimulus';++export default class PermanentOnFocusController extends Controller {+ togglePermanentAttribute(event:FocusEvent) {+ if (event.target) {+ (event.target as HTMLElement).toggleAttribute('data-turbo-permanent', event.type === 'focus');+ }+ }+}diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview-progress.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview-progress.controller.tsindex 00b4c2238b7..3ab71313ac9 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview-progress.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/progress/preview-progress.controller.ts@@ -46,7 +46,6 @@ export default class PreviewProgressController extends Controller {private debouncedPreview:(event:Event) => void;private frameMorphRenderer:(event:CustomEvent<TurboBeforeFrameRenderEventDetail>) => void;- private togglePermanentAttribute:(event:Event) => void;connect() {this.debouncedPreview = debounce((event:Event) => { void this.preview(event); }, 100);@@ -68,16 +67,7 @@ export default class PreviewProgressController extends Controller {};};- this.togglePermanentAttribute = (event:FocusEvent) => {- if (event.target) {- (event.target as HTMLInputElement).toggleAttribute('data-turbo-permanent', event.type === 'focus');- }- };-this.progressInputTargets.forEach((target) => {- target.addEventListener('focus', this.togglePermanentAttribute);- target.addEventListener('blur', this.togglePermanentAttribute);-target.addEventListener('input', this.debouncedPreview);});@@ -88,8 +78,6 @@ export default class PreviewProgressController extends Controller {disconnect() {this.progressInputTargets.forEach((target) => {target.removeEventListener('input', this.debouncedPreview);- target.removeEventListener('focus', this.togglePermanentAttribute);- target.removeEventListener('blur', this.togglePermanentAttribute);});const turboFrame = this.formTarget.closest('turbo-frame') as HTMLFrameElement;turboFrame.removeEventListener('turbo:before-frame-render', this.frameMorphRenderer);