Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

118 lines
3.9 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
module Primer
module OpenProject
module Forms
module Dsl
module InputMethods
2025-11-21 09:12:40 +01:00
include AttributeHelpTextsHelper
def multi(**, &)
super(**decorate_options(**), &)
end
def check_box(**, &)
super(**decorate_options(**), &)
end
def radio_button_group(**, &)
super(**decorate_options(**), &)
end
def check_box_group(include_hidden: false, **, &)
add_input Primer::Forms::Dsl::HiddenInput.new(builder:, form:, multiple: true, value: "", **) if include_hidden
super(**decorate_options(**), &)
end
def advanced_radio_button_group(**, &)
add_input AdvancedRadioButtonGroupInput.new(builder:, form:, **decorate_options(**), &)
end
def advanced_check_box_group(**, &)
add_input AdvancedCheckBoxGroupInput.new(builder:, form:, **decorate_options(**), &)
end
def autocompleter(**, &)
add_input AutocompleterInput.new(builder:, form:, **decorate_options(**), &)
end
def segmented_control(**, &)
add_input SegmentedControlInput.new(builder:, form:, **decorate_options(**), &)
end
2025-06-25 12:40:06 +02:00
def block_note_editor(**, &)
add_input BlockNoteEditorInput.new(builder:, form:, **decorate_options(**), &)
2024-12-16 16:35:40 +01:00
end
def color_select_list(**, &)
add_input ColorSelectInput.new(builder:, form:, **decorate_options(**), &)
end
2025-08-29 16:50:32 +01:00
def html_content(&)
add_input HtmlContent.new(&)
end
2025-06-25 12:40:06 +02:00
def pattern_input(**, &)
add_input PatternInput.new(builder:, form:, **decorate_options(**), &)
end
2024-05-06 11:02:16 +02:00
def project_autocompleter(**, &)
add_input ProjectAutocompleterInput.new(builder:, form:, **decorate_options(**), &)
end
def range_date_picker(**)
add_input RangeDatePickerInput.new(builder:, form:, **decorate_options(**))
2024-05-06 11:02:16 +02:00
end
def rich_text_area(**)
add_input RichTextAreaInput.new(builder:, form:, **decorate_options(**))
end
def single_date_picker(**)
add_input SingleDatePickerInput.new(builder:, form:, **decorate_options(**))
end
def storage_manual_project_folder_selection(**)
add_input StorageManualProjectFolderSelectionInput.new(builder:, form:, **decorate_options(**))
2024-10-07 09:20:51 +02:00
end
def work_package_autocompleter(**, &)
add_input WorkPackageAutocompleterInput.new(builder:, form:, **decorate_options(**), &)
end
2025-11-26 18:55:20 -03:00
def select_panel(**, &)
add_input SelectPanelInput.new(builder:, form:, **decorate_options(**), &)
end
def filterable_tree_view(**, &)
add_input FilterableTreeViewInput.new(builder:, form:, **decorate_options(**), &)
2025-11-26 18:55:20 -03:00
end
def decorate_options(include_help_text: true, help_text_options: {}, **options)
if include_help_text && supports_help_texts?(form.model)
attribute_name = help_text_options[:attribute_name] || options[:name]
options[:label] = form.wrap_attribute_label_with_help_text(options[:label], attribute_name)
2025-11-21 09:12:40 +01:00
options[:caption] ||= help_text_caption_for(attribute_name)
end
options
end
private
2025-11-21 09:12:40 +01:00
def help_text_caption_for(attribute_name)
help_text = help_text_for(form.model, attribute_name)
help_text&.caption
end
def supports_help_texts?(model)
return @supports_help_texts if defined?(@supports_help_texts)
2026-03-26 12:31:57 +01:00
@supports_help_texts = model.respond_to?(:model_name) &&
::AttributeHelpText.available_types.include?(model.model_name)
end
end
end
end
end
end