diff --git a/Gemfile b/Gemfile index 6176695..768e046 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,7 @@ gem 'sass-rails' gem 'less-rails' # WE SHOULD PROBABLY USE SASS OR LESS NOT BOTH gem 'jquery-rails' +gem 'font-awesome-rails' gem 'twitter-bootstrap-rails', '2.2.8' gem 'tinymce-rails' # WYSIWYG EDITOR gem 'contact_us', '>= 1.2.0' # COULD BE EASILY REPLACED WITH OUR OWN CODE diff --git a/Gemfile.lock b/Gemfile.lock index 50e0c71..31af02b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -125,6 +125,8 @@ loofah (~> 2.0) sax-machine (~> 1.0) flag_shih_tzu (0.3.15) + font-awesome-rails (4.7.0.1) + railties (>= 3.2, < 5.1) formtastic (3.1.4) actionpack (>= 3.2.13) friendly_id (5.1.0) @@ -366,6 +368,7 @@ dragonfly feedjira flag_shih_tzu + font-awesome-rails formtastic friendly_id gettext (>= 3.0.2) diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 27cca0d..526f76a 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -1,11 +1,8 @@ class PlansController < ApplicationController require 'pp' helper SettingsTemplateHelper - #Uncomment the line below in order to add authentication to this page - users without permission will not be able to add new plans - #load_and_authorize_resource - # - after_action :verify_authorized + after_action :verify_authorized def index authorize Plan @@ -15,111 +12,83 @@ # GET /plans/new + # ------------------------------------------------------------------------------------ def new @plan = Plan.new authorize @plan - @funders = Org.funders.order('name ASC') - - no_org = Org.new() - no_org.id = -1 - no_org.name = "No Funder" - @funders.unshift(no_org) - - - respond_to do |format| - format.html # new.html.erb - end + + # Get all of the available funders and non-funder orgs + @funders = Org.funders.sort{|x,y| x.name <=> y.name } + @orgs = (Org.institutions + Org.managing_orgs).flatten.uniq.sort{|x,y| x.name <=> y.name } + + # Get the current user's org + @default_org = current_user.org if @orgs.include?(current_user.org) + + respond_to :html end - - # we get here either from selecting a funder or if if the first selection - # results in multiple templates, from a template selection screen + # POST /plans + # ------------------------------------------------------------------- def create @plan = Plan.new authorize @plan - message = "" - - # if we have a template_id we've been selcting between templates, otherwise funders - if params[:template_id] - @templates = [ Template.find(params[:template_id] ) ] - else - funder_id = params[:plan][:funder_id].to_i - - if funder_id.present? && funder_id != -1 - @templates = [] - - # get all funder @templates - funder = Org.find(params[:plan][:funder_id]) - funder_templates = get_most_recent( funder.templates.where(published: true).all ) - - # get org templates and index by customization id - if current_user.org.nil? - orgtemplates = [] - else - orgtemplates = get_most_recent( current_user.org.templates.all ) - end - - orgt_by_customization = orgtemplates.collect{|t| [t.customization_of, t]}.to_h - - # go through funder templates and replace with org cusomizations if needed - funder_templates.each do |ft| - if orgt_by_customization.has_key?(ft.dmptemplate_id) - message = _(" - using template customised by your institution") - @templates << orgt_by_customization[ft.dmptemplate_id] - else - @templates << ft - end - end - - else # either didn't select funder or selected "No Funder" - - # get all org @templates which are not customisations - @templates = get_most_recent( current_user.org.templates.where(customization_of: nil) ) - - message = _(" - choosing default template for your institution") - - # if none of these get the default template - if @templates.blank? - @templates = get_most_recent( Template.where(is_default: true, customization_of: nil) ) - message = _(" - no funder or institution template, choosing default template") - end - end - end - - # if we have more than one template then back to the user - # using the 'create' template - # to choose otherwise just create the plan - # and go to the plan/show template - if @templates.length > 1 - message += _(" - there are more than one to choose from") - flash.notice = message - respond_to do |format| - format.html - end - return - end - - @plan.template = @templates[0] - - @based_on = @plan.base_template() - - @plan.principal_investigator = current_user.name - - @plan.title = _('My plan')+' ('+@plan.template.title+')' # We should use interpolated string since the order of the words from this message could vary among languages - - @all_guidance_groups = @plan.get_guidance_group_options - @selected_guidance_groups = @plan.guidance_groups.pluck(:id) + @plan.principal_investigator = current_user.surname.blank? ? nil : "#{current_user.firstname} #{current_user.surname}" + @plan.data_contact = current_user.email + @plan.funder_name = plan_params[:funder_name] + # If a template hasn't been identified look for the available templates + if plan_params[:template_id].blank? + template_options(plan_params[:org_id], plan_params[:funder_id]) - respond_to do |format| - if @plan.save - @plan.assign_creator(current_user.id) - flash.notice = _('Plan was successfully created.') + message - format.html { redirect_to({:action => "show", :id => @plan.id, :editing => true }) } + # Return the 'Select a template' section + respond_to do |format| + format.js {} + end + + # Otherwise create the plan + else + @plan.template = Template.find(plan_params[:template_id]) + + if plan_params[:title].blank? + @plan.title = current_user.firstname.blank? ? _('My Plan') + '(' + @plan.template.title + ')' : + current_user.firstname + "'s" + _(" Plan") else - flash[:notice] = failed_create_error(@plan, _('plan')) - format.html { render action: "new" } + @plan.title = plan_params[:title] + end + + if @plan.save + @plan.assign_creator(current_user) + + default = Template.find_by(is_default: true) + + msg = "#{_('Plan was successfully created.')} " + + if !default.nil? && default == @plan.template + # We used the generic/default template + msg += _('This plan is based on the default template.') + + elsif !@plan.template.customization_of.nil? + # We used a customized version of the the funder template + msg += "#{_('This plan is based on the')} #{plan_params[:funder_name]} #{_('template with customisations by the')} #{plan_params[:org_name]}" + + else + # We used the specified org's or funder's template + msg += "#{_('This plan is based on the')} #{@plan.template.org.name} template." + end + + flash[:notice] = msg + + respond_to do |format| + format.js { render js: "window.location='#{plan_url(@plan)}?editing=true'" } + end + + else + # Something went wrong so report the issue to the user + flash[:notice] = failed_create_error(@plan, 'Plan') + respond_to do |format| + format.js {} + end end end end @@ -150,7 +119,7 @@ @all_ggs_grouped_by_org = @all_ggs_grouped_by_org.sort_by {|org,gg| org.name} @selected_guidance_groups = @plan.guidance_groups.pluck(:id) - @based_on = @plan.base_template + @based_on = (@plan.template.customization_of.nil? ? @plan.template : Template.live(@plan.template.customization_of)) respond_to :html end @@ -412,6 +381,9 @@ private + def plan_params + params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title) + end # different versions of the same template have the same dmptemplate_id # but different version numbers so for each set of templates with the @@ -476,4 +448,49 @@ plan.delete(src_plan_key) end + # Collect all of the templates available for the org+funder combination + # -------------------------------------------------------------------------- + def template_options(org_id, funder_id) + @templates = [] + + if !org_id.blank? || !funder_id.blank? + if funder_id.blank? + # Load the org's template(s) + unless org_id.nil? + org = Org.find(org_id) + @templates = Template.where(published: true, org: org, customization_of: nil).to_a + @msg = _("We found multiple DMP templates corresponding to the research organisation.") if @templates.count > 1 + end + + else + funder = Org.find(funder_id) + # Load the funder's template(s) + @templates = Template.where(published: true, org: funder).to_a + + unless org_id.blank? + org = Org.find(org_id) + + # Swap out any organisational cusotmizations of a funder template + @templates.each do |tmplt| + customization = Template.find_by(published: true, org: org, customization_of: tmplt.dmptemplate_id) + unless customization.nil? + @templates.delete(tmplt) + @templates << customization + end + end + end + + msg = _("We found multiple DMP templates corresponding to the funder.") if @templates.count > 1 + end + end + + # If no templates were available use the generic templates + if @templates.empty? + @msg = _("Using the generic Data Management Plan") + @templates << Template.find_by(is_default: true) + end + + @templates = @templates.sort{|x,y| x.title <=> y.title } if @templates.count > 1 + end + end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 448efa8..dbc8dd4 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -6,6 +6,7 @@ @orgs = Org.where(parent_id: nil).order("name") @other_organisations = Org.where(parent_id: nil, is_other: true).pluck(:id) @identifier_schemes = IdentifierScheme.where(active: true).order(:name) + @default_org = current_user.org end # GET /resource diff --git a/app/models/org.rb b/app/models/org.rb index 3c23dcc..e11d5e1 100644 --- a/app/models/org.rb +++ b/app/models/org.rb @@ -49,7 +49,7 @@ # Predefined queries for retrieving the managain organisation and funders scope :managing_orgs, -> { where(abbreviation: Rails.configuration.branding[:organisation][:abbreviation]) } scope :funders, -> { where(org_type: 2) } - scope :institutions, -> { where(org_type: 3) } + scope :institutions, -> { where(org_type: 1) } # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/models/plan.rb b/app/models/plan.rb index 50d075d..8c8d3c7 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -1,4 +1,7 @@ class Plan < ActiveRecord::Base + + before_validation :set_creation_defaults + ## # Associations belongs_to :template @@ -1104,4 +1107,14 @@ (num_lines * font_height) + vertical_margin + leading end + # Initialize the title and dirty flags for new templates + # -------------------------------------------------------- + def set_creation_defaults + # Only run this before_validation because rails fires this before save/create + if self.id.nil? + self.title = "My plan (#{self.template.title})" if self.title.nil? && !self.template.nil? + self.visibility = 1 + end + end + end diff --git a/app/models/template.rb b/app/models/template.rb index 63b4b3e..94a845b 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -17,7 +17,7 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :id, :org_id, :description, :published, :title, :locale, + attr_accessible :id, :org_id, :description, :published, :title, :locale, :customization_of, :is_default, :guidance_group_ids, :org, :plans, :phases, :dmptemplate_id, :version, :visibility, :published, :as => [:default, :admin] @@ -130,6 +130,7 @@ self.published = false self.dirty = false self.visibility = 1 + self.is_default = false self.version = 0 if self.version.nil? # Generate a unique identifier for the dmptemplate_id if necessary diff --git a/app/policies/plan_policy.rb b/app/policies/plan_policy.rb index 318608d..d6c8703 100644 --- a/app/policies/plan_policy.rb +++ b/app/policies/plan_policy.rb @@ -43,6 +43,10 @@ def status? @plan.readable_by?(@user.id) end + + def possible_templates? + @plan.id.nil? + end # TODO: These routes are no lonmger used =begin diff --git a/app/views/contact_us/contacts/new.html.erb b/app/views/contact_us/contacts/new.html.erb index 57596a5..c4d2f30 100644 --- a/app/views/contact_us/contacts/new.html.erb +++ b/app/views/contact_us/contacts/new.html.erb @@ -1,122 +1,111 @@ - +<% javascript "contacts/new_contact.js" %> +

