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 %> -
    -
  • <%= s.select :is_example, {t("org_admin.questions.example_answer_label") => true, t("org_admin.questions.suggested_answer_label") => false} %>
  • -
  • <%= s.text_area :text, :rows => 5 %>
  • -
- <%end%> -
-
- <%= 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"))%> -
- - -
-
- - -
- <%= hidden_field_tag :section_id, section.id, :class => "section_id" %> - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary new_question_save_button" %> - <%= hidden_field_tag :section_id, section.id, :class => "section_id_new" %> - <%= link_to t("helpers.submit.cancel"), '#', :class => "btn cancel cancel_add_new_question" %> -
-
+<%= 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") %> -<%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 %> +
    +
  • <%= s.select :is_example, {t("org_admin.questions.example_answer_label") => true, t("org_admin.questions.suggested_answer_label") => false} %>
  • +
  • <%= s.text_area :text, rows: 5 %>
  • +
+ <% end %> +
+
+ <%= 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"))%> +
+ + +
+
+ + +
+ <%= hidden_field_tag :section_id, section.id, class: "section_id" %> + <%= f.submit t("helpers.submit.save"), class: "btn btn-primary new_question_save_button" %> + <%= hidden_field_tag :section_id, section.id, class: "section_id_new" %> + <%= link_to t("helpers.submit.cancel"), '#', class: "btn cancel cancel_add_new_question" %> +
+
+ +<% end %> diff --git a/app/views/templates/_add_section.html.erb b/app/views/templates/_add_section.html.erb index b445c85..a6bfd97 100644 --- a/app/views/templates/_add_section.html.erb +++ b/app/views/templates/_add_section.html.erb @@ -1,54 +1,53 @@ <% @new_section = Section.new %> -<% @new_section.number = version.sections.count + 1 %> - +<% @new_section.number = phase.sections.count + 1 %> -<%= form_for @new_section, :url => {:action => "admin_createsection"} do |f| %> - <%= f.hidden_field :version_id, :value => version.id %> - <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> - -
-
-
-
- - <%= f.text_field :title, :as => :string, :class => "text_field", :placeholder => t("org_admin.templates.section_title_placeholder")%> -
- - -
- -
-
-
- - - - - - - - - -
<%= 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"))%> -
-
- -
- <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.cancel"), "#", :id => "", :class => "btn cancel" %> -
-
-
-
-
-<%end%> + +<%= form_for @new_section, url: {action: "admin_createsection"} do |f| %> + <%= f.hidden_field :phase_id, value: phase.id %> + +
+
+
+
+ + <%= f.text_field :title, as: :string, class: "text_field", placeholder: t("org_admin.templates.section_title_placeholder")%> +
+ + +
+ +
+
+
+ + + + + + + + + +
<%= 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"))%> +
+
+ +
+ <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <%= link_to t("helpers.submit.cancel"), "#", id: "", class: "btn cancel" %> +
+
+
+
+
+<%end%> diff --git a/app/views/templates/_edit_phase.html.erb b/app/views/templates/_edit_phase.html.erb index 1536a48..1aefe61 100644 --- a/app/views/templates/_edit_phase.html.erb +++ b/app/views/templates/_edit_phase.html.erb @@ -1,45 +1,45 @@ -<%= form_for(phase, :url => admin_updatephase_dmptemplate_path(phase), :html => { :method => :put}) do |f| %> - -

- <%= t('org_admin.templates.phase_details_label')%> -

-
- <%= raw t('org_admin.templates.phase_details_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'))%> -
-
-
- - -
- <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t('helpers.submit.cancel'), admin_phase_dmptemplate_path(phase), :class => 'btn cancel' %> -
- -<%end%> \ No newline at end of file +<%= form_for(phase, url: admin_updatephase_template_path(phase), html: { method: :put}) do |f| %> + +

+ <%= t('org_admin.templates.phase_details_label')%> +

