diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb
index 7de0789..c19acc6 100644
--- a/app/controllers/templates_controller.rb
+++ b/app/controllers/templates_controller.rb
@@ -19,8 +19,25 @@
end
end
@templates_own = current_templates.values
- #funders templates
- @templates_funders = []#Org.funders.collect{|o| o.templates } #Template.funders_templates
+
+ # funders templates
+ funders_templates = {}
+ Org.includes(:templates).funder.each do |org|
+ org.templates.where(customization_of: nil, published: true).order(version: :desc).each do |temp|
+ if funders_templates[temp.dmptemplate_id].nil?
+ funders_templates[temp.dmptemplate_id] = temp
+ end
+ end
+ end
+
+ @templates_funders = funders_templates.values
+ # are any funder templates customized
+ @templates_customizations = {}
+ Template.where(org_id: current_user.org_id, customization_of: funders_templates.keys).order(version: :desc).each do |temp|
+ if @templates_customizations[temp.dmptemplate_id].nil?
+ @templates_customizations[temp.dmptemplate_id] = temp
+ end
+ end
end
@@ -28,9 +45,6 @@
def admin_template
@template = Template.find(params[:id])
authorize @template
- if @template.published
- # create a new template version
- end
end
@@ -38,8 +52,22 @@
def admin_update
@template = Template.find(params[:id])
authorize @template
+ if @template.published?
+ # published templates cannot be edited
+ redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.read_only')
+ end
@template.description = params["template-desc"]
if @template.update_attributes(params[:template])
+ if @template.published
+ # create a new template version
+ new_version = Template.deep_copy(@template)
+ new_version.version = @template.version + 1
+ new_version.save!
+ # if the organisation is a funder
+ if @template.org.funder?
+ # do something about all the customizations
+ end
+ end
redirect_to admin_index_template_path(), notice: I18n.t('org_admin.templates.updated_message')
else
render action: "edit"
@@ -180,6 +208,7 @@
@section = Section.new(params[:section])
authorize @section.phase.template
@section.description = params["section-desc"]
+ @section.modifiable = true
if @section.save
redirect_to admin_phase_template_path(id: @section.phase_id,
:section_id => @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message')
@@ -221,7 +250,7 @@
authorize @question.section.phase.template
@question.guidance = params["new-question-guidance"]
@question.default_value = params["new-question-default-value"]
- if @question.save
+ if @question.save!
redirect_to admin_phase_template_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message')
else
render action: "admin_phase"
diff --git a/app/models/section.rb b/app/models/section.rb
index 710e8c7..87e98b6 100644
--- a/app/models/section.rb
+++ b/app/models/section.rb
@@ -10,12 +10,12 @@
accepts_nested_attributes_for :questions, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true
# accepts_nested_attributes_for :version
- attr_accessible :organisation_id, :description, :number, :title, :published,
+ attr_accessible :phase_id, :description, :number, :title, :published,
:questions_attributes, :organisation, :phase, :modifiable,
:as => [:default, :admin]
-
+
validates :phase, :title, :number, presence: true
-
+
##
# return the title of the section
#
diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb
index 8f427c6..91ce3aa 100644
--- a/app/models/suggested_answer.rb
+++ b/app/models/suggested_answer.rb
@@ -12,7 +12,7 @@
:org, :question, :as => [:default, :admin]
- validates :question, :org, :text, presence: true
+ validates :question, :org, presence: true
# EVALUATE CLASS AND INSTANCE METHODS BELOW
#
diff --git a/app/views/templates/_show_section.html.erb b/app/views/templates/_show_section.html.erb
index 128728e..1c652ad 100644
--- a/app/views/templates/_show_section.html.erb
+++ b/app/views/templates/_show_section.html.erb
@@ -23,17 +23,20 @@
<%= raw section.description %>
- <% last_question_id = section.questions.order("number DESC").first.id %>
- <% section.questions.order("number").each do |question| %>
-
-
- <%= render partial: 'show_question', locals: {question: question}%>
-
+ <% section_questions = section.questions.order("number") %>
+ <% if section_questions.present? %>
+ <% last_question_id = section_questions.last.id %>
+ <% section_questions.each do |question| %>
+
+
+ <%= render partial: 'show_question', locals: {question: question}%>
+
- <% if last_question_id == question.id %>
-
- <% else %>
-
+ <% if last_question_id == question.id %>
+
+ <% else %>
+
+ <% end %>
<% end %>
<% end %>
diff --git a/app/views/templates/admin_index.html.erb b/app/views/templates/admin_index.html.erb
index 027aa65..81d0a82 100644
--- a/app/views/templates/admin_index.html.erb
+++ b/app/views/templates/admin_index.html.erb
@@ -46,16 +46,16 @@
<% #Yes if published version exists, Yes[Unpublished changes] if newer version modified, No otherwise%>
<% if org_template.published %>
- <%= "Yes" %>
+ <%= t("helpers.yes_label") %>
<% elsif org_template.version > 0 && Template.where(dmptemplate_id: org_template.dmptemplate_id, published: true).present? %>
<% #there is a published version, but this version is not %>
<% if org_template.created_at < org_template.updated_at %>
- <%= "Yes [Unpublished Changes]" %>
+ <%= t("org_admin.templates.unpublished_changes") %>
<% else %>
- <%= "Yes" %>
+ <%= t("helpers.yes_label") %>
<% end %>
<% else %>
- <%= "No" %>
+ <%= t("helpers.no_label") %>
<% end %>
|
@@ -84,66 +84,69 @@
<% if !current_user.org.funder? then %>
-
- <%= t("org_admin.templates.funders_temp") %>
-
+
+ <%= t("org_admin.templates.funders_temp") %>
+
-
- <% if @templates_funders.length > 0 then %>
-
-
-
-
- | <%= t('org_admin.templates.title_label') %> |
- <%= t('org_admin.templates.desc_label') %> |
- <%= t('org_admin.templates.published_label') %> |
- <%= t('org_admin.templates.last_updated') %> |
- <%= t('org_admin.templates.actions') %> |
-
-
-
-
- <% @templates_funders.each do |org_template| %>
- <% if org_template.published ||org_template.has_customisations?(current_user.organisation_id, org_template) then %>
-
- |
- <%= org_template.title%>
- |
-
- <%= raw org_template.description.truncate(90, omission: t('helpers.truncate_continued')) %>
- |
-
- <%if org_template.published? then %>
- <%= org_template.published%>
- <%else%>
- <%= t("helpers.false_lowercase")%>
- <%end%>
- |
-
- <% last_updated = org_template.updated_at %>
- <%= l last_updated.to_date, formats: :short %>
-
- |
-
- <%if current_user.can_org_admin? then%>
- <% if org_template.org.org_type == constant("organisation_types.funder") then %>
- <%if org_template.has_customisations?(current_user.org_id, org_template) then%>
- <% b_label = t("org_admin.templates.edit_customisation")%>
- <%else%>
- <% b_label = t("org_admin.templates.customise")%>
- <%end%>
- <%else%>
- <% b_label = t("helpers.submit.edit")%>
- <%end%>
- <%else%>
- <% b_label = t("helpers.view")%>
- <%end%>
- <%= link_to b_label, admin_template_template_path(org_template), class: "dmp_table_link"%>
- |
-
- <%end%>
- <%end%>
-
-
- <%end%>
-<%end%>
+
+ <% if @templates_funders.length > 0 then %>
+
+
+
+ | <%= t('org_admin.templates.title_label') %> |
+ <%= t('org_admin.templates.desc_label') %> |
+ <%= t('org_admin.templates.customise_label') %> |
+ <%= t('org_admin.templates.last_updated') %> |
+ <%= t('org_admin.templates.actions') %> |
+
+
+
+ <% @templates_funders.each do |org_template| %>
+
+ |
+ <%= org_template.title%>
+ |
+
+ <%= raw org_template.description.truncate(90, omission: t('helpers.truncate_continued')) %>
+ |
+
+ <% customized = 0 %>
+ <% template = org_template %>
+ <% if @templates_customizations[org_template.dmptemplate_id].present? %>
+ <% if @templates_customizations[org_template.dmptemplate_id].updated_at < org_template.updated_at %>
+ <%= t("org_admin.templates.original_changed") %>
+ <% customized = 3 %>
+ <% else %>
+ <% template = @templates_customizations[org_template.dmptemplate_id] %>
+ <% if !@templates_customizations[org_template.dmptemplate_id].published %>
+ <%= t("org_admin.templates.unpublished_changes") %>
+ <% customized = 2 %>
+ <% else %>
+ <%= t("helpers.yes_label") %>
+ <% customized = 1 %>
+ <% end %>
+ <% end %>
+ <% else %>
+ <%= t("helpers.no_label") %>
+ <% end %>
+ |
+
+ <% last_updated = org_template.updated_at %>
+ <%= l last_updated.to_date, formats: :short %>
+ |
+
+ <% if customized == 0 %>
+ <% b_label = t("org_admin.templates.customise") %>
+ <% elsif customized == 1 || customized == 2 %>
+ <% b_label = t("org_admin.templates.edit_customisation") %>
+ <% elsif customized == 3 %>
+ <% b_label = t("org_admin.templates.update_customisation") %>
+ <% end %>
+ <%= link_to b_label, admin_template_template_path(org_template), class: "dmp_table_link" %>
+ |
+
+ <% end %>
+
+
+ <% end %>
+<% end %>
diff --git a/app/views/templates/admin_phase.html.erb b/app/views/templates/admin_phase.html.erb
index 575e86a..d267086 100644
--- a/app/views/templates/admin_phase.html.erb
+++ b/app/views/templates/admin_phase.html.erb
@@ -63,7 +63,7 @@
<%end%>
diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml
index a99a922..7c2a3c3 100644
--- a/config/locales/en-UK.yml
+++ b/config/locales/en-UK.yml
@@ -277,11 +277,17 @@
desc_label: "Description"
actions: "Actions"
customise: "Customise"
+ customise_label: "Customised"
edit_customisation: "Edit customisation"
+ update_customisation: "Update Customisation"
created_message: "Information was successfully created."
updated_message: "Information was successfully updated."
destroyed_message: "Information was successfully deleted."
+ read_only: "Published templates cannot be edited."
section_delete_message: "You are about to delete '%{section_title}'. This will affect questions linked to this section. Are you sure?"
+ unpublished_changes: "Yes [Unpublished Changes]"
+ original_changed: "Yes [Original Template Has Changed]"
+
versions:
clone_versions_label: "Make big changes"
edit_versions_label: "Make small changes"
|