This is the facebox popup content
<div class="form_container">
<% form_remote_tag :url => { :action => 'custom', :d=>params[:day], :h=>params[:hour] },
:class => 'general-form',
:update => 'grid['+params[:day]+']['+params[:hour]+']',
:success => 'handle_success('+params[:day]+','+params[:hour]+')' do -%>
<table width="300px" style="border:none">
<% @availability_hash.each_key do |availability_id| %>
#some view related stuff
<% end %>
</table>
<input type="submit" class="btn" value="Re-assign Coaches" />
<% end %>
</div>
This is the controller method
def custom
master_scheduler
h = params[:h].to_i
d = params[:d].to_i
render(:partial => "grid_item" , :locals => {:day=>d, :hour=>h})
end
This is the partial, (_grid_item.html.erb)
<div class ="left_inner_element">
<div class="l_upper_element">
<div class="coaches_committed"><%= data[:committed_coaches] %></div>
<div class="coaches_available"><%= data[:available_coaches] %></div>
</div>
<div class="l_lower_element"><%= data[:classes] %> : <%= data[:avg_attendance] %>
</div>
</div>
<a id="link[<%= day %>][<%= hour %>]" rel="facebox" href="coach_selector_popup?(bla bla)" >
<div class ="right_inner_element right_inner_color_<%= data[:color_code] %>">
#some ui stuff
</div>
</a>
This is the script used in the main page
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('a[rel*=facebox]').facebox()
$.facebox.settings.opacity = 0.5
})
function handle_success(d,h){
jQuery(document).trigger('close.facebox');
var link_div = document.getElementById('link['+d+']['+h+']');
jQuery(link_div).facebox();
}
</script>
<div class="master_view">
<table class="master_scheduler_table" id="master_scheduler_table" >
<% HOURS_IN_A_DAY.each do |hour| %>
<tr>
<td><%= time(hour*2) %></td>
<% DAYS_IN_A_WEEK.each do |day| %>
<td id="grid[<%= day %>][<%= hour %>]" >
<%= render(:partial => "grid_item" , :locals => {:day=>day, :hour=>hour, :data=>@data[day][hour]}) %>
</td>
<% end %>
</tr>
<% end %>
</table>
</div>
After this rendering is done, I would like to invoke a javscript. How to do that? I am using a form_remote_tag from the view.
The render partial is done in Ajax context, no page reloads will happen. The form_remote_tag has a :success method where I can call a javascript. Unfortunately, the javascript that I put in the success method is getting called 'before' the rendering is done. But, I need to invoke a javascript 'after' the rendering is complete.
I have simply put an alert message for clarity in Question. Actually I am calling a facebox() method on the DIV element that I am rendering. The facebox() (jQuery's) method should be applied to the DIV element after it is rendered only then it will be effective.
Edit: I have added the complete code. If you can see, I am calling the javascript method handle_success once the Ajax returns. (I apologize for putting the :success method inside the partial). The handle_success is called before the actual rendering completes. That should be 'after' it completes