Skip to content

Commit 6c877ea

Browse files
committed
Allow actions to be shown disabled instead of completely hidden
Closes #1765
1 parent 5aaee51 commit 6c877ea

3 files changed

Lines changed: 44 additions & 9 deletions

File tree

app/assets/stylesheets/rails_admin/ra.widgets.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ iframe.wysihtml5-sandbox, .wysihtml5-editor{
1818

1919
.form-group.hidden_type {
2020
display: none;
21+
}
22+
23+
.links .inline.list-inline .disabled span {
24+
color: $gray-light;
2125
}

app/helpers/rails_admin/application_helper.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,23 @@ def menu_for(parent, abstract_model = nil, object = nil, only_icon = false) # pe
142142
actions = actions(parent, abstract_model, object).select { |a| a.http_methods.include?(:get) && a.show_in_menu }
143143
actions.collect do |action|
144144
wording = wording_for(:menu, action)
145-
%(
146-
<li title="#{wording if only_icon}" rel="#{'tooltip' if only_icon}" class="icon #{action.key}_#{parent}_link #{'active' if current_action?(action)}">
147-
<a class="#{action.pjax? ? 'pjax' : ''}" href="#{rails_admin.url_for(action: action.action_name, controller: 'rails_admin/main', model_name: abstract_model.try(:to_param), id: (object.try(:persisted?) && object.try(:id) || nil))}">
148-
<i class="#{action.link_icon}"></i>
149-
<span#{only_icon ? " style='display:none'" : ''}>#{wording}</span>
150-
</a>
151-
</li>
152-
)
153-
end.join.html_safe
145+
li_class = ['icon', "#{action.key}_#{parent}_link"].
146+
concat(current_action?(action) ? ['active'] : []).
147+
concat(action.enabled? ? [] : ['disabled'])
148+
content_tag(:li, {class: li_class}.merge(only_icon ? {title: wording, rel: 'tooltip'} : {})) do
149+
label = content_tag(:i, '', {class: action.link_icon}) + content_tag(:span, wording, (only_icon ? {style: 'display:none'} : {}))
150+
if action.enabled? || !only_icon
151+
href = if action.enabled?
152+
rails_admin.url_for(action: action.action_name, controller: 'rails_admin/main', model_name: abstract_model.try(:to_param), id: (object.try(:persisted?) && object.try(:id) || nil))
153+
else
154+
'javascript:void(0)'
155+
end
156+
content_tag(:a, label, {href: href}.merge(action.pjax? ? {class: ['pjax']} : {}))
157+
else
158+
content_tag(:span, label)
159+
end
160+
end
161+
end.join(' ').html_safe
154162
end
155163

156164
def bulk_menu(abstract_model = @abstract_model)

spec/integration/actions/base_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,28 @@
4444
end
4545
end
4646
end
47+
48+
context 'when used with #visible?' do
49+
let!(:player) { FactoryBot.create(:player) }
50+
before do
51+
RailsAdmin.config do |config|
52+
config.actions do
53+
index
54+
show
55+
edit do
56+
enabled false
57+
visible true
58+
end
59+
end
60+
end
61+
end
62+
63+
it 'allows disabled links to be shown' do
64+
visit index_path(model_name: 'player')
65+
is_expected.to have_css('.edit_member_link.disabled span', text: /Edit/, visible: false)
66+
visit show_path(model_name: 'player', id: player.id)
67+
is_expected.to have_css('.edit_member_link.disabled a[href*="void(0)"]')
68+
end
69+
end
4770
end
4871
end

0 commit comments

Comments
 (0)