Changeset 587

Show
Ignore:
Timestamp:
03/22/07 02:38:34 (2 years ago)
Author:
jarmo
Message:
  • Added new functionality that allows the user to create a new task after filling a form, and to fill a form after closing a task.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/baseline/app/controllers/form_controller.rb

    r585 r587  
    7070 
    7171    @title = _('Fill out a form') 
     72    @task_types = TaskType.find(:all, :readonly => true) 
    7273    @form_type = FormType.find(params[:id], :conditions => ['ready = ?', true]) 
    7374    @form = @form_type.create_empty_form(@selected_asset) 
     
    7980    session[:image_fields] ||= { } 
    8081    session[:image_fields][@form_cookie] ||= {} 
     82 
     83    if params[:task_id] 
     84      begin 
     85        @closing_task = Task.find_authorized_to_edit(params[:task_id]) 
     86        if @closing_task.closing_form_id 
     87          flash[:error] = _('A closing form has already been filled for this task') 
     88          redirect_to :controller => 'task', :action => 'view', :id => @closed_task.id 
     89          return 
     90        end 
     91      rescue 
     92        redirect_to :controller => 'task', :action => 'view', :id => @closed_task.id 
     93      end 
     94    end 
    8195 
    8296    if request.post? 
     
    101115 
    102116        if @form.save and @form.update_automatic_field_values 
    103           redirect_to :action => 'view', :id => @form.id 
     117          if @closing_task 
     118            @closing_task.closing_form_id = @form.id 
     119            @closing_task.save 
     120          end 
     121          if params[:task_type_id_enabled] and params[:task_type_id] 
     122            redirect_to :controller => 'task', :action => 'create', :task_type_id => params[:task_type_id], :form_id => @form.id 
     123          else 
     124            redirect_to :action => 'view', :id => @form.id 
     125          end 
    104126          return 
    105127        end 
     
    129151    end 
    130152 
     153    @task_types = TaskType.find(:all, :readonly => true) 
    131154    @form_type = @form.form_type 
    132155    # Form cookies are used to match image field values in the session 
     
    154177        if @form.save_with_values 
    155178          flash[:notice] = msg_changes_saved 
    156           redirect_to :action => 'view', :id => @form.id and return 
     179          if params[:task_type_id_enabled] and params[:task_type_id] 
     180            redirect_to :controller => 'task', :action => 'create', :task_type_id => params[:task_type_id], :form_id => @form.id 
     181          else 
     182            redirect_to :action => 'view', :id => @form.id 
     183          end 
     184          return 
    157185        else 
    158186          flash[:error] = msg_saving_failed 
     
    318346    @title = _('Filled-out form %s (%s)', @form.to_s, @form.form_type.name) 
    319347    info("Displaying form ID:#{params[:id]}") 
     348 
     349    @associated_tasks = (@form.opened_tasks + @form.closed_tasks).uniq 
    320350 
    321351    if @form.form_type and @form.form_type.form_html_template 
  • branches/baseline/app/controllers/task_controller.rb

    r585 r587  
    8484    @wo_title = _('Task %s (%s)', @task.to_s, @task.task_type.name) 
    8585 
     86    @form_types = FormType.find(:all, :readonly => true, :conditions => ['ready = ?', true]) 
     87    @show_close_and_fill = @selected_asset.authorized_to(:create_form) and not @form_types.empty? and not @task.closing_form_id and @task.authorized_to_edit? 
     88 
    8689    if request.post? 
    8790      old_worker_ids = @task.workers.collect {|i| i.id} 
     
    116119        @task.accept 
    117120        flash[:notice] = _('Task accepted') 
    118       when 'close' 
     121      when 'close', 'close_and_fill' 
    119122        @task.close 
    120123        flash[:notice] = _('Task closed') 
     
    138141        if @task.save(true) 
    139142          flash[:notice] = msg_changes_saved 
     143          if params[:task_action] == 'close_and_fill' and params[:form_type_id] 
     144            redirect_to :controller => 'form', :action => 'create', :id => params[:form_type_id].to_i, :task_id => @task.id 
     145          end 
    140146        else 
    141147          flash[:notice] = nil 
     
    222228      @task.starting_time = nil unless params[:starting_time_enabled] 
    223229      @task.deadline = nil unless params[:deadline_enabled] 
     230 
     231      if params[:task][:opening_form_id] 
     232        begin 
     233          form = Form.find_authorized_to_read(params[:task][:opening_form_id]) 
     234          @task.opening_form_id = form.id 
     235        rescue ActiveRecord::RecordNotFound 
     236          error 'Unable to read the opening form' 
     237          @task.opening_form_id = nil 
     238        end 
     239      end 
    224240 
    225241      @task.ready = true 
     
    233249    else 
    234250      @task = Task.new 
     251 
     252      if params[:task_type_id] and not (@task_types.select { |type| type.id == params[:task_type_id].to_i }).empty? 
     253        @task.task_type_id = params[:task_type_id].to_i  
     254      end 
     255 
     256      if params[:form_id] 
     257        @task.opening_form_id = params[:form_id].to_i 
     258      end 
    235259    end 
    236260  end 
  • branches/baseline/app/models/form.rb

    r585 r587  
    1313  has_many :form_events, :dependent => :delete_all 
    1414  has_many :data_permissions, :dependent => :delete_all, :class_name => 'FormPermission' 
     15  has_many :opened_tasks, :class_name => 'Task', :foreign_key => 'opening_form_id' 
     16  has_many :closed_tasks, :class_name => 'Task', :foreign_key => 'closing_form_id' 
    1517#  has_many :user_groups, :through => :data_permissions 
    1618 
  • branches/baseline/app/models/task.rb

    r585 r587  
    1616  belongs_to :task_type 
    1717  belongs_to :responsible_user, :class_name => 'User', :foreign_key => 'responsible_user_id' 
     18  belongs_to :opening_form, :class_name => 'Form', :foreign_key => 'opening_form_id' 
     19  belongs_to :closing_form, :class_name => 'Form', :foreign_key => 'closing_form_id' 
    1820  has_many :task_events, :dependent => :delete_all 
    1921  has_many :data_permissions, :dependent => :delete_all, :class_name => 'TaskPermission' 
  • branches/baseline/app/views/form/_creation_form.rhtml

    r585 r587  
    2727  <%= render(:partial => 'form/inputs_for_fields', :locals => { :fields => remaining_fields, :form => form }) %> 
    2828 
     29  <%= hidden_field_tag('task_id', @closing_task.id) if @closing_task %> 
     30 
    2931  <% if form_type.editable -%> 
    3032  <br/> 
     
    3537      <td><%= check_box(:form, :editable) %></td> 
    3638    </tr> 
     39    <% if @selected_asset.authorized_to(:create_task) and not @task_types.empty? %> 
     40      <tr> 
     41        <th><%= _('Create new a task associated to this form') %></th> 
     42        <td><%= check_box_tag('task_type_id_enabled', '1', false, :onclick => "update_field_enabled('task_type_id')") %></td> 
     43        <th><%= _('Task type') %></th> 
     44        <td><%= select_tag("task_type_id", options_from_collection_for_select(@task_types, :id, :name), :disabled => true) %></td> 
     45      </tr> 
     46    <% end -%> 
    3747  </table> 
    3848  <% end -%> 
     
    4555  <% end -%> 
    4656</form> 
     57 
     58<script type="text/javascript"> 
     59Event.observe(window, 'load', update_field_enabled); 
     60</script> 
     61 
  • branches/baseline/app/views/form/view.rhtml

    r585 r587  
    99</object> 
    1010 
    11 <b><%= _('Asset') %>:</b> <%= link_to_asset(@form.asset) %><br/> 
     11<table> 
     12  <tr> 
     13    <th><%= _('Asset') %></th> 
     14  </td><tr> 
     15    <td><%= link_to_asset(@form.asset) %></td> 
     16  </tr> 
     17  <% unless @associated_tasks.empty? %> 
     18    <tr> 
     19      <th><%= _('Associated tasks') %></th> 
     20    </tr> 
     21    <% for task in @associated_tasks %> 
     22      <tr><td> 
     23        <%= link_to_task(task) %> 
     24      </td></tr> 
     25    <% end -%> 
     26  <% end -%> 
     27</table> 
     28 
    1229<br/> 
    1330<table class="actions"> 
  • branches/baseline/app/views/task/_form.rhtml

    r533 r587  
    123123  </table> 
    124124 
     125  <% if @task.opening_form_id or @task.closing_form_id -%> 
     126    <table class="task"> 
     127      <tr> 
     128        <th colspan="2"><%= _('Associated filled-out forms') %></th> 
     129      </tr> 
     130      <tr> 
     131        <td><%= link_to_form(@task.opening_form) %></td> 
     132        <td><%= link_to_form(@task.closing_form) %></td> 
     133      </tr> 
     134    </table> 
     135  <% end -%> 
     136 
    125137  <% if action == :view -%> 
    126138    <table> 
  • branches/baseline/app/views/task/create.rhtml

    r585 r587  
    4141  </table> 
    4242 
     43  <%= hidden_field('task', 'opening_form_id') %> 
     44 
    4345  <%= buttons_table(_('Create task'), {:action => 'list'}) %> 
    4446</form> 
  • branches/baseline/app/views/task/view.rhtml

    r585 r587  
    1616        <%= radio_button_tag('task_action', 'accept') %><%= _('Accept task') %><br/> 
    1717        <%= radio_button_tag('task_action', 'close') %><%= _('Close task') %><br/> 
     18        <% if @show_close_and_fill -%> 
     19          <%= radio_button_tag('task_action', 'close_and_fill') %><%= _('Close task and fill a form') %> 
     20          <%= select_tag("form_type_id", options_from_collection_for_select(@form_types, :id, :name)) %><br/> 
     21        <% end -%> 
    1822        <%= radio_button_tag('task_action', 'assign') %><%= _('Assign responsibility to') %>: 
    1923        <%= select_tag("responsible_user_id", options_from_collection_for_select(@users, "id", "login_and_name")) %><br/> 
     
    2226        <%= radio_button_tag('task_action', 'accept') %><%= _('Accept task') %><br/> 
    2327        <%= radio_button_tag('task_action', 'close') %><%= _('Close task') %><br/> 
     28        <% if @show_close_and_fill -%> 
     29          <%= radio_button_tag('task_action', 'close_and_fill') %><%= _('Close task and fill a form') %> 
     30          <%= select_tag("form_type_id", options_from_collection_for_select(@form_types, :id, :name)) %><br/> 
     31        <% end -%> 
    2432        <%= radio_button_tag('task_action', 'assign') %><%= _('Reassign responsibility to') %>: 
    2533        <%= select_tag("responsible_user_id", options_from_collection_for_select(@users, "id", "login_and_name")) %><br/> 
     
    2735        <%= radio_button_tag('task_action', 'leave', true) %><%= _('Leave as accepted') %><br/> 
    2836        <%= radio_button_tag('task_action', 'close') %><%= _('Close task') %><br/> 
     37        <% if @show_close_and_fill -%> 
     38          <%= radio_button_tag('task_action', 'close_and_fill') %><%= _('Close task and fill a form') %> 
     39          <%= select_tag("form_type_id", options_from_collection_for_select(@form_types, :id, :name)) %><br/> 
     40        <% end -%> 
    2941        <%= radio_button_tag('task_action', 'assign') %><%= _('Reassign responsibility to') %>: 
    3042        <%= select_tag("responsible_user_id", options_from_collection_for_select(@users, "id", "login_and_name")) %><br/> 
     
    3244        <%= radio_button_tag('task_action', 'leave', true) %><%= _('Leave as closed') %><br/> 
    3345        <%= radio_button_tag('task_action', 'reopen') %><%= _('Reopen task') %><br/> 
    34     <% end -%> 
     46    <% end -%>     
    3547 
    3648    <h4><%= _('Comments') %></h4> 
    37     <%= text_area_tag('task_comment', '', :cols => 80, :rows => 4) %> 
     49    <%= text_area_tag('task_comment', '', :cols => 80, :rows => 4) %><br/> 
    3850 
    3951    <%= buttons_table(_('Save changes'), {:action => 'list'}) %> 
     
    7082  </tr> 
    7183</table> 
     84 
     85<script type="text/javascript"> 
     86Event.observe(window, 'load', update_field_enabled); 
     87</script> 
  • branches/baseline/db/migrate/001_baseline.rb

    r586 r587  
    264264      t.column 'task_type_id', :integer, :references => :task_types, :null => false, :on_delete => :restrict, :on_update => :restrict 
    265265      t.column 'asset_id', :integer, :references => :assets, :null => false, :on_delete => :restrict, :on_update => :restrict 
     266      t.column 'opening_form_id', :integer, :references => :forms, :on_delete => :restrict, :on_update => :restrict 
     267      t.column 'closing_form_id', :integer, :references => :forms, :on_delete => :restrict, :on_update => :restrict 
    266268      t.column 'starting_time', :datetime 
    267269      t.column 'deadline', :datetime 

© 2004-2007 Norfello Oy All Rights Reserved