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

[32817] Disable advanced settings in project template (#8537)

Oliver Güntherebfd3ce0099b
diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb
index 5f3fdd01f18..c1f98f6fd1c 100644
--- a/app/views/projects/_form.html.erb
+++ b/app/views/projects/_form.html.erb
@@ -28,7 +28,7 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
<% content_for :header_tags do %>
- <meta name="required_script" content="project_identifier_listener" />
+ <meta name="required_script" content="project_form_listener" />
<% end %>
<%= error_messages_for_contract(project, errors) unless local_assigns[:no_error_messages] %>
diff --git a/app/views/projects/form/_select_template.html.erb b/app/views/projects/form/_select_template.html.erb
index d945545c5c1..6ca5b14b6a3 100644
--- a/app/views/projects/form/_select_template.html.erb
+++ b/app/views/projects/form/_select_template.html.erb
@@ -32,6 +32,7 @@ See docs/COPYRIGHT.rdoc for more details.
<div class="form--field-container">
<%= styled_select_tag :from_template,
options_for_select(project_options_for_templated),
+ id: 'project-select-template',
prompt: "(#{t(:label_none)})",
container_class: '-wide' %>
</div>
diff --git a/frontend/src/app/modules/augmenting/dynamic-scripts/project_identifier_listener.js b/frontend/src/app/modules/augmenting/dynamic-scripts/project_form_listener.js
similarity index 95%
rename from frontend/src/app/modules/augmenting/dynamic-scripts/project_identifier_listener.js
rename to frontend/src/app/modules/augmenting/dynamic-scripts/project_form_listener.js
index 9dfad32365c..1bf9e04d578 100644
--- a/frontend/src/app/modules/augmenting/dynamic-scripts/project_identifier_listener.js
+++ b/frontend/src/app/modules/augmenting/dynamic-scripts/project_form_listener.js
@@ -104,7 +104,20 @@
});
}
+ function observeTemplateChanges() {
+ jQuery('#project-select-template').on('change', function() {
+ let templateSelected = $(this).val() !== '';
+ let settings = $('#advanced-settings');
+
+ settings
+ .toggle(!templateSelected)
+ .find('input:not(#project_identifier), select, textarea')
+ .prop('disabled', templateSelected);
+ });
+ }
+
observeProjectIdentifier();
observeProjectName();
+ observeTemplateChanges();
});
}(jQuery));
diff --git a/spec/features/projects/template_spec.rb b/spec/features/projects/template_spec.rb
index de71a434250..a95a88bd411 100644
--- a/spec/features/projects/template_spec.rb
+++ b/spec/features/projects/template_spec.rb
@@ -77,13 +77,12 @@ describe 'Project templates', type: :feature, js: true do
visit new_project_path
fill_in 'project[name]', with: 'Foo bar'
- select 'My template', from: 'Use template'
- click_on 'Advanced settings'
- fill_in 'project[identifier]', with: 'foo'
- # Fill status
- select 'On track', from: 'Status'
- status_description.click_and_type_slowly 'Status is OKAYDOKEY'
+ expect(page).to have_selector('#advanced-settings', visible: true, text: 'ADVANCED SETTINGS')
+
+ # Choosing template hides advanced settings
+ select 'My template', from: 'project-select-template'
+ expect(page).to have_no_selector('#advanced-settings', visible: true, text: 'ADVANCED SETTINGS')
sleep 1
click_on 'Create'
@@ -101,15 +100,13 @@ describe 'Project templates', type: :feature, js: true do
expect(mail).not_to be_nil
- expect(page).to have_current_path '/projects/foo/', wait: 20
+ expect(page).to have_current_path '/projects/foo-bar/', wait: 20
- project = Project.find_by identifier: 'foo'
+ project = Project.find_by identifier: 'foo-bar'
expect(project.name).to eq 'Foo bar'
expect(project).not_to be_templated
expect(project.users.first).to eq current_user
expect(project.enabled_module_names.sort).to eq(template.enabled_module_names.sort)
- expect(project.status.code).to eq 'on_track'
- expect(project.status.explanation).to eq 'Status is OKAYDOKEY'
wp_source = template.work_packages.first.attributes.except(*%w[id author_id project_id updated_at created_at])
wp_target = project.work_packages.first.attributes.except(*%w[id author_id project_id updated_at created_at])