Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change updated object in several places #66

Closed
link-er opened this issue Dec 26, 2011 · 6 comments
Closed

Change updated object in several places #66

link-er opened this issue Dec 26, 2011 · 6 comments

Comments

@link-er
Copy link

link-er commented Dec 26, 2011

Hello
I use best_in_place in dialog window over the page that contains same objects, that I'm updating in dialog.
I.e. I have page:

......
<div id="project_groups_index">
<% @project_groups.each do |group| %>
    <p id="<%= "project_group_link_container_#{group.id}" %>"><%= link_to group.name, "#{projects_path}?scope=#{group.id}" %></p>
<% end %>
 </div>
  <input type="button" value="<%= t('project_group.manage') %>" id="project_groups_dialog_link" />
  <div id="project_groups_dialog" style="display:none"><%= render 'project_groups/list' %></div>
.......

I have _list:

 <div id="project_groups">
<%= render @project_groups %>
 </div>
 </br>
   <p><%= t "project_group.new_project_group" %></p>
    <%= semantic_form_for current_account.project_groups.new, :validate => true, :remote => true do |f| %>
     <%= render 'project_groups/form', :f => f %>
  <% end %>

And I have _project_group:

 <p id="<%= "project_group_#{project_group.id}" %>">
 <%= best_in_place project_group, :name, :type => :input, :path => update_inline_project_group_path(project_group) %> 
 <% if project_group.projects.all.empty? %>
  <%= link_to t('share.destroy'), project_group, "data-confirm" => t('share.are_you_sure'), "data-method" => :delete, :remote => true, :disable_with => '<img src="/assets/spinner.gif"/>' %>
   <% end %>
  </p>

So I want to change project groups names on page after user update it in dialog. Is it possible?

@pilap82
Copy link

pilap82 commented Dec 27, 2011

Hi, same request here.
this image:

<%= image_tag "led#{@status_led[budget.negotiation_status]}.png" %>

is dependant on this best_in_place field

<%= best_in_place budget, :negotiation_status, :type => :select, :collection => $budget_status %>

I haven't found the way to refresh the image based on the changed version of negotiation_status.

@tbuyle
Copy link

tbuyle commented Jan 6, 2012

You may want to try adding the follwing JS

$('.best_in_place[data-attribute="negociation_status"]').bind(
"ajax:success", function(event, data) {
    // function that will update your image
});

@link-er
Copy link
Author

link-er commented Jan 6, 2012

Thanks! Worked perfectly for me!

@link-er link-er closed this as completed Jan 6, 2012
@pilap82
Copy link

pilap82 commented Jan 8, 2012

This indeed works, thanks!
but I'm still puzzled by how to get anything else than the value of display_as.
I'd like to access the value of my :budget object and can't figure out how :(

@link-er
Copy link
Author

link-er commented Jan 9, 2012

I'm afraid that you can't get any objects in js-files...maybe you can move needed columns to attributes of your html tag with best_in_place ?

@tbuyle
Copy link

tbuyle commented Jan 9, 2012

It's up to your controllers to return the objects so that your JS can access them and update the page accordingly.

In the function(event, data) above, 'data' will contains what your update controller returns. So you could code your update controller in a way that it will return the needed info.

Another solution is to call another controller from your JS (using $.load , $.get or other) that will return the object.

for example, here is what i have in my update controller :

// respond to json request with
render :json => {"model" => @model}
"ajax:success", function(event, data) {
var result = $.parseJSON(data);
// from here the result var will be accessible with all the data returned by the controller.
// result.model is your object - use result.model.attribute  to get specific values...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants