Verified Commit 143c239b authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

modify button helpers slightly and add glyph_action_button_link helper

parent b04aaaec
Pipeline #22211 passed with stage
in 48 minutes and 48 seconds
module NavigationAndButtonHelper
GLYPH_TRANSLATE = {
show: { text: 'Anzeigen', glyph: 'eye-open' },
edit: { text: 'Bearbeiten', glyph: 'pencil' },
delete: { text: 'Löschen', glyph: 'trash' },
terminate: { text: 'Beenden', glyph: 'off' },
activate: { text: 'Aktivieren', glyph: 'ok' },
deactivate: { text: 'Deaktivieren', glyph: 'remove' },
back: { text: 'Zurück', glyph: 'arrow-left' },
print: { text: 'Ausdrucken', glyph: 'print' },
download: { text: 'Herunterladen', glyph: 'download-alt' },
yes: { text: 'Ja', glyph: 'ok' },
no: { text: 'Nein', glyph: 'remove' },
journal: { text: 'Journal', glyph: 'book' },
hours: { text: 'Stunden erfassen', glyph: 'time' },
billing_expenses: { text: 'Spesen', glyph: 'usd' },
assignment: { text: 'Begleitung', glyph: 'user' },
certificate: { text: 'Nachweis', glyph: 'education' }
}.freeze
def form_navigation_btn(action, cols: 12, with_row: true, md_cols: nil, with_col: false,
add_class: nil)
button = make_nav_button(action)
......@@ -12,6 +31,29 @@ module NavigationAndButtonHelper
link_to text, target, class: "btn btn-#{type}#{btn_size}", **options
end
def yield_button_link(target, **options)
btn_size = options[:dimension] && " btn-#{options[:dimension]}"
type = options.delete(:type)
link_to(target, class: "btn btn-#{type || 'default'}#{btn_size}", **options) do
yield
end
end
# bootstrap button link with action glyphicon
# Params:
# action_type - one of GLYPH_TRANSLATE's keys
# target - the path target for the link
# title: 'string' - optional title attribute, else it will be taken from
# GLYPH_TRANSLATE[action_type][:text]
# dimension: [xs|md|lg] - optional dimension (Bootstrap's: xs, lg, md)
# ..options - any optional parameter link_to accepts
def glyph_action_button_link(action_type, target, **options)
options[:title] ||= GLYPH_TRANSLATE[action_type.to_sym][:text]
yield_button_link(target, **options) do
navigation_glyph(action_type)
end
end
def make_nav_button(action)
if action == :back
text = navigation_glyph(:back)
......@@ -32,25 +74,7 @@ module NavigationAndButtonHelper
end
def navigation_glyph(icon_type = :back)
translate_glyph = {
show: { text: 'Anzeigen', glyph: 'eye-open' },
edit: { text: 'Bearbeiten', glyph: 'pencil' },
delete: { text: 'Löschen', glyph: 'trash' },
terminate: { text: 'Beenden', glyph: 'off' },
activate: { text: 'Aktivieren', glyph: 'ok' },
deactivate: { text: 'Deaktivieren', glyph: 'remove' },
back: { text: 'Zurück', glyph: 'arrow-left' },
print: { text: 'Ausdrucken', glyph: 'print' },
download: { text: 'Herunterladen', glyph: 'download-alt' },
yes: { text: 'Ja', glyph: 'ok' },
no: { text: 'Nein', glyph: 'remove' },
journal: { text: 'Journal', glyph: 'book' },
hours: { text: 'Stunden erfassen', glyph: 'time' },
billing_expenses: { text: 'Spesen', glyph: 'usd' },
assignment: { text: 'Begleitung', glyph: 'user' },
certificate: { text: 'Nachweis', glyph: 'education' }
}
glyph_span(translate_glyph[icon_type.to_sym])
glyph_span(GLYPH_TRANSLATE[icon_type.to_sym])
end
def glyph_span(text: 'Zurück', glyph: 'arrow-left')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment