NewbieQ: How do I refresh view after return from popup windo

Hi,
I have this bitta code that is supposed to open a new window and allow
the user to create a new Organisation on the fly whilst editing a new
Person i.e. if the Organisation exists they can select it from the drop
down select. Otherwise they can click on the cute button and enter a
skeleton Organisation record. What I need to do next is refresh the drop
down select on returno the new organisation is shown and selected.

I have no idea how to do that - Any ideas? BTW - I’m not yet using AJAX

Usual Person data… Name, Position, etc
Then;

<%= link_to(image_tag("new_organisation.png", :alt => 'New', :border =>1), { :controller => 'organisations', :action => 'new'}, :popup => ['new_window', 'height=100,width=100']) %> <%= options_from_collection_for_select @org, "id", "organisation_name", @person.organisation_id %>

I would be very interested in this question too…has anybody
figured this out?

Thanks
Victor

Eric S. wrote:

Hi,
I have this bitta code that is supposed to open a new window and allow
the user to create a new Organisation on the fly whilst editing a new
Person i.e. if the Organisation exists they can select it from the drop
down select. Otherwise they can click on the cute button and enter a
skeleton Organisation record. What I need to do next is refresh the drop
down select on returno the new organisation is shown and selected.

I have no idea how to do that - Any ideas? BTW - I’m not yet using AJAX

Usual Person data… Name, Position, etc
Then;

<%= link_to(image_tag("new_organisation.png", :alt => 'New', :border =>1), { :controller => 'organisations', :action => 'new'}, :popup => ['new_window', 'height=100,width=100']) %> <%= options_from_collection_for_select @org, "id", "organisation_name", @person.organisation_id %>

I’d be too… will try tomorrow… with some Ajax request…

Victor wrote:

I would be very interested in this question too…has anybody
figured this out?

Thanks
Victor

Eric S. wrote:

What I need to do next is refresh the drop
down select on returno the new organisation
is shown and selected.

I have no idea how to do that - Any ideas?
BTW - I’m not yet using AJAX

You need to be using Ajax (probably via RJS). Put the drop-down in a

and re-render it after you're done entering the new Org record.

To learn RJS, I strongly recommend Cody F.'s “RJS Templates” PDF
from
O’Reilly. One of the best $10 I ever spent to learn a new programming
tool
/ technique.

hth,
Bill

AJAX seems like a good option here. But if you don’t want to get into
that and don’t mind the whole page being refreshed you could also try
something like this:

  • Add a hidden field to your form called “organisation_added” which is
    set to false by default.
  • Then when an organisation is added, use JavaScript to set
    “organisation_added” to true and post the form.
  • Then with Ruby, if params[‘organisation_added’] is set to true create
    a person object using the data that has already been entered (@person =
    Person.new(params[:person]) ), and re-render the form.
  • params[‘organisation_added’] == false means the user posted the form
    manually, so in that case you can save the person to your DB.

Good luck!

In Javascript window.opener is your reference to the parent window,
i.e. the window it was popped up from. Example:

In your main page where the form exists:

In the pop-up page:

Hi

  • Then when an organisation is added, use JavaScript to set
    “organisation_added” to true and post the form.

How to do this bit?

In particular how to use javascript from the popup to reference the page
it was popped up from. Also how to set the field and post the form
whilst not loosing any of the data already entered?

In my case I want to let the user enter som Lat/Lon position data, OR
for convenience popup a google maps object and have it fill in the
details in the original form when the user clicks on a location. I
don’t feel that I need to post the form, just figure out how to
reference back from the popped up page back to the original page?

Cheers

Ed W