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

chore[#47147]: Replace jQuery with dynamic ts script

Kabiru Mwenja8a4723f97254
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
new file mode 100644
index 00000000000..0e7dbce5134
--- /dev/null
+++ b/frontend/src/app/core/augmenting/dynamic-scripts/project_folder_mode_selection.ts
@@ -0,0 +1,51 @@
+// -- 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.visibility = 'visible';
+}
+
+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.visibility = 'visible';
+ } else {
+ projectFolderSelectionSection.style.visibility = 'hidden';
+ }
+ }
+})
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 588242ecab1..de162171d17 100644
--- a/modules/storages/app/views/storages/project_settings/_form.html.erb
+++ b/modules/storages/app/views/storages/project_settings/_form.html.erb
@@ -1,3 +1,9 @@
+<% if OpenProject::FeatureDecisions.storage_project_folders_active? %>
+ <% content_for :header_tags do %>
+ <meta name="required_script" content="project_folder_mode_selection" />
+ <% end %>
+<% end %>
+
<div class="form--field -required">
<% case action_name %>
<% when 'new' %>
@@ -46,7 +52,7 @@
</p>
</div>
- <div style="display:none;" id="storages_manual_folder_selection" class="form--field -required">
+ <div style="visibility:hidden;" id="storages_manual_folder_selection" class="form--field -required">
<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,
@@ -56,21 +62,6 @@
%>
</div>
</div>
-
- <%= nonced_javascript_tag do -%>
- jQuery(function($) {
- <%# Show manual folder selection on reload when checked %>
- $("#storages_project_storage_project_folder_mode_manual").is(':checked') && $("#storages_manual_folder_selection").show();
-
- $("input[type='radio']").change(function() {
- if ($(this).val() == 'manual') {
- $("#storages_manual_folder_selection").show();
- } else {
- $("#storages_manual_folder_selection").hide();
- }
- })
- });
- <% end -%>
<% end %>
<div class="form--field">