Various improvements to context drag&drop

-Don't botch other fields on context change
-Better status message
-Flash context title on drop
-Drop target close to context name
-Bolder drop target border

Closes #1033
This commit is contained in:
Eric Allen 2010-05-17 11:36:41 -04:00
parent b50a1ce26f
commit d9d08fac35
5 changed files with 29 additions and 6 deletions

View file

@ -230,6 +230,23 @@ class TodosController < ApplicationController
end end
end end
def change_context
@todo = Todo.find(params[:todo][:id])
@original_item_context_id = @todo.context_id
@context = Context.find(params[:todo][:context_id])
@todo.context = @context
@saved = @todo.save
@context_changed = true
@message = "Context changed to #{@context.name}"
determine_remaining_in_context_count(@original_item_context_id)
respond_to do |format|
format.js {render :action => :update }
format.xml { render :xml => @todo.to_xml( :except => :user_id ) }
end
end
def update def update
@source_view = params['_source_view'] || 'todo' @source_view = params['_source_view'] || 'todo'
init_data_for_sidebar unless mobile? init_data_for_sidebar unless mobile?

View file

@ -10,11 +10,11 @@
<%= link_to_context( context ) %> <%= link_to_context( context ) %>
<% end %> <% end %>
</h2> </h2>
<div id="c_<%=context.id%>_target" class="context_target drop_target"></div>
<div id="c<%= context.id %>items" class="items toggle_target"> <div id="c<%= context.id %>items" class="items toggle_target">
<div id="c<%= context.id %>empty-nd" style="display:<%= @not_done.empty? ? 'block' : 'none'%>;"> <div id="c<%= context.id %>empty-nd" style="display:<%= @not_done.empty? ? 'block' : 'none'%>;">
<div class="message"><p>Currently there are no incomplete actions in this context</p></div> <div class="message"><p>Currently there are no incomplete actions in this context</p></div>
</div> </div>
<%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "context" } %> <%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "context" } %>
</div><!-- [end:items] --> </div><!-- [end:items] -->
<div id="c_<%=context.id%>_target" class="context_target drop_target"></div>
</div><!-- [end:c<%= context.id %>] --> </div><!-- [end:c<%= context.id %>] -->

View file

@ -4,6 +4,7 @@ if @saved
status_message += ' to tickler' if @todo.deferred? status_message += ' to tickler' if @todo.deferred?
status_message = 'Added new project / ' + status_message if @new_project_created status_message = 'Added new project / ' + status_message if @new_project_created
status_message = 'Added new context / ' + status_message if @new_context_created status_message = 'Added new context / ' + status_message if @new_context_created
status_message = @message || status_message
page.notify :notice, status_message, 5.0 page.notify :notice, status_message, 5.0
if source_view_is_one_of(:todo, :context, :tag) if source_view_is_one_of(:todo, :context, :tag)
@ -46,12 +47,18 @@ if @saved
page.replace_html("badge_count", @down_count) if source_view_is :todo page.replace_html("badge_count", @down_count) if source_view_is :todo
# show todo in context # show todo in context
page.delay(0.5) do page.delay(0.3) do
page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items" page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items"
if source_view_is_one_of(:todo, :tag) && @todo.active? if source_view_is_one_of(:todo, :tag) && @todo.active?
page.call "todoItems.ensureContainerHeight", "c#{@todo.context_id}items" page.call "todoItems.ensureContainerHeight", "c#{@todo.context_id}items"
page.visual_effect :highlight, dom_id(@todo), :duration => 3 page.visual_effect :highlight, dom_id(@todo), :duration => 3
end end
if @context_changed
source_view do |from|
from.todo {page << "$('#c#{@todo.context_id} h2').effect('highlight', {}, 3000)" }
from.tag {page << "$('#c#{@todo.context_id} h2').effect('highlight')" }
end
end
end end
else else
if @original_item_was_deferred && source_view_is(:tag) if @original_item_was_deferred && source_view_is(:tag)

View file

@ -259,9 +259,8 @@ function enable_rich_interaction(){
ui.draggable.remove(); ui.draggable.remove();
target.block({message: null}); target.block({message: null});
setTimeout(function() {target.show()}, 0); setTimeout(function() {target.show()}, 0);
$.post(relative_to_root('todos/update'), $.post(relative_to_root('todos/change_context'),
{id: dragged_todo, {"todo[id]": dragged_todo,
"todo[id]": dragged_todo,
"todo[context_id]": context_id}, "todo[context_id]": context_id},
function(){target.unblock(); target.hide();}, 'script'); function(){target.unblock(); target.hide();}, 'script');
} }

View file

@ -951,7 +951,7 @@ div.message {
.context_target { .context_target {
height: 15px; height: 15px;
margin: 4px; margin: 4px;
border: thick dotted #CCC; border: 4px dotted #999;
} }
.context_target.hover { .context_target.hover {