diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb
index c2140f7..e44ec67 100644
--- a/app/controllers/plans_controller.rb
+++ b/app/controllers/plans_controller.rb
@@ -24,6 +24,8 @@
# Get the current user's org
@default_org = current_user.org if @orgs.include?(current_user.org)
+ @is_test = params[:test] ||= false
+
respond_to :html
end
@@ -37,6 +39,9 @@
@plan.data_contact = current_user.email
@plan.funder_name = plan_params[:funder_name]
+ @plan_params.visibility = (plan_params[:visibility].blank? ? Rails.application.config.default_plan_visibility :
+ plan_params[:visibility])
+
# 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])
@@ -158,8 +163,11 @@
@plan = Plan.find(params[:id])
authorize @plan
+ attrs = plan_params
+ attrs['visibility'] = Rails.application.config.default_plan_visibility if plan_params['visibility'].blank?
+
respond_to do |format|
- if @plan.update_attributes(params[:plan])
+ if @plan.update_attributes(attrs)
format.html { redirect_to @plan, :editing => false, notice: _('Plan was successfully updated.') }
format.json { head :no_content }
else
@@ -402,11 +410,25 @@
end
end
end
+
+ # AJAX access to update the plan's visibility
+ # POST /plans/:id
+ def visibility
+ plan = Plan.find(params[:id])
+ authorize plan
+ plan.visibility = "#{plan_params[:visibility]}"
+ if plan.save
+ render json: {code: 1, msg: ''}
+ else
+ render json: {code: 0, msg: _("Unable to change the plan's Test status")}
+ end
+ end
+
private
def plan_params
- params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title)
+ params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title, :visibility)
end
# different versions of the same template have the same dmptemplate_id
diff --git a/app/helpers/plans_helper.rb b/app/helpers/plans_helper.rb
index bff80a5..d14421a 100644
--- a/app/helpers/plans_helper.rb
+++ b/app/helpers/plans_helper.rb
@@ -1,74 +1,4 @@
module PlansHelper
-
- # Build variable column headings for the project list
- # --------------------------------------------------------
- def plan_list_column_heading(column)
- if column.kind_of?(Array)
- heading = (column.first.kind_of?(String) ? column.first : _(' - '))
-
- elsif column.kind_of?(String)
- heading = column
-
- else
- heading = _(' - ')
- end
-
- klass = (['name', 'description'].include?(heading) ? :dmp_th_big : :dmp_th_small)
-
- content_tag(:th, t("helpers.project.columns.#{heading}"), class: klass) # parametrised YAML keys are no longer possible with gettext, TODO
- end
-
- # Populate a variable column for the project list
- # --------------------------------------------------------
- def plan_list_column_body(column, plan)
-
- col = (column.kind_of?(Array) ? column[0] : column)
-
- klass, content = case col
- when 'name'
- [ "dmp_td_big", link_to(plan.title, plan_path(plan), class: "dmp_table_link") ]
- when 'owner'
- user = plan.owner
- text = if user.nil?
- _(' - ')
- elsif user == current_user
- _('Me')
- else
- user.name
- end
-
- [ "tmp_td_small", text ]
- when 'shared'
- shared_num = plan.users.count - 1
- text = shared_num > 0 ? (_('Yes') + " (with #{shared_num} people) ") : _('No') # Hardcoded strings are not internationalised
- [ "dmp_td_small", text ]
- when 'visibility'
- text = if plan.visibility == 'organisationally_visible'
- _('Organisational')
- elsif plan.visibility == 'publicly_visible'
- _('Public')
- elsif plan.visibility == 'is_test'
- _('Test/Practice')
- elsif plan.visibility == 'privately_visible'
- _('Private')
- end
- ["dmp_td_small", text ]
- when 'last_edited'
- [ "dmp_td_small", l(plan.latest_update.to_date, formats: :short) ]
- when 'description'
- [ "dmp_td_medium", (plan.try(col) || _(' - ')) ]
- when 'non_link_name'
- [ "dmp_td_big", plan.title ]
- when 'template'
- ["dmp_td_big", plan.template.title]
- when 'organisation'
- ["dmp_td_medium", plan.template.org.name] # This will trigger 2 queries for each function call, i.e. one for templates and another for orgs tables
- else
- [ "dmp_td_small", (plan.try(col) || _(' - ')) ]
- end
- content_tag(:td, content, class: klass)
- end
-
# Shows whether the user has default, template-default or custom settings
# for the given plan.
# --------------------------------------------------------
@@ -87,18 +17,34 @@
content_tag(:small, t("helpers.settings.plans.#{key}"))
end
-
# display the role of the user for a given plan
def display_role(role)
- case role.access_level
- when 3
- access = 'Co-owner'
- when 2
- access = 'Editor'
- when 1
- access = 'Read only'
+ if role.creator?
+ access = _('Owner')
+
+ else
+ case role.access_level
+ when 3
+ access = _('Co-owner')
+ when 2
+ access = _('Editor')
+ when 1
+ access = _('Read only')
+ end
end
return access
end
+ # display the visibility of the plan
+ def display_visibility(val)
+ case val
+ when 'organisationally_visible'
+ return _('My Inst.')
+ when 'publicly_visible'
+ return _('Public')
+ else
+ return _('Private') # Both Test and Private
+ end
+ end
+
end
diff --git a/app/models/plan.rb b/app/models/plan.rb
index c13ffc0..b2691ff 100644
--- a/app/models/plan.rb
+++ b/app/models/plan.rb
@@ -1164,7 +1164,6 @@
# 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
diff --git a/app/policies/plan_policy.rb b/app/policies/plan_policy.rb
index 8d05ac8..e6d6d15 100644
--- a/app/policies/plan_policy.rb
+++ b/app/policies/plan_policy.rb
@@ -51,6 +51,10 @@
def duplicate?
@plan.editable_by?(@user.id)
end
+
+ def visibility?
+ @plan.administerable_by?(@user.id)
+ end
# TODO: These routes are no lonmger used
=begin
diff --git a/app/views/branding b/app/views/branding
new file mode 120000
index 0000000..dd1660a
--- /dev/null
+++ b/app/views/branding
@@ -0,0 +1 @@
+/Users/briley/Documents/workspace/dmptool_config/app/views/branding/
\ No newline at end of file
diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb
index ee420d1..64cd46f 100644
--- a/app/views/plans/_plan_details.html.erb
+++ b/app/views/plans/_plan_details.html.erb
@@ -1,3 +1,5 @@
+<% javascript 'plans/edit.js' %>
+
@@ -23,6 +25,20 @@
'title': _('If applying for funding, state the name exactly as in the grant proposal.') %>
+
+ />
+
+
+
+
+
+ /> <%= _('Public anyone can view') %>
+ /> <%= _('Limited: anyone in my institution can view') %>
+ /> <%= _('Private: restricted to me and people I invite') %>
+
+ <%= f.hidden_field :visibility %>
+
+
<%= 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.') %>
@@ -89,6 +105,28 @@
+ <%=
+ case @plan.visibility
+ when 'publicly_visible'
+ _('Public: anyone can view')
+ when 'organisationally_visible'
+ _('Limited: anyone in my institution can view')
+ when 'is_test'
+ _('Not applicable: this is a test plan')
+ else
+ _('Private: restricted to me and people I invite')
+ end
+ %>
+
+
+
+
<%= _('ID') %>
<% if !@plan.identifier.nil? && @plan.identifier != "" then %>
diff --git a/app/views/plans/_plan_list_head.html.erb b/app/views/plans/_plan_list_head.html.erb
deleted file mode 100644
index 6b05f86..0000000
--- a/app/views/plans/_plan_list_head.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-
- <% ['name', 'owner', 'shared', 'last_edited'].each do |column| %>
- <%= plan_list_column_heading(column) %>
- <% end %>
-
- <% ['name', 'owner', 'shared', 'last_edited'].each do |column| %>
- <%= plan_list_column_body(column, plan) %>
- <% end %>
-
- <% if plan.editable_by?(current_user.id) then %>
- <%= link_to _('Edit'), plan_path(plan), :class => "dmp_table_link"%>
-
- <% if plan.administerable_by?(current_user.id) then %>
- <%= link_to _('Share'), share_plan_path(plan), :class => "dmp_table_link"%>
- <% end %>
-
- <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%>
-
- <%= link_to _('Duplicate'), duplicate_plan_path(plan), method: :post, remote: true, :class => "dmp_table_link"%>
-
- <% if plan.owned_by?(current_user.id) then %>
- <%= link_to _('Delete'), plan_path(plan), :class => "dmp_table_link",
- :method => :delete, :data => {
- :confirm => _('Are you sure you wish to delete this plan? If the plan is being shared with other users, by deleting it from your list, the plan will be deleted from their plan list as well')
- }%>
- <% end %>
- <% else %>
- <%= link_to _('View'), plan_path(plan), :class => "dmp_table_link"%>
- <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%>
- <% end %>
-
-
+ <% if plan.editable_by?(current_user.id) then %>
+ <%= link_to _('Edit'), plan_path(plan), :class => "dmp_table_link"%>
+
+ <% if plan.administerable_by?(current_user.id) then %>
+ <%= link_to _('Share'), share_plan_path(plan), :class => "dmp_table_link"%>
+ <% end %>
+
+ <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%>
+
+ <%= link_to _('Duplicate'), duplicate_plan_path(plan), method: :post, remote: true, :class => "dmp_table_link"%>
+
+ <% if plan.owned_by?(current_user.id) then %>
+ <%= link_to _('Delete'), plan_path(plan), :class => "dmp_table_link",
+ :method => :delete, :data => {
+ :confirm => _('Are you sure you wish to delete this plan? If the plan is being shared with other users, by deleting it from your list, the plan will be deleted from their plan list as well')
+ }%>
+ <% end %>
+ <% else %>
+ <%= link_to _('View'), plan_path(plan), :class => "dmp_table_link"%>
+ <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%>
+ <% end %>
+