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

Replace project_folder_mode_selection

Oliver Güntherc68318ca05db
diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/project_folder_mode_selection.ts b/frontend/src/app/core/augmenting/dynamic-scripts/project_folder_mode_selection.ts
deleted file mode 100644
index 1df2945923f..00000000000
--- a/frontend/src/app/core/augmenting/dynamic-scripts/project_folder_mode_selection.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-// -- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 2012-2023 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.
-//++
-
-const projectFolderModeRadioButtons = document.querySelectorAll('input[name="storages_project_storage[project_folder_mode]"]');
-const projectFolderSelectionSection = document.getElementById('storages_manual_folder_selection');
-const manualProjectFolderModeInput = document.getElementById('storages_project_storage_project_folder_mode_manual') as HTMLInputElement;
-
-// Show the manual folder selection section if the manual radio button is checked
-if (manualProjectFolderModeInput.checked && projectFolderSelectionSection !== null) {
- projectFolderSelectionSection.style.display = 'flex';
-}
-
-projectFolderModeRadioButtons.forEach((radio:HTMLInputElement) => {
- radio.onchange = () => {
- if (projectFolderSelectionSection === null) {
- return;
- }
-
- // If the manual radio button is selected, show the manual folder selection section
- if (radio.value === 'manual') {
- projectFolderSelectionSection.style.display = 'flex';
- } else {
- projectFolderSelectionSection.style.display = 'none';
- }
- };
-});
diff --git a/frontend/src/stimulus/controllers/dynamic/project-storage-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/project-storage-form.controller.ts
new file mode 100644
index 00000000000..41f2710b9dd
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/project-storage-form.controller.ts
@@ -0,0 +1,54 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 2023 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 ProjectStorageFormController extends Controller {
+ static targets = [
+ 'projectFolderSection',
+ ];
+
+ declare readonly projectFolderSectionTarget:HTMLElement;
+
+ declare readonly hasProjectFolderSectionTarget:boolean;
+
+ updateDisplay(evt:InputEvent) {
+ if (!this.hasProjectFolderSectionTarget) {
+ return;
+ }
+
+ // If the manual radio button is selected, show the manual folder selection section
+ if ((evt.target as HTMLInputElement).value === 'manual') {
+ this.projectFolderSectionTarget.style.display = 'flex';
+ } else {
+ this.projectFolderSectionTarget.style.display = 'none';
+ }
+ }
+}
diff --git a/modules/storages/app/views/storages/project_settings/_form.html.erb b/modules/storages/app/views/storages/project_settings/_form.html.erb
index 1ae4b36af63..a438d9add6b 100644
--- a/modules/storages/app/views/storages/project_settings/_form.html.erb
+++ b/modules/storages/app/views/storages/project_settings/_form.html.erb
@@ -27,24 +27,21 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<% if OpenProject::FeatureDecisions.storage_project_folders_active? %>
- <% content_for :header_tags do %>
- <meta name="required_script" content="project_folder_mode_selection" />
- <% end %>
-<% end %>
+<% page_controller 'project-storage-form', dynamic: true %>
<div class="form--field -required">
<% case action_name %>
<% when 'new' %>
<%= f.select :storage_id,
- available_storages.map { |storage| ["#{storage.name} (#{storage.short_provider_type})", storage.id] },
- selected: available_storages.first.id.to_s,
- class: '-bold',
- container_class: '-slim' %>
+ available_storages.map { |storage| ["#{storage.name} (#{storage.short_provider_type})", storage.id] },
+ selected: available_storages.first.id.to_s,
+ class: '-bold',
+ container_class: '-slim' %>
<% if User.current.admin? %>
<span class="form--field-instructions">
- <%= t(:"storages.instructions.setting_up_additional_storages") %>
- <%= link_to "#{t(:label_administration)} / #{t(:project_module_storages)}", controller: '/storages/admin/storages', action: :index %>.
+ <%= t(:"storages.instructions.setting_up_additional_storages") %>
+ <%= link_to "#{t(:label_administration)} / #{t(:project_module_storages)}", controller: '/storages/admin/storages', action: :index %>
+ .
</span>
<% end %>
<% when 'edit' %>
@@ -59,7 +56,8 @@ See COPYRIGHT and LICENSE files for more details.
<% if OpenProject::FeatureDecisions.storage_project_folders_active? %>
<div class="form--field -required">
- <%= styled_label_tag :project_folder_mode, class: "-bold -flex" do %>
+ <%= styled_label_tag :project_folder_mode,
+ class: "-bold -flex" do %>
<%= t(:"storages.label_project_folder") %>
<%= angular_component_tag 'op-static-attribute-help-text',
inputs: {
@@ -70,32 +68,38 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<div class="form--field-container -horizontal">
<%= f.label :project_folder_mode, class: "form--label-with-radio-button" do %>
- <%= f.radio_button :project_folder_mode, 'inactive', no_label: true %>
+ <%= f.radio_button :project_folder_mode,
+ 'inactive',
+ no_label: true,
+ data: { action: 'project-storage-form#updateDisplay' } %>
<%= t(:"storages.label_no_specific_folder") %>
<% end %>
</div>
<p class="form--field-instructions">
- <%= t(:"storages.instructions.no_specific_folder") %>
+ <%= t(:"storages.instructions.no_specific_folder") %>
</p>
<div class="form--field-container -horizontal">
<%= f.label :project_folder_mode, class: "form--label-with-radio-button" do %>
- <%= f.radio_button :project_folder_mode, 'manual', no_label: true %>
+ <%= f.radio_button :project_folder_mode,
+ 'manual',
+ no_label: true,
+ data: { action: 'project-storage-form#updateDisplay' } %>
<%= t(:"storages.label_existing_manual_folder") %>
<% end %>
</div>
<p class="form--field-instructions -xwide">
- <%= t(:"storages.instructions.existing_manual_folder") %>
+ <%= t(:"storages.instructions.existing_manual_folder") %>
</p>
</div>
- <div style="display:none;" id="storages_manual_folder_selection" class="form--field -required">
+ <div style="display:none;" class="form--field -required" data-project-storage-form-target="projectFolderSection">
<label class="form--label -bold"> <%= t(:"storages.label_existing_manual_folder_selection") %> </label>
<div class="form--field-container -horizontal">
<%= f.text_field :project_folder_id,
- placeholder: t(:"storages.placeholder_existing_folder_selection"),
- container_class: "-middle",
- no_label: true
+ placeholder: t(:"storages.placeholder_existing_folder_selection"),
+ container_class: "-middle",
+ no_label: true
%>
</div>
</div>