ManageIQ: Adding flexibility to Custom buttons

18:44 0 Comments

Custom buttons functionality allows you to hide/show buttons depending on user role, and assign buttons to particular service items. But sometimes buttons visibility could depend on different thing, like VM state or user quota etc.
In addition custom button are placed in one row at top bar, so it might become confusing if you have a lot of buttons for different purposes.
This workaround will help you to put your buttons wherever you want on a page, also allowing you to customize it with any picture or text you want.
First, you need to create haml view in any directory, for example  app/views/iba_custom/_service_custom_button.html
---
view ||= @record
= link_to_function(text, "$.post('/service/button/#{view.id}',{button_id: '#{button_id}', cls: 'Service', desc: '', id: '#{view.id}', pressed: 'custom_button'});", :style => "#{style}")

Then in service view you need to render this button with some params app/views/service/_svcs_show.html.haml
---
= render :partial => "iba_custom/service_custom_button", :locals => {:button_id => _("20"), :style => 'outline: none', :text => image_tag(image_path("image.png"), :class => "img", :width => 32, :height => 32)}

:button_id - id of custom button, which will be called from this button, button could be unassigned or not seen by any user, it still will be working
:style - any css style for your <a> tag which would appear in UI
:text - text of <a> tag. Could be plain text, image tag like in this case or any tag supported by rails haml formatting

0 comments: