Author: assaf
Date: Fri Jun  6 20:26:44 2008
New Revision: 664260

URL: http://svn.apache.org/viewvc?rev=664260&view=rev
Log:
Fixed can_delegate? to only allow delegation when other potential owners exist.
Fixed can_claim? to not allow claiming for excluded owner.
POST to complete task, redirects back to task list.
Now showing details URL if no perform URL provided (manual tasks).

Modified:
    ode/sandbox/singleshot/app/controllers/tasks_controller.rb
    ode/sandbox/singleshot/app/models/task.rb
    ode/sandbox/singleshot/app/views/tasks/show.html.erb
    ode/sandbox/singleshot/config/routes.rb
    ode/sandbox/singleshot/public/stylesheets/default.css

Modified: ode/sandbox/singleshot/app/controllers/tasks_controller.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/tasks_controller.rb?rev=664260&r1=664259&r2=664260&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/tasks_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/tasks_controller.rb Fri Jun  6 
20:26:44 2008
@@ -92,38 +92,13 @@
     render :text=>"<script>frames.top.location.href='#{tasks_url}'</script>"
   end
 
-
-
-  def new
-    @task = Task.new(:creator=>authenticated)
-    respond_to :html
-  end
-
-  def create
-    if input = params[:task]
-      input[:outcome_type] = suggested_outcome_type
-      input[:admins] = Array(input[:admins]) + [authenticated]
-      input.delete(:status)
-      @task = Task.create!(input)
-      respond_to do |format|
-        format.html { redirect_to tasks_url }
-        format.xml  { render :xml=>@task, :location=>task_url(@task), 
:status=>:created }
-        format.json { render :json=>@task, :location=>task_url(@task), 
:status=>:created }
-      end
-    else
-      task = Task.reserve!(authenticated)
-      render :nothing=>true, :location=>task_url(task), :status=>:see_other
-    end
-  end
-
   def complete
-    raise ActiveRecord::StaleObjectError, 'This task already completed.' if 
@task.completed?
-    raise NotAuthorized, 'You are not allowed to complete this task.' unless 
@task.can_complete?(authenticated)
-    data = params[:task][:data] if params[:task]
-    @task.complete!(data)
-    respond_to do |format|
-      format.xml  { render :xml=>@task }
-      format.json { render :json=>@task }
+    update = (params[:task] || {}).update(:status=>'completed')
+    @task.modify_by(authenticated).update_attributes!(update)
+    respond_to do |wants|
+      wants.html { redirect_to tasks_url }
+      # TODO: wants.xml
+      # TODO: wants.json
     end
   end
 

Modified: ode/sandbox/singleshot/app/models/task.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=664260&r1=664259&r2=664260&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Fri Jun  6 20:26:44 2008
@@ -139,8 +139,7 @@
     attr_reader :perform_url, :details_url, :integrated_ui
 
     def initialize(perform_url, details_url, integrated_ui)
-      @perform_url = perform_url
-      @details_url = details_url if perform_url
+      @perform_url, @details_url = perform_url, details_url
       @integrated_ui = (perform_url && integrated_ui) || false
     end
 
@@ -156,7 +155,7 @@
     # option is available, passes query parameters to the rendered URL.  Query
     # parameters are passed as last argument or returned from the block.
     def render_url(perform, params = {})
-      url = perform ? perform_url : details_url
+      url = perform && perform_url || details_url
       return url unless integrated_ui && url
       params = yield if block_given?
       uri = URI(url)
@@ -450,11 +449,11 @@
   end
 
   def can_claim?(person)
-    owner.nil? && (potential_owners.empty? || potential_owner?(person))
+    owner.nil? && (potential_owners.empty? || potential_owner?(person)) && 
!excluded_owner?(person)
   end
 
   def can_delegate?(person)
-    (owner?(person) && active?) || (admin?(person) && active? || ready?)
+    (owner?(person) && active? && !(potential_owners - [owner]).empty?) || 
(admin?(person) && (active? || ready?))
   end
 
   def filter_update_for(person)

Modified: ode/sandbox/singleshot/app/views/tasks/show.html.erb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/tasks/show.html.erb?rev=664260&r1=664259&r2=664260&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/tasks/show.html.erb (original)
+++ ode/sandbox/singleshot/app/views/tasks/show.html.erb Fri Jun  6 20:26:44 
2008
@@ -8,7 +8,7 @@
     <div class='actions'>
       <%= quick_actions(@task) %>
       <%= content_tag 'button', 'More Options', 
:onclick=>"Singleshot.expand(event, '.header .details', 'Less options')", 
:class=>'button-to' %>
-      <%= button_to 'Completed', task_url(@task, 'task[status]'=>'completed'), 
:method=>:put, :title=>'Click when task completed' if performing && 
@task.rendering.use_completion_button?  %>
+      <%= button_to 'Completed', task_url(@task), :title=>'Click when task 
completed' if performing && @task.rendering.use_completion_button?  %>
     </div>
     <div class='vitals'>
       <p class='title'><%= h(@task.title) %></p>

Modified: ode/sandbox/singleshot/config/routes.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/routes.rb?rev=664260&r1=664259&r2=664260&view=diff
==============================================================================
--- ode/sandbox/singleshot/config/routes.rb (original)
+++ ode/sandbox/singleshot/config/routes.rb Fri Jun  6 20:26:44 2008
@@ -2,6 +2,7 @@
 
   map.resource 'session'
   map.resources 'tasks', :collection=>{ 'completed'=>:get, 'following'=>:get, 
'complete_redirect'=>:get } do |tasks|
+    map.connect '/tasks/:id', :controller=>'tasks', :action=>'complete', 
:conditions=>{ :method=>:post }
     tasks.with_options :controller=>'task_for' do |opts|
       opts.connect 'for/:person_id', :action=>'update', :conditions=>{ 
:method=>:put }
       opts.for_person 'for/:person_id', :action=>'show'
@@ -17,6 +18,7 @@
   end
   map.root :controller=>'application'
   map.resource 'sandwich'
+  map.resource 'survey', :controller=>'survey'
 
   
   # The priority is based upon order of creation: first created -> highest 
priority.

Modified: ode/sandbox/singleshot/public/stylesheets/default.css
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/public/stylesheets/default.css?rev=664260&r1=664259&r2=664260&view=diff
==============================================================================
--- ode/sandbox/singleshot/public/stylesheets/default.css (original)
+++ ode/sandbox/singleshot/public/stylesheets/default.css Fri Jun  6 20:26:44 
2008
@@ -363,7 +363,7 @@
   width: 100%;
   height: 0;
   padding: 0;
-  margin: 3.5em 0 0 0;
+  margin: 4.4em 0 0 0;
   background: #fff;
 }
 


Reply via email to