diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 7de0789..313f84d 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -28,9 +28,6 @@ def admin_template @template = Template.find(params[:id]) authorize @template - if @template.published - # create a new template version - end end @@ -38,8 +35,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 +191,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 +233,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 %>