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

Reload form when changing type

Oliver Güntherdc9b28474d5d
diff --git a/app/components/work_packages/dialogs/create_dialog_component.html.erb b/app/components/work_packages/dialogs/create_dialog_component.html.erb
index 70f2e1ff0d4..b4643d2d510 100644
--- a/app/components/work_packages/dialogs/create_dialog_component.html.erb
+++ b/app/components/work_packages/dialogs/create_dialog_component.html.erb
@@ -3,7 +3,9 @@
id: "create-work-package-dialog",
title: I18n.t(:label_work_package_new),
size: :xlarge,
- data: { 'keep-open-on-submit': true }
+ data: {
+ 'keep-open-on-submit': true,
+ }
)) do |dialog|
dialog.with_header(variant: :large)
dialog.with_body do
diff --git a/app/components/work_packages/dialogs/create_form_component.html.erb b/app/components/work_packages/dialogs/create_form_component.html.erb
index 5f26bad5576..d201487ee99 100644
--- a/app/components/work_packages/dialogs/create_form_component.html.erb
+++ b/app/components/work_packages/dialogs/create_form_component.html.erb
@@ -8,7 +8,9 @@
html: {
id: 'create-work-package-form',
data: {
- controller: "work-packages--create-dialog"
+ controller: "work-packages--create-dialog",
+ application_target: "dynamic",
+ "work-packages--create-dialog-refresh-url-value": refresh_form_project_work_packages_dialog_path(project)
}
}
) do |f|
diff --git a/app/controllers/work_packages/dialogs_controller.rb b/app/controllers/work_packages/dialogs_controller.rb
index c2f7c5c493a..06860cc3b27 100644
--- a/app/controllers/work_packages/dialogs_controller.rb
+++ b/app/controllers/work_packages/dialogs_controller.rb
@@ -35,17 +35,15 @@ class WorkPackages::DialogsController < ApplicationController
before_action :find_project_by_project_id
before_action :build_work_package, only: %i[new]
- before_action do
- do_authorize :add_work_packages
- end
- authorization_checked! :new, :create
+
+ authorize_with_permission :add_work_packages
def new
respond_with_dialog WorkPackages::Dialogs::CreateDialogComponent.new(work_package: @work_package, project: @project)
end
def create
- call = WorkPackages::CreateService.new(user: current_user).call(create_params.merge(project: @project))
+ call = WorkPackages::CreateService.new(user: current_user).call(create_params)
if call.success?
redirect_back fallback_location: project_work_package_path(@project, call.result), status: :see_other
@@ -57,6 +55,19 @@ class WorkPackages::DialogsController < ApplicationController
end
end
+ def refresh_form
+ call = WorkPackages::SetAttributesService.new(
+ user: current_user,
+ model: WorkPackage.new,
+ contract_class: EmptyContract
+ ).call(create_params)
+
+ form_component = WorkPackages::Dialogs::CreateFormComponent.new(work_package: call.result, project: @project)
+ update_via_turbo_stream(component: form_component)
+
+ respond_with_turbo_streams
+ end
+
private
def build_work_package
@@ -76,7 +87,7 @@ class WorkPackages::DialogsController < ApplicationController
end
def create_params
- permitted_params.update_work_package
+ permitted_params.update_work_package.merge(project: @project)
end
def default_params(work_package)
diff --git a/app/forms/work_packages/dialogs/create_form.rb b/app/forms/work_packages/dialogs/create_form.rb
index 2180d296308..4d1e8c72f8e 100644
--- a/app/forms/work_packages/dialogs/create_form.rb
+++ b/app/forms/work_packages/dialogs/create_form.rb
@@ -51,7 +51,7 @@ module WorkPackages::Dialogs
autocomplete_options: {
multiple: false,
decorated: true,
- hiddenFieldAction: "change->work-packages--create-dialog#submitForm",
+ hiddenFieldAction: "change->work-packages--create-dialog#refreshForm",
append_to: wrapper_id
}
) do |select|
diff --git a/config/routes.rb b/config/routes.rb
index 535973e40fe..51af3b59b01 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -349,7 +349,9 @@ Rails.application.routes.draw do
end
namespace :work_packages do
- resource :dialog, only: %i[new create]
+ resource :dialog, only: %i[new create] do
+ post :refresh_form
+ end
end
resources :activity, :activities, only: :index, controller: "activities" do
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/create-dialog.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/create-dialog.controller.ts
index 073c8bb1a95..3ab1ed1ee0d 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/create-dialog.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/create-dialog.controller.ts
@@ -36,15 +36,23 @@ export default class CreateDialogController extends Controller<HTMLFormElement>
private turboRequests:TurboRequestsService;
private pathHelper:PathHelperService;
+ static values = {
+ refreshUrl: String,
+ };
+
+ declare refreshUrlValue:string;
+
async connect() {
const context = await window.OpenProject.getPluginContext();
this.turboRequests = context.services.turboRequests;
this.pathHelper = context.services.pathHelperService;
}
- updateForm() {
- void this
- .turboRequests
- .submitForm(this.element);
+ refreshForm() {
+ void this.turboRequests.submitForm(
+ this.element,
+ null,
+ this.refreshUrlValue,
+ );
}
}