diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 59f7f1c..31aebae 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -22,6 +22,7 @@ @templates_funders = Template.funders_templates end + # GET /dmptemplates/1 def admin_template @template = Template.find(params[:id]) @@ -29,7 +30,6 @@ end - # PUT /dmptemplates/1 def admin_update @template = Template.find(params[:id]) @@ -48,6 +48,7 @@ authorize Template end + # POST /dmptemplates def admin_create @template = Template.new(params[:template]) @@ -62,13 +63,12 @@ end - # DELETE /dmptemplates/1 def admin_destroy @template = Template.find(params[:id]) authorize @template @template.destroy - redirect_to admin_index_dmptemplate_path + redirect_to admin_index_template_path end @@ -78,32 +78,19 @@ #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 + authorize @phase.template + @edit = params[:edit] == "true" ? true : false + #verify if there are any sections if not create one + @sections = @phase.sections if !@sections.any?() || @sections.count == 0 then - @section = @version.sections.build + @section = @phase.sections.build + @section.phase = @phase @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 + @section.modifiable = 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 @@ -113,9 +100,6 @@ if params.has_key?(:question_id) then @question_id = params[:question_id].to_i end - respond_to do |format| - format.html - end end @@ -123,9 +107,6 @@ def admin_previewphase @version = Version.find(params[:id]) authorize @version.phase.dmptemplate - respond_to do |format| - format.html - end end @@ -141,19 +122,13 @@ #create a phase def admin_createphase @phase = Phase.new(params[:phase]) - authorize @phase.dmptemplate + authorize @phase.template @phase.description = params["phase-desc"] - @version = @phase.versions.build - @version.title = "#{@phase.title} v.1" - @version.phase_id = @phase.id - @version.number = 1 - @version.published = false - respond_to do |format| - if @phase.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end + @phase.modifiable = true + if @phase.save + redirect_to admin_phase_template_path(id: @phase.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + else + render action: "admin_phase" end end @@ -161,7 +136,7 @@ #update a phase of a template def admin_updatephase @phase = Phase.find(params[:id]) - authorize @phase.dmptemplate + authorize @phase.template @phase.description = params["phase-desc"] respond_to do |format| if @phase.update_attributes(params[:phase]) @@ -175,70 +150,12 @@ #delete a version, sections and questions def admin_destroyphase @phase = Phase.find(params[:phase_id]) - authorize @phase.dmptemplate - @dmptemplate = @phase.dmptemplate + authorize @phase.template + @template = @phase.template @phase.destroy - respond_to do |format| - format.html { redirect_to admin_template_dmptemplate_path(@dmptemplate), notice: I18n.t('org_admin.templates.destroyed_message') } - end + redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.destroyed_message') end -# VERSIONS - - #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 - if @version.published && !@phase.dmptemplate.published then - @phase.dmptemplate.published = true - end - if @version.published == true then - @all_versions = @phase.versions.where('published = ?', true) - @all_versions.each do |v| - if v.id != @version.id && v.published == true then - v.published = false - v.save - end - end - end - respond_to do |format| - if @version.update_attributes(params[:version]) - format.html { redirect_to admin_phase_dmptemplate_path(@phase, :version_id => @version.id, :edit => 'false'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #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 - 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') } - else - format.html { render action: "admin_phase" } - end - end - end - - #delete a version, sections and questions - def admin_destroyversion - @version = Version.find(params[:version_id]) - authorize @version.phase.dmptemplate - @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 - - # SECTIONS #create a section def admin_createsection @@ -247,7 +164,7 @@ @section.description = params["section-desc"] respond_to do |format| if @section.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @section.version.phase_id, :version_id => @section.version_id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } + format.html { redirect_to admin_phase_template_path(:id => @section.version.phase_id, :version_id => @section.version_id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } else format.html { render action: "admin_phase" } end @@ -258,16 +175,13 @@ #update a section of a template def admin_updatesection @section = Section.find(params[:id]) - authorize @section.version.phase.dmptemplate + authorize @section.phase.template @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 + @phase = @section.phase + if @section.update_attributes(params[:section]) + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id , edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end end @@ -275,13 +189,10 @@ #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 + authorize @section.phase.template + @phase = @section.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 + redirect_to admin_phase_template_path(id: @phase.id, edit: 'true' ), notice: I18n.t('org_admin.templates.destroyed_message') end @@ -290,15 +201,13 @@ #create a question def admin_createquestion @question = Question.new(params[:question]) - authorize @question.section.version.phase.dmptemplate + authorize @question.section.phase.template @question.guidance = params["new-question-guidance"] @question.default_value = params["new-question-default-value"] - respond_to do |format| - if @question.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @question.section.version.phase_id, :version_id => @question.section.version_id, :section_id => @question.section_id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end + if @question.save + redirect_to admin_phase_template_path(id: @question.section.version.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" end end diff --git a/app/views/templates/_add_question.html.erb b/app/views/templates/_add_question.html.erb index 1caf54c..62232bd 100644 --- a/app/views/templates/_add_question.html.erb +++ b/app/views/templates/_add_question.html.erb @@ -1,179 +1,182 @@ - <% @new_question = Question.new %> <% @new_question.number = section.questions.count + 1 %> - -<%= form_for @new_question, :url => {:action => "admin_createquestion"}, :html => {:id => "new_question_#{section.id}"} do |f| %> -<%= f.hidden_field :section_id, :value => section.id %> -
| <%= t("org_admin.questions.question_number_label")%> | -<%= f.number_field :number, :in => 1..50, :class => "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> - - - | -
| <%= t("org_admin.questions.question_text_label")%> | -<%= f.text_area :text, :rows => "5", :id => "new_question_text_#{section.id}" %> - - | -
| <%= t("org_admin.questions.answer_format_label")%> | -<%= f.hidden_field :section_id, :value => section.id, :class => "section_id" %>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <%= f.select :question_format_id,
- options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, QuestionFormat.find_by_title(t("helpers.text_area")).id),
- {}, :id => "new-select-format-#{section.id}"%>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_format_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%>
-
-
- |
-
| <%= t("org_admin.questions.suggested_or_example_answer_label")%> | -
- <% suggested_answer = @new_question.suggested_answers.build %>
- <%= f.fields_for :suggested_answers, suggested_answer do |s|%>
- <%= s.hidden_field :organisation_id, :value => current_user.organisation.id %>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "suggested_answer_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.suggested_answer_help_text_html"))%>
-
-
-
-
- |
-
| <%= t("org_admin.questions.guidance_label")%> | -
- <%= text_area_tag("new-question-guidance", "", class: "tinymce") %>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_guidance_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_guidance_help_text_html"))%>
-
-
-
- |
-
| <%= t("org_admin.questions.themes_label")%> | -
- <%= f.collection_select(:theme_ids,
- Theme.all.order("title"),
- :id, :title, {:prompt => false, :include_blank => t('helpers.none')}, {:multiple => true})%>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_themes_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_themes_help_text_html"))%>
-
-
-
- |
-
| <%= t("org_admin.questions.question_number_label")%> | +<%= f.number_field :number, in: 1..50, class: "number_field has-tooltip", "data-toggle" => "tooltip", title: t("org_admin.questions.number_help_text") %> -<%end%> + + | +
| <%= t("org_admin.questions.question_text_label")%> | +<%= f.text_area :text, rows: "5", id: "new_question_text_#{section.id}" %> + + | +
| <%= t("org_admin.questions.answer_format_label")%> | +<%= f.hidden_field :section_id, value: section.id, class: "section_id" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <%= f.select :question_format_id,
+ options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, QuestionFormat.find_by_title(t("helpers.text_area")).id),
+ {}, id: "new-select-format-#{section.id}"%>
+
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "question_format_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%>
+
+
+ |
+
| <%= t("org_admin.questions.suggested_or_example_answer_label")%> | +
+
+ <% suggested_answer = @new_question.suggested_answers.build %>
+ <%= f.fields_for :suggested_answers, suggested_answer do |s|%>
+ <%= s.hidden_field :org_id, value: current_user.org_id %>
+
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "suggested_answer_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.suggested_answer_help_text_html"))%>
+
+
+
+
+ |
+
| <%= t("org_admin.questions.guidance_label")%> | +
+
+ <%= text_area_tag("new-question-guidance", "", class: "tinymce") %>
+
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "question_guidance_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_guidance_help_text_html"))%>
+
+
+
+ |
+
| <%= t("org_admin.questions.themes_label")%> | +
+
+ <%= f.collection_select(:theme_ids,
+ Theme.all.order("title"),
+ :id, :title, {prompt: false, include_blank: t('helpers.none')}, {multiple: true})%>
+
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "question_themes_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_themes_help_text_html"))%>
+
+
+
+ |
+
| <%= t("org_admin.templates.phase_order_label") %> | -- <%= f.number_field :number, :in => 1..15, :class => "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.templates.section_number_help_text") %> | -
| <%= t("org_admin.templates.desc_label") %> | -
-
- <%= text_area_tag("section-desc", "" , class: "tinymce") %>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "section_desc_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.templates.section_desc_help_text_html"))%>
-
- |
-
| <%= t("org_admin.templates.phase_order_label") %> | ++ <%= f.number_field :number, in: 1..15, class: "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.templates.section_number_help_text") %> | +
| <%= t("org_admin.templates.desc_label") %> | +
+
+ <%= text_area_tag("section-desc", "" , class: "tinymce") %>
+
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "section_desc_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.templates.section_desc_help_text_html"))%>
+
+ |
+
| <%= 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.phase_title_help_text') %> | -
| <%= t('org_admin.templates.phase_order_label') %> | -<%= f.number_field :number, :in => 0..5, :class => "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_number_help_text') %> | -
| <%= t('org_admin.templates.desc_label') %> | -
-
- <%= text_area_tag("phase-desc", phase.description, class: "tinymce") %>
-
-
- <%= link_to( image_tag('help_button.png'), '#', :class => 'phase_desc_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.phase_desc_help_text_html'))%>
-
- |
-
| <%= 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.phase_title_help_text') %> | +
| <%= t('org_admin.templates.phase_order_label') %> | +<%= f.number_field :number, in: 0..5, class: "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_number_help_text') %> | +
| <%= t('org_admin.templates.desc_label') %> | +
+
+ <%= text_area_tag("phase-desc", phase.description, class: "tinymce") %>
+
+
+ <%= link_to( image_tag('help_button.png'), '#', class: 'phase_desc_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.phase_desc_help_text_html'))%>
+
+ |
+
| <%= t('org_admin.templates.phase_order_label') %> | -<%= s.number_field :number, :in => 1..15, :class => "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.section_number_help_text') %> | -
| <%= t('org_admin.templates.desc_label') %> | -
-
- <%= text_area_tag("section-desc-#{section.id}", section.description , class: "tinymce") %>
-
-
- <%= link_to( image_tag('help_button.png'), '#', :class => 'section_desc_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.section_desc_help_text_html'))%>
-
- |
-
| <%= t('org_admin.templates.phase_order_label') %> | +<%= s.number_field :number, in: 1..15, class: "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.section_number_help_text') %> | +
| <%= t('org_admin.templates.desc_label') %> | +
+
+ <%= text_area_tag("section-desc-#{section.id}", section.description , class: "tinymce") %>
+
+
+ <%= link_to( image_tag('help_button.png'), '#', class: 'section_desc_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.section_desc_help_text_html'))%>
+
+ |
+