4

I have that action_item on my admin page:

action_item :only => :index do link_to I18n.t('admin.dem_ref_nvl_etb'), :action => 'whatever' end 

I'd like to know how I could display a pop-up window by clicking that link above, pretty much just like batch_action does when you use it with a "form" option (I don't need such an action here, it's just a basic link).

Any hint ?

Thanks a million for reading and helping!

2 Answers 2

10

Building on Hugues's answer, here's a more fleshed-out example that I managed to cobble together with my very meager javascript skills:

In app/assets/javascripts/active_admin.js:

//= require active_admin/base $(document).on('ready page:load turbolinks:load', function() { $('a.lextest').click(function(e) { e.stopPropagation(); // prevent Rails UJS click event e.preventDefault(); ActiveAdmin.modal_dialog("Send email to: ", {emails: 'text'}, function(inputs) {alert (inputs.emails)}) }) }) 

Note that I don't use the default active_admin.js.coffee because I dislike coffeescript -- just a personal preference. This code adds an onClick event handler to all links with class lextest. Now you can create such a link with a link_to:

link_to('Modal', '#', class: 'lextest')

I cobbled this all together from the way batch_action is implemented.

Sign up to request clarification or add additional context in comments.

1 Comment

Full example including round-tripping data back into rails: github.com/heroku/retrodot/pull/28/files
4

I found out your answer to your question. I won't go into much details as I suppose you know your Javascript, but this could be expand further.

ActiveAdmin come with a modal dialog javascript library. It is quite crude, but can get the job done. You can read about its existance on this documentation page: http://activeadmin.info/docs/9-batch-actions.html toward the 3/4 down at the end of the Batch Action form section. For the exact code check github: https://github.com/activeadmin/activeadmin/blob/master/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee

And this is a very basic example you can copy paste in a javascript console to check the effect.

ActiveAdmin.modal_dialog("Send email to: ", {emails: 'text'}, function(inputs) {alert (inputs.emails)}) 

As long as your good with your Javascript skills, you should be on track.

3 Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.