- <%= t("contact_page.title") %> + <%= _("Contact Us") %>

- <%= raw t("contact_page.intro_text_html", - organisation_name: Rails.configuration.branding[:organisation][:name], - organisation_email: Rails.configuration.branding[:organisation][:email], - organisation_url: Rails.configuration.branding[:organisation][:url], - application_name: Rails.configuration.branding[:application][:name], - application_url: Rails.configuration.branding[:application][:url], - application_issue_list_url: Rails.configuration.branding[:application][:issue_list_url]) %> - <%= raw t("contact_page.github_text_html") %> + <%= raw _('%{application_name} is provided by the %{organisation_name}. You can find out more about us on our website. If you would like to contact us about %{application_name}, please fill out the form below.') % {organisation_name: Rails.configuration.branding[:organisation][:name], + organisation_url: Rails.configuration.branding[:organisation][:url], + application_name: Rails.configuration.branding[:application][:name]} %>

- -
-
- <%= form_for @contact, :url => contacts_path do |f| %> -
- - <% if ContactUs.require_name %> - - - - - <% end %> - - - - - <% if ContactUs.require_subject %> - - - - - <% end %> - - - - - <% if !user_signed_in? then %> - - - - - <% end %> -
- <%= f.label :name, (t('.name') + content_tag(:abbr, "*", :class => "required")).html_safe %> - - <% if user_signed_in? then %> - <%= f.text_field :name, :value => current_user.name(false) %> - <% else %> - <%= f.text_field :name %> - <% end %> - <% if f.object.errors[:name].present? %> -

<%= f.object.errors[:name].join(" and ") %>

- <% end %> -
- <%= f.label :email, (t('.email') + content_tag(:abbr, "*", :class => "required")).html_safe %> - - <% if user_signed_in? then %> - <%= f.email_field :email, :value => current_user.email %> - <% else %> - <%= f.email_field :email %> - <% end %> - <% if f.object.errors[:email].present? %> -

<%= f.object.errors[:email].join(" and ") %>

- <% end %> -
- <%= f.label :subject, (t('.subject') + content_tag(:abbr, "*", :class => "required")).html_safe %> - - <%= f.text_field :subject %> - <% if f.object.errors[:subject].present? %> -

<%= f.object.errors[:subject].join(" and ") %>

- <% end %> -
- <%= f.label :message, (t('.message') + content_tag(:abbr, "*", :class => "required")).html_safe %> - - <%= f.text_area :message, :rows => 10 %> - <% if f.object.errors[:message].present? %> -

<%= f.object.errors[:message].join(" and ") %>

- <% end %> -
- <%= t('helpers.security_check') %> - - <%= recaptcha_tags %> -
-
-
- <%= f.submit :submit, :class => "btn btn-primary", :label => t('.submit') %> -
- <% end %> -
-
- - -
-
- <%= raw t("contact_page.address_text_html", - organisation_name: Rails.configuration.branding[:organisation][:name], - organisation_email: Rails.configuration.branding[:organisation][:email], - application_name: Rails.configuration.branding[:application][:name], - organisation_telephone: Rails.configuration.branding[:organisation][:telephone], - organisation_address_line1: Rails.configuration.branding[:organisation][:address_line1], - organisation_address_line2: Rails.configuration.branding[:organisation][:address_line2], - organisation_address_line3: Rails.configuration.branding[:organisation][:address_line3], - organisation_address_line4: Rails.configuration.branding[:organisation][:address_line4], - organisation_address_country: Rails.configuration.branding[:organisation][:address_country]) %> - -
- + +
+
+ <%= form_for @contact, url: contacts_path, html: {class: "roadmap-form"} do |f| %> +
+ <% if ContactUs.require_name %> +
+ <%= f.label :name, (_('Name') + content_tag(:abbr, "*", class: "required")).html_safe %> + <% if user_signed_in? then %> + <%= f.text_field :name, value: current_user.name(false) %> + <% else %> + <%= f.text_field :name %> + <% end %> + <% if f.object.errors[:name].present? %> +

<%= f.object.errors[:name].join(_(" and ")) %>

+ <% end %> +
+ <% end %> + +
+ <%= f.label :email, (_('Email') + content_tag(:abbr, "*", class: "required")).html_safe %> + <% if user_signed_in? then %> + <%= f.email_field :email, value: current_user.email %> + <% else %> + <%= f.email_field :email %> + <% end %> + <% if f.object.errors[:email].present? %> +

<%= f.object.errors[:email].join(_(" and ")) %>

+ <% end %> +
+ + <% if ContactUs.require_subject %> +
+ <%= f.label :subject, (_('Subject') + content_tag(:abbr, "*", class: "required")).html_safe %> + <%= f.text_field :subject %> + <% if f.object.errors[:subject].present? %> +

<%= f.object.errors[:subject].join(_(" and ")) %>

+ <% end %> +
+ <% end %> + +
+ <%= f.label :message, (_('Message') + content_tag(:abbr, "*", class: "required")).html_safe %> + <%= f.text_area :message, rows: 10, class: "input-large" %> + <% if f.object.errors[:message].present? %> +

<%= f.object.errors[:message].join(_(" and ")) %>

+ <% end %> +
+ + <% if !user_signed_in? then %> +
+ <%= t('helpers.security_check') %> + <%= recaptcha_tags %> +
+ <% end %> + +
+ + <%= render partial: 'shared/accessible_submit_button', + locals: {id: 'create_contact_submit', + val: 'Submit', + disabled_initially: true, + tooltip: _('Fill in the required fields')} %> +
+
-
-
-
- + <% end %> +
+
+ + +
+
+ <%= raw _("
  • %{organisation_name}
  • +
  • %{organisation_address_line1}
  • +
  • %{organisation_address_line2}
  • +
  • %{organisation_address_line3}
  • +
  • %{organisation_address_line4}
  • +
  • %{organisation_address_country}
  • +
+

Helpline: %{organisation_telephone}

+

Email %{organisation_email}

") % + { organisation_name: Rails.configuration.branding[:organisation][:name], + organisation_address_line1: Rails.configuration.branding[:organisation][:address_line1], + organisation_address_line2: Rails.configuration.branding[:organisation][:address_line2], + organisation_address_line3: Rails.configuration.branding[:organisation][:address_line3], + organisation_address_line4: Rails.configuration.branding[:organisation][:address_line4], + organisation_address_country: Rails.configuration.branding[:organisation][:address_country], + organisation_telephone: Rails.configuration.branding[:organisation][:telephone], + organisation_email: Rails.configuration.branding[:organisation][:email], + application_name: Rails.configuration.branding[:application][:name]} %> + +
+ + +
+
+
+
diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 5acc77e..22ac7ef 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,138 +1,114 @@ -

<%= _('Edit profile') %>

-<%= raw _('

Please note that your email address is used as your username. If you change this, remember to use your new email address on sign in.

') %> +
+

<%= _('Edit profile') %>

-
- <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put}) do |f| %> - <%= hidden_field_tag :unlink_flag, "false", id: "unlink_flag" %> - -
+

+ <%= _("Please note that your email address is used as your username. If you change this, remember to use your new email address on sign in.") %> +

-

<%= raw _('You can edit any of the details below.') %>

+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put, class: "roadmap-form white_background"}) do |f| %> + +
+ <%= _('You can edit any of the details below.') %> + + <%= hidden_field_tag :unlink_flag, "false", id: "unlink_flag" %> - - - - - - - - - - - - - - - - - - "> - - - - <% if MANY_LANGUAGES %> - - - - - <% end %> - - <% @identifier_schemes.each do |scheme| %> - - - - - <% end %> - - - <% unless @user.api_token.blank? %> - - - - - - - - - <% end %> -
<%= (_('Email') + " *") %><%= f.email_field :email, as: :email %>
<%= _('First name') %><%= f.text_field :firstname, as: :string, - id: "first_time_login_firstname", - autofocus: true, - class: "text_field has-tooltip", - "data-toggle" => "tooltip", - "data-trigger" => "focus" , - "title" => _('Please enter your first name.') %>
<%= _('Last name') %><%= f.text_field :surname, - as: :string, id: "first_time_login_surname", - class: "text_field has-tooltip", - "data-toggle" => "tooltip", - "data-trigger" => "focus" , - "title" => _('Please enter your surname or family name.') %>
<%= _('Organisation') %><%= collection_select(:user, - :org_id, @orgs, - :id, :name, {include_blank: _('Select Organisation')}, - { class: "typeahead org_sign_up" }) %>
<%= _('Language') %> - - <% locale = current_user.get_locale(); %> - <%= @languages.each do |l| %> - <% end %> -
<%= scheme.description %> - <%= render partial: 'external_identifier', - locals: {scheme: scheme, - id: current_user.identifier_for(scheme)} %> -
<%= _('API token') %><%= @user.api_token %>
<%= _('API Information') %><%= link_to( _('How to use the API'), controller: "token_permission_types", action: "index")%>
-
-

- -

-
-
-
-

- <%= _('If you would like to change your password please complete the following fields.') %> -

