diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index ea3fc36..7ad732e 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -8,8 +8,7 @@ # GET /dmptemplates def admin_index authorize Template - #institutional templates - #@dmptemplates_own = Template.own_institutional_templates(current_user.org_id) + #institutional templates all_versions_own_templates = Template.where(org_id: current_user.org_id, customization_of: nil).order(:version) current_templates = {} all_versions_own_templates.each do |temp| @@ -17,34 +16,31 @@ current_templates[temp.dmptemplate_id] = temp end end - @dmptemplates_own = current_templates.values + @templates_own = current_templates.values #funders templates - @dmptemplates_funders = Template.funders_templates + @templates_funders = Template.funders_templates end # GET /dmptemplates/1 def admin_template - @dmptemplate = Dmptemplate.find(params[:id]) - authorize @dmptemplate - respond_to do |format| - format.html # show.html.erb - end + @template = Template.find(params[:id]) + authorize @template end # PUT /dmptemplates/1 def admin_update - @dmptemplate = Dmptemplate.find(params[:id]) + @dmptemplate = Dmptemplate.find(params[:id]) authorize @dmptemplate - @dmptemplate.description = params["template-desc"] - respond_to do |format| + @dmptemplate.description = params["template-desc"] + respond_to do |format| if @dmptemplate.update_attributes(params[:dmptemplate]) format.html { redirect_to admin_template_dmptemplate_path(params[:dmptemplate]), notice: I18n.t('org_admin.templates.updated_message') } else format.html { render action: "edit" } end - end + end end @@ -76,91 +72,91 @@ # DELETE /dmptemplates/1 def admin_destroy - @dmptemplate = Dmptemplate.find(params[:id]) + @dmptemplate = Dmptemplate.find(params[:id]) authorize @dmptemplate @dmptemplate.destroy respond_to do |format| format.html { redirect_to admin_index_dmptemplate_path } end - end + end - # PHASES + # PHASES - #show and edit a phase of the template - def admin_phase - @phase = Phase.find(params[:id]) + #show and edit a phase of the template + def admin_phase + @phase = Phase.find(params[:id]) authorize @phase.dmptemplate - if !params.has_key?(:version_id) then - @edit = 'false' - #check for the most recent published version, if none is available then return the most recent one - versions = @phase.versions.where('published = ?', true).order('updated_at DESC') - if versions.any?() then - @version = versions.first - else - @version = @phase.versions.order('updated_at DESC').first - end - # When the version_id is passed as an argument - else - @edit = params[:edit] - @version = Version.find(params[:version_id]) - end - #verify if there are any sections if not create one - @sections = @version.sections - if !@sections.any?() || @sections.count == 0 then - @section = @version.sections.build - @section.title = '' - @section.version_id = params[:version_id] - @section.number = 1 - @section.organisation_id = current_user.organisation.id - @section.published = true + if !params.has_key?(:version_id) then + @edit = 'false' + #check for the most recent published version, if none is available then return the most recent one + versions = @phase.versions.where('published = ?', true).order('updated_at DESC') + if versions.any?() then + @version = versions.first + else + @version = @phase.versions.order('updated_at DESC').first + end + # When the version_id is passed as an argument + else + @edit = params[:edit] + @version = Version.find(params[:version_id]) + end + #verify if there are any sections if not create one + @sections = @version.sections + if !@sections.any?() || @sections.count == 0 then + @section = @version.sections.build + @section.title = '' + @section.version_id = params[:version_id] + @section.number = 1 + @section.organisation_id = current_user.organisation.id + @section.published = true @section.save @new_sec = true - end - #verify if section_id has been passed, if so then open that section - if params.has_key?(:section_id) then - @open = true - @section_id = params[:section_id].to_i - end - if params.has_key?(:question_id) then - @question_id = params[:question_id].to_i - end - respond_to do |format| - format.html - end - end - - - #preview a phase - def admin_previewphase - @version = Version.find(params[:id]) - authorize @version.phase.dmptemplate - respond_to do |format| - format.html - end - end - - - #add a new phase to a template - def admin_addphase - @dmptemplate = Dmptemplate.find(params[:id]) - @phase = Phase.new - authorize @dmptemplate - if @dmptemplate.phases.count == 0 then - @phase.number = '1' - else - @phase.number = @dmptemplate.phases.count + 1 - end - respond_to do |format| + end + #verify if section_id has been passed, if so then open that section + if params.has_key?(:section_id) then + @open = true + @section_id = params[:section_id].to_i + end + if params.has_key?(:question_id) then + @question_id = params[:question_id].to_i + end + respond_to do |format| format.html end - end + end - #create a phase - def admin_createphase - @phase = Phase.new(params[:phase]) + #preview a phase + def admin_previewphase + @version = Version.find(params[:id]) + authorize @version.phase.dmptemplate + respond_to do |format| + format.html + end + end + + + #add a new phase to a template + def admin_addphase + @dmptemplate = Dmptemplate.find(params[:id]) + @phase = Phase.new + authorize @dmptemplate + if @dmptemplate.phases.count == 0 then + @phase.number = '1' + else + @phase.number = @dmptemplate.phases.count + 1 + end + respond_to do |format| + format.html + end + end + + + #create a phase + def admin_createphase + @phase = Phase.new(params[:phase]) authorize @phase.dmptemplate @phase.description = params["phase-desc"] @version = @phase.versions.build @@ -174,15 +170,15 @@ else format.html { render action: "admin_phase" } end - end + end end - #update a phase of a template - def admin_updatephase - @phase = Phase.find(params[:id]) + #update a phase of a template + def admin_updatephase + @phase = Phase.find(params[:id]) authorize @phase.dmptemplate - @phase.description = params["phase-desc"] + @phase.description = params["phase-desc"] respond_to do |format| if @phase.update_attributes(params[:phase]) format.html { redirect_to admin_phase_dmptemplate_path(@phase), notice: I18n.t('org_admin.templates.updated_message') } @@ -190,24 +186,24 @@ format.html { render action: "admin_phase" } end end - end + end - #delete a version, sections and questions - def admin_destroyphase - @phase = Phase.find(params[:phase_id]) + #delete a version, sections and questions + def admin_destroyphase + @phase = Phase.find(params[:phase_id]) authorize @phase.dmptemplate - @dmptemplate = @phase.dmptemplate + @dmptemplate = @phase.dmptemplate @phase.destroy respond_to do |format| format.html { redirect_to admin_template_dmptemplate_path(@dmptemplate), notice: I18n.t('org_admin.templates.destroyed_message') } end - end + end # VERSIONS - #update a version of a template - def admin_updateversion - @version = Version.find(params[:id]) + #update a version of a template + def admin_updateversion + @version = Version.find(params[:id]) authorize @version.phase.dmptemplate @version.description = params["version-desc"] @phase = @version.phase @@ -230,14 +226,14 @@ format.html { render action: "admin_phase" } end end - end + end - #clone a version of a template - def admin_cloneversion + #clone a version of a template + def admin_cloneversion @old_version = Version.find(params[:version_id]) authorize @old_version.phase.dmptemplate - @version = @old_version.amoeba_dup - @phase = @version.phase + @version = @old_version.amoeba_dup + @phase = @version.phase respond_to do |format| if @version.save format.html { redirect_to admin_phase_dmptemplate_path(@phase, :version_id => @version.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } @@ -245,23 +241,23 @@ format.html { render action: "admin_phase" } end end - end + end - #delete a version, sections and questions - def admin_destroyversion - @version = Version.find(params[:version_id]) + #delete a version, sections and questions + def admin_destroyversion + @version = Version.find(params[:version_id]) authorize @version.phase.dmptemplate - @phase = @version.phase + @phase = @version.phase @version.destroy respond_to do |format| format.html { redirect_to admin_phase_dmptemplate_path(@phase), notice: I18n.t('org_admin.templates.destroyed_message') } end - end + end # SECTIONS - #create a section - def admin_createsection + #create a section + def admin_createsection @section = Section.new(params[:section]) authorize @section.version.phase.dmptemplate @section.description = params["section-desc"] @@ -271,45 +267,45 @@ else format.html { render action: "admin_phase" } end - end + end end - #update a section of a template - def admin_updatesection - @section = Section.find(params[:id]) + #update a section of a template + def admin_updatesection + @section = Section.find(params[:id]) authorize @section.version.phase.dmptemplate - @section.description = params["section-desc-#{params[:id]}"] - @version = @section.version - @phase = @version.phase - respond_to do |format| + @section.description = params["section-desc-#{params[:id]}"] + @version = @section.version + @phase = @version.phase + respond_to do |format| if @section.update_attributes(params[:section]) format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id , :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } else format.html { render action: "admin_phase" } end end - end + end - #delete a section and questions - def admin_destroysection - @section = Section.find(params[:section_id]) + #delete a section and questions + def admin_destroysection + @section = Section.find(params[:section_id]) authorize @section.version.phase.dmptemplate - @version = @section.version - @phase = @version.phase + @version = @section.version + @phase = @version.phase @section.destroy respond_to do |format| format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :edit => 'true' ), notice: I18n.t('org_admin.templates.destroyed_message') } end - end + end # QUESTIONS - #create a question - def admin_createquestion - @question = Question.new(params[:question]) + #create a question + def admin_createquestion + @question = Question.new(params[:question]) authorize @question.section.version.phase.dmptemplate @question.guidance = params["new-question-guidance"] @question.default_value = params["new-question-default-value"] @@ -319,44 +315,44 @@ else format.html { render action: "admin_phase" } end - end - end + end + end - #update a question of a template - def admin_updatequestion - @question = Question.find(params[:id]) + #update a question of a template + def admin_updatequestion + @question = Question.find(params[:id]) authorize @question.section.version.phase.dmptemplate - @question.guidance = params["question-guidance-#{params[:id]}"] - @question.default_value = params["question-default-value-#{params[:id]}"] - @section = @question.section - @version = @section.version - @phase = @version.phase - respond_to do |format| + @question.guidance = params["question-guidance-#{params[:id]}"] + @question.default_value = params["question-default-value-#{params[:id]}"] + @section = @question.section + @version = @section.version + @phase = @version.phase + respond_to do |format| if @question.update_attributes(params[:question]) format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } else format.html { render action: "admin_phase" } end end - end + end - #delete a version, sections and questions - def admin_destroyquestion - @question = Question.find(params[:question_id]) + #delete a version, sections and questions + def admin_destroyquestion + @question = Question.find(params[:question_id]) authorize @question.section.version.phase.dmptemplate - @section = @question.section - @version = @section.version - @phase = @version.phase + @section = @question.section + @version = @section.version + @phase = @version.phase @question.destroy respond_to do |format| format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } end - end + end - #SUGGESTED ANSWERS - #create suggested answers - def admin_createsuggestedanswer + #SUGGESTED ANSWERS + #create suggested answers + def admin_createsuggestedanswer @suggested_answer = SuggestedAnswer.new(params[:suggested_answer]) authorize @suggested_answer.question.section.version.phase.dmptemplate respond_to do |format| @@ -369,42 +365,42 @@ end - #update a suggested answer of a template - def admin_updatesuggestedanswer - @suggested_answer = SuggestedAnswer.find(params[:id]) + #update a suggested answer of a template + def admin_updatesuggestedanswer + @suggested_answer = SuggestedAnswer.find(params[:id]) authorize @suggested_answer.question.section.version.phase.dmptemplate @question = @suggested_answer.question @section = @question.section @version = @section.version @phase = @version.phase - respond_to do |format| + respond_to do |format| if @suggested_answer.update_attributes(params[:suggested_answer]) format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } else format.html { render action: "admin_phase" } end end - end + end - #delete a suggested answer - def admin_destroysuggestedanswer - @suggested_answer = SuggestedAnswer.find(params[:suggested_answer]) + #delete a suggested answer + def admin_destroysuggestedanswer + @suggested_answer = SuggestedAnswer.find(params[:suggested_answer]) authorize @suggested_answer.question.section.version.phase.dmptemplate - @question = @suggested_answer.question - @section = @question.section - @version = @section.version - @phase = @version.phase + @question = @suggested_answer.question + @section = @question.section + @version = @section.version + @phase = @version.phase @suggested_answer.destroy respond_to do |format| format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } end - end + end # GUIDANCES - #create a guidance - def admin_createguidance + #create a guidance + def admin_createguidance @question = Question.find(params[:question][:id]) authorize @question.section.version.phase.dmptemplate @guidance = Guidance.new(params[:guidance]) @@ -417,19 +413,19 @@ else format.html { render action: "admin_phase" } end - end - end + end + end - #update a guidance of a template - def admin_updateguidance - @question = Question.find(params[:id]) + #update a guidance of a template + def admin_updateguidance + @question = Question.find(params[:id]) authorize @question.section.version.phase.dmptemplate - @question.guidance = params["question-guidance-#{params[:id]}"] - @question.default_value = params["question-default-value-#{params[:id]}"] - @section = @question.section - @version = @section.version - @phase = @version.phase - respond_to do |format| + @question.guidance = params["question-guidance-#{params[:id]}"] + @question.default_value = params["question-default-value-#{params[:id]}"] + @section = @question.section + @version = @section.version + @phase = @version.phase + respond_to do |format| if @question.update_attributes(params[:question]) format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } else @@ -438,18 +434,18 @@ end end - #delete a version, sections and guidance - def admin_destroyguidance - @question = Question.find(params[:question_id]) + #delete a version, sections and guidance + def admin_destroyguidance + @question = Question.find(params[:question_id]) authorize @question.section.version.phase.dmptemplate - @section = @question.section - @version = @section.version - @phase = @version.phase + @section = @question.section + @version = @section.version + @phase = @version.phase @question.destroy respond_to do |format| format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } end - end + end end \ No newline at end of file diff --git a/app/views/templates/_admin_nav_tabs.html.erb b/app/views/templates/_admin_nav_tabs.html.erb index 49c3c20..a4b8ad8 100644 --- a/app/views/templates/_admin_nav_tabs.html.erb +++ b/app/views/templates/_admin_nav_tabs.html.erb @@ -1,34 +1,32 @@
- + + \ No newline at end of file diff --git a/app/views/templates/_edit_template.html.erb b/app/views/templates/_edit_template.html.erb index dbea10a..051d4b4 100644 --- a/app/views/templates/_edit_template.html.erb +++ b/app/views/templates/_edit_template.html.erb @@ -1,52 +1,52 @@ -<%= form_for(dmptemplate, :url => admin_update_dmptemplate_path(dmptemplate), :html => { :method => :put}) do |f| %> -| <%= t('org_admin.templates.title_label') %> | -<%= f.text_field :title, :as => :string, - :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.title_help_text') %> | -
| <%= t('org_admin.templates.desc_label') %> | -
- <%= text_area_tag("template-desc", dmptemplate.description, class: "tinymce") %>
-
-
- <%= link_to( image_tag('help_button.png'), '#', :class => 'template_desc_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.desc_help_text_html'))%>
-
- |
-
| <%= t('org_admin.templates.published_label') %> | -<%if dmptemplate.published? || dmptemplate.has_published_versions? then%> - <%= f.check_box :published, :as => :check_boxes %> - <%else%> - <%= t('org_admin.templates.cannot_publish')%> - <%end%> - | -
| <%= t('org_admin.templates.created') %> | -- <%= l dmptemplate.created_at.to_date, :formats => :short %> - | -
| <%= t('org_admin.templates.last_updated') %> | -- <%= l dmptemplate.updated_at.to_date, :formats => :short %> - | -
| <%= t('org_admin.templates.title_label') %> | +<%= f.text_field :title, as: :string, + class: 'text_field has-tooltip', 'data-toggle' => "tooltip", title: t('org_admin.templates.title_help_text') %> | +
| <%= t('org_admin.templates.desc_label') %> | +
+ <%= text_area_tag("template-desc", template.description, class: "tinymce") %>
+
+
+ <%= link_to( image_tag('help_button.png'), '#', class: 'template_desc_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.desc_help_text_html'))%>
+
+ |
+
| <%= t('org_admin.templates.published_label') %> | +<%if template.published? || template.has_published_versions? then%> + <%= f.check_box :published, as: :check_boxes %> + <%else%> + <%= t('org_admin.templates.cannot_publish')%> + <%end%> + | +
| <%= t('org_admin.templates.created') %> | ++ <%= l template.created_at.to_date, formats: :short %> + | +
| <%= t('org_admin.templates.last_updated') %> | ++ <%= l template.updated_at.to_date, formats: :short %> + | +
<%= raw phase.description %>
+<%= raw phase.description %>
| <%= t('helpers.sections_label')%> | -<%= t('helpers.questions_label')%> | -
|---|---|
|
- <%= section.title %> - |
-
- <% if section.questions.any? %>
- <% questions = section.questions.order("number ASC") %>
-
|
-
| <%= t('helpers.sections_label')%> | +<%= t('helpers.questions_label')%> | +
|---|---|
|
+ <%= section.title %> + |
+
+ <% if section.questions.any? %>
+ <% questions = section.questions.order("number ASC") %>
+
|
+
| <%= t('org_admin.templates.title_label') %> | -<%= dmptemplate.title %> | -
| <%= t('org_admin.templates.desc_label') %> | -<% if !dmptemplate.description.nil? && dmptemplate.description != "" then %> - <%= raw dmptemplate.description %> - <%else%> - - - <%end%> - | -
| <%= t('org_admin.templates.published_label') %> | -<%if dmptemplate.published || dmptemplate.has_published_versions? then%> - <%= dmptemplate.published %> - <%else%> - <%= t('org_admin.templates.cannot_publish')%> - <%end%> - | -
| <%= t('org_admin.templates.created') %> | -<%= l dmptemplate.created_at.to_date, :formats => :short %> | -
| <%= t('org_admin.templates.last_updated') %> | -<%= l dmptemplate.updated_at.to_date, :formats => :short %> | -
| <%= t('org_admin.templates.title_label') %> | +<%= template.title %> | +
| <%= t('org_admin.templates.desc_label') %> | +<% if !template.description.nil? && template.description != "" then %> + <%= raw template.description %> + <% else %> + - + <% end %> + | +
| <%= t('org_admin.templates.published_label') %> | +<% if template.published || template.has_published_versions? then%> + <%= template.published %> + <% else %> + <%= t('org_admin.templates.cannot_publish')%> + <% end %> + | +
| <%= t('org_admin.templates.created') %> | +<%= l template.created_at.to_date, formats: :short %> | +
| <%= t('org_admin.templates.last_updated') %> | +<%= l template.updated_at.to_date, formats: :short %> | +
| @@ -53,7 +53,7 @@ <% last_temp_updated = phase.updated_at %> <% end %> <% end %> - <%= l last_temp_updated.to_date, :formats => :short %> + <%= l last_temp_updated.to_date, formats: :short %> | <%if current_user.can_org_admin? then%> @@ -61,7 +61,7 @@ <%else%> <% b_label = t('helpers.view')%> <%end%> - <%= link_to b_label, admin_template_template_path(org_template), :class => "dmp_table_link"%> + <%= link_to b_label, admin_template_template_path(org_template), class: "dmp_table_link"%> |
| @@ -112,7 +112,7 @@ | <% last_updated = org_template.updated_at %> - <%= l last_updated.to_date, :formats => :short %> + <%= l last_updated.to_date, formats: :short %> | @@ -129,7 +129,7 @@ <%else%> <% b_label = t("helpers.view")%> <%end%> - <%= link_to b_label, admin_template_template_path(org_template), :class => "dmp_table_link"%> + <%= link_to b_label, admin_template_template_path(org_template), class: "dmp_table_link"%> |