diff --git a/app/views/phases/_edit_phase.html.erb b/app/views/phases/_edit_phase.html.erb index fe0edf8..8c989de 100644 --- a/app/views/phases/_edit_phase.html.erb +++ b/app/views/phases/_edit_phase.html.erb @@ -12,7 +12,7 @@
<%= f.label(:description, _('Description'), class: 'control-label') %>
"> - <%= text_area_tag('phase-desc', phase.description, class: 'tinymce form-control') %> + <%= text_area_tag('phase-desc', phase.description, class: 'phase form-control') %>
diff --git a/app/views/question_options/_option_fields.html.erb b/app/views/question_options/_option_fields.html.erb index 1d00634..0282d82 100644 --- a/app/views/question_options/_option_fields.html.erb +++ b/app/views/question_options/_option_fields.html.erb @@ -1,10 +1,43 @@ - - - <%= f.number_field :number, in: 1..20, class: "number_field option"%> - <%= f.text_field :text, as: :string, class: "small_text_field" %> - <%= f.check_box :is_default %> - - <%= f.hidden_field :_destroy %> - <%= _('Remove') %> - - +
+
+ <%= _('Order')%> +
+
+ <%= _('Text')%> +
+
+ <%= _('Default')%> +
+
+
+
+<% if q.question_options.count == 0 %> + <% 2.times {q.question_options.build } %> +<% end %> +<% i = 0 %> + <% q.question_options.to_a.sort_by{|op| op['number']}.each do |options_q| %> + <%= f.fields_for :question_options, options_q do |op|%> + <% i = i + 1 %> + <% options_q.number = i %> +
+
+ <%= op.number_field :number, in: 1..20, class: 'form-control' %> +
+
+ <%= op.text_field :text, as: :string, class: 'form-control' %> +
+
+ <%= op.check_box :is_default %> +
+
+ <%= op.hidden_field :_destroy %> + <%= _('Remove') %> +
+
+ <% end %> + <% end %> + diff --git a/app/views/questions/_add_question.html.erb b/app/views/questions/_add_question.html.erb index df2229e..006baed 100644 --- a/app/views/questions/_add_question.html.erb +++ b/app/views/questions/_add_question.html.erb @@ -5,144 +5,92 @@ **Arguments transferred: an instance of 'section' **Copyright: Digital Curation Centre and California Digital Library --> - <% @new_question = Question.new %> <% @new_question.number = section.questions.count + 1 %> - - -<%= form_for @new_question, url: admin_create_question_path , html: {id: "new_question_#{section.id}"} do |f| %> +<%= form_for @new_question, url: admin_create_question_path , html: {id: "new_question_#{section.id}", class: 'form-horizontal question_form'} do |f| %> <%= f.hidden_field :section_id, value: section.id %> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "> - - - - - - - - -
<%= _('Question number')%><%= f.number_field :number, in: 1..50, class: "number_field has-tooltip", "data-toggle": "tooltip", title: _('This allows you to order questions within a section.') %> - -
-
<%= _('Question text')%> - <%= text_area_tag('question[text]', "", id: "new_question_text_#{section.id}", class: "tinymce") %> -
-
<%= _('Answer format')%><%= 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.id_for(QuestionFormat.formattypes[:textarea])), - {}, class: "question_format", 'data-toggle': 'tooltip', 'data-html': true, title: _("You can choose from:
  • - text area (large box for paragraphs);
  • - text field (for a short answer);
  • - checkboxes where options are presented in a list and multiple values can be selected;
  • - radio buttons where options are presented in a list but only one can be selected;
  • - dropdown like this box - only one option can be selected;
  • - multiple select box allows users to select several options from a scrollable list, using the CTRL key;
") %> -
-
-
- - -
-
-
<%= _('Default answer')%> -
-
- <%= text_field_tag("question-default-value-textfield", @new_question.default_value, class: "default_answer_textfield", style: 'display:none') %> - <%= text_area_tag("question-default-value-textarea", @new_question.default_value, class: "default_answer_textarea tinymce") %> -
-
-
-
-
- <%= _('Example Answer')%> - -
- <%= text_area_tag(:example_answer, "", class: "tinymce") %> -
-
-
-
<%= _('Guidance')%> -
- <%= text_area_tag(:guidance, "", class: "tinymce") %> -
-
-
-
<%= _('Themes')%> -
- <%= f.collection_select(:theme_ids, - Theme.all.order("title"), - :id, :title, {prompt: false, include_blank: _('None')}, {multiple: true, 'data-toggle': 'tooltip', 'data-html': true, title: _("

Select themes that are relevant to this question.

This allows your generic institution-level guidance to be drawn in, as well as that from other sources e.g. the %{organisation_abbreviation} or any Schools/Departments that you provide guidance for.

You can select multiple themes by using the CTRL button.

")})%> -
-
-
- - -
- <%= hidden_field_tag :section_id, section.id, class: "section_id" %> - <%= f.submit _('Save'), class: "btn btn-default", role:'button' %> - <%= hidden_field_tag :section_id, section.id, class: "section_id_new" %> - <%= link_to _('Cancel'), '#', class: "btn btn-default new_question_cancel", role: 'button' %> + <%= hidden_field_tag :section_id, section.id, class: "section_id_new" %> + +
+ <%= f.label(:number, _('Question Number'), class: 'col-md-2 control-label') %> +
+ <%= f.number_field(:number, in: 1..50, class: "form-control", "aria-required": true, 'aria-required': true) %>
- + +
+ <%= f.label(:text, _('Question text'), class: 'col-md-2 control-label') %> +
+ <%= f.text_area(:text, class: "question") %> +
+
+ +
+ <%= f.label(:question_format_id, _('Answer format'), class: 'col-md-2 control-label') %> +
+ <%= f.select :question_format_id, + options_from_collection_for_select(QuestionFormat.all.order("title"), + :id, + :title, + QuestionFormat.id_for(QuestionFormat.formattypes[:textarea])), + {}, + class: "form-control", + 'data-toggle': 'tooltip', + 'data-html': true, + title: _("You can choose from:
  • - text area (large box for paragraphs);
  • - text field (for a short answer);
  • - checkboxes where options are presented in a list and multiple values can be selected;
  • - radio buttons where options are presented in a list but only one can be selected;
  • - dropdown like this box - only one option can be selected;
  • - multiple select box allows users to select several options from a scrollable list, using the CTRL key;
") + %> +
+
+ + + +
+ <%= f.label(:default_value, _('Default answer'), class: 'col-md-2 control-label') %> +
+ + <%= text_field_tag("question-default-value-textfield", @new_question.default_value, class: 'form-control') %> + + + <%= text_area_tag("question-default-value-textarea", @new_question.default_value, class: 'question') %> + +
+
+ +
+ <%= f.label(:example_answer, _('Example Answer'), class: 'col-md-2 control-label') %> +
+ <%= text_area_tag(:example_answer, "", id: "question_example_answer", class: 'question') %> +
+
+ +
+ <%= f.label(:guidance, _('Guidance'), class: 'col-md-2 control-label') %> +
"> + <%= text_area_tag(:guidance, "", id: "question_guidance", class: 'question') %> +
+
+ +
+ <%= f.label(:theme_ids, _('Themes'), class: 'col-md-2 control-label') %> +
+ <%= f.collection_select(:theme_ids, + Theme.all.order("title"), + :id, :title, {prompt: false, include_blank: _('None')}, {multiple: true, 'data-toggle': 'tooltip', 'data-html': true, title: _("

Select themes that are relevant to this question.

This allows your generic institution-level guidance to be drawn in, as well as that from other sources e.g. the %{organisation_abbreviation} or any Schools/Departments that you provide guidance for.

You can select multiple themes by using the CTRL button.

"), class: 'form-control'}) %> +
+
+
+ <%= f.submit _('Save'), class: "btn btn-default", role:'button' %> + <%= link_to _('Cancel'), '#', class: "btn btn-default new_question_cancel", role: 'button' %> +
<% end %> diff --git a/app/views/questions/_edit_question.html.erb b/app/views/questions/_edit_question.html.erb index a7ce7a8..f776f86 100644 --- a/app/views/questions/_edit_question.html.erb +++ b/app/views/questions/_edit_question.html.erb @@ -5,151 +5,114 @@ **Arguments transferred: an instance of 'question' **Copyright: Digital Curation Centre and California Digital Library --> - -<%= form_for(question, url: admin_update_question_path(question), html: { method: :put}) do |f| %> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "> - - - - - - - - -
<%= _('Question number')%><%= f.number_field :number, in: 1..50, class: "number_field", "data-toggle": "tooltip", "title" => _('This allows you to order questions within a section.') %> -
-
<%= _('Question text')%> - <%= f.text_area(:text, class: "tinymce") %> -
-
<%= _('Answer format')%> -
-
- <%= f.hidden_field :id,{ class: "quest_id" } %> +
+
+
+
+ <%= form_for(question, url: admin_update_question_path(question), html: { method: :put, class: 'form-horizontal question_form' }) do |f| %> + <%= f.hidden_field :id,{ class: "quest_id" } %> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + +
+ <%= f.label(:number, _('Question Number'), class: 'col-md-2 control-label') %> +
+ <%= f.number_field(:number, in: 1..50, class: "form-control", "aria-required": true, 'aria-required': true) %> +
+
+ +
+ <%= f.label(:text, _('Question text'), class: 'col-md-2 control-label') %> +
+ <%= f.text_area(:text, class: "question") %> +
+
+ +
+ <%= f.label(:question_format_id, _('Answer format'), class: 'col-md-2 control-label') %> +
<%= f.select :question_format_id, - options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id), - {}, class: "question_format", id: "#{question.id}-select-format", 'data-toggle': 'tooltip', 'data-html': true, title: _("You can choose from:
  • - text area (large box for paragraphs);
  • - text field (for a short answer);
  • - checkboxes where options are presented in a list and multiple values can be selected;
  • - radio buttons where options are presented in a list but only one can be selected;
  • - dropdown like this box - only one option can be selected;
  • - multiple select box allows users to select several options from a scrollable list, using the CTRL key;
")%> + options_from_collection_for_select(QuestionFormat.all.order("title"), + :id, + :title, + question.question_format_id), + {}, + class: "form-control", + 'data-toggle': 'tooltip', + 'data-html': true, + title: _("You can choose from:
  • - text area (large box for paragraphs);
  • - text field (for a short answer);
  • - checkboxes where options are presented in a list and multiple values can be selected;
  • - radio buttons where options are presented in a list but only one can be selected;
  • - dropdown like this box - only one option can be selected;
  • - multiple select box allows users to select several options from a scrollable list, using the CTRL key;
") + %>
- - -
- - - - - - - - - - - <% if question.question_options.count == 0 %> - <% 2.times {question.question_options.build } %> - - <% end %> - <% i = 0 %> - <% question.question_options.to_a.sort_by{|op| op["number"]}.each do |options_q|%> - <%= f.fields_for :question_options, options_q do |op|%> - <% i = i + 1%> - <% options_q.number = i %> - <%= render "question_options/option_fields", f: op %> - <% end %> - <% end %> - - -
<%= _('Order')%><%= _('Text')%><%= _('Default')%>
- - <%= _('Add option') %> - -
- - <%= f.check_box :option_comment_display, as: :check_boxes%><%= f.label _('Display additional comment area.'), class: "checkbox inline"%> -
-
-
-
<%= _('Default answer')%> -
-
- <%= text_field_tag("question-default-value-textfield", question.default_value, class: "default_answer_textfield", style: question.question_format.textfield? ? '' : 'display:none;') %> - <%= text_area_tag("question-default-value-textarea", question.default_value, class: "default_answer_textarea tinymce", style: question.question_format.textarea? ? '' : 'display:none;') %> + +
+
+ <%= render "/question_options/option_fields", f: f, q: question %> + +
+ +
-
-
-
<%= _('Example Answer')%>
- <% example_answer = question.get_example_answer(current_user.org.id) %> - <% if example_answer.nil? %> - <% example_answer = question.annotations.build %> - <% example_answer.type = :example_answer %> - <% end %> - <%= f.fields_for :annotations, example_answer do |s|%> - <%= s.hidden_field :org_id, value: current_user.org.id %> -
    -
  • <%= s.text_area(:text, class: "tinymce") %> -
  • -
- <% end %> + +
+ <%= f.label(:default_value, _('Default answer'), class: 'col-md-2 control-label') %> +
+ + <%= text_field_tag("question-default-value-textfield", question.default_value, class: 'form-control') %> + + + <%= text_area_tag("question-default-value-textarea", question.default_value, class: 'question') %> + +
-
-
-
<%= _('Guidance')%> -
- <% guidance = question.get_guidance_annotation(current_user.org_id) %> - <% guidance_text = guidance.present? ? guidance.text : "" %> - <%= text_area_tag("question-guidance-#{question.id}", guidance_text , class: "tinymce") %> + +
+ <%= f.label(:example_answer, _('Example Answer'), class: 'col-md-2 control-label') %> +
+ <% example_answer = question.get_example_answer(current_user.org.id) %> + <% if example_answer.nil? %> + <% example_answer = question.annotations.build %> + <% example_answer.type = :example_answer %> + <% end %> + <%= f.fields_for :annotations, example_answer do |s|%> + <%= s.hidden_field :org_id, value: current_user.org.id %> + <%= s.text_area(:text, class: 'question') %> + <% end %> +
-
-
-
<%= _('Themes')%>
- <%= f.collection_select(:theme_ids, - Theme.all.order("title"), - :id, :title, {prompt: false, include_blank: "None"}, {multiple: true, 'data-toggle': 'tooltip', 'data-html': true, title: _("

Select themes that are relevant to this question.

This allows your generic institution-level guidance to be drawn in, as well as that from other sources e.g. the %{organisation_abbreviation} or any Schools/Departments that you provide guidance for.

You can select multiple themes by using the CTRL button.

")})%> + +
+ <%= f.label(:guidance, _('Guidance'), class: 'col-md-2 control-label') %> +
"> + <% guidance = question.get_guidance_annotation(current_user.org_id) %> + <% guidance_text = guidance.present? ? guidance.text : "" %> + <%= text_area_tag("question-guidance-#{question.id}", guidance_text , class: 'question') %> +
-
-
- -
- <%= f.submit _('Save'), class: "btn btn-primary", role:'button' %> - <% if !question.section.phase.template.published? %> - <%= link_to _('Delete'), admin_destroy_question_path(question_id: question.id), - confirm: _("You are about to delete '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-primary", role:'button'%> - <% end %> - <%= hidden_field_tag :question_id, question.id, class: "question_id" %> - <%= link_to _('Cancel'), "#", class: "btn cancel cancel_edit_question", role:'button' %> + +
+ <%= f.label(:theme_ids, _('Themes'), class: 'col-md-2 control-label') %> +
+ <%= f.collection_select(:theme_ids, + Theme.all.order("title"), + :id, :title, {prompt: false, include_blank: _('None')}, {multiple: true, 'data-toggle': 'tooltip', 'data-html': true, title: _("

Select themes that are relevant to this question.

This allows your generic institution-level guidance to be drawn in, as well as that from other sources e.g. the %{organisation_abbreviation} or any Schools/Departments that you provide guidance for.

You can select multiple themes by using the CTRL button.

"), class: 'form-control'}) %> +
+
+
+ <%= f.submit _('Save'), class: "btn btn-default", role:'button' %> + <% if !question.section.phase.template.published? %> + <%= link_to _('Delete'), admin_destroy_question_path(question_id: question.id), + confirm: _("You are about to delete '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-default", role:'button'%> + <% end %> + <%= link_to _('Cancel'), '#', class: "btn btn-default edit_question_cancel", role: 'button' %> +
+ <% end %> +
- - - -<%= render partial: "guidances/guidance_display", locals: {question: question} %> -<% end %> +
+ <%#= render partial: "guidances/guidance_display", locals: {question: question} %> +
+
diff --git a/app/views/questions/_show_question.html.erb b/app/views/questions/_show_question.html.erb index 4e20c6a..d31bf6b 100644 --- a/app/views/questions/_show_question.html.erb +++ b/app/views/questions/_show_question.html.erb @@ -4,141 +4,78 @@ **Arguments transferred: 'question' **Copyright: Digital Curation Centre and California Digital Library --> - -
- - - - - - - - - - - - - - <% if q_format.title == _('Text field') || q_format.title == _('Text area') %> - <% if !question.default_value.nil? %> - - - - - <% end %> - <% end %> - - - - - - - - <% if !question.section.phase.template.org.funder? %> - <% example_answer = question.get_example_answer(@original_org.id) %> - <% if example_answer.present? && example_answer.text.present? %> - - - - - <% end %> - <% end %> - - <% guidance = question.get_guidance_annotation(@original_org.id) %> - <% if guidance.present? %> - - - - - <% end %> - - <% themes_q = question.themes %> - <% if !themes_q.nil? %> - - - - - <% end %> -
<%= _('Question number')%><%= question.number %>
<%= _('Question text')%><%= raw question.text %> -
-
- <% q_format = question.question_format %> - <% if q_format.title == _('Check box') || q_format.title == _('Multi select box') || q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') %> -
    - <% if question.question_options.is_a? QuestionOption %> -
  • - <%= question.question_options.text %>
  • - <% else %> - <% if !question.question_options.to_a.nil? %> - <% question.question_options.to_a.sort_by{|op| op['number']}.each do |o| %> -
  • - <%= o.text %>
  • - <% end %> - <% end %> +
    +
    +
    +
    + <% q_format = question.question_format %> +
    +
    <%= _('Question number')%>
    +
    <%= question.number %>
    +
    <%= _('Question text')%>
    +
    <%= raw question.text %>
    + +
    +
    + + <% if q_format.textfield? || q_format.textarea? %> + <% if !question.default_value.nil? %> +
    <%= _('Default value')%>
    +
    <%= raw question.default_value %>
    <% end %> -
<% end %> -
-
<%= _('Default value')%><%= raw question.default_value %>
<%= _('Answer format')%><%= q_format.title %> -
- <% if q_format.title == _('Check box') || q_format.title == _('Multi select box') || q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') %> - <% if question.option_comment_display == true %> - <%= _('Additional comment area will be displayed.')%> - <% else %> - <%= _('No additional comment area will be displayed.')%> + +
<%= _('Answer format')%>
+
+ <%= q_format.title %> + <% if q_format.option_based? %> + <%= _('Additional comment area will be displayed.')%> + <% else %> + <%= _('No additional comment area will be displayed.')%> + <% end %> +
+ + <% if !question.section.phase.template.org.funder? %> + <% example_answer = question.get_example_answer(@original_org.id) %> + <% if example_answer.present? && example_answer.text.present? %> +
<%= _('example answer')%>
+
<%= raw example_answer.text %>
+ <% end %> + <% end %> + + <% guidance = question.get_guidance_annotation(@original_org.id) %> + <% if guidance.present? %> +
<%= _('Guidance')%>
+
<%= raw guidance.text %>
+ <% end %> + + <% themes_q = question.themes %> + <% if !themes_q.nil? %> +
<%= _('Themes')%>
+
<%= themes_q.join(', ') %>
+ <% end %> + + + +
+
+
+ <% if (question.modifiable) %> + <%= link_to _('Edit question'), "#question_edit#{question.id}", class: "btn btn-default question_edit_link", role: "button" %> + <%= link_to _('Delete question'), admin_destroy_question_path(question_id: question.id), + confirm: _("You are about to delete '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-default", role:"button" %> + <% else %> + <% if example_answer.nil? && guidance.nil? %> +
+ <%= link_to _('Add Annotations'), '# ', class: "btn btn-default add_annotations_button", role:"button"%> +
<% end %> <% end %> -
-
- <%= _('example answer')%> - <%= raw example_answer.text %>
<%= _('Guidance')%><%= raw guidance.text %>
<%= _('Themes')%><% i = 1%> - <% themes_q.each do |t|%> - <%= t.title %> - <% if themes_q.count > i %> - , - <% i +=1 %> - <% end %> - <% end %> -
-
- - <% example_answer = question.get_example_answer(current_user.org_id) %> - <% guidance = question.get_guidance_annotation(current_user.org_id) %> - <% if !question.modifiable %> - <% if example_answer.present? || guidance.present? %> -
- <%= render partial: 'annotations/show_annotation', locals: {example_answer: example_answer, guidance: guidance, question: question} %> -
- - <% end %> - - <% end %> - -
- - <% if (@edit && question.modifiable) %> -
- <%= hidden_field_tag :question_id, question.id, class: "question_id" %> - <%= link_to _('Edit question'), '# ', class: "btn btn-primary edit_question_button", role:"button"%> - - <%= link_to _('Delete question'), admin_destroy_question_path(question_id: question.id), - confirm: _("You are about to delete '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-primary", role:"button"%> -
- <% else %> - <% if example_answer.nil? && guidance.nil? %> -
-
- <%= hidden_field_tag :question_id, question.id, class: "question_id" %> - <%= link_to _('Add Annotations'), '# ', class: "btn btn-primary add_annotations_button", role:"button"%>
- <% end %> - <% end %> -
-
- - - -<%= render partial: 'guidances/guidance_display', locals: {question: question}%> +
+
+
+ <%#= render partial: 'guidances/guidance_display', locals: {question: question} %> +
+ \ No newline at end of file diff --git a/app/views/sections/_edit_section.html.erb b/app/views/sections/_edit_section.html.erb index 05b6bd1..a3506ea 100644 --- a/app/views/sections/_edit_section.html.erb +++ b/app/views/sections/_edit_section.html.erb @@ -10,19 +10,16 @@ <%= f.label(:title, _('Title'), { class: "control-label" }) %> <%= f.text_field(:title, { class: "form-control", 'aria-required': false, placeholder: _('Enter a title for the section'), 'data-toggle': 'tooltip', title: _('Enter a title for the section')} ) %> -
<%= f.label(:number, _('Order of display'), class: "control-label") %> <%= f.number_field(:number, in: 1..15, class: "form-control", 'aria-required': false, 'data-toggle': 'tooltip', title: _('This allows you to order sections.')) %>
-
<%= f.label(:description, _('Description'), class: "control-label") %>
"> - <%= text_area_tag('section-desc', section.description, class: 'tinymce form-control') %> + <%= text_area_tag('section-desc', section.description, class: 'section') %>
-
<%= f.button(_('Save'), class: 'btn btn-default', type: "submit") %> <%= link_to _('Delete'), admin_destroy_section_path(section_id: section.id), @@ -38,12 +35,14 @@ <% questions = section.questions.order('number') %> <% if questions.present? %> <% questions.each do |question| %> - <% if question.modifiable %> - <%#= render partial: 'questions/edit_question', locals: {question: question} %> - <% else %> - <%#= render partial: 'questions/show_question', locals: {question: question} %> - <% end %> - <% if questions.last.id != question.id %> +
+
"> + <%= render partial: 'questions/show_question', locals: {question: question} %> +
+
" style="display: none;"> + <%= render partial: 'questions/edit_question', locals: {question: question} %> +
+ <% if questions.last.id == question.id %>
<% end %> <% end %> diff --git a/app/views/sections/_show_section.html.erb b/app/views/sections/_show_section.html.erb index 55930c7..5e15582 100644 --- a/app/views/sections/_show_section.html.erb +++ b/app/views/sections/_show_section.html.erb @@ -11,10 +11,14 @@ <% questions = section.questions.order('number') %> <% if questions.present? %> <% questions.each do |question| %> +
+
"> + <%= render partial: 'questions/show_question', locals: {question: question} %> +
<% if question.modifiable %> - <%#= render partial: 'questions/edit_question', locals: {question: question} %> - <% else %> - <%#= render partial: 'questions/show_question', locals: {question: question} %> +
" style="display: none;"> + <%= render partial: 'questions/edit_question', locals: {question: question} %> +
<% end %> <% if questions.last.id != question.id %>
@@ -22,4 +26,4 @@ <% end %> <% end %>
- + \ 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 0300ddd..7b18016 100644 --- a/app/views/templates/_edit_template.html.erb +++ b/app/views/templates/_edit_template.html.erb @@ -4,11 +4,11 @@ <%= f.label(:title, _('Title'), class: "control-label") %> <%= f.text_field(:title, class: "form-control", "aria-required": false, 'data-toggle': 'tooltip', title: _('Please enter a title for your template.')) %> - +
<%= f.label(:description, _('Description'), class: "control-label") %>
- <%= text_area_tag("template-desc", template.description, { class: 'form-control tinymce', "aria-required": false }) %> + <%= text_area_tag("template-desc", template.description, { class: 'template', "aria-required": false }) %>
diff --git a/lib/assets/javascripts/admin.js b/lib/assets/javascripts/admin.js deleted file mode 100644 index e1e8ea6..0000000 --- a/lib/assets/javascripts/admin.js +++ /dev/null @@ -1,251 +0,0 @@ -/* -**Project: DMPRoadmap -**Description: This file include all javascript regarding admin interface -**Copyright: Digital Curation Centre and California Digital Library -*/ - - -$( document ).ready(function() { - /*---------------- - Listener for removing a question_option for option_based questions - Note the usage of event-delegation approach through the presence of the selector (e.g. .remove-option) which means the handler - is ONLY called when the event occurs at .remove-option and has the advantage of processing events from descendant elements (e.g. tr class="options_content") - that are added to the document at a later time - ------------------*/ - $('.options_table').on('click','.remove-option', function(e){ - e.preventDefault(); - $(this).prev().val(true); - $(this).closest('.options_content').hide(); - }); - /*---------------- - Listener for adding a question_option for option_based questions - ------------------*/ - $(".add-option").click(function(e){ - e.preventDefault(); - - var tbl = $(this).parent().find("table.options_table > tbody.options_tbody"), - last = tbl.find("tr:last"), - clone = last.clone(); - nbr = parseInt(last.find(".number_field").val()); - - // Update the input field names and ids - clone.find("input").each(function(index){ - $(this).prop("id", $(this).prop("id").replace(/_\d+_/g, "_" + nbr + "_")); - $(this).prop("name", $(this).prop("name").replace(/\[\d+\]/g, "[" + nbr + "]")); - }); - - // Remove the hidden class and make sure the new row is not marked for removal - clone.removeClass('hidden'); - clone.find("[id$=" + nbr + "__destroy]").val(false); - - // Default the other values - clone.find("[id$=" + nbr + "_number]").val("" + (nbr + 1)); - clone.find("[id$=" + nbr + "_text]").val(""); - clone.find("[id$=" + nbr + "_is_default]").prop("checked", false); - - last.after(clone); - }); - - if($('.in').length > 0) { - if ($('.in .current_question').length > 0) { - $(document.body).animate({ - 'scrollTop': $('.in .current_question').offset().top - }, 1000); - } - else { - $(document.body).animate({ - 'scrollTop': $('.in').offset().top - }, 1000); - } - } - - // This handler serves to display/hide default_answer field as well as to display/hide question_options fields - // depending on the question_format selected - $('.question_format').change(function(){ - var selected = $(this).val(); - var question_div = $(this).closest('.question-div'); - if(selected === '1' || selected === '2') { - question_div.find('.ques_format_option').hide(); - question_div.find('.default_answer').show(); - if(selected === '1') { //textarea - question_div.find('.default_answer_textfield').hide(); - question_div.find('.default_answer_textarea').prev().show() - } - else { //textfield - question_div.find('.default_answer_textarea').prev().hide(); - question_div.find('.default_answer_textfield').show(); - } - } - else if(selected === '3' || selected === '4' || selected === '5' || selected === '6') { // option_based - question_div.find('.default_answer').hide(); - question_div.find('.ques_format_option').show(); - } - }); - - //action for show or hide template editing display - $('#edit_template_button').click(function(e){ - e.preventDefault(); - - $('#edit_template_div').show(); - $('#show_template_div').hide(); - }); - - - //action for show or hide phase display - $('#edit_phase_button').click(function(e){ - e.preventDefault(); - $('#edit_phase_div').show(); - $('#show_phase_div').hide(); - }); - - //action to hide the alert to edit a version - $("#edit-version-confirmed").click(function (e){ - $("#version_edit_alert").modal("hide"); - }); - - //action to clone/add a version - $("#clone-version-confirmed").click(function (){ - $("#new_project").submit(); - }); - - //action for show question editing display - $('.edit_question_button').click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#edit_question_div_'+ q_id).show(); - $('#show_question_div_'+ q_id).hide(); - e.preventDefault(); - }); - - - $(".cancel_edit_question").click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#edit_question_div_'+ q_id).hide(); - $('#show_question_div_'+ q_id).show(); - e.preventDefault(); - }); - - //action for adding a new question - $('.add_question_button').click(function(e){ - var s_id = $(this).prev(".section_id").val(); - $('#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){ - var s_id = $(this).prev(".section_id").val(); - if ($('#new_question_text_'+ s_id).tinymce().getContent() === ''){ - alert(__('Question text is empty, please enter your question.')); - 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(); - $('#add_question_block_div_'+ s_id_new).hide(); - $('#add_question_button_div_'+ s_id_new).show(); - e.preventDefault(); - }); - - //action for adding a new section - $('#add_section_button').click(function(e){ - $('#add_section_block_div').show(); - $('#add_section_button_div').hide(); - e.preventDefault(); - }); - - - //action for cancelling a new section - $('#cancel_add_section').click(function(e){ - $('#add_section_block_div').hide(); - $('#add_section_button_div').show(); - e.preventDefault(); - }); - - //ANNOTATIONS - //action for adding a new annotation - $('.add_annotations_button').click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#add_annotations_block_'+ q_id).show(); - $('#add_annotations_button_'+ q_id).hide(); - e.preventDefault(); - }); - - //cancelling edit of an annotation - $(".cancel_edit_annotations").click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#edit_annotations_div_'+ q_id).hide(); - $('#show_annotations_div_'+ q_id).show(); - e.preventDefault(); - }); - - //cancelling addition of an annotation - $(".cancel_add_annotations").click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#add_annotations_block_'+ q_id).hide(); - $('#add_annotations_button_'+ q_id).show(); - e.preventDefault(); - }); - - //edit an annotation - $('.edit_form_for_annotations').click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#edit_annotations_div_'+ q_id).show(); - $('#show_annotations_div_'+ q_id).hide(); - e.preventDefault(); - }); - - //GUIDANCE - //action for adding a new guidance next to the question - $('.add_guidance_button').click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#add_guidance_block_'+ q_id).show(); - $('#add_guidance_button_'+ q_id).hide(); - e.preventDefault(); - }); - - //cancelling edit of guidance next to the question - $(".cancel_guidance_answer").click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#edit_guidance_div_'+ q_id).hide(); - $('#show_guidance_div_'+ q_id).show(); - e.preventDefault(); - }); - - //edit guidance next to the question - $('.edit_form_for_guidance').click(function(e){ - var q_id = $(this).prev(".question_id").val(); - $('#edit_guidance_div_'+ q_id).show(); - $('#show_guidance_div_'+ q_id).hide(); - e.preventDefault(); - }); - - }); - - -//remove option when question format is base on a choice -function remove_object(link){ - $(link).prev("input[type=hidden]").val("1"); - $(link).closest(".options_content").hide(); - -} -function add_object(link, association, content) { - var new_id = new Date().getTime(); - var regexp = new RegExp("new_" + association, "g"); - - if (association == 'options') { - $(link).parent().children('.options_table').children('.options_tbody').children('.new_option_before').before(content.replace(regexp, new_id)); - } -} - -// 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 diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js index 94e863e..bb948af 100644 --- a/lib/assets/javascripts/application.js +++ b/lib/assets/javascripts/application.js @@ -24,10 +24,14 @@ import './views/plans/index'; import './views/plans/new'; import './views/plans/share'; -import './views/questions/index'; -import './views/questions/new'; +import './views/sections/edit'; import './views/sections/index'; import './views/sections/new'; +import './views/questions/edit'; +import './views/questions/index'; +import './views/questions/new'; +import './views/questions/show'; +import './views/question_options/index'; import './views/shared/create_account_form'; import './views/shared/sign_in_form'; import './views/templates/edit'; diff --git a/lib/assets/javascripts/utils/isValidInputType.js b/lib/assets/javascripts/utils/isValidInputType.js index 5fcfc94..d31550c 100644 --- a/lib/assets/javascripts/utils/isValidInputType.js +++ b/lib/assets/javascripts/utils/isValidInputType.js @@ -20,7 +20,8 @@ @param value Number to validate */ export const isValidNumber = (value) => { - if (isString(value)) { // Only if is string value we try to convert to Number + if (isString(value) + && value.trim().length > 0) { // Only if is non-empty string value we try to convert to Number // since Number([]), Number(new Date()), Number(null) are converted to zero return !isNaN(Number(value)); } diff --git a/lib/assets/javascripts/views/phases/edit.js b/lib/assets/javascripts/views/phases/edit.js index 6ab9f1e..d3bbefd 100644 --- a/lib/assets/javascripts/views/phases/edit.js +++ b/lib/assets/javascripts/views/phases/edit.js @@ -1,9 +1,11 @@ import 'bootstrap-sass/assets/javascripts/bootstrap/collapse'; import expandCollapseAll from '../../utils/expandCollapseAll'; +import { Tinymce } from '../../utils/tinymce'; $(() => { // Attach handlers for the expand/collapse all accordions expandCollapseAll(); + Tinymce.init({ selector: '.phase' }); $('.phase_show_link').on('click', (e) => { e.preventDefault(); $(e.target).closest('.phase_edit').hide(); diff --git a/lib/assets/javascripts/views/question_options/index.js b/lib/assets/javascripts/views/question_options/index.js new file mode 100644 index 0000000..fbbfc9f --- /dev/null +++ b/lib/assets/javascripts/views/question_options/index.js @@ -0,0 +1,30 @@ +$(() => { + $('.delete_question_option').on('click', (e) => { + e.preventDefault(); + const source = e.target; + $(source).closest('[data-attribute="question_option"]').hide(); + }); + $('.new_question_option').on('click', (e) => { + e.preventDefault(); + const source = e.target; + const last = $(source).closest('[data-attribute="question_options"]').find('[data-attribute="question_option"]').last(); + const cloned = last.clone(true); + const array = $(cloned).find('[id$="_number"]').prop('id').match(/[^\d]*(\d)+[^$]*/); + if (array) { + const index = Number(array[1]); + // Reset values for the new cloned inputs + cloned.find(`[id$="${index}_number"]`).val(index + 2); + cloned.find(`[id$=${index}_text]`).val(''); + cloned.find(`[id$=${index}_is_default]`).prop('checked', false); + cloned.find(`[id$="${index}__destroy"]`).val(false); + cloned.find('input').each((i, el) => { + // Rename id and name for the cloned inputs + $(el).prop('id', $(el).prop('id').replace(/_\d+_/g, `_${index + 1}_`)); + $(el).prop('name', $(el).prop('name').replace(/\[\d+\]/g, `[${index + 1}]`)); + }); + last.after(cloned); + cloned.show(); + } + }); +}); + diff --git a/lib/assets/javascripts/views/questions/edit.js b/lib/assets/javascripts/views/questions/edit.js new file mode 100644 index 0000000..2a12c4b --- /dev/null +++ b/lib/assets/javascripts/views/questions/edit.js @@ -0,0 +1,15 @@ +import { Tinymce } from '../../utils/tinymce'; +import ariatiseForm from '../../utils/ariatiseForm'; +import onChangeQuestionFormat from './sharedEventHandlers'; + +$(() => { + Tinymce.init({ selector: '.question' }); + ariatiseForm({ selector: '.question_form' }); + $('.edit_question_cancel').on('click', (e) => { + e.preventDefault(); + const questionEdit = $(e.target).closest('.question_edit'); + questionEdit.hide(); + questionEdit.parent().find('.question_show').show(); + }); + $('[name="question[question_format_id]"]').on('change', onChangeQuestionFormat); +}); diff --git a/lib/assets/javascripts/views/questions/new.js b/lib/assets/javascripts/views/questions/new.js index 1bf910c..b26541e 100644 --- a/lib/assets/javascripts/views/questions/new.js +++ b/lib/assets/javascripts/views/questions/new.js @@ -1,7 +1,14 @@ +import { Tinymce } from '../../utils/tinymce'; +import ariatiseForm from '../../utils/ariatiseForm'; +import onChangeQuestionFormat from './sharedEventHandlers'; + $(() => { + Tinymce.init({ selector: '.question' }); + ariatiseForm({ selector: '.question_form' }); $('.new_question_cancel').on('click', (e) => { const questionNew = $(e.target).closest('.question_new'); questionNew.hide(); questionNew.closest('.row').find('.question_new_link').show(); }); + $('[name="question[question_format_id]"]').on('change', onChangeQuestionFormat); }); diff --git a/lib/assets/javascripts/views/questions/sharedEventHandlers.js b/lib/assets/javascripts/views/questions/sharedEventHandlers.js new file mode 100644 index 0000000..e29cfea --- /dev/null +++ b/lib/assets/javascripts/views/questions/sharedEventHandlers.js @@ -0,0 +1,32 @@ +const onChangeQuestionFormat = (e) => { + const source = e.target; + const selected = source.value; + const defaultValue = $(source).closest('form').find('[data-attribute="default_value"]'); + const questionOptions = $(source).closest('form').find('[data-attribute="question_options"]'); + switch (selected) { + case '1': + questionOptions.hide(); + defaultValue.show(); + defaultValue.find('[data-attribute="textfield"]').hide(); + defaultValue.find('[data-attribute="textarea"]').show(); + break; + case '2': + questionOptions.hide(); + defaultValue.show(); + defaultValue.find('[data-attribute="textarea"]').hide(); + defaultValue.find('[data-attribute="textfield"]').show(); + break; + case '3': + case '4': + case '5': + case '6': + defaultValue.hide(); + questionOptions.show(); + break; + default : + break; + } +}; + +export { onChangeQuestionFormat as default }; + diff --git a/lib/assets/javascripts/views/questions/show.js b/lib/assets/javascripts/views/questions/show.js new file mode 100644 index 0000000..668c007 --- /dev/null +++ b/lib/assets/javascripts/views/questions/show.js @@ -0,0 +1,8 @@ +$(() => { + $('.question_edit_link').on('click', (e) => { + const source = e.target; + const target = $(source).attr('href'); + $(source).closest('.question_show').hide(); + $(target).show(); + }); +}); diff --git a/lib/assets/javascripts/views/sections/edit.js b/lib/assets/javascripts/views/sections/edit.js new file mode 100644 index 0000000..44a1faa --- /dev/null +++ b/lib/assets/javascripts/views/sections/edit.js @@ -0,0 +1,5 @@ +import { Tinymce } from '../../utils/tinymce'; + +$(() => { + Tinymce.init({ selector: '.section' }); +}); diff --git a/lib/assets/javascripts/views/templates/edit.js b/lib/assets/javascripts/views/templates/edit.js index f98eb3d..eb4de0d 100644 --- a/lib/assets/javascripts/views/templates/edit.js +++ b/lib/assets/javascripts/views/templates/edit.js @@ -1,4 +1,7 @@ +import { Tinymce } from '../../utils/tinymce'; + $(() => { + Tinymce.init({ selector: '.template' }); $('.template_show_link').on('click', (e) => { e.preventDefault(); $(e.target).closest('.template_edit').hide();