Scriptaculous droppable groups

Does rails have a way to easily implement droppables for dynamically
changing lists. I’d like to be able to take my database of employees,
and my database of projects for that day and assign employees to
projects by dropping them onto the project. My problem is, the
projects are different every day, so I need to figure out how to create
my groups dynamically.

Thanks

On 9/19/06, Garrett [email protected] wrote:

Does rails have a way to easily implement droppables for dynamically
changing lists. I’d like to be able to take my database of employees,
and my database of projects for that day and assign employees to
projects by dropping them onto the project. My problem is, the
projects are different every day, so I need to figure out how to create
my groups dynamically.

Thanks

What I have done in these cases is to create a helper function that
inserts the appropriate javascript block and call that function once
for each droppable. Not the use of the :with parameter in the
link_to_remote call. This will be executed as javascript in the
context of the onDrop callback, this is how I get the id of the
dropped employee. Code is untested, so there are likely some bugs in
there, but the general idea works.

class SomeHelper

def project_drop_target(project)
html = <<-HTML

HTML
end

def employee_draggable(employee)
html = <<-HTML

HTML
end

end

And in your view:

<% for project in @projects %>

Some project details here
<%= project_drop_target project %> <% end %>

<% for employee in @employees %>

Some employee details here
<%= employee_draggable employee %> <% end %>
> > How do I get the Javascript to properly inject? >

Going back through my code. I realized the snippet I posted has some
bugs.

Try:

Droppables.add(“bucket_#{bucket.id}”,
{
onDrop:function(element){
#{remote_function(:update=>“project_#{project.id},
:url=>{:controller=>‘projects’, :action=>‘add_employee’,
:id=>project}, :with=>”‘dropped=’ + element.employee_id")}
}
}
);

Note the :with parameter changes to :with=>"‘dropped=’ +
element.employee_id".

Let me know if that works, if not, please post the full html source of
the generated page.

Cheers,
Max

Sorry for the delay when I run the new piece of code I get a syntax
error. The little arrow shows the error on the close parenthesis
behind element.employee_id. If I only remove the # at {remote_function
I get “can’t find string “HTML” anywhere before EOF”

app/helpers/schedule_helper.rb:11: syntax error
:id=>project}, :with=>"‘dropped=’ + element.employee_id")}

Thanks… I can tell this is exactally what I need, but I can’t get the
Injection of the javascript to work. My header is

Build: index

How do I get the Javascript to properly inject?

I figured it out. There were a few bugs in your code, but I fixed
them. Also the javascript for add employee is completely incorrect,
simply using the rails built in method works great.
<%= draggable_element “employee_#{employee.id}”, :revert => true %>

Thanks for your help

Oh and
<%= drop_receiving_element(“task_#{task.id}”, :url =>
{ :controller => “tasks”, :action => “add_employee” }) %>

Droppables.add(“bucket_#{bucket.id}”,
{
onDrop:function(element){
#{remote_function(:update=>“project_#{project.id}”,
:url=>{:controller=>‘projects’, :action=>‘add_employee’,
:id=>project}, :with=>"‘dropped=’ + element.employee_id")}
}
}
);

There was a missing " after “project_#{project.id}”

the #{something} is a string replacement notation the # in that case
it not a comment.

Give it another try.

Max

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs