Commit b0348f2c5da83dca912de7edcfe5dd8b877b4471

Authored by Larissa Reis
1 parent 8d3bc892

Makes it possible for the admin to see pending submissions

plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb
... ... @@ -93,6 +93,14 @@ class CustomFormsPluginMyprofileController < MyProfileController
93 93 @form = @submission.form
94 94 end
95 95  
  96 + def pending
  97 + @form = CustomFormsPlugin::Form.find(params[:id])
  98 + @pendings = CustomFormsPlugin::AdmissionSurvey.from(@form.profile).pending.select {|task| task.form_id == @form.id}.map {|a| {:profile => a.target, :time => a.created_at} }
  99 +
  100 + @sort_by = params[:sort_by]
  101 + @pendings = @pendings.sort_by { |s| s[:profile].name } if @sort_by == 'user'
  102 + end
  103 +
96 104 private
97 105  
98 106 def normalize_positions(form)
... ...
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
... ... @@ -216,5 +216,14 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase
216 216 assert_not_nil assigns(:sort_by)
217 217 assert_select 'table.action-table', /Author\W*Time\W*bob[\W\dh]*john[\W\dh]*/
218 218 end
219   -end
220 219  
  220 + should 'list pending submissions for a form' do
  221 + person = fast_create(Person)
  222 + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :for_admission => true)
  223 + task = CustomFormsPlugin::AdmissionSurvey.create!(:form_id => form.id, :target => person, :requestor => profile)
  224 +
  225 + get :pending, :profile => profile.identifier, :id => form.id
  226 +
  227 + assert_tag :td, :content => person.name
  228 + end
  229 +end
... ...
plugins/custom_forms/views/custom_forms_plugin_myprofile/index.html.erb
... ... @@ -17,7 +17,9 @@
17 17 <td><%= access_text(form) %></td>
18 18 <td class="actions">
19 19 <%= button_without_text :edit, _('Edit'), :action => 'edit', :id => form.id %>
20   - <%= button_without_text :remove, _('Remove'), {:action => 'remove', :id => form.id}, :confirm => _('Are you sure you want to remove this form?') %></td>
  20 + <%= button_without_text :remove, _('Remove'), {:action => 'remove', :id => form.id}, :confirm => _('Are you sure you want to remove this form?') %>
  21 + <%= button_without_text :search, _('Pending'), :action => 'pending', :id => form.id if form.for_admission %>
  22 + </td>
21 23 </tr>
22 24 <% end %>
23 25 <tr id="new-item">
... ...
plugins/custom_forms/views/custom_forms_plugin_myprofile/pending.html.erb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +<% self.extend CustomFormsPlugin::Helper %>
  2 +
  3 +<h1><%= _('Pending submissions for %s') % @form.name %></h1>
  4 +
  5 +<% if @pendings.empty? %>
  6 + <%= _('There are no pending submissions for this form.') %>
  7 +<% else %>
  8 + <p>
  9 + <%= labelled_select(_('Sort by')+': ', :sort_by, :first, :last, @sort_by, [['time', _('Time')], ['user', _('User')]], :onchange => 'document.location.href = "?sort_by="+this.value') %>
  10 + </p>
  11 + <table class="action-table">
  12 + <tr>
  13 + <th style='width: 50%'><%= _('User') %></th>
  14 + <th style='width: 50%'><%= _('Time') %></th>
  15 + </tr>
  16 + <% @pendings.each do |pending| %>
  17 + <tr>
  18 + <td><%= link_to(pending[:profile].name, {:controller => :profile, :profile => pending[:profile].identifier}) %></td>
  19 + <td><%= time_format(pending[:time]) %></td>
  20 + </tr>
  21 + <% end %>
  22 + </table>
  23 +<% end %>
  24 +
  25 +<% button_bar do %>
  26 + <%= button :back, _('Back to forms'), :action => 'index' %>
  27 +<% end %>
... ...