2023-09-19 16:34:47 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
module Primer
|
|
|
|
|
module OpenProject
|
|
|
|
|
module Forms
|
|
|
|
|
module Dsl
|
|
|
|
|
module InputMethods
|
2025-11-21 09:12:40 +01:00
|
|
|
include AttributeHelpTextsHelper
|
|
|
|
|
|
2025-06-05 20:27:14 +01:00
|
|
|
def multi(**, &)
|
|
|
|
|
super(**decorate_options(**), &)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_box(**, &)
|
|
|
|
|
super(**decorate_options(**), &)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def radio_button_group(**, &)
|
|
|
|
|
super(**decorate_options(**), &)
|
|
|
|
|
end
|
|
|
|
|
|
2026-04-30 11:10:28 +02:00
|
|
|
def check_box_group(include_hidden: false, **, &)
|
|
|
|
|
add_input Primer::Forms::Dsl::HiddenInput.new(builder:, form:, multiple: true, value: "", **) if include_hidden
|
2025-06-05 20:27:14 +01:00
|
|
|
super(**decorate_options(**), &)
|
|
|
|
|
end
|
|
|
|
|
|
2025-11-14 13:24:39 +00:00
|
|
|
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
|
|
|
|
|
|
2023-09-28 14:48:07 +02:00
|
|
|
def autocompleter(**, &)
|
2025-05-20 17:37:27 +02:00
|
|
|
add_input AutocompleterInput.new(builder:, form:, **decorate_options(**), &)
|
2023-09-19 16:34:47 +02:00
|
|
|
end
|
|
|
|
|
|
2026-05-19 14:59:09 +02:00
|
|
|
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
|
|
|
|
|
|
2024-12-02 18:09:09 +02:00
|
|
|
def color_select_list(**, &)
|
2025-05-20 17:37:27 +02:00
|
|
|
add_input ColorSelectInput.new(builder:, form:, **decorate_options(**), &)
|
2024-12-02 18:09:09 +02:00
|
|
|
end
|
|
|
|
|
|
2025-08-29 16:50:32 +01:00
|
|
|
def html_content(&)
|
|
|
|
|
add_input HtmlContent.new(&)
|
2024-05-06 10:54:05 +02:00
|
|
|
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(**, &)
|
2025-05-20 17:37:27 +02:00
|
|
|
add_input ProjectAutocompleterInput.new(builder:, form:, **decorate_options(**), &)
|
2024-12-02 18:09:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def range_date_picker(**)
|
2025-05-20 17:37:27 +02:00
|
|
|
add_input RangeDatePickerInput.new(builder:, form:, **decorate_options(**))
|
2024-05-06 11:02:16 +02:00
|
|
|
end
|
|
|
|
|
|
2023-09-19 16:34:47 +02:00
|
|
|
def rich_text_area(**)
|
2025-05-20 17:37:27 +02:00
|
|
|
add_input RichTextAreaInput.new(builder:, form:, **decorate_options(**))
|
2023-09-19 16:34:47 +02:00
|
|
|
end
|
2024-07-18 10:27:48 +03:00
|
|
|
|
2024-12-02 18:09:09 +02:00
|
|
|
def single_date_picker(**)
|
2025-05-20 17:37:27 +02:00
|
|
|
add_input SingleDatePickerInput.new(builder:, form:, **decorate_options(**))
|
2024-07-18 10:27:48 +03:00
|
|
|
end
|
2024-09-11 18:37:22 +02:00
|
|
|
|
2024-12-02 18:09:09 +02:00
|
|
|
def storage_manual_project_folder_selection(**)
|
2025-05-20 17:37:27 +02:00
|
|
|
add_input StorageManualProjectFolderSelectionInput.new(builder:, form:, **decorate_options(**))
|
2024-10-07 09:20:51 +02:00
|
|
|
end
|
|
|
|
|
|
2024-12-02 18:09:09 +02:00
|
|
|
def work_package_autocompleter(**, &)
|
2025-05-20 17:37:27 +02:00
|
|
|
add_input WorkPackageAutocompleterInput.new(builder:, form:, **decorate_options(**), &)
|
2024-09-11 18:37:22 +02:00
|
|
|
end
|
2025-06-03 12:16:48 +01:00
|
|
|
|
2025-11-26 18:55:20 -03:00
|
|
|
def select_panel(**, &)
|
|
|
|
|
add_input SelectPanelInput.new(builder:, form:, **decorate_options(**), &)
|
2026-06-03 12:52:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def filterable_tree_view(**, &)
|
|
|
|
|
add_input FilterableTreeViewInput.new(builder:, form:, **decorate_options(**), &)
|
2025-11-26 18:55:20 -03:00
|
|
|
end
|
|
|
|
|
|
2025-06-05 14:17:54 +01:00
|
|
|
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)
|
2025-06-03 12:16:48 +01:00
|
|
|
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
|
|
|
|
|
|
2025-06-03 12:16:48 +01:00
|
|
|
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)
|
2025-06-03 12:16:48 +01:00
|
|
|
end
|
2023-09-19 16:34:47 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|