Commit 7358e1d0c949434a87b62946890680f70075c6fd

Authored by Rodrigo Souto
1 parent 91942873

[work-assignment] Views

plugins/work_assignment/lib/work_assignment_plugin/helper.rb
1 1 module WorkAssignmentPlugin::Helper
2   - def display_submissions(work_assignment)
3   - "Displaying submissions..."
  2 + def display_submissions(work_assignment, user)
  3 + return if work_assignment.submissions.empty?
  4 + content_tag('table',
  5 + content_tag('tr',
  6 + content_tag('th', _('Author'), :style => 'width: 50%') +
  7 + content_tag('th', _('Submission date')) +
  8 + content_tag('th', _('Versions'), :style => 'text-align: center') +
  9 + content_tag('th', '')
  10 + ) +
  11 + work_assignment.children.map {|author_folder| display_author_folder(author_folder, user)}.join("\n")
  12 + )
4 13 end
  14 +
  15 + def display_author_folder(author_folder, user)
  16 + return if author_folder.children.empty?
  17 + content_tag('tr',
  18 + content_tag('td', link_to_last_submission(author_folder, user)) +
  19 + content_tag('td', time_format(author_folder.children.last.created_at)) +
  20 + content_tag('td', author_folder.children.count, :style => 'text-align: center') +
  21 + content_tag('td', content_tag('button', _('View all versions'), :class => 'view-author-versions', 'data-folder-id' => author_folder.id))
  22 + ) +
  23 + author_folder.children.map {|submission| display_submission(submission, user)}.join("\n")
  24 + end
  25 +
  26 + def display_submission(submission, user)
  27 + content_tag('tr',
  28 + content_tag('td', link_to_submission(submission, user)) +
  29 + content_tag('td', time_format(submission.created_at), :colspan => 3),
  30 + :class => "submission-from-#{submission.parent.id}",
  31 + :style => 'display: none'
  32 + )
  33 + end
  34 +
  35 + def link_to_submission(submission, user)
  36 + if WorkAssignmentPlugin.can_download_submission?(user, submission)
  37 + link_to(submission.name, submission.url)
  38 + else
  39 + submission.name
  40 + end
  41 + end
  42 +
  43 +
  44 + def link_to_last_submission(author_folder, user)
  45 + if WorkAssignmentPlugin.can_download_submission?(user, author_folder.children.last)
  46 + link_to(author_folder.name, author_folder.children.last.url)
  47 + else
  48 + author_folder.name
  49 + end
  50 + end
  51 + # FIXME Copied from custom-froms. Consider passing it to core...
  52 + def time_format(time)
  53 + minutes = (time.min == 0) ? '' : ':%M'
  54 + hour = (time.hour == 0 && minutes.blank?) ? '' : ' %H'
  55 + h = hour.blank? ? '' : 'h'
  56 + time.strftime("%Y-%m-%d#{hour+minutes+h}")
  57 + end
  58 +
5 59 end
... ...
plugins/work_assignment/public/show_versions.js 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +jQuery(".view-author-versions").each(function(index, bt){
  2 + jQuery(bt).button({
  3 + icons: {
  4 + primary: "ui-icon-info"
  5 + },
  6 + text: false
  7 + });
  8 + bt.onclick = function(){
  9 + var folderId = this.getAttribute("data-folder-id");
  10 + var tr = jQuery(".submission-from-"+folderId);
  11 + if ( tr[0].style.display == "none" )
  12 + tr.show();
  13 + else
  14 + tr.hide();
  15 + }
  16 +});
... ...
plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
1 1 <%= render :partial => 'folder', :locals => {:f => f} %>
2 2  
3   -Extra content...
  3 +<%= f.check_box(:publish_submissions) %>
... ...
plugins/work_assignment/views/content_viewer/work_assignment.html.erb
... ... @@ -5,4 +5,6 @@
5 5 <hr/>
6 6 <% end %>
7 7  
8   -<%= display_submissions(@page) %>
  8 +<%= display_submissions(@page, user) %>
  9 +
  10 +<%= javascript_include_tag '../plugins/work_assignment/show_versions' %>
... ...