Changeset 587
- Timestamp:
- 03/22/07 02:38:34 (2 years ago)
- Files:
-
- branches/baseline/app/controllers/form_controller.rb (modified) (6 diffs)
- branches/baseline/app/controllers/task_controller.rb (modified) (5 diffs)
- branches/baseline/app/models/form.rb (modified) (1 diff)
- branches/baseline/app/models/task.rb (modified) (1 diff)
- branches/baseline/app/views/form/_creation_form.rhtml (modified) (3 diffs)
- branches/baseline/app/views/form/view.rhtml (modified) (1 diff)
- branches/baseline/app/views/task/_form.rhtml (modified) (1 diff)
- branches/baseline/app/views/task/create.rhtml (modified) (1 diff)
- branches/baseline/app/views/task/view.rhtml (modified) (5 diffs)
- branches/baseline/db/migrate/001_baseline.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/baseline/app/controllers/form_controller.rb
r585 r587 70 70 71 71 @title = _('Fill out a form') 72 @task_types = TaskType.find(:all, :readonly => true) 72 73 @form_type = FormType.find(params[:id], :conditions => ['ready = ?', true]) 73 74 @form = @form_type.create_empty_form(@selected_asset) … … 79 80 session[:image_fields] ||= { } 80 81 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 81 95 82 96 if request.post? … … 101 115 102 116 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 104 126 return 105 127 end … … 129 151 end 130 152 153 @task_types = TaskType.find(:all, :readonly => true) 131 154 @form_type = @form.form_type 132 155 # Form cookies are used to match image field values in the session … … 154 177 if @form.save_with_values 155 178 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 157 185 else 158 186 flash[:error] = msg_saving_failed … … 318 346 @title = _('Filled-out form %s (%s)', @form.to_s, @form.form_type.name) 319 347 info("Displaying form ID:#{params[:id]}") 348 349 @associated_tasks = (@form.opened_tasks + @form.closed_tasks).uniq 320 350 321 351 if @form.form_type and @form.form_type.form_html_template branches/baseline/app/controllers/task_controller.rb
r585 r587 84 84 @wo_title = _('Task %s (%s)', @task.to_s, @task.task_type.name) 85 85 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 86 89 if request.post? 87 90 old_worker_ids = @task.workers.collect {|i| i.id} … … 116 119 @task.accept 117 120 flash[:notice] = _('Task accepted') 118 when 'close' 121 when 'close', 'close_and_fill' 119 122 @task.close 120 123 flash[:notice] = _('Task closed') … … 138 141 if @task.save(true) 139 142 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 140 146 else 141 147 flash[:notice] = nil … … 222 228 @task.starting_time = nil unless params[:starting_time_enabled] 223 229 @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 224 240 225 241 @task.ready = true … … 233 249 else 234 250 @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 235 259 end 236 260 end branches/baseline/app/models/form.rb
r585 r587 13 13 has_many :form_events, :dependent => :delete_all 14 14 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' 15 17 # has_many :user_groups, :through => :data_permissions 16 18 branches/baseline/app/models/task.rb
r585 r587 16 16 belongs_to :task_type 17 17 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' 18 20 has_many :task_events, :dependent => :delete_all 19 21 has_many :data_permissions, :dependent => :delete_all, :class_name => 'TaskPermission' branches/baseline/app/views/form/_creation_form.rhtml
r585 r587 27 27 <%= render(:partial => 'form/inputs_for_fields', :locals => { :fields => remaining_fields, :form => form }) %> 28 28 29 <%= hidden_field_tag('task_id', @closing_task.id) if @closing_task %> 30 29 31 <% if form_type.editable -%> 30 32 <br/> … … 35 37 <td><%= check_box(:form, :editable) %></td> 36 38 </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 -%> 37 47 </table> 38 48 <% end -%> … … 45 55 <% end -%> 46 56 </form> 57 58 <script type="text/javascript"> 59 Event.observe(window, 'load', update_field_enabled); 60 </script> 61 branches/baseline/app/views/form/view.rhtml
r585 r587 9 9 </object> 10 10 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 12 29 <br/> 13 30 <table class="actions"> branches/baseline/app/views/task/_form.rhtml
r533 r587 123 123 </table> 124 124 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 125 137 <% if action == :view -%> 126 138 <table> branches/baseline/app/views/task/create.rhtml
r585 r587 41 41 </table> 42 42 43 <%= hidden_field('task', 'opening_form_id') %> 44 43 45 <%= buttons_table(_('Create task'), {:action => 'list'}) %> 44 46 </form> branches/baseline/app/views/task/view.rhtml
r585 r587 16 16 <%= radio_button_tag('task_action', 'accept') %><%= _('Accept task') %><br/> 17 17 <%= 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 -%> 18 22 <%= radio_button_tag('task_action', 'assign') %><%= _('Assign responsibility to') %>: 19 23 <%= select_tag("responsible_user_id", options_from_collection_for_select(@users, "id", "login_and_name")) %><br/> … … 22 26 <%= radio_button_tag('task_action', 'accept') %><%= _('Accept task') %><br/> 23 27 <%= 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 -%> 24 32 <%= radio_button_tag('task_action', 'assign') %><%= _('Reassign responsibility to') %>: 25 33 <%= select_tag("responsible_user_id", options_from_collection_for_select(@users, "id", "login_and_name")) %><br/> … … 27 35 <%= radio_button_tag('task_action', 'leave', true) %><%= _('Leave as accepted') %><br/> 28 36 <%= 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 -%> 29 41 <%= radio_button_tag('task_action', 'assign') %><%= _('Reassign responsibility to') %>: 30 42 <%= select_tag("responsible_user_id", options_from_collection_for_select(@users, "id", "login_and_name")) %><br/> … … 32 44 <%= radio_button_tag('task_action', 'leave', true) %><%= _('Leave as closed') %><br/> 33 45 <%= radio_button_tag('task_action', 'reopen') %><%= _('Reopen task') %><br/> 34 <% end -%> 46 <% end -%> 35 47 36 48 <h4><%= _('Comments') %></h4> 37 <%= text_area_tag('task_comment', '', :cols => 80, :rows => 4) %> 49 <%= text_area_tag('task_comment', '', :cols => 80, :rows => 4) %><br/> 38 50 39 51 <%= buttons_table(_('Save changes'), {:action => 'list'}) %> … … 70 82 </tr> 71 83 </table> 84 85 <script type="text/javascript"> 86 Event.observe(window, 'load', update_field_enabled); 87 </script> branches/baseline/db/migrate/001_baseline.rb
r586 r587 264 264 t.column 'task_type_id', :integer, :references => :task_types, :null => false, :on_delete => :restrict, :on_update => :restrict 265 265 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 266 268 t.column 'starting_time', :datetime 267 269 t.column 'deadline', :datetime