i’m trying to apply the “refresh” trigger in my coffeescript code, but I don’t find the correct syntax:
in standard jquery, it would be: $(‘.milestone_chain’).sortable(‘refresh’)
What would it be in coffeescript, knowing that this is my code:
$('.milestone_chain').sortable
axis: 'y'
containment: 'parent'
cursor: 'move'
tolerance: 'pointer'
update: (event,ui)->
$('li > a > div > span.number').each (i, element) =>
$(element).html i+1
$.ajax($(this).attr('data-update-url') + '/' + ui.item.attr('id') + '/reorder/' + (ui.item.index() + '.js'))
The html is the following:
<ul class="milestone_chain" data-update-url="projectmilestones">
<% projectcapstone.projectmilestones.rank(:rank).includes(:projectdepartment).each.with_index do |projectmilestone, i| %>
<li class="milestone_<%=projectmilestone.projectdepartment.ranking%>" id="<%=projectmilestone.id%>">
<div class="chainpie"><%= percent_pie(projectmilestone.status)%></div>
<div class="milestone<%=projectmilestone.projectdepartment.ranking%>"><%= link_to content_tag(:span, i+1, :class => "number"), projects_projectmilestone_path(projectmilestone) %></div>
<div class="milestonenum">
<%= link_to projectmilestone.name, projects_projectmilestone_path(projectmilestone) %>
<b class="notch"></b>
</div>
</li>
<% end %>
</ul>
It is working well. The problem is that the code needs sometimes to be loaded in Ajax and then it doesn’t work anymore. This is why I want to implement the refresh method. If I understood correctly, it addresses this issue
Thanks!
The answer was that Refresh wasn’t supposed to be triggered in the above question but after reloading the Ajax bloc of code, as part of the ajax function loading this code.
Should be obvious for javascript pro’s but not for newbies like me… Thanks