forked from fixin.me/fixin.me
parent
80f05ba45f
commit
af152c5e8b
@ -138,29 +138,28 @@ module ApplicationHelper
|
|||||||
end.join.html_safe
|
end.join.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
[:button_to, :link_to, :link_to_unless_current].each do |method_name|
|
def image_button_to(name, image = nil, options = nil, html_options = {})
|
||||||
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
name, html_options = link_or_button_options(:button, name, image, html_options)
|
||||||
def image_#{method_name}(name, image = nil, options = nil, html_options = {}, &block)
|
button_to name, options, html_options
|
||||||
name = name.to_s
|
end
|
||||||
name = svg_tag("pictograms/\#{image}") + name if image
|
|
||||||
|
|
||||||
html_options[:class] = class_names(
|
def image_link_to(name, image = nil, options = nil, html_options = {})
|
||||||
html_options[:class],
|
name, html_options = link_or_button_options(:link, name, image, html_options)
|
||||||
'button',
|
link_to name, options, html_options
|
||||||
dangerous: html_options[:method] == :delete
|
end
|
||||||
)
|
|
||||||
if html_options[:onclick]&.is_a? Hash
|
|
||||||
html_options[:onclick] = "return confirm('\#{html_options[:onclick][:confirm]}');"
|
|
||||||
end
|
|
||||||
|
|
||||||
if __method__.start_with?('image_link_to') &&
|
DISABLED_ATTRIBUTES = {disabled: true, aria: {disabled: true}, tabindex: -1}
|
||||||
!(html_options[:onclick] || html_options.dig(:data, :turbo_stream))
|
|
||||||
name = name + '...'
|
|
||||||
end
|
|
||||||
|
|
||||||
send :#{method_name}, name, options, html_options, &block
|
def image_button_to_if(condition, name, image = nil, options = nil, html_options = {})
|
||||||
end
|
name, html_options = link_or_button_options(:button, name, image, html_options)
|
||||||
RUBY_EVAL
|
html_options = html_options.deep_merge DISABLED_ATTRIBUTES unless condition
|
||||||
|
button_to name, options, html_options
|
||||||
|
end
|
||||||
|
|
||||||
|
def image_link_to_unless_current(name, image = nil, options = nil, html_options = {})
|
||||||
|
name, html_options = link_or_button_options(:link, name, image, html_options)
|
||||||
|
html_options = html_options.deep_merge DISABLED_ATTRIBUTES if current_page?(options)
|
||||||
|
link_to name, options, html_options
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_errors(record)
|
def render_errors(record)
|
||||||
@ -188,7 +187,25 @@ module ApplicationHelper
|
|||||||
"Turbo.renderStreamMessage('#{j(render partial: partial, locals: locals)}'); return false;"
|
"Turbo.renderStreamMessage('#{j(render partial: partial, locals: locals)}'); return false;"
|
||||||
end
|
end
|
||||||
|
|
||||||
def disabled_attributes(disabled)
|
private
|
||||||
disabled ? {disabled: true, aria: {disabled: true}, tabindex: -1} : {}
|
|
||||||
|
def link_or_button_options(type, name, image = nil, html_options)
|
||||||
|
name = (image ? svg_tag("pictograms/#{image}") : '') + name.to_s
|
||||||
|
|
||||||
|
html_options[:class] = class_names(
|
||||||
|
html_options[:class],
|
||||||
|
'button',
|
||||||
|
dangerous: html_options[:method] == :delete
|
||||||
|
)
|
||||||
|
|
||||||
|
if html_options[:onclick]&.is_a? Hash
|
||||||
|
html_options[:onclick] = "return confirm('\#{html_options[:onclick][:confirm]}');"
|
||||||
|
end
|
||||||
|
|
||||||
|
if type == :link && !(html_options[:onclick] || html_options.dig(:data, :turbo_stream))
|
||||||
|
name += '...'
|
||||||
|
end
|
||||||
|
|
||||||
|
[name, html_options]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,17 +7,17 @@
|
|||||||
<td class="actions">
|
<td class="actions">
|
||||||
<% unless unit.portable.nil? %>
|
<% unless unit.portable.nil? %>
|
||||||
<% if unit.default? %>
|
<% if unit.default? %>
|
||||||
<%= image_button_to t('.import'), 'download-outline', import_default_unit_path(unit),
|
<%= image_button_to_if unit.portable?, t('.import'), 'download-outline',
|
||||||
disabled_attributes(!unit.portable?) %>
|
import_default_unit_path(unit) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if current_user.at_least(:admin) %>
|
<% if current_user.at_least(:admin) %>
|
||||||
<% if unit.default? %>
|
<% if unit.default? %>
|
||||||
<%= image_button_to t('.delete'), 'delete-outline', default_unit_path(unit),
|
<%= image_button_to_if unit.movable?, t('.delete'), 'delete-outline',
|
||||||
method: :delete, **disabled_attributes(!unit.movable?) %>
|
default_unit_path(unit), method: :delete %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= image_button_to t('.export'), 'upload-outline', export_default_unit_path(unit),
|
<%= image_button_to_if unit.portable?, t('.export'), 'upload-outline',
|
||||||
disabled_attributes(!unit.portable?) %>
|
export_default_unit_path(unit) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
class: "extendedright" %>
|
class: "extendedright" %>
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<%= image_link_to_unless_current(current_user, "account-wrench-outline",
|
<%= image_link_to_unless_current(current_user, "account-wrench-outline",
|
||||||
edit_user_registration_path) {} %>
|
edit_user_registration_path) %>
|
||||||
<% if current_user_disguised? %>
|
<% if current_user_disguised? %>
|
||||||
<%= image_link_to t(".revert"), "incognito-off", revert_users_path %>
|
<%= image_link_to t(".revert"), "incognito-off", revert_users_path %>
|
||||||
<% else %>
|
<% else %>
|
||||||
@ -37,9 +37,9 @@
|
|||||||
method: :delete, data: {turbo: false} %>
|
method: :delete, data: {turbo: false} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= image_link_to_unless_current(t(:sign_in), "login", new_user_session_path) {} %>
|
<%= image_link_to_unless_current(t(:sign_in), "login", new_user_session_path) %>
|
||||||
<%= image_link_to_unless_current(t(:register), "account-plus-outline",
|
<%= image_link_to_unless_current(t(:register), "account-plus-outline",
|
||||||
new_user_registration_path) {} %>
|
new_user_registration_path) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
id: dom_id(unit, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %>
|
id: dom_id(unit, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= image_button_to t('.destroy'), 'delete-outline', unit_path(unit),
|
<%= image_button_to_if unit.movable?, t('.destroy'), 'delete-outline', unit_path(unit),
|
||||||
method: :delete, **disabled_attributes(!unit.movable?) %>
|
method: :delete %>
|
||||||
</td>
|
</td>
|
||||||
<% if unit.movable? %>
|
<% if unit.movable? %>
|
||||||
<td class="handle" draggable="true">⠿</td>
|
<td class="handle" draggable="true">⠿</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user