From b77f743beeff9dece959d66762084ae40e454e77 Mon Sep 17 00:00:00 2001 From: lukemelia Date: Mon, 3 Jul 2006 00:59:31 +0000 Subject: [PATCH] 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 --- tracks/app/controllers/todo_controller.rb | 17 ++++++++++ tracks/app/views/shared/sidebar.rhtml | 8 ++--- tracks/app/views/todo/update_action.rjs | 3 +- tracks/public/javascripts/todo-items.js | 38 +++++++++++++++++++++-- 4 files changed, 57 insertions(+), 9 deletions(-) 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:

@@ -9,7 +9,7 @@

Completed Projects:

@@ -17,7 +17,7 @@

Active Contexts:

@@ -25,7 +25,7 @@

Hidden Contexts:

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);