+
+ <%= raw t('org_admin.templates.phase_details_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'))%> +
+
+
+ + +
+ <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t('helpers.submit.cancel'), admin_phase_template_path(phase), class: 'btn cancel' %> +
+ +<% end %> \ No newline at end of file diff --git a/app/views/templates/_edit_section.html.erb b/app/views/templates/_edit_section.html.erb index 8f7f8b4..0cf9752 100644 --- a/app/views/templates/_edit_section.html.erb +++ b/app/views/templates/_edit_section.html.erb @@ -1,116 +1,116 @@ - -<%= form_for(section, :url => admin_updatesection_dmptemplate_path(section, :phase => phase, :edit => edit), :html => { :method => :put}) do |s| %> - <%if @open && @section_id == section.id then%> - <% toggle = 'accordion-body section-collapse in collapse'%> - <%else%> - <% toggle = 'accordion-body collapse section-collapse' %> - <%end%> +<%= form_for(section, url: admin_updatesection_template_path(section, phase: phase, edit: edit), html: { method: :put}) do |s| %> + <% if @open && @section_id == section.id then%> + <% toggle = 'accordion-body section-collapse in collapse'%> + <% else %> + <% toggle = 'accordion-body collapse section-collapse' %> + <% end %> - <%if @new_sec then%> - <% toggle = 'accordion-body section-collapse in collapse'%> - <%end%> + <% if @new_sec %> + <% toggle = 'accordion-body section-collapse in collapse'%> + <% end %> -
-
-
-
- <%= s.text_field :title, :as => :string, :class => 'text_field', :placeholder => t('org_admin.templates.section_title_placeholder') %> +
+
+
+
+ <%= s.text_field :title, as: :string, class: 'text_field', placeholder: t('org_admin.templates.section_title_placeholder') %> -
-
- -
+
+
+ +
-
-
- - - - - - - - - -
<%= 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'))%> -
-
- -
- <%= s.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <% if !section.version.published? || phase.dmptemplate.org_type == constant("organisation_types.funder") then%> - <%= link_to t("helpers.submit.delete"), admin_destroysection_dmptemplate_path(:section_id => section.id), - :confirm => t("org_admin.templates.section_delete_message", :section_title => section.title ), :method => :delete, :class => "btn btn-primary"%> - <%end%> - <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn cancel' %> -
- <%end%> -
- <% @questions = section.questions.order("number")%> - <%if @questions.count > 0 %> - <% question_left = @questions.count %> - <% @questions.each do |question| %> -
-
"> - - <%= render :partial => 'show_question', locals: {question: question} %> -
+
+
+ + + + + + + + + +
<%= 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'))%> +
+
+ +
+ <%= s.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <% if section.modifiable then%> + <%= link_to t("helpers.submit.delete"), admin_destroysection_template_path(section_id: section.id), + confirm: t("org_admin.templates.section_delete_message", section_title: section.title ), method: :delete, class: "btn btn-primary"%> + <% end %> + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn cancel' %> +
+<% end %> +
+ <% @questions = section.questions.order("number")%> + <% if @questions.count > 0 %> + <% question_left = @questions.count %> + <% @questions.each do |question| %> +
+
"> + + <%= render partial: 'show_question', locals: {question: question} %> +
- -
- - <%if question_left.to_i > 1 then %> -
- <%else%> -
- <%end%> - <% question_left = question_left - 1 %> + +
+ + <% if question_left.to_i > 1 then %> +
+ <% else %> +
+ <% end %> + <% question_left = question_left - 1 %> - <%end%> - <%end%> + <% end %> + <% end %> - - <% if !section.version.published? || phase.dmptemplate.org_type == constant("organisation_types.funder") then%> + + <% if section.modifiable then%> - <%if @questions.count != 0 %> -
- <%end%> - - + <% if @questions.count != 0 %> +
+ <% end%> + + - -
-
- <%= hidden_field_tag :section_id, section.id, :class => "section_id" %> - <%= link_to t("org_admin.add_question_label"), '#', :class => "btn btn-primary add_question_button" %> -
-
- <%end%> + +
+
+ <%= hidden_field_tag :section_id, section.id, class: "section_id" %> + <%= link_to t("org_admin.add_question_label"), '#', class: "btn btn-primary add_question_button" %> +
+
+ <% end %> -
-
-
-
+
+
+
+
diff --git a/app/views/templates/_show_phase.html.erb b/app/views/templates/_show_phase.html.erb index 01117cf..c00c71e 100644 --- a/app/views/templates/_show_phase.html.erb +++ b/app/views/templates/_show_phase.html.erb @@ -4,18 +4,18 @@ <%= t('org_admin.templates.phase_details_label')%> - <% if @phase.dmptemplate.org_type != constant("organisation_types.funder") || current_user.org_type == constant("organisation_types.funder") then %> + <% if @phase.modifiable %>
- <%= link_to t("org_admin.templates.edit_phase_details_label"), '#', :class => "btn btn-primary", :id => "edit_phase_button"%> + <%= link_to t("org_admin.templates.edit_phase_details_label"), '#', class: "btn btn-primary", id: "edit_phase_button"%>
- <%end%> + <% end %> -<%if @phase.dmptemplate.org_type != constant("organisation_types.funder") then%> +<% if @phase.template.org.not_funder %>
<%= raw t('org_admin.templates.phase_details_text_html')%>
-<%end%> +<% end %>
diff --git a/app/views/templates/admin_phase.html.erb b/app/views/templates/admin_phase.html.erb index b85927b..067ce1b 100644 --- a/app/views/templates/admin_phase.html.erb +++ b/app/views/templates/admin_phase.html.erb @@ -2,81 +2,70 @@ <%= stylesheet_link_tag "admin" %> <% javascript 'admin.js' %> -<%= tinymce :content_css => asset_path('application.css') %> +<%= tinymce content_css: asset_path('application.css') %>

