Fix rendering of successors, drag and drop

This commit is contained in:
Eric Allen 2009-11-29 20:00:54 -05:00
parent 34aeb83891
commit d0a5f6b731
7 changed files with 24 additions and 20 deletions

View file

@ -69,6 +69,10 @@ module TodosHelper
return "$('#ul#{dom_id(todo)}').css('visibility', 'hidden'); $('##{dom_id(todo)}').block({message: null})"
end
def successor_start_waiting_js(successor)
return "$('##{dom_id(successor, "successor")}').block({message: null})"
end
def todo_stop_waiting_js(todo)
return "$('##{dom_id(todo)}').unblock();enable_rich_interaction();"
end

View file

@ -16,8 +16,7 @@ parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
{:url => {:controller => 'todos', :action => 'remove_predecessor', :id => successor.id},
:method => 'delete',
:with => "'#{parameters}&predecessor=#{predecessor.id}'",
:before => todo_start_waiting_js(dom_id(successor, 'successor')),
:complete => todo_stop_waiting_js},
:before => successor_start_waiting_js(successor)},
{:style => "background: transparent;"}) %>
<%= render(:partial => "todos/toggle_successors", :locals => { :item => successor, :suppress_button => true }) unless successor.pending_successors.empty? %>

View file

@ -45,14 +45,3 @@ parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
<% end -%>
</div>
</div>
<%=
draggable_element(dom_id(todo), :revert => "'true'", :handle => "'grip'", :onDrop => "''")
%>
<%=
drop_receiving_element(dom_id(todo),
:url => {:controller => "todos", :action => "add_predecessor"},
:with => "'#{parameters}&successor=' + encodeURIComponent(element.id.split('_').last()) + '&predecessor=' + encodeURIComponent(#{todo.id})",
:hoverclass => 'hover'
)
%>

View file

@ -19,8 +19,6 @@ if @saved
:pending => @todo.project.pending_todos }
end
page << "TodoBehavior.enableToggleNotes();"
page << "TodoBehavior.enableToggleSuccessors();"
page.notify :notice, status_message, 5.0
else
page.replace_html "status", content_tag("div", content_tag("h2", "Unable to add dependency"), "id" => "errorExplanation", "class" => "errorExplanation")

View file

@ -34,8 +34,7 @@ if @saved
page << "}"
end
# make sure the behavior of the new/updated todo is enabled
page << "TodoBehavior.enableToggleNotes()"
page << "TodoBehavior.enableToggleSuccessors()"
page << "enable_rich_interaction();"
else
page.show 'status'
page.replace_html 'status', "#{error_messages_for('todo', :object_name => 'action')}"

View file

@ -19,9 +19,7 @@ if @removed
page.replace dom_id(@successor), :partial => 'todos/todo', :locals => {
:todo => @successor, :parent_container_type => parent_container_type }
end
page << "TodoBehavior.enableToggleNotes()"
page << "TodoBehavior.enableToggleSuccessors()"
page << "enable_rich_interaction();"
else
page.notify :error, "There was an error removing the dependency", 8.0
end

View file

@ -203,6 +203,23 @@ function enable_rich_interaction(){
$('input[name=tag_list]').live('keypress', function(){
$(this).attr('edited', 'true');
});
/* Drag & Drop for successor/predecessor */
function drop_todo(evt, ui) {
dragged_todo = ui.draggable[0].id.split('_')[2];
dropped_todo = this.id.split('_')[2];
ui.draggable.hide();
$(this).block({message: null});
$.post('/todos/add_predecessor',
{successor: dragged_todo, predecessor: dropped_todo},
null, 'script');
}
$('.item-show').draggable({handle: '.grip', revert: 'invalid'});
$('.item-show').droppable({
drop: drop_todo,
hoverClass: 'hover'
});
}
$(document).ready(function() {