<%= _('Create a new plan') %>
+ <% if @is_test %> +<%= _("Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs.") %>
@@ -88,7 +95,7 @@diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 44ce2ea..e44ec67 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -39,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]) @@ -160,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 @@ -404,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 3b9b21b..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,16 +17,20 @@ 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 @@ -104,12 +38,12 @@ # display the visibility of the plan def display_visibility(val) case val - when 0 - return 'My Org.' - when 1 - return 'Public' + when 'organisationally_visible' + return _('My Inst.') + when 'publicly_visible' + return _('Public') else - return 'Private' # Both Test and Private + return _('Private') # Both Test and Private 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' %> +
| <%= _('Plan') %> | -<%= _('Template') %> | -<%= _('Edited') %> | -<%= _('Role') %> | -<%= _('Visibility') %> | -<%= _('Test') %> | -<%= _('Select an Action') %> | +<%= _('Template') %> | +<%= _('Edited') %> | +<%= _('Role') %> | +<%= _('Visibility') %> | +<%= _('Test') %> | +<%= _('Select an Action') %> | <% @plans.each do |plan| %>
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| <%= plan.title %> | -<%= plan.template.title %> | -<%= l(plan.latest_update.to_date, formats: :short) %> | -<%= display_role(plan.roles.find_by(user: current_user)) %> | -<%= display_visibility(plan.visibility) %> | -- /> + | <%= plan.template.title %> | +<%= l(plan.latest_update.to_date, formats: :short) %> | +<%= display_role(plan.roles.find_by(user: current_user)) %> | +<%= display_visibility(plan.visibility) %> | ++ <%= plan.administerable_by?(current_user.id) ? '' : 'disabled="true"' %> /> | -+ |
<% if plan.editable_by?(current_user.id) then %>
<%= link_to _('Edit'), plan_path(plan), :class => "dmp_table_link"%>
diff --git a/app/views/plans/new.html.erb b/app/views/plans/new.html.erb
index 08d44a8..ba02a8f 100644
--- a/app/views/plans/new.html.erb
+++ b/app/views/plans/new.html.erb
@@ -1,8 +1,15 @@
-<% javascript "plans/new_plan.js" %>
+<% javascript "plans/new.js" %>
<%= _('Create a new plan') %>+ <% if @is_test %> +
+
+ <%= _('This is a') %> <%= _('test plan') %>.
+
+ <% end %>
+
<%= _("Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs.") %> @@ -88,7 +95,7 @@ |