diff --git a/app/assets/javascripts/sufia/batch.js b/app/assets/javascripts/sufia/batch.js index a484351f70..159866f82b 100644 --- a/app/assets/javascripts/sufia/batch.js +++ b/app/assets/javascripts/sufia/batch.js @@ -1,7 +1,12 @@ Blacklight.onLoad(function() { - $('#add_descriptions').click(function() { + $('#show_addl_descriptions').click(function() { $('#more_descriptions').show(); - $('#add_descriptions').hide(); + $('#show_addl_descriptions').hide(); + return false; + }); + $('#hide_addl_descriptions').click(function() { + $('#more_descriptions').hide(); + $('#show_addl_descriptions').show(); return false; }); $('#more_descriptions').hide(); diff --git a/app/assets/stylesheets/batch-edit.css.scss b/app/assets/stylesheets/batch-edit.css.scss new file mode 100644 index 0000000000..9f452c4dcb --- /dev/null +++ b/app/assets/stylesheets/batch-edit.css.scss @@ -0,0 +1,21 @@ +.help-icon { + @extend .glyphicon; + @extend .glyphicon-question-sign; + @extend .large-icon; + top: 5px; +} + +.form-horizontal .batch-group { + @extend .form-group; + margin-left: 0px; + margin-right: 0px; +} + +#hide_addl_descriptions { + margin-bottom: 10px; +} + +#additional_title_clone { + padding-top: 5px; +} + diff --git a/app/assets/stylesheets/sufia.css.scss b/app/assets/stylesheets/sufia.css.scss index 16f225b848..bf58e28647 100644 --- a/app/assets/stylesheets/sufia.css.scss +++ b/app/assets/stylesheets/sufia.css.scss @@ -23,6 +23,7 @@ @import 'styles'; @import 'file-listing'; @import 'collections'; +@import 'batch-edit'; #browse-everything { top:10%; diff --git a/app/helpers/sufia/records_helper_behavior.rb b/app/helpers/sufia/records_helper_behavior.rb index e2ea4496a6..4496984432 100644 --- a/app/helpers/sufia/records_helper_behavior.rb +++ b/app/helpers/sufia/records_helper_behavior.rb @@ -13,16 +13,16 @@ def help_icon(key, content = nil, title = nil) title = title || get_label(key) link_to '#', id: "generic_file_#{key.to_s}_help", rel: 'popover', 'data-content' => content, - 'data-original-title' => title do - content_tag(:span, "help", class: "sr-only") + - content_tag('i', '', "aria-hidden" => true, class: "glyphicon glyphicon-question-sign large-icon") + 'data-original-title' => title, + 'aria-label' => get_aria_label(key) do + content_tag 'i', '', "aria-hidden" => true, class: "help-icon" end end def help_icon_modal(modal_id) - link_to '#' + modal_id, id: "generic_file_#{modal_id}_help_modal", rel: 'button', data: { toggle: 'modal' } do - content_tag(:span, "help", class: "sr-only") + - content_tag('i', '', "aria-hidden" => true, class: 'glyphicon glyphicon-question-sign large-icon') + link_to '#' + modal_id, id: "generic_file_#{modal_id}_help_modal", rel: 'button', + data: { toggle: 'modal' }, 'aria-label' => get_aria_label(modal_id) do + content_tag 'i', '', "aria-hidden" => true, class: 'help-icon' end end @@ -33,16 +33,28 @@ def metadata_help(key) def get_label(key) I18n.t("sufia.field_label.#{key}", default: key.to_s.humanize) end + + def get_aria_label(key) + I18n.t("sufia.aria_label.#{key}", default: default_aria_label(key.to_s.humanize)) + end private def more_or_less_button(key, html_class, symbol) # TODO, there could be more than one element with this id on the page, but the fuctionality doesn't work without it. content_tag('button', class: "#{html_class} btn", id: "additional_#{key}_submit", name: "additional_#{key}") do - (symbol + content_tag('span', class: 'sr-only') do + (sr_hidden(symbol) + content_tag('span', class: 'sr-only') do "add another #{key.to_s}" end).html_safe end end + + def sr_hidden text + content_tag :span, text, "aria-hidden" => true + end + + def default_aria_label text + I18n.t("sufia.aria_label.default", title: text) + end end end diff --git a/app/views/batch/_metadata.html.erb b/app/views/batch/_metadata.html.erb index 6f42ca931c..4746e07f0a 100644 --- a/app/views/batch/_metadata.html.erb +++ b/app/views/batch/_metadata.html.erb @@ -1,16 +1,15 @@ -

Individual Titles (applied to individual files uploaded)* indicates required fields

+

Individual Titles

-

- Filename will be the default title. Please provide a more meaningful title, and filenames will still be preserved by the system. -

+

Applies to individual files uploaded

+ <%= content_tag :p, t('sufia.batch.help.title'), class: "help-block" %> <% @batch.generic_files.sort! { |a,b| a.label.downcase <=> b.label.downcase }.each_with_index do |gen_f, index| %> -
- <%= f.label :title, "* Title #{index + 1}".html_safe, class: "control-label" %> +
+ <%= f.label :title, "* Title #{index + 1}".html_safe, class: "control-label" %> + <%= help_icon(:title) %>
<%= f.text_field :title, name: "title[#{gen_f.id}][]", value: gen_f.label, required: true %> - <%= help_icon(:title) %>
<% end %> @@ -24,55 +23,50 @@ <%= hidden_field_tag(:extra_description_count, "1") %>
-

Bulk Descriptions (applied to all files just uploaded) * indicates required fields

+

Bulk Descriptions

-
+

Applies to all files just uploaded

+
<%# See if this works: render_edit_field_partial(:type, f:f) %> <%= f.label :resource_type, "Resource Types", class: "control-label", for: "resource_type" %> -

You may select multiple types to apply to all files

- <%= f.select "resource_type", Sufia::Engine::config.resource_types, {}, { multiple: true, size: 7 } %> <%= help_icon(:resource_type) %> + <%= content_tag :p, t('sufia.batch.help.resource_type'), class: "help-block" %> + <%= f.select "resource_type", Sufia::Engine::config.resource_types, {}, { multiple: true, size: 7, "aria-label" => "Rights combo box" } %>

-
- <%= f.label :tag, "* Keyword".html_safe, class: "control-label" %> +
+ <%= f.label :tag, "* Keyword".html_safe, class: "control-label" %> + <%= help_icon(:tag) %>
<%= f.text_field :tag, name: "generic_file[tag][]", value: "", required: true %> - -   - <%= help_icon(:tag) %> +
-
- <%= f.label :creator, "* Creator".html_safe, class: "control-label" %> +
+ <%= f.label :creator, "* Creator".html_safe, class: "control-label" %> + <%= help_icon(:creator) %>
<%= f.text_field :creator, name: "generic_file[creator][]", value: "", required: true %> - -   - <%= help_icon(:creator) %> +
-
- <%= f.label :rights, '* Rights'.html_safe, class: "control-label" %> +
+ <%= f.label :rights, '* Rights'.html_safe, class: "control-label" %> + <%= help_icon_modal('rightsModal') %>
<%= f.select "rights", options_for_select(Sufia::Engine::config.cc_licenses, 'http://creativecommons.org/licenses/by-nc-nd/3.0/us/'), required: true %> - -   - <%= help_icon_modal('rightsModal') %> + <%= render partial: "generic_files/rights_modal" %>
-
- - + + <%= render partial: 'more_metadata', locals: {f:f} %> diff --git a/app/views/batch/_more_metadata.html.erb b/app/views/batch/_more_metadata.html.erb index 1cfb1e5391..cf573709e0 100644 --- a/app/views/batch/_more_metadata.html.erb +++ b/app/views/batch/_more_metadata.html.erb @@ -1,5 +1,6 @@ -
- <% (@generic_file.terms_for_editing - [:title, :creator, :rights, :tag, :resource_type]).each do |term| %> - <%= render partial: "generic_files/field_form", locals: { generic_file: @generic_file, f: f, render_req: false, key: term } %> - <% end %> -
+
+ + <% (@generic_file.terms_for_editing - [:title, :creator, :rights, :tag, :resource_type]).each do |term| %> + <%= render partial: "generic_files/field_form", locals: { generic_file: @generic_file, f: f, render_req: false, key: term } %> + <% end %> +
diff --git a/app/views/batch/edit.html.erb b/app/views/batch/edit.html.erb index a6e7c5a114..6671e5ce6b 100644 --- a/app/views/batch/edit.html.erb +++ b/app/views/batch/edit.html.erb @@ -3,13 +3,13 @@ <% end %>

Apply Metadata

-
+

The information you provide for Title will be applied to the corresponding file only; however all other information you provide will be applied to the entire batch of files you have just deposited into <%= t('sufia.product_name') %>. You may edit individual files from <%= link_to " #{t('sufia.bread_crumb.file_list')}".html_safe, sufia.dashboard_files_path %> - once this step is finished. -

+ once this step is finished. * indicates required fields. +

<%= form_for([@batch, @generic_file], url: sufia.batch_generic_files_path, html: { multipart: true, class: 'form-horizontal' }) do |f| %> <%= render partial: 'metadata', formats: [:html], locals: {f: f} %> diff --git a/app/views/generic_files/_field_form.html.erb b/app/views/generic_files/_field_form.html.erb index d90a9b762e..7c0be9b563 100644 --- a/app/views/generic_files/_field_form.html.erb +++ b/app/views/generic_files/_field_form.html.erb @@ -1,5 +1,5 @@ <% render_req ||= true # render_req is true for single file edit, false for batch edit%> -
+
<% vals = generic_file[key] %> <% if render_req && required?(key) %> <% tmp = '*' + get_label(key) %> @@ -7,7 +7,7 @@ <% else %> <%= f.label key, get_label(key) %> <% end %> - + <%= help_icon(key) %> <% if key == :resource_type %> <%# resource_type is a multiselect box, so don't render one row for each %> <%= render_edit_field_partial(key, record: generic_file, f: f, render_req: render_req) %> @@ -16,4 +16,4 @@ <%= render_edit_field_partial(key, record: generic_file, f: f, v: v, index: index, render_req: render_req) %> <% end %> <% end %> -
+
diff --git a/app/views/records/edit_fields/_suffix.html.erb b/app/views/records/edit_fields/_suffix.html.erb index f397f27c21..ba3f75e171 100644 --- a/app/views/records/edit_fields/_suffix.html.erb +++ b/app/views/records/edit_fields/_suffix.html.erb @@ -4,7 +4,6 @@ <%= add_field(key) %> <% end %>   - <%= help_icon(key) %> <%= render partial: "records/rights_modal" if key == "rights" %> <% else %> <%= subtract_field(key) %> diff --git a/config/locales/sufia.en.yml b/config/locales/sufia.en.yml index dae43b2e90..563e0abb28 100644 --- a/config/locales/sufia.en.yml +++ b/config/locales/sufia.en.yml @@ -119,9 +119,15 @@ en: date_created: "The date on which the file was generated. Dates are accepted in the form YYYY-MM-DD, e.g. 1776-07-04." description: "Free-text notes about the file itself. Examples include abstracts of a paper, citation information for a journal article, or a tag indicating a larger collection to which the file belongs." identifier: "A unique handle describing the file. An example would be a DOI for a journal article, or an ISBN or OCLC number for a book." - language: " The language of the file content." + language: "The language of the file content." publisher: "The person or group making the file available. Generally this is the institution." rights: "Licensing and distribution information governing access to the file. Select from the provided drop-down list. This is a required field." + aria_label: + default: "Usage information for %{title}" + based_near: "Usage information for location" + description: "Usage information for abstract or summary" + tag: "Usage information for keyword" + rightsModal: "Usage information for rights" background_attribution: "Background image courtesy of Penn State University" bread_crumb: search_results: "Back to search results" @@ -131,3 +137,7 @@ en: user_profile: no_followers: "No one is following you." no_following: "You are not following anyone." + batch: + help: + title: "Filename will be the default title. Please provide a more meaningful title, and filenames will still be preserved by the system." + resource_type: "You may select multiple types to apply to all files" diff --git a/spec/helpers/records_helper_spec.rb b/spec/helpers/records_helper_spec.rb index bfd496f46f..8fe248356c 100644 --- a/spec/helpers/records_helper_spec.rb +++ b/spec/helpers/records_helper_spec.rb @@ -1,38 +1,38 @@ require 'spec_helper' describe RecordsHelper do + let(:adder) { + "" + } + let(:remover) { + "" + } it "draws add button" do - helper.add_field(:test).should == - "" + expect(helper.add_field(:test)).to eql(adder) end it "draws subtract button" do - helper.subtract_field(:test).should == - "" + expect(helper.subtract_field(:test)).to eql(remover) end it "draws help_icon" do str = String.new(helper.help_icon(:tag)) doc = Nokogiri::HTML(str) a = doc.xpath('//a').first - - expect(a.attr('data-content')).to eq "Words or phrases you select to describe what the file is about. These are used to search for content. This is a required field." - expect(a.attr('data-original-title')).to eq "Keyword" - expect(a.attr('id')).to eq "generic_file_tag_help" - expect(a.at_css('.sr-only').content).to eq('help') - expect(a.at_css(':not(.sr-only)').attr('class')).to eq('glyphicon glyphicon-question-sign large-icon') + expect(a.attr('data-content')).to eql("Words or phrases you select to describe what the file is about. These are used to search for content. This is a required field.") + expect(a.attr('data-original-title')).to eql("Keyword") + expect(a.attr('id')).to eql("generic_file_tag_help") + expect(a.children.first.attr('class')).to eql('help-icon') end specify "draws help_icon_modal" do str = String.new(helper.help_icon_modal('myModal')) doc = Nokogiri::HTML(str) a = doc.xpath('//a').first - expect(a.attr('href')).to eq('#myModal') expect(a.attr('data-toggle')).to eq('modal') expect(a.attr('id')).to eq('generic_file_myModal_help_modal') - expect(a.at_css('.sr-only').content).to eq('help') - expect(a.at_css(':not(.sr-only)').attr('class')).to eq('glyphicon glyphicon-question-sign large-icon') + expect(a.children.first.attr('class')).to eq('help-icon') end describe "download links" do @@ -42,32 +42,60 @@ assign :generic_file, @file end + let(:link_text) { helper.render_download_link("Download Fake") } + let(:icon_text) { helper.render_download_icon("Download the full-sized Fake") } + describe "#render_download_link" do it "has default text" do - helper.render_download_link.should have_selector("#file_download") - helper.render_download_link.should have_content("Download") + expect(helper.render_download_link).to have_selector("#file_download") + expect(helper.render_download_link).to have_content("Download") end - it "includes user-supplied text" do - content = helper.render_download_link("Download Fake") - content.should have_selector("#file_download") - content.should have_content("Download Fake") + it "includes user-supplied link text" do + expect(link_text).to have_selector("#file_download") + expect(link_text).to have_content("Download Fake") end end describe "#render_download_icon" do it "has default text" do - helper.render_download_icon.should have_selector("#file_download") - helper.render_download_icon.should match("Download the document") + expect(helper.render_download_icon).to have_selector("#file_download") + expect(helper.render_download_icon).to match("Download the document") end - it "includes user-supplied text" do - content = helper.render_download_icon("Download the full-sized Fake") - content.should have_selector("#file_download") - content.should match("Download the full-sized Fake") + it "includes user-supplied icon text" do + expect(icon_text).to have_selector("#file_download") + expect(icon_text).to match("Download the full-sized Fake") end end end + describe "#metadata_help" do + specify "default" do + expect(helper.metadata_help("foo")).to eql("Foo") + end + specify "using a key" do + expect(helper.metadata_help("language")).to eql("The language of the file content.") + end + end + + describe "#get_label" do + specify "default" do + expect(helper.get_label("foo")).to eql("Foo") + end + specify "using a key" do + expect(helper.get_label("tag")).to eql("Keyword") + end + end + + describe "#get_aria_label" do + specify "default" do + expect(helper.get_aria_label("foo")).to eql("Usage information for Foo") + end + specify "using a key" do + expect(helper.get_aria_label("tag")).to eql("Usage information for keyword") + end + end + end