mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
98 lines
3.0 KiB
Ruby
98 lines
3.0 KiB
Ruby
# 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 AttributeHelpTexts
|
|
class Form < ApplicationForm
|
|
form do |attribute_form|
|
|
attribute_form.hidden(
|
|
name: :type,
|
|
value: model.type
|
|
)
|
|
|
|
attribute_form.select_list(
|
|
name: :attribute_name,
|
|
label: AttributeHelpText.human_attribute_name(:attribute_name),
|
|
required: true,
|
|
disabled: model.persisted?
|
|
) do |list|
|
|
selectable_attributes.each do |label, value|
|
|
list.option(
|
|
label:,
|
|
value:
|
|
)
|
|
end
|
|
end
|
|
|
|
attribute_form.text_field(
|
|
name: :caption,
|
|
caption: I18n.t("attribute_help_texts.caption"),
|
|
label: AttributeHelpText.human_attribute_name(:caption),
|
|
required: false
|
|
)
|
|
|
|
attribute_form.rich_text_area(
|
|
name: :help_text,
|
|
label: AttributeHelpText.human_attribute_name(:help_text),
|
|
required: true,
|
|
rich_text_options: {
|
|
showAttachments: true,
|
|
primerized: true,
|
|
resource: ::API::V3::HelpTexts::HelpTextRepresenter.new(
|
|
model,
|
|
current_user: User.current,
|
|
embed_links: true
|
|
),
|
|
footer: render(Primer::Beta::Text.new(color: :muted)) { I18n.t("attribute_help_texts.note_public") }
|
|
}
|
|
)
|
|
|
|
attribute_form.submit(
|
|
name: :submit,
|
|
label: I18n.t(:button_save),
|
|
scheme: :primary
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def selectable_attributes
|
|
@selectable_attributes ||= begin
|
|
available = model.class.available_attributes
|
|
used = AttributeHelpText.used_attributes(model.type)
|
|
|
|
available
|
|
.reject { |key,| used.include? key }
|
|
.map { |key, label| [label, key] }
|
|
.sort_by { |label, _key| label.downcase }
|
|
end
|
|
end
|
|
end
|
|
end
|