From fe066e3bcb1020465ebe5535c53cd9afae05cca0 Mon Sep 17 00:00:00 2001 From: Henrik Bohre Date: Wed, 10 Jun 2009 00:07:23 +0200 Subject: [PATCH] #300: Added infrastructure for drag and drop dependency creation --- app/controllers/todos_controller.rb | 9 +++++++++ app/helpers/todos_helper.rb | 8 ++++++++ app/views/todos/_todo.html.erb | 11 +++++++++++ public/stylesheets/standard.css | 10 +++++----- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 56c9213c..20afba9b 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -140,6 +140,15 @@ class TodosController < ApplicationController format.xml { render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ) } end end + + def add_predecessor + logger.debug "add_predecessor" + @predecessor = Todo.find(params['predecessor']) + @successor = Todo.find(params['successor']) + respond_to do |format| + format.js + end + end # Toggles the 'done' status of the action # diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 23cda92f..111d0adf 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -106,6 +106,14 @@ module TodosHelper end end + def grip_span + unless @todo.completed? + image_tag('grip.png', :width => '7', :height => '16', :border => '0', + :title => 'Drag onto another action to make it depend on this action', + :class => 'grip') + end + end + def tag_list_text @todo.tags.collect{|t| t.name}.join(', ') end diff --git a/app/views/todos/_todo.html.erb b/app/views/todos/_todo.html.erb index d253f760..59134ad9 100644 --- a/app/views/todos/_todo.html.erb +++ b/app/views/todos/_todo.html.erb @@ -22,6 +22,7 @@ parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag' <% end %>
+ <%= grip_span %> <%= date_span -%> <%= h sanitize(todo.description) %> <%= successors_span %> @@ -39,3 +40,13 @@ parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag' <% end -%>
+<%= +draggable_element(dom_id(todo), :revert => "'failure'", :handle => "'grip'", :onDrop => "''") +%> +<%= +drop_receiving_element(dom_id(todo), + :url => {:controller => "todos", :action => "add_predecessor"}, + :with => "'successor=' + encodeURIComponent(element.id.split('_').last()) + '&predecessor=' + encodeURIComponent(#{todo.id})" +) +%> + diff --git a/public/stylesheets/standard.css b/public/stylesheets/standard.css index 2c7330bd..8fb551f8 100644 --- a/public/stylesheets/standard.css +++ b/public/stylesheets/standard.css @@ -381,11 +381,7 @@ input.item-checkbox { .description, .stale_l1, .stale_l2, .stale_l3 { margin-left: 60px; - position:relative; -} - -.stale_l1, .stale_l2, .stale_l3 { - padding-left: 3px; + position:relative; } .stale_l1 { @@ -939,6 +935,10 @@ div.message { color: #666; } +.grip { + cursor: move; +} + /* Error message styles */ .fieldWithErrors { padding: 2px;