- - <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> -
<%= t('custom_devise.waiting_for_confirmation') %><%= resource.unconfirmed_email %>
- <% end %> - - - - - - - - - - - - -
<%= _('Current password') %> - <%= f.password_field :current_password, as: :password %> -
<%= _('New password') %><%= f.password_field :password, as: :password, autocomplete: "off" %> -
<%= _('Password confirmation') %><%= f.password_field :password_confirmation, as: :password, autocomplete: "off" %>
-
- <%= f.submit _('Save'), class: "btn btn-primary" %> - <%= link_to _('Cancel'), :back, class: "btn btn-primary" %> -
+ + <% @identifier_schemes.each do |scheme| %> +
+ +
+ <%= render partial: 'external_identifier', + locals: {scheme: scheme, + id: current_user.identifier_for(scheme)} %> +
+
+ <% end %> + + <% unless @user.api_token.blank? %> +
+ <%= f.label :api_token, _('API token') %> +
<%= @user.api_token %>
+ + +
<%= link_to( _('How to use the API'), controller: "token_permission_types", action: "index")%>
+
+ <% end %> + +
+ + <%= _('If you would like to change your password please complete the following fields.') %> + +
+ <%= f.label :current_password, _('Current password') %> + <%= f.password_field :current_password, as: :password, class: 'input-medium' %> +
+ +
+ <%= f.label :password, _('New password') %> + <%= f.password_field :password, as: :password, autocomplete: "off", class: 'input-medium' %> +
+ +
+ <%= f.label :password_confirmation, _('Password confirmation') %> + <%= f.password_field :password_confirmation, as: :password, autocomplete: "off", + class: 'input-medium' %> +
+ +
+ + +
+
+ <% end %> -
diff --git a/app/views/phases/_add_note.html.erb b/app/views/phases/_add_note.html.erb index bcfcab7..51e81e2 100644 --- a/app/views/phases/_add_note.html.erb +++ b/app/views/phases/_add_note.html.erb @@ -8,21 +8,17 @@ <%= form_for( :new_note, url: notes_path, remote: true, - method: :post, - id: "new_note_form_#{questionid}", - class: "add_note_form") do |f| %> + html: {method: :post, class: "add_note_form roadmap-form"}, + id: "new_note_form_#{questionid}") do |f| %> <%= f.hidden_field :user_id, value: current_user.id %> <%= f.hidden_field :question_id, value: questionid %> <%= f.hidden_field :answer_id, value: answer.id %> <%= f.hidden_field :plan_id, value: plan_id %> - <%= text_area_tag "#{questionid}new_note_text", nil, class: "tinymce" %> - <%= tinymce :content_css => asset_path("application.css"), :setup => "function(editor){editor.on('change', function(e){$.fn.check_textarea(editor)});}" %> -
- - -
- <%= f.submit _('Save'), class: "btn btn-primary new_comment_submit_button" %> -
-
+
+ <%= label_tag "#{questionid}new_note_text", _('Share note with collaborators') %> + <%= text_area_tag "#{questionid}new_note_text", nil, class: "tinymce" %> + <%= tinymce :content_css => asset_path("application.css"), :setup => "function(editor){editor.on('change', function(e){$.fn.check_textarea(editor)});}" %> + +
<% end %> diff --git a/app/views/phases/_answer_form.html.erb b/app/views/phases/_answer_form.html.erb index 85be632..bdd8c1d 100644 --- a/app/views/phases/_answer_form.html.erb +++ b/app/views/phases/_answer_form.html.erb @@ -19,12 +19,12 @@ %>
- <%= semantic_form_for answer, :url => {:controller => :answers, :action => :update }, method: "put", :remote => true do |f| %> - <%= f.inputs do %> - <%= f.input :id, :as => :hidden, :input_html => { :value => answer.id } %> - <%= f.input :plan_id, :as => :hidden, :input_html => { :value => @plan.id } %> - <%= f.input :user_id, :as => :hidden, :input_html => { :value => current_user.id } %> - <%= f.input :question_id, :as => :hidden, :input_html => { :value => question_id, :class => "question_id" } %> + <%= semantic_form_for answer, :url => {controller: :answers, action: :update }, html: {method: "put", class: "roadmap-form"}, remote: true do |f| %> +
+ <%= f.input :id, as: :hidden, input_html: { value: answer.id } %> + <%= f.input :plan_id, as: :hidden, input_html: { value: @plan.id } %> + <%= f.input :user_id, as: :hidden, input_html: { value: current_user.id } %> + <%= f.input :question_id, as: :hidden, input_html: { value: question_id, class: "question_id" } %> <%= f.hidden_field :lock_version, id: "answer_lock_version-#{question_id}" %> @@ -62,23 +62,23 @@ <% if q_format.checkbox? %> - <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, :input_html => { :id => "options-#{question.id}" } %> + <%= f.input :options, as: :check_boxes, collection: options, label: false, input_html: { id: "options-#{question.id}" } %> <% elsif q_format.multiselectbox? %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true , :id => "options-#{question.id}" } %> + <%= f.input :options, as: :select, collection: options, label: false, input_html: { multiple: true , id: "options-#{question.id}" } %> <% elsif q_format.radiobuttons? %>
    <% options.each do |op| %>
  1. <% if answer.question_option_ids[0] == op.id then%> - <%= f.radio_button :option_ids, op.id, :checked => true, id: "answer_option_ids_#{op.id}"%> + <%= f.radio_button :option_ids, op.id, checked: true, id: "answer_option_ids_#{op.id}"%> <%else%> - <%= f.radio_button :option_ids, op.id, :checked => false, id: "answer_option_ids_#{op.id}"%> + <%= f.radio_button :option_ids, op.id, checked: false, id: "answer_option_ids_#{op.id}"%> <% end %> <%= raw op.text %>
  2. <% end %>
