diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb
index 17f9b6d9..b3979a71 100644
--- a/tracks/app/controllers/todo_controller.rb
+++ b/tracks/app/controllers/todo_controller.rb
@@ -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
diff --git a/tracks/app/views/shared/sidebar.rhtml b/tracks/app/views/shared/sidebar.rhtml
index 010a9e7a..963b0c8e 100644
--- a/tracks/app/views/shared/sidebar.rhtml
+++ b/tracks/app/views/shared/sidebar.rhtml
@@ -1,7 +1,7 @@
Active Projects:
<% for project in @projects.reject{|p| p.done? } -%>
- - <%= link_to( sanitize(project.name), { :controller => "project", :action => "show",
+
<% end -%>
@@ -9,7 +9,7 @@
Completed Projects:
<% for project in @projects.reject{|p| !p.done? } -%>
- - <%= link_to( sanitize(project.name), { :controller => "project", :action => "show",
+
<% end -%>
@@ -17,7 +17,7 @@
Active Contexts:
<% for context in @contexts.reject{|c| c.hide? } -%>
- - <%= link_to( sanitize(context.name), { :controller => "context", :action => "show",
+
<% end -%>
@@ -25,7 +25,7 @@
Hidden Contexts:
<% for context in @contexts.reject{|c| !c.hide? } -%>
- - <%= link_to( sanitize(context.name), { :controller => "context", :action => "show",
+
<% end -%>
diff --git a/tracks/app/views/todo/update_action.rjs b/tracks/app/views/todo/update_action.rjs
index 952dae81..af0da8d2 100644
--- a/tracks/app/views/todo/update_action.rjs
+++ b/tracks/app/views/todo/update_action.rjs
@@ -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
diff --git a/tracks/public/javascripts/todo-items.js b/tracks/public/javascripts/todo-items.js
index 4ab26782..d3a6e0dc 100644
--- a/tracks/public/javascripts/todo-items.js
+++ b/tracks/public/javascripts/todo-items.js
@@ -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);