Enabled dropping of actions on projects in the sidebar to ajaxomagically update the project for an action. Needs a little CSS work, but it's functional.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@276 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2006-07-03 00:59:31 +00:00
parent 9263249e77
commit b77f743bee
4 changed files with 57 additions and 9 deletions

View file

@ -206,6 +206,23 @@ class TodoController < ApplicationController
end
end
end
def update_project
self.init
@item = check_user_return_item
project = Project.find(params['project_id']);
if @user == project.user
@original_item_context_id = @item.context_id
@item.project_id = project.id
@item.project = project
@saved = @item.save
render :action => 'update_action'
else
render :update do |page|
page.replace_html "info", content_tag("div", "Error updating the project of the dragged item. Item and project user mis-match: #{@item.user.name} and #{@project.user.name}! - refresh the page to see them.", "class" => "warning")
end
end
end
def deferred_update_action
#self.init

View file

@ -1,7 +1,7 @@
<h3>Active Projects:</h3>
<ul>
<% for project in @projects.reject{|p| p.done? } -%>
<li><%= link_to( sanitize(project.name), { :controller => "project", :action => "show",
<li id="sidebar-project-<%= project.id %>" class="sidebar-project"><%= link_to( sanitize(project.name), { :controller => "project", :action => "show",
:name => urlize(project.name) } ) + " (" + project.count_undone_todos("actions") + ")" %></li>
<% end -%>
</ul>
@ -9,7 +9,7 @@
<h3>Completed Projects:</h3>
<ul>
<% for project in @projects.reject{|p| !p.done? } -%>
<li><%= link_to( sanitize(project.name), { :controller => "project", :action => "show",
<li id="sidebar-project-<%= project.id %>" class="sidebar-project"><%= link_to( sanitize(project.name), { :controller => "project", :action => "show",
:name => urlize(project.name) } ) + " (" + project.count_undone_todos("actions") + ")" %></li>
<% end -%>
</ul>
@ -17,7 +17,7 @@
<h3>Active Contexts:</h3>
<ul>
<% for context in @contexts.reject{|c| c.hide? } -%>
<li><%= link_to( sanitize(context.name), { :controller => "context", :action => "show",
<li id="sidebar-context-<%= context.id %>" class="sidebar-context"><%= link_to( sanitize(context.name), { :controller => "context", :action => "show",
:name => urlize(context.name) } ) + " (" + context.count_undone_todos("actions") + ")" %></li>
<% end -%>
</ul>
@ -25,7 +25,7 @@
<h3>Hidden Contexts:</h3>
<ul>
<% for context in @contexts.reject{|c| !c.hide? } -%>
<li><%= link_to( sanitize(context.name), { :controller => "context", :action => "show",
<li id="sidebar-context-<%= context.id %>" class="sidebar-context"><%= link_to( sanitize(context.name), { :controller => "context", :action => "show",
:name => urlize(context.name) } ) + " (" + context.count_undone_todos("actions") + ")" %></li>
<% end -%>
</ul>

View file

@ -1,9 +1,8 @@
if @saved
item_container_id = "item-#{@item.id}-container"
logger.info("@item.context_id = #{@item.context_id}")
logger.info("@original_item_context.id = #{@original_item_context_id}")
if @item.context_id == @original_item_context_id
page.replace_html item_container_id, :partial => 'todo/item'
page.call "todoItems.makeItemDraggable", item_container_id
page.visual_effect :highlight, item_container_id, :duration => 3
else
page["item-#{@item.id}-container"].remove

View file

@ -162,6 +162,12 @@ var todoItems = {
$$('.context').each(function(contextElem){
todoItems.makeContextDroppable(contextElem);
});
$$('.sidebar-project').each(function(projectElem){
todoItems.makeProjectDroppable(projectElem);
});
$$('.sidebar-context').each(function(contextElem){
todoItems.makeContextDroppable(contextElem);
});
},
makeItemDraggable: function(itemContainerElem)
{
@ -179,8 +185,16 @@ var todoItems = {
{
accept:'item-container',
hoverclass:'item-container-drop-target',
onDrop: todoItems.itemDrop,
zindex: 1000
onDrop: todoItems.itemContextDrop
});
},
makeProjectDroppable: function(projectElem)
{
Droppables.add($(projectElem).id,
{
accept:'item-container',
hoverclass:'item-container-drop-target',
onDrop: todoItems.itemProjectDrop
});
},
startDraggingItem:function(draggable)
@ -195,7 +209,7 @@ var todoItems = {
todoItems.setNextActionListingTogglesToCookiedState();
},
itemDrop:function(draggableElement, droppableElement) {
itemContextDrop:function(draggableElement, droppableElement) {
if (draggableElement.parentContainer == droppableElement) {
return; //same destination as original, nothing to be done
}
@ -212,6 +226,24 @@ var todoItems = {
evalScripts:true,
parameters:"id=" + todoId + "&context_id=" + contextId
})
},
itemProjectDrop:function(draggableElement, droppableElement) {
if (draggableElement.parentContainer == droppableElement) {
return; //same destination as original, nothing to be done
}
itemElementId = draggableElement.id
todoId = draggableElement.id.match(/\d+/)[0];
projectId = droppableElement.id.match(/\d+/)[0];
Draggables.drags.each(function(drag) {
if (drag.element == draggableElement) {
drag.destroy();
}
})
new Ajax.Request('/todo/update_project', {
asynchronous:true,
evalScripts:true,
parameters:"id=" + todoId + "&project_id=" + projectId
})
}
}
Event.observe(window, "load", todoItems.addNextActionListingToggles);