<% elsif q_format.dropdown? %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :id => "options-#{question.id}" } %> + <%= f.input :options, as: :select, collection: options, label: false, input_html: { multiple: false, id: "options-#{question.id}" } %> <% end %> @@ -95,13 +95,13 @@ <%= text_area_tag("answer-text-#{question_id}".to_sym, answer.text, class: "tinymce") %> <% end %> - <% end %> - - - <%= f.actions do %> - <%= f.action :submit, :label => _('Save'), :button_html => { :class => "btn btn-primary"} %> - - <% end %> + + + + + +
+ <% end %>
@@ -111,22 +111,20 @@ <%= _('Answered')%> <%= answer.updated_at.iso8601 %><%= _(' by')%> <%= answer.user.name %> <% end %>
- -
<% comments = answer.notes.all %> - <%= hidden_field_tag :question_id, question_id, :class => "question_id" %> + <%= hidden_field_tag :question_id, question_id, class: "question_id" %>
diff --git a/app/views/phases/_edit_note.html.erb b/app/views/phases/_edit_note.html.erb index b0a7bdf..17a75bc 100644 --- a/app/views/phases/_edit_note.html.erb +++ b/app/views/phases/_edit_note.html.erb @@ -3,18 +3,13 @@ <%= form_for(note, url: note_path(note), remote: true, - method: :put, - class: "edit_note_form", + html: {method: :put, class: "edit_note_form roadmap-form"}, id: "edit_note_form_#{note.id}") do |f| %> +
<%= f.hidden_field :id, :value => note.id %> <%= text_area_tag("#{note.id}_note_text".to_sym, note.text , class: "tinymce") %> -
- - -
- <%= f.submit _('Save'), :class => "btn btn-primary edit_note_submit_button" %> -
-
+ <%= f.submit _('Save'), :class => "form-submit edit_note_submit_button" %> +
<%end%> diff --git a/app/views/phases/_note.html.erb b/app/views/phases/_note.html.erb index 95d38ec..5cc8df3 100644 --- a/app/views/phases/_note.html.erb +++ b/app/views/phases/_note.html.erb @@ -28,6 +28,5 @@ <%= render :partial => "/phases/add_note", locals: {answer: answer, question: question, plan_id: plan.id }%>
<% else%> - <%= _('Share note with collaborators')%> <%= render :partial => "/phases/add_note", locals: {answer: answer, question: question, plan_id: plan.id }%> <% end%> diff --git a/app/views/plans/_answer_form.html.erb b/app/views/plans/_answer_form.html.erb index b53e013..45f908b 100644 --- a/app/views/plans/_answer_form.html.erb +++ b/app/views/plans/_answer_form.html.erb @@ -1,4 +1,4 @@ - - <% q_format = question.question_format%> + + <% q_format = question.question_format%> - <% if readonly != "always" then %> -
> - <%= semantic_form_for answer, :url => {:controller => :answers, :action => :create }, :html=>{:method=>:post}, :remote => true do |f| %> - <%= f.inputs do %> - <%= f.input :plan_id, :as => :hidden %> - <%= f.input :user_id, :as => :hidden, :input_html => { :value => current_user.id } %> - <%= f.input :question_id, :as => :hidden, :input_html => { :class => "question_id" } %> + <% if readonly != "always" then %> +
> + <%= semantic_form_for answer, :url => {:controller => :answers, :action => :create }, :html=>{:method=>:post}, :remote => true do |f| %> + <%= f.inputs do %> + <%= f.input :plan_id, :as => :hidden %> + <%= f.input :user_id, :as => :hidden, :input_html => { :value => current_user.id } %> + <%= f.input :question_id, :as => :hidden, :input_html => { :class => "question_id" } %> - <% if q_format.title == "Check box" then %> - <% if readonly then %> - <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, input_html => { :disabled => true, :id => "options-#{question.id}" } %> - <% else %> - <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, :input_html => { :id => "options-#{question.id}" } %> - <% end %> - - <% elsif q_format.title == "Multi select box" then %> - <% if readonly then %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true, :disabled => true , :id => "options-#{question.id}" } %> - <% else %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true , :id => "options-#{question.id}" } %> - <% end %> - - <% elsif q_format.title == "Radio buttons" then%> -
    + <% options = question.options.order("number") %> + + <% if q_format.title == "Check box" then %> + <% if readonly then %> + <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, input_html => { :disabled => true, :id => "options-#{question.id}" } %> + <% else %> + <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, :input_html => { :id => "options-#{question.id}" } %> + <% end %> + + <% elsif q_format.title == "Multi select box" then %> + <% if readonly then %> + <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true, :disabled => true , :id => "options-#{question.id}" } %> + <% else %> + <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true , :id => "options-#{question.id}" } %> + <% end %> + + <% elsif q_format.title == "Radio buttons" then%> +
      <% options.each do |op| %>
    1. <% if answer.option_ids[0] == op.id then%> <% if readonly then %> <%= f.radio_button :option_ids, op.id, :checked => true, disabled: true, id: "answer_option_ids_#{op.id}"%> <% else %> - <%= f.radio_button :option_ids, op.id, :checked => true, id: "answer_option_ids_#{op.id}"%> + <%= f.radio_button :option_ids, op.id, :checked => true, id: "answer_option_ids_#{op.id}"%> <% end %> <%else%> <% if readonly then %> - <%= f.radio_button :option_ids, op.id, :checked => false, disabled: true, id: "answer_option_ids_#{op.id}"%> + <%= f.radio_button :option_ids, op.id, :checked => false, disabled: true, id: "answer_option_ids_#{op.id}"%> <% else %> - <%= f.radio_button :option_ids, op.id, :checked => false, id: "answer_option_ids_#{op.id}"%> + <%= f.radio_button :option_ids, op.id, :checked => false, id: "answer_option_ids_#{op.id}"%> <% end %> <% end %> <%= op.text %>
    2. <% end %>
    - <% elsif q_format.title == "Dropdown" then%> - <% if readonly then %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :disabled => true, :id => "options-#{question.id}" } %> - <% else %> + <% elsif q_format.title == "Dropdown" then%> + <% if readonly then %> + <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :disabled => true, :id => "options-#{question.id}" } %> + <% else %> <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :id => "options-#{question.id}" } %> - <% end %> - <% end %> + <% end %> + <% end %> + + + <% if question.option_comment_display == true then%> <%= label_tag("answer-text-#{question.id}".to_sym, _('Comment')) %> @@ -116,7 +125,7 @@ <% if readonly then %> <%= f.action :submit, :label => _('Save'), :button_html => { :class => "btn btn-primary"}, :input_html => { :disabled => true } %> <% else %> - + <%= f.action :submit, :label => _('Save'), :button_html => { :class => "btn btn-primary"} %> <% end %> @@ -204,7 +213,7 @@
    - <%= question.section.organisation.abbreviation %> + <%= question.section.organisation.abbreviation %> <%if question.section.organisation.abbreviation == "EPSRC" then %> <%= _('Policy Expectations')%> <%else%> @@ -254,7 +263,7 @@
    <% if last_question_id == question.id then %> -
    +
    <% else %> -
    +
    <% end %> diff --git a/app/views/plans/_available_templates.html.erb b/app/views/plans/_available_templates.html.erb new file mode 100644 index 0000000..59eb6fa --- /dev/null +++ b/app/views/plans/_available_templates.html.erb @@ -0,0 +1,20 @@ +<%= _('Which DMP template would you like to use?') %> + + + + + +
    + <%= _('We found multiple DMP templates corresponding to your funder.') %> +
    + + \ No newline at end of file diff --git a/app/views/plans/_dropdowns_new_plan.html.erb b/app/views/plans/_dropdowns_new_plan.html.erb deleted file mode 100644 index c7e9d7e..0000000 --- a/app/views/plans/_dropdowns_new_plan.html.erb +++ /dev/null @@ -1,41 +0,0 @@ - - -<%= semantic_form_for @plan, url: plans_path(@plan) do |f| %> - <%= f.inputs do %> - <%= hidden_field_tag :default_tag, "false" ,:id => "default_tag" %> -
    - -

    <%= _('Create a new plan') %>

    -
    -

    <%= raw _("

    Please select from the following drop-down so we can determine what questions and guidance should be displayed in your plan.

    ")%>

    -
    - - - - <% end %> - - - <%= f.actions do %> - <%= f.action :submit, - :as => :button, - :input_html => { :id => "create-plan-button", :class => "btn btn-primary"}, - :label => _('Create plan') %> - <% end %> - -<% end %> diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb index 03f5f0b..2ce0220 100644 --- a/app/views/plans/_plan_details.html.erb +++ b/app/views/plans/_plan_details.html.erb @@ -9,84 +9,70 @@
    "> - -
    -

    - <%= raw _("Please fill in the basic project details below and click 'Update' to save")%> -

    -
    -
    + <%= form_for @plan, url: {controller: :plans, action: :update }, + html: {method: :put, class: "roadmap-form"} do |f| %> +
    -
    - - <%= semantic_form_for @plan, :url => {:controller => :plans, :action => :update }, :html=>{:method=>:put} do |f| %> - <%= f.inputs do %> -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    <%= _('Plan name') %> - <%= f.text_field :title, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('If applying for funding, state the name exactly as in the grant proposal.') %> -
    <%= _('ID') %> - <%= f.text_field :identifier, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('A pertinent ID as determined by the funder and/or institution.') %> -
    <%= _('Grant number') %> - <%= f.text_field :grant_number, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('Grant reference number if applicable [POST-AWARD DMPs ONLY]') %> -
    <%= _('Principal Investigator/Researcher') %> - <%= f.text_field :principal_investigator, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('Name of Principal Investigator(s) or main researcher(s) on the project.') %> -
    <%= _('Principal Investigator/Researcher ID') %> - <%= f.text_field :principal_investigator_identifier, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('E.g ORCID http://orcid.org/.') %> -
    <%= _('Plan data contact') %> - <%= f.text_field :data_contact, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('Name (if different to above), telephone and email contact details') %> -
    <%= _('Description') %> - <%= f.text_area :description, { :rows => 7, :class => 'text_area has-tooltip', 'data-toggle' => "tooltip", 'data-html' => "true", 'title'=> _("

    Questions to consider:

    • - What is the nature of your research project?
    • - What research questions are you addressing?
    • - For what purpose are the data being collected or created?

    Guidance:

    Briefly summarise the type of study (or studies) to help others understand the purposes for which the data are being collected or created.

    ")} %> -
    + +
    + <%= _('Please fill in the basic project details below') %> + +
    + <%= f.label :title, _('Plan name') %> + <%= f.text_field :title, class: "input-large has-tooltip", 'data-toggle': "tooltip", + 'title': _('If applying for funding, state the name exactly as in the grant proposal.') %>
    - <% end %> - - <%= f.actions do %> -
    - <%= f.submit _('Save'), :class => 'btn btn-primary' %> - <%= _('Cancel') %> +
    + <%= f.label :identifier, _('ID') %> + <%= f.text_field :identifier, class: 'input-medium has-tooltip', 'data-toggle': "tooltip", + 'title': _('A pertinent ID as determined by the funder and/or institution.') %>
    - <%end%> - <%end%> +
    + <%= f.label :grant_number, _('Grant number') %> + <%= f.text_field :grant_number, class: 'input-medium has-tooltip', + 'data-toggle': "tooltip", + 'title': _('Grant reference number if applicable [POST-AWARD DMPs ONLY]') %> +
    +
    + <%= f.label :principal_investigator, _('Principal Investigator/Researcher') %> + <%= f.text_field :principal_investigator, class: 'input-medium has-tooltip', + 'data-toggle': "tooltip", + 'title': _('Name of Principal Investigator(s) or main researcher(s) on the project.') %> +
    +
    + <%= f.label :principal_investigator_identifier, _('Principal Investigator/Researcher ID') %> + <%= f.text_field :principal_investigator_identifier, class: 'input-medium has-tooltip', + 'data-toggle': "tooltip", 'title': _('E.g ORCID http://orcid.org/.') %> +
    +
    + <%= f.label :data_contact, _('Plan data contact') %> + <%= f.text_field :data_contact, class: 'input-medium has-tooltip', + 'data-toggle': "tooltip", + 'title': _('Name (if different to above), telephone and email contact details') %> +
    +
    + <%= f.label :description, _('Description') %> + <%= f.text_area :description, { rows: 7, class: 'input-large has-tooltip', + 'data-toggle': "tooltip", 'data-html': "true", + 'title': _("

    Questions to consider:

    • - What is the nature of your research project?
    • - What research questions are you addressing?
    • - For what purpose are the data being collected or created?

    Guidance:

    Briefly summarise the type of study (or studies) to help others understand the purposes for which the data are being collected or created.

    ")} %> +
    + +
    + + + +
    +
    +
    + + <%end%>
    ">
    -

    <%= _('This page gives you an overview of your plan. It tells what your plan is based on and gives an overview of the questions that you will be asked.')%>

    +

    @@ -230,127 +216,118 @@
    -

    <%= _('This plan is based on:')%>

    +

    <%= _('This plan is based on:')%>

    - - - <%if based_on.present? %> - - - - - <%end%> - <%if plan.template.org.name.present? %> - - - - - <%end%> - -
    <%= _('Funder') %><%= based_on.org.name %>
    <%= _('Institution') %><%= plan.template.org.name %>
    +

    + <% if based_on.org != plan.template.org %> + <%= _('A version of ') %> "<%= based_on.title %>" <%= based_on.title.downcase.include?(_('template')) ? '' : _('template') %><%= _(' that has been customised by ') %> <%= plan.template.org.name %> + <% else %> + <%= _('The')%> "<%= plan.template.title %>" <%= (plan.template.is_default ? _('generic template') : plan.template.title.downcase.include?(_('template')) ? '' : _('template')) %> <%= _(' provided by ') %><%= plan.template.org.name %> + <% end %> +

    - + <% phases = plan.template.phases %> - <% if phases.count == 1 %> - <% phases.each do |phase| %> -
    - <%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary' %> - <%= _('Export') %> -
    - <%= render :partial => "plans/export", locals: {plan: plan, phase: phases[0] } %> -
    -

    <%= raw phase.description %>

    - <% if phase.sections.any? %> - - - - - - - - - <% phase.sections.each do |section| %> - - - - - <%end%> - -
    <%= _('Sections')%><%= _('Questions')%>
    -

    <%= section.title %>

    -
    - <% if section.questions.any? %> -
      - <% section.questions.each do |ques|%> -
    • - <%= raw ques.text %> -
    • - <%end%> -
    - <%end%> -
    - <%end%> - <%end%> + <% if phases.count == 1 %> + <% phases.each do |phase| %> +
    + <%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary' %> + <%= _('Export') %> +
    + <%= render :partial => "plans/export", locals: {plan: plan, phase: phases[0] } %> +
    +

    <%= raw phase.description %>

    + <% if phase.sections.any? %> + + + + + + + + + <% phase.sections.each do |section| %> + + + + + <%end%> + +
    <%= _('Sections')%><%= _('Questions')%>
    +

    <%= section.title %>

    +
    + <% if section.questions.any? %> +
      + <% section.questions.each do |ques|%> +
    • + <%= raw ques.text %> +
    • + <%end%> +
    + <%end%> +
    + <%end%> + <%end%> <%else%> -
    - <%= raw plan.template.description %> -
    - <% phases.each do |phase| %> -
    -
    - -
    -
    -
    - <%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary' %> - <%= _('Export') %> -
    - <%= render :partial => "plans/export", locals: {plan: plan, phase: phase} %> -
    -

    <%= raw phase.description %> -

    +
    + <%= raw plan.template.description %> +
    + <% phases.each do |phase| %> +
    +
    + +
    +
    +
    + <%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary' %> + <%= _('Export') %> +
    + <%= render :partial => "plans/export", locals: {plan: plan, phase: phase} %> +
    +

    <%= raw phase.description %> +

    - <% if phase.sections.any? %> - - - - - - - - - <% phase.sections.each do |section| %> - - - - - <%end%> - -
    <%= _('Sections')%><%= _('Questions')%>
    -

    <%= section.title %>

    -
    - <% if section.questions.any? %> -
      - <% section.questions.each do |ques|%> -
    • - - <%= raw ques.text %> -
    • - <%end%> -
    - <%end%> -
    - <%end%> -
    -
    -
    -
    - <%end%> + <% if phase.sections.any? %> + + + + + + + + + <% phase.sections.each do |section| %> + + + + + <%end%> + +
    <%= _('Sections')%><%= _('Questions')%>
    +

    <%= section.title %>

    +
    + <% if section.questions.any? %> +
      + <% section.questions.each do |ques|%> +
    • + - <%= raw ques.text %> +
    • + <%end%> +
    + <%end%> +
    + <%end%> +
    +
    +
    +
    + <%end%>
    diff --git a/app/views/plans/create.js.erb b/app/views/plans/create.js.erb new file mode 100644 index 0000000..11be185 --- /dev/null +++ b/app/views/plans/create.js.erb @@ -0,0 +1,16 @@ +$("#available-templates").fadeOut(); + +<% if @templates.nil? %> + $(".main_page_content").prepend('

    <%= raw notice %>

    '); + +<% elsif @templates.count > 1 %> + // Clear the existing contents of the modal and then display template combobox + $("#available-templates").html("<%= escape_javascript(render partial: 'available_templates') %>").fadeIn(); + +<% else %> + // Only one template so fill in the id + $("#plan_template_id").val("<%= @templates.first.id %>"); +<% end %> + +// Force the submit button toggle +$("#plan_template_id").change(); \ No newline at end of file diff --git a/app/views/plans/new.html.erb b/app/views/plans/new.html.erb index 81d824c..a40b41b 100644 --- a/app/views/plans/new.html.erb +++ b/app/views/plans/new.html.erb @@ -1,10 +1,90 @@ -<% javascript "projects.js" %> +<% javascript "plans/new_plan.js" %> -
    -

    <%= @error %>

    - - <%= render "dropdowns_new_plan" %> +
    +

    <%= _('Create a new plan') %>

    +

    + <%= _("Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs.") %> +

    + + <%= form_for @plan, html: {method: :post, class: "roadmap-form"}, remote: true do |f| %> +
    + + +
    + <%= _('What research project are you planning?') %> + + + + +
    + <%= _('If applying for funding, state the title exactly as in the proposal.') %> +
    +
    + + +
    + <%= _('Primary research organisation') %> + + + + <%= render partial: "shared/accessible_combobox", + locals: {name: 'plan[org_name]', + id: 'plan_org_name', + default_selection: @default_org, + models: @orgs, + attribute: 'name', + classes: 'fixed-width-large'} %> + + + + +
    + + +
    + <%= _('Funding organisation') %> + + + + <%= render partial: "shared/accessible_combobox", + locals: {name: 'plan[funder_name]', + id: 'plan_funder_name', + default_selection: nil, + models: @funders, + attribute: 'name', + classes: 'fixed-width-large'} %> + + + +
    + + +
    +
    + +
    + + + + <%= render partial: 'shared/accessible_submit_button', + locals: {id: 'create_plan_submit', + val: 'Create Plan', + disabled_initially: true, + tooltip: _('You can not continue until you have filled in all of the required information.')} %> + + <% end %>
    - diff --git a/app/views/plans/share.html.erb b/app/views/plans/share.html.erb index bf8837b..42f6988 100644 --- a/app/views/plans/share.html.erb +++ b/app/views/plans/share.html.erb @@ -8,67 +8,72 @@
    - - <%= raw _('

    You can give other people access to your plan here. There are three permission levels.

    • Users with "read only" access can only read the plan.
    • Editors can contribute to the plan.
    • Co-owners can also contribute to the plan, but additionally can edit the plan details and control access to the plan.

    Add each collaborator in turn by entering their email address below, choosing a permission level and clicking "Add collaborator".

    Those you invite will receive an email notification that they have access to this plan, inviting them to register with %{application_name} if they don\'t already have an account. A notification is also issued when a user\'s permission level is changed.

    ') % { application_name: Rails.configuration.branding[:application][:name] } %> + + <%= raw _('

    You can give other people access to your plan here. There are three permission levels.

    • Users with "read only" access can only read the plan.
    • Editors can contribute to the plan.
    • Co-owners can also contribute to the plan, but additionally can edit the plan details and control access to the plan.

    Add each collaborator in turn by entering their email address below, choosing a permission level and clicking "Add collaborator".

    Those you invite will receive an email notification that they have access to this plan, inviting them to register with %{application_name} if they don\'t already have an account. A notification is also issued when a user\'s permission level is changed.

    ') % { application_name: Rails.configuration.branding[:application][:name] } %> -
    -

    <%= _('Collaborators')%>

    -
    - <% if @plan.roles.any? then %> +
    +

    <%= _('Collaborators')%>

    +
    + <% if @plan.roles.any? then %> - - - - - - - - - - <% plan_roles = @plan.roles.all %> - <% plan_roles.each do |role| %> - - - - + <% end %> -

    <%= _('Permissions')%>:

    - <%= f.select :access_level, [[_('Co-owner'), 3], [ _('Editor') , 2], [ _('Read only'), 1]], {}, {:class => 'has-tooltip', 'data-toggle' => "tooltip", 'title' => _('Editors can contribute to plans. Co-owners have additional rights to edit plan details and control access.') } %> - <% end %> - <%= f.actions do %> - <%= f.action :submit, :label => _('Add collaborator'), :button_html => { :class => "btn btn-primary" } %> - <% end %> - <% end %> - - + +
    <%= _('Email address')%><%= _('Permissions')%>
    <%= role.user.name %> - <% if role.creator? then %> - <%= _('Owner')%> - <% else %> - <%= form_for role, :url => {:controller => :roles, :action => :update, :id => role.id }, :html=>{:method=>:put} do |f| %> - <%= f.select :access_level, {_('Co-owner') => 3, _('Editor') => 2, _('Read only') => 1}, {}, {:id => "#{role.id}-can-edit", :class => "toggle-existing-user-access has-tooltip", 'data-toggle' => "tooltip", 'title' => _('Editors can contribute to plans. Co-owners have additional rights to edit plan details and control access.') } %> - <% end %> - <% end %> - + + + + + + + + + + <% plan_roles = @plan.roles.all %> + <% plan_roles.each do |role| %> + + + + - - <% end %> - -
    <%= _('Email address')%><%= _('Permissions')%>
    <%= role.user.name %> + <% if role.creator? then %> + <%= _('Owner')%> + <% else %> + <%= form_for role, url: {controller: :roles, action: :update, id: role.id }, html: {method: :put} do |f| %> +
    + <%= f.select :access_level, {"#{_('Co-owner')}": 3, "#{_('Editor')}": 2, "#{_('Read only')}": 1}, {}, {id: "#{role.id}-can-edit", class: "toggle-existing-user-access has-tooltip", 'data-toggle': "tooltip", 'title': _('Editors can contribute to plans. Co-owners have additional rights to edit plan details and control access.') } %> +
    + <% end %> + <% end %> +
    <% unless role.creator? || role.user == current_user then %> - <%= link_to _('Remove user access'), role, method: :delete, data: { confirm: _('Are you sure?') }, :class => "a-orange" %> - <% end %> -
    - <% end %> - - -
    -

    <%= _('Add collaborator')%>

    - -
    - <% new_role = Role.new %> - <% new_role.plan = @plan %> - <%= semantic_form_for new_role, :url => {:controller => :roles, :action => :create }, :html=>{:method=>:post} do |f| %> - <%= f.inputs do %> - <%= f.input :plan_id, :as => :hidden %> - <%= f.semantic_fields_for :user do |user| %> - <%= user.email_field :email, :for => :user, :name => "user", :label => false, placeholder: _('Email') %> + <%= link_to _('Remove user access'), role, method: :delete, data: { confirm: _('Are you sure?') }, :class => "a-orange" %> + <% end %> +
    + <% end %> +
    + +
    + +
    + <% new_role = Role.new %> + <% new_role.plan = @plan %> + <%= form_for new_role, url: {controller: :roles, action: :create }, + html: {method: :post, class: 'roadmap-form'} do |f| %> +
    + <%= _('Add collaborator') %> + + <%= f.hidden_field :plan_id %> + + <%= f.fields_for :user do |user| %> + <%= user.label :email, _('Email') %> + <%= user.email_field :email, for: :user, name: "user", class: "left-indent" %> + <% end %> + + <%= f.label :access_level, _('Permissions') %> + <%= f.select :access_level, [[_('Co-owner'), 3], [ _('Editor') , 2], [ _('Read only'), 1]], {}, {class: 'has-tooltip left-indent', 'data-toggle': "tooltip", 'title': _('Editors can contribute to plans. Co-owners have additional rights to edit plan details and control access.') } %> + +
    + <% end %> +
    +
    diff --git a/app/views/projects/_dropdowns_new_project.html.erb b/app/views/projects/_dropdowns_new_project.html.erb deleted file mode 100644 index f9a91ce..0000000 --- a/app/views/projects/_dropdowns_new_project.html.erb +++ /dev/null @@ -1,110 +0,0 @@ - -<%= semantic_form_for @project, :url => {:controller => :projects, :action => :create }, :html=>{:method=>:post} do |f| %> - <%= f.inputs do %> - <%= hidden_field_tag :default_tag, "false" ,:id => "default_tag" %> -
    -

    <%= _('Create a new plan')%>

    -
    -

    <%= raw _("

    Please select from the following drop-downs so we can determine what questions and guidance should be displayed in your plan.

    If you aren't responding to specific requirements from a funder or an institution, select here to write a generic DMP based on the most common themes.

    ")%>

    - -
    - -
    - - <% # - # The following JSON arrays are used to build/filter the contents of - # the select2 dropdown box for dmptemplates and the checkboxes for - # the guidance group selections - # (they are referenced in /app/assets/javascripts/projects.js) - # %> - - <%= hash_to_js_json_variable('funders', - @funders.collect{ |inst| - {'id': inst.id, - 'text': inst.name} - }) %> - - <%= hash_to_js_json_variable('institutions', - @institutions.collect{ |inst| - {'id': inst.id, - 'text': inst.name, - 'default': (current_user.org.id == inst.id)} - }) %> - - <%= hash_to_js_json_variable('templates', - @templates.collect{ |tmplt| - {'organisation': tmplt.organisation_id, - 'id': tmplt.id, - 'text': tmplt.title} - }) %> - - <%= hash_to_js_json_variable('guidance_for_template_or_organisation', - @guidance_groups.collect{ |grp| - {'organisation': grp.organisation_id, - 'templates': grp.dmptemplates.collect{ |t| t.id }, - 'id': grp.id, - 'text': grp.name} - }) %> - - <%= hash_to_js_json_variable('guidance_always_available', - @always_guidance.collect{ |grp| - {'id': grp.id, - 'text': grp.name} - }) %> - - <% end %> - - <%= f.actions do %> - - <% end %> -<% end %> diff --git a/app/views/shared/_accessible_combobox.html.erb b/app/views/shared/_accessible_combobox.html.erb new file mode 100644 index 0000000..c2f99e0 --- /dev/null +++ b/app/views/shared/_accessible_combobox.html.erb @@ -0,0 +1,65 @@ +<% if !models.nil? %> + <% json = {} %> + <% models.map{|m| json[m[attribute]] = m.id} %> + + + + <% models.each do |model| %> + + + + + + " name="<%= name.gsub("_#{attribute}]", "_id]") %>" + value="<%= default_selection.id unless default_selection.nil? %>" /> + + + +<% else %> + <%= _('No items available.') %> +<% end %> \ No newline at end of file diff --git a/app/views/shared/_accessible_submit_button.html.erb b/app/views/shared/_accessible_submit_button.html.erb new file mode 100644 index 0000000..2966a91 --- /dev/null +++ b/app/views/shared/_accessible_submit_button.html.erb @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/app/views/shared/_export_links.html.erb b/app/views/shared/_export_links.html.erb index 6ce39cd..6908e62 100644 --- a/app/views/shared/_export_links.html.erb +++ b/app/views/shared/_export_links.html.erb @@ -1,12 +1,13 @@ <% javascript("export_configure") %>
    - - <%= label_tag(:format, _('format')) %> + <%= label_tag(:format, _('Format')) %> <%= select_tag(:format, options_for_select(ExportedPlan::VALID_FORMATS, :pdf), class: 'export-format-selection') %> - + + +
    -

    Export Settings <%= plan_settings_indicator(plan) -%>

    - <%= render(partial: "settings/phases/export_formatting_form", locals: { plan: plan, phase: phase }) %> +

    Export Settings <%= plan_settings_indicator(plan) -%>

    + <%= render(partial: "settings/phases/export_formatting_form", locals: { plan: plan, phase: phase }) %>
    diff --git a/config/application.rb b/config/application.rb index 9dbff4e..8994e51 100644 --- a/config/application.rb +++ b/config/application.rb @@ -72,11 +72,16 @@ config.assets.precompile += %w(projects.js) config.assets.precompile += %w(jquery.placeholder.js) config.assets.precompile += %w(jquery.tablesorter.js) + config.assets.precompile += %w(jquery-accessible-autocomplet-list-aria.js) config.assets.precompile += %w(export_configure.js) config.assets.precompile += %w(toolbar.js) config.assets.precompile += %w(admin.js) config.assets.precompile += %w(admin.css) + config.assets.precompile += %w(roadmap-form.scss) + config.assets.precompile += %w(plans/new_plan.js) + config.assets.precompile += %w(contacts/new_contact.js) + config.autoload_paths += %W(#{config.root}/lib) config.action_controller.include_all_helpers = true diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js index fe85da0..59b9a26 100644 --- a/lib/assets/javascripts/application.js +++ b/lib/assets/javascripts/application.js @@ -21,6 +21,7 @@ //= require i18n/translations //= require_tree ./locale //= require gettext/all +//= require jquery-accessible-autocomplet-list-aria.js $( document ).ready(function() { diff --git a/lib/assets/javascripts/contacts/new_contact.js b/lib/assets/javascripts/contacts/new_contact.js new file mode 100644 index 0000000..1b692e2 --- /dev/null +++ b/lib/assets/javascripts/contacts/new_contact.js @@ -0,0 +1,14 @@ +var RecaptchaOptions = { + theme : "clean" +}; + +$(document).ready(function(){ + $("input[type='text'], input[type='email'], textarea").change(function(e){ + var enable = ($("#contact_us_contact_name").val().trim().length > 0 && + $("#contact_us_contact_email").val().trim().length > 0 && + $("#contact_us_contact_subject").val().trim().length > 0 && + $("#contact_us_contact_message").val().trim().length > 0); + + $("#create_contact_submit").attr('aria-disabled', !enable); + }); +}); \ No newline at end of file diff --git a/lib/assets/javascripts/jquery-accessible-autocomplet-list-aria.js b/lib/assets/javascripts/jquery-accessible-autocomplet-list-aria.js new file mode 100755 index 0000000..dfb04c9 --- /dev/null +++ b/lib/assets/javascripts/jquery-accessible-autocomplet-list-aria.js @@ -0,0 +1,354 @@ +$(document).ready(function(){ + + /* + * jQuery accessible and keyboard-enhanced autocomplete list + * Website: http://a11y.nicolas-hoffmann.net/autocomplet-list/ + * License MIT: https://github.com/nico3333fr/jquery-accessible-autocomplete-list-aria/blob/master/LICENSE + */ + // loading combobox ------------------------------------------------------------------------------------------------------------ + // init + var $js_combobox = $('.js-combobox'), + $body = $('body'), + default_text_help = 'Use tabulation (or down) key to access and browse suggestions after input. Confirm your choice with enter key, or esc key to close suggestions box.', + default_class_for_invisible_text = 'invisible', + suggestion_single = 'There is ', + suggestion_plural = 'There are ', + suggestion_word = 'suggestion', + button_clear_title = 'clear this field', + button_clear_text = 'X', + case_sensitive = 'yes', + min_length = 0, + limit_number_suggestions = 666, + search_option = 'beginning', // or 'containing' + see_more_text = 'See more results…', + tablo_suggestions = []; + + if ( $js_combobox.length ) { // if there are at least one :) + + // init + $js_combobox.each( function(index_combo) { + var $this = $(this), + $this_id = $this.attr('id'), + $label_this = $( 'label[for="' + $this_id + '"]' ), + index_lisible = index_combo+1, + options = $this.data() + $combobox_prefix_class = typeof options.comboboxPrefixClass !== 'undefined' ? options.comboboxPrefixClass + '-' : '', + $combobox_help_text = typeof options.comboboxHelpText !== 'undefined' ? options.comboboxHelpText : default_text_help, + $list_suggestions = $( '#' + $this.attr('list') ), + $combobox_button_title = typeof options.comboboxButtonTitle !== 'undefined' ? options.comboboxButtonTitle : button_clear_title, + $combobox_button_text = typeof options.comboboxButtonText !== 'undefined' ? options.comboboxButtonText : button_clear_text, + $combobox_case_sensitive = typeof options.comboboxCaseSensitive !== 'undefined' ? options.comboboxCaseSensitive : case_sensitive, + tablo_temp_suggestions = [] ; + + // input + $this.attr({ + 'data-number' : index_lisible, + 'autocorrect' : 'off', + 'autocapitalize' : 'off', + 'spellcheck' : 'off', + 'autocomplete' : 'off', + 'aria-describedby' : $combobox_prefix_class + 'help-text' + index_lisible, + 'aria-autocomplete' : 'list', + 'data-lastval' : '', + 'aria-owns' : $combobox_prefix_class + 'suggest_' + index_lisible + }); + // stock into tables + $list_suggestions.find('option').each( function(index_option, index_element) { + tablo_temp_suggestions.push(index_element.value); + }); + if ($combobox_case_sensitive === 'no'){ + // order case tablo_temp_suggestions + tablo_suggestions[index_lisible] = tablo_temp_suggestions.sort(function(a,b) { + a = a.toLowerCase(); + b = b.toLowerCase(); + if ( a == b) { + return 0; + } + if ( a > b) { + return 1; + } + return -1; + }); + } + else { tablo_suggestions[index_lisible] = tablo_temp_suggestions.sort(); } + + // wrap into a container + $this.wrap('
    '); + + var $combobox_container = $this.parent(); + + // custom datalist/listbox linked to input + $combobox_container.append( '
    ' ); + $list_suggestions.remove(); + + // status zone + $combobox_container.prepend( '
    ' ); + + // help text + $combobox_container.prepend( '' + $combobox_help_text + '' ); + + // label id + $label_this.attr('id', 'label-id-' + $this_id); + + // button clear + $this.after(''); + + }); + + function do_see_more_option ( ) { + var $output_content = $('#js-codeit'); + $output_content.html('You have to code a function or a redirection to display more results ;)'); + } + + // listeners + // keydown on field + $body.on( 'keyup', '.js-combobox', function( event ) { + var $this = $(this), + options_combo = $this.data(), + $container = $this.parent(), + $form = $container.parents('form'), + options = $container.data(), + $combobox_prefix_class = typeof options.comboboxPrefixClass !== 'undefined' ? options.comboboxPrefixClass : '', // no "-"" because already generated + $suggestions = $container.find('.js-suggest div'), + $suggestion_list = $suggestions.find('.js-suggestion'), + $suggestions_text = $container.find('.js-suggestion-text'), + $combobox_suggestion_single = typeof options_combo.suggestionSingle !== 'undefined' ? options_combo.suggestionSingle : suggestion_single, + $combobox_suggestion_plural = typeof options_combo.suggestionPlural !== 'undefined' ? options_combo.suggestionPlural : suggestion_plural, + $combobox_suggestion_word = typeof options_combo.suggestionWord !== 'undefined' ? options_combo.suggestionWord : suggestion_word, + combobox_min_length = typeof options_combo.comboboxMinLength !== 'undefined' ? Math.abs(options_combo.comboboxMinLength) : min_length, + $combobox_case_sensitive = typeof options_combo.comboboxCaseSensitive !== 'undefined' ? options_combo.comboboxCaseSensitive : case_sensitive, + combobox_limit_number_suggestions = typeof options_combo.comboboxLimitNumberSuggestions !== 'undefined' ? Math.abs(options_combo.comboboxLimitNumberSuggestions) : limit_number_suggestions, + $combobox_search_option = typeof options_combo.comboboxSearchOption !== 'undefined' ? options_combo.comboboxSearchOption : search_option, + $combobox_see_more_text = typeof options_combo.comboboxSeeMoreText !== 'undefined' ? options_combo.comboboxSeeMoreText : see_more_text, + index_table = $this.attr('data-number'), + value_to_search = $this.val(), + text_number_suggestions = ''; + + if ( event.keyCode === 13 ) { + $form.submit(); + } + else { + + if ( event.keyCode !== 27 ) { // No Escape + + $this.attr( 'data-lastval', value_to_search ); + // search for text suggestion in the array tablo_suggestions[index_table] + var size_tablo = tablo_suggestions[index_table].length, + i = 0, + counter = 0; + + $suggestions.empty(); + + if ( value_to_search != '' && value_to_search.length >= combobox_min_length ){ + while ( i= 0) ) + || + ( $combobox_case_sensitive==='no' && (tablo_suggestions[index_table][i].toUpperCase().indexOf(value_to_search.toUpperCase()) >= 0) ) + ) + || + ( + $combobox_search_option === 'beginning' && + ( $combobox_case_sensitive==='yes' && tablo_suggestions[index_table][i].substring(0,value_to_search.length) === value_to_search ) + || + ( $combobox_case_sensitive==='no' && tablo_suggestions[index_table][i].substring(0,value_to_search.length).toUpperCase() === value_to_search.toUpperCase() ) + ) + ) { + $suggestions.append( '
    ' + tablo_suggestions[index_table][i] + '
    ' ); + counter++; + } + } + i++; + } + if ( counter >= combobox_limit_number_suggestions ) { + $suggestions.append( '
    ' + $combobox_see_more_text + '
    ' ); + counter++; + } + // update number of suggestions + if ( counter > 1 ){ + text_number_suggestions = $combobox_suggestion_plural + counter + ' ' + $combobox_suggestion_word + 's.'; + } + if ( counter === 1 ){ + text_number_suggestions = $combobox_suggestion_single + counter + ' ' + $combobox_suggestion_word + '.'; + } + if ( counter === 0 ){ + text_number_suggestions = $combobox_suggestion_single + counter + ' ' + $combobox_suggestion_word + '.'; + } + if ( counter >= 0 ){ + var text_number_suggestions_default = $suggestions_text.text(); + if (text_number_suggestions != text_number_suggestions_default) { // @Goestu trick to make it work on all AT + suggestions_to_add=$("

    ").text(text_number_suggestions); + $suggestions_text.attr('aria-live','polite'); + $suggestions_text.empty(); + $suggestions_text.append(suggestions_to_add); + } + } + + } + + } + } + + }) + .on('click', function(event) { + var $target = $(event.target), + $suggestions_text = $('.js-suggestion-text:not(:empty)'), // if a suggestion text is not empty => suggestion opened somewhere + $container = $suggestions_text.parents('.js-container'), + $input_text = $container.find('.js-combobox'), + $suggestions = $container.find('.js-suggest div'); + + // if click outside => close opened suggestions + if ( !$target.is('.js-suggestion') && !$target.is('.js-combobox') && $suggestions_text.length) { + $input_text.val( $input_text.attr('data-lastval') ); + $suggestions.empty(); + $suggestions_text.empty(); + } + }) + // tab + down management for autocomplete (when list of suggestion) + .on( 'keydown', '.js-combobox', function( event ) { + var $this = $(this), + $container = $this.parent(), + $input_text = $container.find('.js-combobox'), + $suggestions = $container.find('.js-suggest div'), + $suggestion_list = $suggestions.find('.js-suggestion'), + $suggestions_text = $container.find('.js-suggestion-text'), + $autorise_tab_options = typeof $this.attr('data-combobox-notab-options') !== 'undefined' ? false : true, + $first_suggestion = $suggestion_list.first(); + + if ( ( !event.shiftKey && event.keyCode == 9 && $autorise_tab_options ) || event.keyCode == 40 ) { // tab (if authorised) or bottom + // See if there are suggestions, and yes => focus on first one + if ($suggestion_list.length) { + $input_text.val($first_suggestion.html()); + $suggestion_list.first().focus(); + event.preventDefault(); + } + } + if ( event.keyCode == 27 || ($autorise_tab_options === false && event.keyCode == 9 ) ) { // esc or (tab/shift tab + notab option) = close + $input_text.val( $input_text.attr('data-lastval') ); + $suggestions.empty(); + $suggestions_text.empty(); + if ( event.keyCode == 27) { // Esc prevented only, tab can go :) + event.preventDefault(); + setTimeout(function(){ $input_text.focus(); }, 300); // timeout to avoid problem in suggestions display + } + } + }) + // tab + down management in list of suggestions + .on( 'keydown', '.js-suggestion', function( event ) { + var $this = $(this), + $container = $this.parents('.js-container'), + $input_text = $container.find('.js-combobox'), + $autorise_tab_options = typeof $input_text.attr('data-combobox-notab-options') !== 'undefined' ? false : true, + $suggestions = $container.find('.js-suggest div'), + $suggestions_text = $container.find('.js-suggestion-text'), + $next_suggestion = $this.next(), + $previous_suggestion = $this.prev(); + + if ( event.keyCode == 27 || ($autorise_tab_options === false && event.keyCode == 9 ) ) { // esc or (tab/shift tab + notab option) = close + if ( event.keyCode == 27) { // Esc prevented only, tab can go :) + $input_text.val( $input_text.attr('data-lastval') ); + $suggestions.empty(); + $suggestions_text.empty(); + setTimeout(function(){ $input_text.focus(); }, 300); // timeout to avoid problem in suggestions display + event.preventDefault(); + } + if ( $autorise_tab_options === false && event.keyCode == 9 ) { + $suggestions.empty(); + $suggestions_text.empty(); + $input_text.focus(); + } + } + if ( event.keyCode == 13 || event.keyCode == 32 ) { // Enter or space + if ( $this.hasClass('js-seemore') ) { + $input_text.val($input_text.attr('data-lastval')); + $suggestions.empty(); + $suggestions_text.empty(); + setTimeout(function(){ $input_text.focus(); }, 300); // timeout to avoid problem in suggestions display + // go define the function you need when we click the see_more option + setTimeout(function(){ do_see_more_option(); }, 301); // timeout to avoid problem in suggestions display + event.preventDefault(); + } + else { + $input_text.val( $this.html() ); + $input_text.attr('data-lastval', $this.html() ); + $suggestions.empty(); + $suggestions_text.empty(); + setTimeout(function(){ $input_text.focus(); }, 300); // timeout to avoid problem in suggestions display + event.preventDefault(); + } + + } + if ( ( !event.shiftKey && event.keyCode == 9 && $autorise_tab_options ) || event.keyCode == 40 ) { // tab (if authorised) or bottom + if ($next_suggestion.length) { + $input_text.val($next_suggestion.html()); + $next_suggestion.focus(); + } + else { + $input_text.val( $input_text.attr('data-lastval') ); + if ( !event.shiftKey && event.keyCode == 9 ) { // tab closes the list + var e = jQuery.Event("keydown"); + e.which = 27; // # Some key code value + e.keyCode = 27; + $this.trigger(e); + } + else { setTimeout(function(){ $input_text.focus(); }, 300); } // timeout to avoid problem in suggestions display + + } + event.preventDefault(); + } + + if ( ( event.shiftKey && event.keyCode == 9 && $autorise_tab_options ) || event.keyCode == 38 ) { // top or Maj+tab (if authorised) + if ($previous_suggestion.length) { + $input_text.val($previous_suggestion.html()); + $previous_suggestion.focus(); + } + else { + $input_text.val( $input_text.attr('data-lastval') ).focus(); + } + event.preventDefault(); + } + }) + // clear button + .on( 'click', '.js-clear-button', function( event ) { + var $this = $(this), + $container = $this.parent(), + $input_text = $container.find('.js-combobox'), + $suggestions = $container.find('.js-suggest div'), + $suggestions_text = $container.find('.js-suggestion-text'); + + $suggestions.empty(); + $suggestions_text.empty(); + $input_text.val(''); + $input_text.attr( 'data-lastval', ''); + + }) + .on( 'click', '.js-suggestion', function( event ) { + var $this = $(this), + value = $this.html(), + $container = $this.parents('.js-container'), + $input_text = $container.find('.js-combobox'), + $suggestions = $container.find('.js-suggest div'), + $suggestions_text = $container.find('.js-suggestion-text'); + + if ( $this.hasClass('js-seemore') ) { + $suggestions.empty(); + $suggestions_text.empty(); + $input_text.focus(); + // go define the function you need when we click the see_more option + do_see_more_option( ); + } + else { + $input_text.val(value).focus(); + $suggestions.empty(); + $suggestions_text.empty(); + } + + }); + + + } + +}); diff --git a/lib/assets/javascripts/plans.js b/lib/assets/javascripts/plans.js index db33faa..1a690e4 100644 --- a/lib/assets/javascripts/plans.js +++ b/lib/assets/javascripts/plans.js @@ -119,7 +119,7 @@ $("form.answer").submit(function(){ var submit_button = $(this).find('input[type="submit"]'); var saving_message = $(this).find('.saving-message'); - submit_button.parent().hide(); + submit_button.hide(); q_id = $(this).find(".question_id").val(); saving_message.show(); s_status = $(this).closest(".accordion-group").find(".section-status:first"); diff --git a/lib/assets/javascripts/plans/new_plan.js b/lib/assets/javascripts/plans/new_plan.js new file mode 100644 index 0000000..7bf6e19 --- /dev/null +++ b/lib/assets/javascripts/plans/new_plan.js @@ -0,0 +1,65 @@ +$(document).ready(function(){ + $("#available-templates").hide(); + + // retrieve the template options and toggle the submit button on page reload + handleComboboxChange(); + handleCheckboxClick("org", $("#plan_no_org").prop("checked")); + handleCheckboxClick("funder", $("#plan_no_funder").prop("checked")); + + // When the hidden org and funder id fields change toogle the submit button + $("#plan_org_id, #plan_funder_id").change(function(){ + handleComboboxChange(); + }); + + // Make sure the checkbox is unchecked if we're entering text + $(".js-combobox").keyup(function(){ + var whichOne = $(this).prop('id').split('_')[1]; + $("#plan_no_" + whichOne).prop("checked", false); + }); + + // If the user clicks the no Org/Funder checkbox disable the dropdown + // and hide clear button + $("#plan_no_org, #plan_no_funder").click(function(){ + var whichOne = $(this).prop('id').split('_')[2]; + handleCheckboxClick(whichOne, this.checked); + }); + + $("#plan_template_id").change(function(){ + $("#create_plan_submit").attr('aria-disabled', ($(this).val().trim().length <= 0)); + }); +}); + +// Only display the submit button if the user has made each decision +// ------------------------------------------------------------- +function handleComboboxChange(){ + // If the (no_org checkbox is checked OR an org was selected) AND + // (no_funder checkbox is checked OR a funder was selected) AND + // (the template selector is not visible OR a template has been selected) + var retrieve = ($("#plan_no_org").prop("checked") || + $("#plan_org_id").val().trim().length > 0) && + ($("#plan_no_funder").prop("checked") || + $("#plan_funder_id").val().trim().length > 0); + + if(retrieve){ + if($("#plan_template_id").val().trim().length <= 0){ + $("form").submit(); + } + + }else{ + $("#available-templates").fadeOut(); + $("#plan_template_id").val(""); + } +} + +// Clear the combobox and disable it if the box was checked +// ------------------------------------------------------------- +function handleCheckboxClick(name, checked){ + $("#plan_" + name + "_name").prop("disabled", checked); + $("#plan_template_id").val("").change(); + + if(checked){ + $("#plan_" + name + "_name").val(""); + $("#plan_" + name + "_id").val("").change(); + $("#plan_" + name + "_name").siblings(".combobox-clear-button").hide(); + } +} diff --git a/lib/assets/stylesheets/application.css b/lib/assets/stylesheets/application.css index 8635967..becfdeb 100644 --- a/lib/assets/stylesheets/application.css +++ b/lib/assets/stylesheets/application.css @@ -14,4 +14,5 @@ *= require bootstrap.css *= require select2.css *= require bootstrap_and_overrides.css.less + *= require roadmap-form.scss */ \ No newline at end of file diff --git a/lib/assets/stylesheets/roadmap-form.scss b/lib/assets/stylesheets/roadmap-form.scss new file mode 100644 index 0000000..9abd90a --- /dev/null +++ b/lib/assets/stylesheets/roadmap-form.scss @@ -0,0 +1,260 @@ +@import "font-awesome"; + +$font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; +$header-font: "GillSansLight"; + +$white: #FFF; +$dark-grey: #333; + +$primary-color: #F49700; +$primary-admin-color: #0057A7; +$disabled-button-color: #CCC; +$cancel-button-color: #827D7E; +$reverse-text: #FFF; + +/* See `.combobox-clear-button` for an example of this mixin in use */ +@mixin icon($icon) { + @extend .fa; + @extend .fa-#{$icon}:before; +} + +.arrow-left { + display: inline-block; + width: 0; + height: 0; + border-top: 12px solid transparent; + border-bottom: 12px solid transparent; + border-right: 12px solid $dark-grey; +} + +.main_header { + margin-bottom: 20px; +} + +.content-box { + +} + +/* Roadmap Form Styling */ +/* ------------------------------------------------ */ +form.roadmap-form { + + fieldset.padded { + padding: 10px 10px 25px 10px; + } + + /* Fieldset with labels over inputs */ + fieldset.standard { + background-color: $white; + + margin-bottom: 25px; + + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + + label, + input[type="checkbox"], + .combobox-container, + .left-indent { + margin-left: 15px; + } + + input[type="text"], select { + margin-bottom: 15px; + } + + input[type="checkbox"] { + vertical-align: top; + } + + .checkbox-label { + display: inline-block; + margin-left: 5px; + } + } + + /* Fieldset with labels to the left of inputs */ + fieldset.side-by-side { + .mce-tinymce { + display: inline-block; + } + + div { + label, + input[type="checkbox"], + .combobox-container, + .identifier-scheme { + display: inline-block; + } + + .identifier-scheme-indent { + margin-left: -5px; + } + + label { + width: 25%; + text-align: right; + margin-right: 10px; + vertical-align: middle; + } + + input.form-submit, + button.form-cancel { + font-size: 10pt; + } + } + + .button-spacer { + display: inline-block; + width: 21%; + } + } + + /* Generic Fieldset Settings */ + fieldset legend { + font-family: $header-font; + color: $primary-color; + font-size: 26px; + font-weight: normal; + text-decoration: none; + + float: left; /* positions the legend within the fieldset box */ + border-bottom: none; + } + + div.inline { + display: inline-block; + } + .left-indent { + margin-left: 15px; + } + .input-extra-large { + width: 70%; + } + .input-large { + width: 50%; + } + .input-medium { + width: 30%; + } + .input-small { + width: 10%; + } + /* Used for the jquery autocomplete combobox on side-by-side fieldsets */ + .fixed-width-large { + width: 550px; + } + + /* Accessible Form Buttons */ + input.form-submit { + background-color: $primary-color; + color: $reverse-text; + padding: 10px 30px; + font-size: 12pt; + margin-top: 15px; + + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + } + /* Override the button color for the Org Admin sections */ + input[type="submit"].admin{ + background-color: $primary-admin-color; + } + input.form-submit[aria-disabled='true'] { + background-color: $disabled-button-color; + } + input.form-submit:focus + [role="tooltip"] { + display: inline-block; + } + button.form-cancel { + background-color: $cancel-button-color; + color: $reverse-text; + padding: 10px 30px; + font-size: 12pt; + margin-top: 15px; + + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + } + .submit-tooltip { + display: none; + margin-left: 5px; + + .arrow-left { + vertical-align: middle; + margin-right: -5px; + } + .submit-tooltip-msg { + color: $white; + background-color: $dark-grey; + padding: 5px 5px 8px 5px; + + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + } + } +} + +/* Accessible JQuery combobox */ +/* ------------------------------------------------------ */ +.invisible { + border: 0; + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} + +.combobox-container { + position: relative; + max-width: 585px; + + font-family: $font-family; +} + +.combobox-suggestions { + position: absolute; + left: 0; + width: 562px; + margin-top: -10px; + background: #fff; + z-index: 99; +} +.combobox-suggestion { + color: #666; + border-bottom: 1px solid #000; + border-left: 1px solid #000; + border-right: 1px solid #000; + padding: 5px 10px 5px 10px; + cursor: pointer; + text-align: left; +} +.combobox-suggestion:first-child { + border-top: 1px solid #000; +} +.combobox-suggestion:hover, +.combobox-suggestion:focus { + color: $white; + background-color: $primary-color; +} + +.combobox-clear-button { + @include icon(times-circle); + display: inline; + position: absolute; + border: none; + background: transparent; + padding-top: 3px; + font-size: 16pt; +} + +/* http://geektnt.com/how-to-remove-x-from-search-input-field-on-chrome-and-ie.html */ +.js-combobox[type=text]::-ms-clear { display: none; width: 0; height: 0; } +.js-combobox[type=text]::-ms-reveal { display: none; width: 0; height: 0; } \ No newline at end of file diff --git a/test/functional/plans_controller_test.rb b/test/functional/plans_controller_test.rb index 7386a2f..259bfbf 100644 --- a/test/functional/plans_controller_test.rb +++ b/test/functional/plans_controller_test.rb @@ -71,34 +71,26 @@ get new_plan_path assert_response :success assert assigns(:plan) + assert assigns(:orgs) assert assigns(:funders) + assert assigns(:default_org) end # POST /plans (plans_path) # ---------------------------------------------------------- test "create a new plan" do - params = {template_id: @template.id} + params = {plan: {org_id: @template.org.id, template_id: @template.id, title: 'Testing Create'}} # Should redirect user to the root path if they are not logged in! - post plans_path, params + post plans_path(format: :js), params assert_unauthorized_redirect_to_root_path sign_in @user - post plans_path, params - assert_equal _('Plan was successfully created.'), flash[:notice] - assert_response :redirect - assert_redirected_to "#{plan_url(Plan.last)}?editing=true" + post plans_path(format: :js), params + assert flash[:notice].include?(_('Plan was successfully created.')) + assert_response :success assert assigns(:plan) - assert_equal "#{_('My plan')} (#{@template.title})", Plan.last.title, "expected the record to have been created" - -# TODO: We should also test the various template routes: funder, institution, generic - -# TODO: Reactivate this once the validations on the model are in place! - # Invalid object -# post plans_path, {plan: {title: nil, template: @template}} -# assert flash[:notice].starts_with?(_('Could not create your')) -# assert_response :success -# assert assigns(:plan) + assert_equal "Testing Create", Plan.last.title, "expected the record to have been created" end # GET /plan/:id (plan_path) diff --git a/test/functional/users/omniauth_callbacks_controller_test.rb b/test/functional/users/omniauth_callbacks_controller_test.rb index 9086351..3dca1ca 100644 --- a/test/functional/users/omniauth_callbacks_controller_test.rb +++ b/test/functional/users/omniauth_callbacks_controller_test.rb @@ -13,7 +13,7 @@ @schemes.each do |scheme| @callback_uris[scheme.name] = Rails.application.routes.url_helpers.send( "user_#{scheme.name.downcase}_omniauth_callback_path") - + OmniAuth.config.mock_auth[:"#{scheme.name.downcase}"] = OmniAuth::AuthHash.new({ :provider => "#{scheme.name.downcase}", :uid => 'foo:bar' diff --git a/test/integration/template_selection_test.rb b/test/integration/template_selection_test.rb new file mode 100644 index 0000000..055db21 --- /dev/null +++ b/test/integration/template_selection_test.rb @@ -0,0 +1,140 @@ +require 'test_helper' + +class TemplateSelectionTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + + setup do + scaffold_template + @template.is_default = true + @template.published = true + @template.save! + + @researcher = User.last + + scaffold_org_admin(@template.org) + + @funder = Org.find_by(org_type: 2) + @funder_template = Template.create(title: 'Funder template', org: @funder) + # Template can't be published on creation so do it afterward + @funder_template.published = true + @funder_template.save + + @org = @researcher.org + @org_template = Template.create(title: 'Org template', org: @org) + # Template can't be published on creation so do it afterward + @org_template.published = true + @org_template.save + end + + # ---------------------------------------------------------- + test 'plan gets publish versions of templates' do + original_id = @template.id + template = version_template(@template) + + sign_in @researcher + + post plans_path(format: :js), {plan: {org_id: @template.org.id}} + assert_response :success + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{original_id}\");") + assert_equal original_id, Template.live(@template.dmptemplate_id).id + + # Version the template again + original_id = template.id + template = version_template(template) + + # Make sure the published version is used + post plans_path(format: :js), {plan: {org_id: @template.org.id}} + assert_response :success + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{original_id}\");") + assert_equal original_id, Template.live(@template.dmptemplate_id).id + + # Update the template and make sure the published version stayed the same + sign_in @user + put admin_update_template_path(template), {template: {title: "Blah blah blah"}} + + sign_in @researcher + + post plans_path(format: :js), {plan: {org_id: @template.org.id}} + assert_response :success + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{original_id}\");") + assert_equal original_id, Template.live(@template.dmptemplate_id).id + end + + # ---------------------------------------------------------- + test 'plan gets generic template when no funder or org' do + @template.is_default = true + @template.save! + + sign_in @researcher + + post plans_path(format: :js), {plan: {org_id: nil}} + assert_response :success + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{@template.id}\");"), @response.body + end + + # ---------------------------------------------------------- + test 'plan gets org template when no funder' do + sign_in @researcher + + post plans_path(format: :js), {plan: {org_id: @org.id, funder_id: nil}} + assert_response :success + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{@org_template.id}\");"), @response.body + end + + # ---------------------------------------------------------- + test 'plan gets funder template when no org' do + sign_in @researcher + + post plans_path(format: :js), {plan: {org_id: nil, funder_id: @funder.id}} + assert_response :success + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{@funder_template.id}\");"), @response.body + end + + # ---------------------------------------------------------- + test 'plan gets funder template when org has no customization' do + sign_in @researcher + + post plans_path(format: :js), {plan: {org_id: @org.id, funder_id: @funder.id}} + assert_response :success + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{@funder_template.id}\");"), @response.body + end + + # ---------------------------------------------------------- + test 'plan gets customized version of funder template' do + customization = Template.create(title: 'Customization', org: @org) + # Template can't be published on creation so do it afterward + customization.published = true + customization.customization_of = @funder_template.dmptemplate_id + customization.save + + sign_in @researcher + + post plans_path(format: :js), {plan: {org_id: @org.id, funder_id: @funder.id}} + assert_response :success + assert @response.body.include?("$(\"#plan_template_id\").val(\"#{customization.id}\");"), @response.body + end + + # ---------------------------------------------------------- + test 'list of templates is returned when the funder has multiples' do + funder_template2 = Template.create(title: 'Funder template 2', org: @funder) + # Template can't be published on creation so do it afterward + funder_template2.published = true + funder_template2.save + + sign_in @researcher + + post plans_path(format: :js), {plan: {org_id: @org.id, funder_id: @funder.id}} + assert_response :success + assert_select "option", 3, "expected a dropdown with 2 templates and a 'please select' option" + assert @response.body.include?("