Is there any way for a sortable_element to execute javascript on
success? I
have a sortable list of editable objects, and whenever they are moved
they
call the ‘update_positions’ function to store the new position
information.
More than one user can update a report at the same time, and in
‘update_positions’ there is a check to see if the report has been
altered by
another user since this user started editing it. Basically i want to
refresh
the page if the data is old, but return nothing if the data is current.
I’ve
tried using :success, :complete etc in the sortable_element call but
none of
them seem to work. The only thing that seems to work is :update, but
it’s
not much use to me because i want to execute returned javascript, not
update
the whole page when most of the time there is no need to. Am I just
using
:success wrongly, or is it not supported for sortable_elements?
In my view:
<%= sortable_element(‘sortable_items’,
:tag => ‘div’,
:constraint => false, #:success => doesn’t work? #:complete => doesn’t work? #:update => works but i don’t want to update every time
:url => {:controller => ‘report’, :action =>
:update_positions}) %>
# update_positions()
# Save the positions of the report components when they are re-ordered
def update_positions
# Security check
unauthorised_action ParamsNotProvidedError unless params
unauthorised_action InsufficientPrivilegesError unless
@session[:navigation][:current_report].is_writable?(@session[:user])
return false if self.auth_err
if @session[:navigation][:current_report].has_been_modified?
force_reload
return false
end
params[:sortable_items].each_index do |i|
item = ReportComponent.find(params[:sortable_items][i])
item.position = i
item.save
end
render :nothing => true
end
private
#--------------------------------------------------------------------------