From 39e847792f15b76c239a2040e34311e95493140c Mon Sep 17 00:00:00 2001 From: ulferts Date: Mon, 9 Feb 2026 09:40:36 +0100 Subject: [PATCH] move groups form to primer --- app/forms/groups/form.rb | 65 +++++++++++++++++++++++++++++ app/views/groups/_form.html.erb | 48 --------------------- app/views/groups/_general.html.erb | 9 ++-- app/views/groups/new.html.erb | 11 +++-- spec/features/groups/groups_spec.rb | 6 +-- 5 files changed, 80 insertions(+), 59 deletions(-) create mode 100644 app/forms/groups/form.rb delete mode 100644 app/views/groups/_form.html.erb diff --git a/app/forms/groups/form.rb b/app/forms/groups/form.rb new file mode 100644 index 00000000000..c63fd9f4b24 --- /dev/null +++ b/app/forms/groups/form.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 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. +# ++ +module Groups + class Form < ApplicationForm + include CustomFields::CustomFieldRendering + + form do |f| + f.text_field( + name: :lastname, + label: Group.human_attribute_name(:name), + required: true, + input_width: :medium, + autocomplete: "off" + ) + + render_custom_fields(form: f) + + f.submit( + name: :submit, + label: submit_label, + scheme: :primary + ) + end + + def initialize(submit_label: I18n.t(:button_save)) + super() + @submit_label = submit_label + end + + private + + attr_reader :submit_label + + def custom_fields + model.available_custom_fields + end + end +end diff --git a/app/views/groups/_form.html.erb b/app/views/groups/_form.html.erb deleted file mode 100644 index 416c8efb177..00000000000 --- a/app/views/groups/_form.html.erb +++ /dev/null @@ -1,48 +0,0 @@ -<%#-- copyright -OpenProject is an open source project management software. -Copyright (C) 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. - -++#%> - -<%# - needs locals: - f: labelled form builder -%> - -<%= error_messages_for :group %> - -
-
- <%= f.text_field :lastname, - label: Group.human_attribute_name(:name), - required: true, - container_class: "-middle" %> -
- - <%= render partial: "customizable/form", locals: { form: f, - all_fields: true, - only_required: false } %> -
diff --git a/app/views/groups/_general.html.erb b/app/views/groups/_general.html.erb index d6387e18b5e..30252135ca5 100644 --- a/app/views/groups/_general.html.erb +++ b/app/views/groups/_general.html.erb @@ -27,7 +27,8 @@ See COPYRIGHT and LICENSE files for more details. ++#%> -<%= labelled_tabular_form_for @group, url: group_path(@group), html: { method: :put }, as: :group do |f| %> - <%= render partial: "form", locals: { f: f } %> - <%= styled_button_tag t(:button_save), class: "-primary -with-icon icon-checkmark" %> -<% end %> +<%= + settings_primer_form_with(model: @group, url: group_path(@group), method: :put) do |f| + render Groups::Form.new(f) + end +%> diff --git a/app/views/groups/new.html.erb b/app/views/groups/new.html.erb index e0faf978cb0..62d3cc360de 100644 --- a/app/views/groups/new.html.erb +++ b/app/views/groups/new.html.erb @@ -41,7 +41,10 @@ See COPYRIGHT and LICENSE files for more details. end %> -<%= labelled_tabular_form_for(@group) do |f| %> - <%= render partial: "form", locals: { f: f } %> -
<%= f.button t(:button_create), class: "button -primary -with-icon icon-checkmark" %>
-<% end %> +<%= error_messages_for @group %> + +<%= + settings_primer_form_with(model: @group) do |f| + render Groups::Form.new(f, submit_label: I18n.t(:button_create)) + end +%> diff --git a/spec/features/groups/groups_spec.rb b/spec/features/groups/groups_spec.rb index f5a8654f4f8..05d999b2352 100644 --- a/spec/features/groups/groups_spec.rb +++ b/spec/features/groups/groups_spec.rb @@ -71,7 +71,7 @@ RSpec.describe "group memberships through groups page", :js do # Should stay on the form page and show validation error expect(page).to have_text("New group") - expect(page).to have_css(".Banner--error", text: /Department can't be blank./) + expect(page).to have_field(custom_field.name, with: "", validation_error: "Value can't be blank.") fill_in custom_field.name, with: "Engineering" @@ -102,8 +102,8 @@ RSpec.describe "group memberships through groups page", :js do click_on "Save" # Should stay on the form page and show validation error - expect(page).to have_text("Updated Marketing Team") - expect(page).to have_css(".Banner--error", text: /Department can't be blank./) + expect(page).to have_field("Name", with: "Updated Marketing Team") + expect(page).to have_field(custom_field.name, with: "", validation_error: "Value can't be blank.") # Now provide a valid value fill_in custom_field.name, with: "Marketing & Sales"