2024-07-15 14:31:54 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-07-15 02:19:27 +02:00
|
|
|
module ApplicationHelper
|
2024-07-21 00:33:38 +02:00
|
|
|
include Pagy::Frontend
|
|
|
|
|
|
|
|
|
|
delegate :filter_params, to: :controller
|
2024-09-05 22:54:38 +02:00
|
|
|
|
|
|
|
|
def multilang_form_field(form, attribute, as: :text_field)
|
2024-09-11 20:44:33 +02:00
|
|
|
return form.send(as, "#{attribute}_de")
|
|
|
|
|
|
2024-09-05 22:54:38 +02:00
|
|
|
col_width = as == :rich_text_area ? 12 : 12 / I18n.available_locales.count
|
|
|
|
|
tag.div(class: "row") do
|
|
|
|
|
fields = I18n.available_locales.map { _1.to_s.split("-").first }.map do |lang|
|
|
|
|
|
tag.div(class: "col-lg-#{col_width}") do
|
|
|
|
|
form.send(as, "#{attribute}_#{lang}")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
safe_join(fields)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-09-11 22:04:55 +02:00
|
|
|
|
|
|
|
|
def safe_display(value, &block)
|
2024-11-12 22:57:47 +01:00
|
|
|
return if value.blank?
|
2024-09-11 22:04:55 +02:00
|
|
|
|
|
|
|
|
yield(value)
|
|
|
|
|
end
|
2024-11-03 21:58:25 +01:00
|
|
|
|
|
|
|
|
def current_page_displayed(page)
|
|
|
|
|
@current_page&.id == page.id ? "open" : nil
|
|
|
|
|
end
|
2024-11-12 23:55:00 +01:00
|
|
|
|
|
|
|
|
def turbo_stream_toast(content, alert)
|
|
|
|
|
turbo_stream.append("toasts", partial: "layouts/toast", locals: { content:, alert: })
|
|
|
|
|
end
|
2024-11-17 13:44:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def dropdown_menu(items, klass: "")
|
|
|
|
|
tag.details(class: "details-dropdown #{klass}") do
|
|
|
|
|
tag.summary do
|
|
|
|
|
tag.div(class: "details-dropdown-trigger") do
|
|
|
|
|
tag.div(tag.i(class: "bi bi-three-dots-vertical"), class: "btn btn-outline-secondary")
|
|
|
|
|
end
|
|
|
|
|
end +
|
|
|
|
|
tag.div(class: "details-dropdown-content bg-secondary") do
|
|
|
|
|
tag.ul(class: "list-group") do
|
|
|
|
|
safe_join(items.map do |item|
|
|
|
|
|
tag.li(class: "list-group-item list-group-item-action#{ item[:color] ? " list-group-item-#{item[:color]}" : ""}") do
|
|
|
|
|
text = item[:icon] ? tag.i(class: "bi bi-#{item[:icon]} me-2") + " #{item[:text]}".html_safe : item[:text]
|
|
|
|
|
case item[:method]
|
|
|
|
|
when nil, :get
|
|
|
|
|
link_to(text, item[:href], class: "text-decoration-none text-body")
|
|
|
|
|
else
|
|
|
|
|
button_to(text,
|
|
|
|
|
item[:href],
|
|
|
|
|
method: item[:method],
|
|
|
|
|
form_class: "no-padding",
|
|
|
|
|
class: "btn btn-link text-decoration-none text-#{item[:color] ? "#{item[:color]}-emphasis" : "body"}",
|
|
|
|
|
data: { turbo_confirm: item[:confirm] })
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-15 02:19:27 +02:00
|
|
|
end
|