- <%= @phase.dmptemplate.title %> - -
- <%= link_to t("org_admin.templates.view_all_templates"), - admin_index_dmptemplate_path, - :class => 'btn btn-primary' %> -
+ <%= @phase.template.title %> + +
+ <%= link_to t("org_admin.templates.view_all_templates"), + admin_index_template_path, + class: 'btn btn-primary' %> +

-<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @phase.dmptemplate, active: @phase.id} %> +<%= render partial: "admin_nav_tabs", locals: {template: @phase.template, active: @phase.id} %>
-
+
- -
-
+ +
+
- -
- <%= render :partial => "show_phase", locals: {phase: @phase}%> -
- <% if @phase.dmptemplate.org_type != constant("organisation_types.funder") || current_user.org_type == constant("organisation_types.funder") then %> - + +
+ <%= render partial: "show_phase", locals: {phase: @phase}%> +
+ <% if @phase.modifiable then %> + + <% end %> +
+
- - <%= render :partial => "versions_table", locals: {phase: @phase}%> - <%end%> + + <% @sections.order("number ASC").each do |section| %> + <% if @edit && section.modifiable %> + <%= render partial: 'edit_section', locals: {section: section, edit: @edit, phase: @phase} %> + <% else %> + <%= render partial: 'show_section', locals: {section: section}%> + <% end %> + <% end %> - - <% if @edit == "false" || (@phase.dmptemplate.org_type == constant("organisation_types.funder") && current_user.org_type != constant("organisation_types.funder")) then%> - <%= render :partial => 'show_version', locals: {version: @version}%> - <%elsif @edit == "true" || current_user.org_type == constant("organisation_types.funder") then %> - <%= render :partial => 'edit_version', locals: {version: @version, edit: @edit, phase: @phase} %> - <%end%> -
-
- - - <% @sections.order("number ASC").each do |section| %> - <%if (@edit == "true" && section.organisation_id == current_user.organisation_id) || - (@phase.dmptemplate.org_type == constant("organisation_types.funder") && section.organisation_id == current_user.organisation_id && current_user.org_type != constant("organisation_types.funder"))then%> - <%= render :partial => 'edit_section', locals: {section: section, edit: @edit, phase: @phase, version: @version} %> - <%elsif (section.organisation_id == @phase.dmptemplate.organisation_id ) || ( section.organisation_id == current_user.organisation_id) then%> - <%= render :partial => 'show_section', locals: {section: section}%> - <%end%> - <% end %> - -
+
- - <% if !@version.published? || (@phase.dmptemplate.org_type == constant("organisation_types.funder") && current_user.org_type != constant("organisation_types.funder"))then %> + + <% if !@phase.template.published %> - - + + - -
-
- <%= link_to t('org_admin.add_section_label'),'#', :id => 'add_section_button', :class =>'btn btn-primary' %> -
-
- <%end%> + +
+
+ <%= link_to t('org_admin.add_section_label'),'#', id: 'add_section_button', aclass: 'btn btn-primary' %> +
+
+ <%end%> diff --git a/lib/assets/javascripts/admin.js b/lib/assets/javascripts/admin.js index 6354869..f3d3aaf 100644 --- a/lib/assets/javascripts/admin.js +++ b/lib/assets/javascripts/admin.js @@ -1,5 +1,5 @@ //= require tinymce -/* +/* **Project: DMPRoadmap **Description: This file include all javascript regarding admin interface **Copyright: Digital Curation Centre and University of California Curation Center @@ -20,7 +20,7 @@ }, 1000); } } - + //set the tinymce popover help text $(".template_desc_popover, .phase_desc_popover, .version_desc_popover, .section_desc_popover, .question_format_popover," + " .default_answer_popover, .suggested_answer_popover, .question_guidance_popover, .question_themes_popover," + @@ -29,13 +29,13 @@ " .guidance_by_question_popover, .guidance_group_select_popover, .org_abbr_popover").on('click', function(e) { e.preventDefault(); }).popover(); - + //show or hide divs based on what the user selects from the question format. New question $('.ques_format').on("change", function(e) { var s_id = $(this).prev(".section_id").val(); - + var selected_format = $('#new-select-format-'+ s_id).val(); - + //text area if (selected_format == 1){ $("#new-options-"+ s_id).hide(); @@ -175,7 +175,7 @@ //action for show or hide template editing display $('#edit_template_button').click(function(e){ e.preventDefault(); - + $('#edit_template_div').show(); $('#show_template_div').hide(); }); @@ -220,18 +220,18 @@ $('#add_question_block_div_'+ s_id).show(); $('#add_question_button_div_'+ s_id).hide(); e.preventDefault(); - + }); - - //if question text area is empty send alert - $('.new_question_save_button').click(function(e){ + + //if question text area is empty send alert + $('.new_question_save_button').click(function(e){ var s_id = $(this).prev(".section_id").val(); if ($('#new_question_text_'+ s_id).val() == ''){ alert(I18n.t("js.question_text_empty")); return false; } }); - + //action for cancelling a new question $('.cancel_add_new_question').click(function(e){ var s_id_new = $(this).prev(".section_id_new").val(); @@ -280,7 +280,7 @@ $('#show_suggested_answer_div_'+ q_id).hide(); e.preventDefault(); }); - + //GUIDANCE //action for adding a new guidance next to the question $('.add_guidance_button').click(function(e){ @@ -305,44 +305,44 @@ $('#show_guidance_div_'+ q_id).hide(); e.preventDefault(); }); - - - //Add new guidance Alerts + + + //Add new guidance Alerts $("#return_to_new_guidance").click(function(){ $('#new_guidance_alert_dialog').modal("hide"); }); - - + + $('#new_guidance_submit').click( function(e){ // $('#new_guidance_alert_dialog').on("hide", function(){ - + var alert_message = []; //verify if text area is not nil var editorContent = tinyMCE.get('guidance-text').getContent(); if (editorContent == ''){ alert_message.push(I18n.t("js.add_guidance_text")); - } - //verify dropdown with questions has a selected option if guidance for a question being used + } + //verify dropdown with questions has a selected option if guidance for a question being used if ($('#g_options').val() == '2') { if ($('#questions_select').val() == '' || isNaN($('#questions_select').val())){ alert_message.push(I18n.t("js.select_question")); } } - //verify dropdown with questions has a selected option if guidance for a question being used + //verify dropdown with questions has a selected option if guidance for a question being used if ($('#g_options').val() == '1' ){ if($('#guidance_theme_ids').val() == undefined || $('#guidance_theme_ids').val() == ''){ alert_message.push(I18n.t("js.select_at_least_one_theme")); } } - //verify if guidance group is selected + //verify if guidance group is selected if ( ($('#guidance_guidance_group_ids').val() == '') || $('#guidance_guidance_group_ids').val() == undefined ) { alert_message.push(I18n.t("js.select_guidance_group")); } if(alert_message.length == 0){ //clear dropdowns before submission $('#new_guidance_alert_dialog').modal("hide"); - + if ($('#g_options').val() == '2'){ $('#guidance_theme_ids').val(null); } @@ -351,12 +351,12 @@ } $('#new_guidance_form').submit(); return false; - + } else if (alert_message.length != 0){ var message = ''; $('#new_guidance_alert_dialog').on("show", function(){ - + $("#missing_fields_new_guidance").empty(); $.each(alert_message, function(key, value){ message += "
  • "+value+"
  • "; @@ -368,43 +368,43 @@ delete alert_message; e.preventDefault(); }); - + //edit guidance alerts $("#return_to_edit_guidance").click(function(){ $('#edit_guidance_alert_dialog').modal("hide"); }); - - + + $('#edit_guidance_submit').click( function(e){ // $('#new_guidance_alert_dialog').on("hide", function(){ - + var alert_message = []; //verify if text area is not nil var editorContent = tinyMCE.get('guidance-text').getContent(); if (editorContent == ''){ alert_message.push(I18n.t("js.add_guidance_text")); - } - //verify dropdown with questions has a selected option if guidance for a question being used + } + //verify dropdown with questions has a selected option if guidance for a question being used if ($('#g_options').val() == '2') { if ($('#questions_select').val() == '' || isNaN($('#questions_select').val())){ alert_message.push(I18n.t("js.select_question")); } } - //verify dropdown with questions has a selected option if guidance for a question being used + //verify dropdown with questions has a selected option if guidance for a question being used if ($('#g_options').val() == '1' ){ if($('#guidance_theme_ids').val() == undefined || $('#guidance_theme_ids').val() == ''){ alert_message.push(I18n.t("js.select_at_least_one_theme")); } } - //verify if guidance group is selected + //verify if guidance group is selected if ( ($('#guidance_guidance_group_ids').val() == '') || $('#guidance_guidance_group_ids').val() == undefined ) { alert_message.push(I18n.t("js.select_guidance_group")); } - + if(alert_message.length == 0){ //clear dropdowns before submission $('#edit_guidance_alert_dialog').modal("hide"); - + if ($('#g_options').val() == '2'){ $('#guidance_theme_ids').val(null);} if($('#g_options').val() == '1'){$('#questions_select').val(null);} $('#edit_guidance_form').submit(); @@ -413,7 +413,7 @@ else if (alert_message.length != 0){ var message = ''; $('#edit_guidance_alert_dialog').on("show", function(){ - + $("#missing_fields_edit_guidance").empty(); $.each(alert_message, function(key, value){ message += "
  • "+value+"
  • "; @@ -424,9 +424,9 @@ } delete alert_message; e.preventDefault(); - }); - - + }); + + //Validate banner_text area for less than 165 character $("form#edit_org_details").submit(function(){ if (getStats('org_banner_text').chars > 165) { @@ -434,10 +434,10 @@ return false; } }); - - - - + + + + }); @@ -459,8 +459,8 @@ // Returns text statistics for the specified editor by id function getStats(id) { var body = tinymce.get(id).getBody(), text = tinymce.trim(body.innerText || body.textContent); - + return { chars: text.length }; -} \ No newline at end of file +} \ No newline at end of file