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" %>
+
- <%= 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]} %>
- <%= 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.') %>
-
- <%= 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.') %>
-
- 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.
")} %>
-
-
-
+
+
">
-
<%= _('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.')%>
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.") %>
+
+
+
+
+ <%= 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 %>
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.
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.