Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add target_window to actions #3419

Merged
merged 7 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/helpers/rails_admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ def menu_for(parent, abstract_model = nil, object = nil, only_icon = false) # pe
else
'javascript:void(0)'
end
content_tag(:a, label, {href: href}.merge(action.pjax? ? {class: ['pjax']} : {}))

extra_classes = []
extra_classes << 'pjax' if action.pjax? && action.target_window != :_blank

extra_tags = {}
extra_tags[:target] = action.target_window if action.target_window.present?

content_tag(:a, label, {href: href, class: extra_classes}.merge(extra_tags))
RocKhalil marked this conversation as resolved.
Show resolved Hide resolved
else
content_tag(:span, label)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/rails_admin/config/actions/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class Base
true
RocKhalil marked this conversation as resolved.
Show resolved Hide resolved
end

# Target window [_self, _blank]
register_instance_option :target_window do
RocKhalil marked this conversation as resolved.
Show resolved Hide resolved
nil
end

# This block is evaluated in the context of the controller when action is called
# You can access:
# - @objects if you're on a model scope
Expand Down