diff --git a/app/views/notes/_add.html.erb b/app/views/notes/_add.html.erb new file mode 100644 index 0000000..2817b90 --- /dev/null +++ b/app/views/notes/_add.html.erb @@ -0,0 +1,24 @@ + + +<% + new_note = Note.new + questionid = question.id +%> + +<%= form_for( :new_note, + url: notes_path, + remote: true, + html: {method: :post, class: "add_note_form roadmap-form"}, + id: "new_note_form_#{questionid}") do |f| %> + <%= f.hidden_field :user_id, value: current_user.id %> + <%= f.hidden_field :question_id, value: questionid %> + <%= f.hidden_field :answer_id, value: answer.id %> + <%= f.hidden_field :plan_id, value: plan_id %> + +
+ <%= label_tag "#{questionid}new_note_text", _('Share note with collaborators') %> + <%= text_area_tag "#{questionid}new_note_text", nil, class: "tinymce" %> + <%= tinymce :content_css => asset_path('application.css') %> + +
+<% end %> diff --git a/app/views/notes/_archive.html.erb b/app/views/notes/_archive.html.erb new file mode 100644 index 0000000..eae2154 --- /dev/null +++ b/app/views/notes/_archive.html.erb @@ -0,0 +1,20 @@ +<%= form_for(note, + url: archive_note_path(note), + remote: true, + class: "archive_note_form", + id: "archive_note_form_#{note.id}") do |f| %> + + <%= f.hidden_field :id, :value => note.id %> + <%= f.hidden_field :archived_by, :value => current_user.id %> + + <%= render :partial => "/notes/view", locals: {note: note} %> + +

<%= _('Are you sure you want to remove this note?')%>

+ + +
+ <%= f.submit _('Remove'), onclick: "archive_note(#{note.id}, #{question_id})", :class => "btn btn-primary archive_comment_submit_button" %> + <%= link_to _('Cancel'), "#", onclick: "cancel_archive_note(#{note.id})", :class => "cancel_archive_comment btn cancel" %> +
+
+<% end %> diff --git a/app/views/notes/_edit.html.erb b/app/views/notes/_edit.html.erb new file mode 100644 index 0000000..17a75bc --- /dev/null +++ b/app/views/notes/_edit.html.erb @@ -0,0 +1,15 @@ + + +<%= form_for(note, + url: note_path(note), + remote: true, + html: {method: :put, class: "edit_note_form roadmap-form"}, + id: "edit_note_form_#{note.id}") do |f| %> + +
+ <%= f.hidden_field :id, :value => note.id %> + + <%= text_area_tag("#{note.id}_note_text".to_sym, note.text , class: "tinymce") %> + <%= f.submit _('Save'), :class => "form-submit edit_note_submit_button" %> +
+<%end%> diff --git a/app/views/notes/_list.html.erb b/app/views/notes/_list.html.erb new file mode 100644 index 0000000..daf6a20 --- /dev/null +++ b/app/views/notes/_list.html.erb @@ -0,0 +1,85 @@ + + +<% if notes.count > 1 then%> + <% style_to_add = "height:150px; overflow-y:auto;" %> +<%else%> + <% style_to_add = "" %> +<%end%> + +
+ +
+ + + <% notes.each do |note|%> + + + + + <%end%> + +
+ <% user = note.user.name %> + <%= user %>
+ (<%= l note.updated_at, format: :custom %>) +
+ + <% if note.archived %> + + <% if note.archived_by == current_user.id %> + <%= _('Note removed by you')%> + <% else %> + <% archived_by_user = User.find(note.archived_by) %> + <%= _('Note removed by')%> <%= archived_by_user.name %> + <%end%> + + <%else%> + + <%= link_to _('View'),"#question-form-#{question_id}", onclick: "view_note_button(#{note.id}, #{question_id})", :class => "dmp_table_link view_comment_button" %> + + <% if current_user.id == note.user_id %> + <%= link_to _('Edit'),"#question-form-#{question_id}", onclick: "edit_note(#{note.id}, #{question_id})", :class => "dmp_table_link edit_comment_button" %> + <%= link_to _('Remove'),"#question-form-#{question_id}", onclick: "archive_note(#{note.id}, #{question_id})", :class => "dmp_table_link archive_comment_button" %> + <% end%> + + <% if plan.administerable_by?(current_user.id) && current_user.id != note.user_id %> + <%= hidden_field_tag :note_id, note.id, :class => "comment_id" %> + <%= link_to _('Remove'),"#question-form-#{question_id}", onclick: "archive_note(#{note.id}, #{question_id})", :class => "dmp_table_link archive_comment_button" %> + <% end%> + <%end%> + +
+
+ +
+ + +<% notes_not_archived = notes.select { |n| n.archived.nil? } %> +<% latest_note = notes_not_archived.sort { |x,y| y.updated_at <=> x.updated_at }.first %> +<% if !latest_note.nil? then%> +
+ <%= render :partial => "/notes/view", locals: {note: latest_note} %> +
+
+<%end%> + +<%notes.each do |note|%> + + + + + + + + + +<%end%> diff --git a/app/views/notes/_view.html.erb b/app/views/notes/_view.html.erb new file mode 100644 index 0000000..0610f0c --- /dev/null +++ b/app/views/notes/_view.html.erb @@ -0,0 +1,11 @@ + +<% user = User.find(note.user_id) %> +
+
+
+ +
diff --git a/app/views/phases/_add_note.html.erb b/app/views/phases/_add_note.html.erb deleted file mode 100644 index 2817b90..0000000 --- a/app/views/phases/_add_note.html.erb +++ /dev/null @@ -1,24 +0,0 @@ - - -<% - new_note = Note.new - questionid = question.id -%> - -<%= form_for( :new_note, - url: notes_path, - remote: true, - html: {method: :post, class: "add_note_form roadmap-form"}, - id: "new_note_form_#{questionid}") do |f| %> - <%= f.hidden_field :user_id, value: current_user.id %> - <%= f.hidden_field :question_id, value: questionid %> - <%= f.hidden_field :answer_id, value: answer.id %> - <%= f.hidden_field :plan_id, value: plan_id %> - -
- <%= label_tag "#{questionid}new_note_text", _('Share note with collaborators') %> - <%= text_area_tag "#{questionid}new_note_text", nil, class: "tinymce" %> - <%= tinymce :content_css => asset_path('application.css') %> - -
-<% end %> diff --git a/app/views/phases/_answer_form.html.erb b/app/views/phases/_answer_form.html.erb index dfa1d6c..a6981b2 100644 --- a/app/views/phases/_answer_form.html.erb +++ b/app/views/phases/_answer_form.html.erb @@ -34,42 +34,30 @@
<% comments = answer.notes.all %> <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <% active_tab = nil %>
- -
+ +
@@ -120,9 +108,9 @@ <% end %>
-
- -
+
+ +
<%= render partial: "note", locals: {question: question, answer: answer, plan: plan, suffix: "" }%>
diff --git a/app/views/phases/_archive_note.html.erb b/app/views/phases/_archive_note.html.erb deleted file mode 100644 index 0e7b244..0000000 --- a/app/views/phases/_archive_note.html.erb +++ /dev/null @@ -1,21 +0,0 @@ - -<%= form_for(note, - url: archive_note_path(note), - remote: true, - class: "archive_note_form", - id: "archive_note_form_#{note.id}") do |f| %> - - <%= f.hidden_field :id, :value => note.id %> - <%= f.hidden_field :archived_by, :value => current_user.id %> - - <%= render :partial => "/phases/view_note", locals: {note: note} %> - -

<%= _('Are you sure you want to remove this note?')%>

- - -
- <%= f.submit _('Remove'), onclick: "archive_note(#{note.id}, #{question_id})", :class => "btn btn-primary archive_comment_submit_button" %> - <%= link_to _('Cancel'), "#", onclick: "cancel_archive_note(#{note.id})", :class => "cancel_archive_comment btn cancel" %> -
-
-<% end %> diff --git a/app/views/phases/_edit_note.html.erb b/app/views/phases/_edit_note.html.erb deleted file mode 100644 index 17a75bc..0000000 --- a/app/views/phases/_edit_note.html.erb +++ /dev/null @@ -1,15 +0,0 @@ - - -<%= form_for(note, - url: note_path(note), - remote: true, - html: {method: :put, class: "edit_note_form roadmap-form"}, - id: "edit_note_form_#{note.id}") do |f| %> - -
- <%= f.hidden_field :id, :value => note.id %> - - <%= text_area_tag("#{note.id}_note_text".to_sym, note.text , class: "tinymce") %> - <%= f.submit _('Save'), :class => "form-submit edit_note_submit_button" %> -
-<%end%> diff --git a/app/views/phases/_list_notes.html.erb b/app/views/phases/_list_notes.html.erb deleted file mode 100644 index 56a8b96..0000000 --- a/app/views/phases/_list_notes.html.erb +++ /dev/null @@ -1,85 +0,0 @@ - - -<% if notes.count > 1 then%> - <% style_to_add = "height:150px; overflow-y:auto;" %> -<%else%> - <% style_to_add = "" %> -<%end%> - -
- -
- - - <% notes.each do |note|%> - - - - - <%end%> - -
- <% user = note.user.name %> - <%= user %>
- (<%= l note.updated_at, format: :custom %>) -
- - <% if note.archived %> - - <% if note.archived_by == current_user.id %> - <%= _('Note removed by you')%> - <% else %> - <% archived_by_user = User.find(note.archived_by) %> - <%= _('Note removed by')%> <%= archived_by_user.name %> - <%end%> - - <%else%> - - <%= link_to _('View'),"#question-form-#{question_id}", onclick: "view_note_button(#{note.id}, #{question_id})", :class => "dmp_table_link view_comment_button" %> - - <% if current_user.id == note.user_id %> - <%= link_to _('Edit'),"#question-form-#{question_id}", onclick: "edit_note(#{note.id}, #{question_id})", :class => "dmp_table_link edit_comment_button" %> - <%= link_to _('Remove'),"#question-form-#{question_id}", onclick: "archive_note(#{note.id}, #{question_id})", :class => "dmp_table_link archive_comment_button" %> - <% end%> - - <% if plan.administerable_by?(current_user.id) && current_user.id != note.user_id %> - <%= hidden_field_tag :note_id, note.id, :class => "comment_id" %> - <%= link_to _('Remove'),"#question-form-#{question_id}", onclick: "archive_note(#{note.id}, #{question_id})", :class => "dmp_table_link archive_comment_button" %> - <% end%> - <%end%> - -
-
- -
- - -<% notes_not_archived = notes.select { |n| n.archived.nil? } %> -<% latest_note = notes_not_archived.sort { |x,y| y.updated_at <=> x.updated_at }.first %> -<% if !latest_note.nil? then%> -
- <%= render :partial => "/phases/view_note", locals: {note: latest_note} %> -
-
-<%end%> - -<%notes.each do |note|%> - - - - - - - - - -<%end%> diff --git a/app/views/phases/_note.html.erb b/app/views/phases/_note.html.erb index 5cc8df3..c296d9b 100644 --- a/app/views/phases/_note.html.erb +++ b/app/views/phases/_note.html.erb @@ -1,6 +1,3 @@ - - <% if answer.present? && answer.notes.any? %> <% notes = answer.notes.all.to_a.sort! {|x,y| y.updated_at <=> x.updated_at } %> <% questionid = question.id %> @@ -18,15 +15,15 @@
- <%= render :partial => "/phases/list_notes", locals: {question_id: question.id, notes: notes, plan: plan} %> + <%= render :partial => "/notes/list", locals: {question_id: question.id, notes: notes, plan: plan} %>
<% else%> - <%= render :partial => "/phases/add_note", locals: {answer: answer, question: question, plan_id: plan.id }%> + <%= render :partial => "/notes/add", locals: {answer: answer, question: question, plan_id: plan.id }%> <% end%> diff --git a/app/views/phases/_show_phase.html b/app/views/phases/_show_phase.html new file mode 100644 index 0000000..ecb5dd4 --- /dev/null +++ b/app/views/phases/_show_phase.html @@ -0,0 +1,37 @@ + + +

+ <%= _('Phase details')%> + + + <% if @phase.modifiable && @edit %> +
+ <%= link_to _('Edit phase details'), '#', class: "btn btn-primary", id: "edit_phase_button"%> +
+ <% end %> +

+ +<% if @phase.template.org.not_funder %> +
+ <%= raw _('

Here you set the title that users will see. If you intend to have multiple phases for you DMP, this should be clear in the title and description.

')%> +

+<% end %> + +
+
+ + + + + + + + + + + + + + +
<%= _('Title') %><%= @phase.title %>
<%= _('Order of display') %><%= @phase.number %>
<%= _('Description') %><%= raw @phase.description %>
+
diff --git a/app/views/phases/_show_phase.html.erb b/app/views/phases/_show_phase.html.erb deleted file mode 100644 index ecb5dd4..0000000 --- a/app/views/phases/_show_phase.html.erb +++ /dev/null @@ -1,37 +0,0 @@ - - -

- <%= _('Phase details')%> - - - <% if @phase.modifiable && @edit %> -
- <%= link_to _('Edit phase details'), '#', class: "btn btn-primary", id: "edit_phase_button"%> -
- <% end %> -

- -<% if @phase.template.org.not_funder %> -
- <%= raw _('

Here you set the title that users will see. If you intend to have multiple phases for you DMP, this should be clear in the title and description.

')%> -

-<% end %> - -
-
- - - - - - - - - - - - - - -
<%= _('Title') %><%= @phase.title %>
<%= _('Order of display') %><%= @phase.number %>
<%= _('Description') %><%= raw @phase.description %>
-
diff --git a/app/views/phases/_view_note.html.erb b/app/views/phases/_view_note.html.erb deleted file mode 100644 index 0610f0c..0000000 --- a/app/views/phases/_view_note.html.erb +++ /dev/null @@ -1,11 +0,0 @@ - -<% user = User.find(note.user_id) %> -
-
-
- -
diff --git a/app/views/phases/edit.html.erb b/app/views/phases/edit.html.erb index 8ddbcc2..7b61c33 100644 --- a/app/views/phases/edit.html.erb +++ b/app/views/phases/edit.html.erb @@ -1,6 +1,7 @@ <%- model_class = Plan -%> <% javascript "plans.js" %> <% javascript "answers/status.js" %> +<% javascript "notes/index.js" %> - <% if session[:question_id_comments].to_i != 0 then %> - <% question_from_comment = Question.find(session[:question_id_comments])%> - <% if sectionid == question_from_comment.section_id then %> - <%= hidden_field_tag :comment_section_id, question_from_comment.section_id, :class => "comment_section_id" %> - <%end%> - <% end%> -
@@ -123,6 +116,3 @@
<%= render :partial => "plans/export", locals: {plan: @plan, plan_data: @plan_data, phase: @phase } %> - - -<% session.delete(:question_id_comments)%> diff --git a/config/application.rb b/config/application.rb index 5693427..728a5cb 100644 --- a/config/application.rb +++ b/config/application.rb @@ -83,6 +83,7 @@ config.assets.precompile += %w(contacts/new_contact.js) config.assets.precompile += %w(shared/register_form.js) config.assets.precompile += %w(answers/status.js) + config.assets.precompile += %w(notes/index.js) config.autoload_paths += %W(#{config.root}/lib) config.action_controller.include_all_helpers = true diff --git a/lib/assets/javascripts/notes/index.js b/lib/assets/javascripts/notes/index.js new file mode 100644 index 0000000..dfcb5b2 --- /dev/null +++ b/lib/assets/javascripts/notes/index.js @@ -0,0 +1,77 @@ +// the "add note" button +/*---------------- + Invoked at app/views/phases/_note.html.erb L.14 +------------------*/ +function add_note_button(q_id){ + $(".alert-notice").hide(); + $('.view_comment_class').hide(); + $('.edit_comment_class').hide(); + $('.archive_comment_class').hide(); + //$('#add_comment_button_bottom_div_'+ q_id).hide(); + $('#add_comment_button_top_div_'+ q_id).hide(); + //$('#{questionid}new_note_text').text(""); + $('#add_comment_block_div_'+ q_id).show(); +} + +// the "view" link +/*---------------- + Invoked at app/views/phases/_list_notes.html.erb L.34 +------------------*/ +function view_note_button(c_id, q_id){ + $(".alert-notice").hide(); + $('.view_comment_class').hide(); + $('.edit_comment_class').hide(); + $('.archive_comment_class').hide(); + $('#lastet_comment_div_'+ q_id).hide(); + $('#edit_comment_div_'+ c_id).hide(); + $('#archive_comment_div_'+ c_id).hide(); + $('#add_comment_block_div_'+ q_id).hide(); + $('#view_comment_div_'+ c_id).show(); + $('#add_comment_button_top_div_'+ q_id).show(); +} + + +// the "edit" link +/*---------------- + Invoked at app/views/phases/_list_notes.html.erb L.37 +------------------*/ +function edit_note(c_id, q_id){ + $('.edit_comment_class').hide(); + $('.view_comment_class').hide(); + $('.archive_comment_class').hide(); + $('#lastet_comment_div_'+ q_id).hide(); + $('#view_comment_div_'+ c_id).hide(); + $('#archive_comment_div_'+ c_id).hide(); + $('#add_comment_block_div_'+ q_id).hide(); + $('#edit_comment_div_'+ c_id).show(); + $('#add_comment_button_top_div_'+ q_id).show(); +} + + +//the "remove" link +/*---------------- + Invoked at app/views/phases/_archive_note.html.erb L.17 + Invoked at app/views/phases/_list_notes.html.erb L.38 + Invoked at app/views/phases/_list_notes.html.erb L.43 +------------------*/ +function archive_note(c_id, q_id){ + $('.edit_comment_class').hide(); + $('.view_comment_class').hide(); + $('.archive_comment_class').hide(); + $('#view_comment_div_'+ c_id).hide(); + $('#lastet_comment_div_'+ q_id).hide(); + $('#edit_comment_div_'+ c_id).hide(); + $('#add_comment_block_div_'+ q_id).hide(); + $('#archive_comment_div_'+ c_id).show() + $('#add_comment_button_top_div_'+ q_id).show(); +} + +// cancel remove +/*---------------- + Invoked at app/views/phases/_archive_note.html.erb L.18 +------------------*/ +function cancel_archive_note(c_id) { + var c_id = $(this).prev(".comment_id").val(); + $('.archive_comment_class').hide(); + $('#view_comment_div_'+ c_id).show(); +} \ No newline at end of file diff --git a/lib/assets/javascripts/plans.js b/lib/assets/javascripts/plans.js index 5837312..8f0762a 100644 --- a/lib/assets/javascripts/plans.js +++ b/lib/assets/javascripts/plans.js @@ -1,149 +1,7 @@ - - -var dirty = {}; - - - -// functions added to buttons and links in the notes section of the answer form - -// the "add note" button -function add_note_button(q_id){ - $(".alert-notice").hide(); - $('.view_comment_class').hide(); - $('.edit_comment_class').hide(); - $('.archive_comment_class').hide(); - //$('#add_comment_button_bottom_div_'+ q_id).hide(); - $('#add_comment_button_top_div_'+ q_id).hide(); - //$('#{questionid}new_note_text').text(""); - $('#add_comment_block_div_'+ q_id).show(); -} - -// the "view" link -function view_note_button(c_id, q_id){ - $(".alert-notice").hide(); - $('.view_comment_class').hide(); - $('.edit_comment_class').hide(); - $('.archive_comment_class').hide(); - $('#lastet_comment_div_'+ q_id).hide(); - $('#edit_comment_div_'+ c_id).hide(); - $('#archive_comment_div_'+ c_id).hide(); - $('#add_comment_block_div_'+ q_id).hide(); - $('#view_comment_div_'+ c_id).show(); - $('#add_comment_button_top_div_'+ q_id).show(); -} - - -// the "edit" link -function edit_note(c_id, q_id){ - $('.edit_comment_class').hide(); - $('.view_comment_class').hide(); - $('.archive_comment_class').hide(); - $('#lastet_comment_div_'+ q_id).hide(); - $('#view_comment_div_'+ c_id).hide(); - $('#archive_comment_div_'+ c_id).hide(); - $('#add_comment_block_div_'+ q_id).hide(); - $('#edit_comment_div_'+ c_id).show(); - $('#add_comment_button_top_div_'+ q_id).show(); -} - - -//the "remove" link -function archive_note(c_id, q_id){ - $('.edit_comment_class').hide(); - $('.view_comment_class').hide(); - $('.archive_comment_class').hide(); - $('#view_comment_div_'+ c_id).hide(); - $('#lastet_comment_div_'+ q_id).hide(); - $('#edit_comment_div_'+ c_id).hide(); - $('#add_comment_block_div_'+ q_id).hide(); - $('#archive_comment_div_'+ c_id).show() - $('#add_comment_button_top_div_'+ q_id).show(); -} - -// cancel remove -function cancel_archive_note(c_id) { - var c_id = $(this).prev(".comment_id").val(); - $('.archive_comment_class').hide(); - $('#view_comment_div_'+ c_id).show(); -} - - - - -// adding functionality on page load - -$( document ).ready(function() { - - //reload page back to where it was before committing comment - - if($('#comment_section_id').length) { - var section_id = $('#comment_section_id').val(); - - $("#collapse-" + section_id).addClass("in"); - $("#collapse-" + section_id).children(".accordion-inner").find(".loading").show(); - $("#collapse-" + section_id).children(".accordion-inner").find(".loaded").hide(); - - setTimeout(function(){ - $("loaded").find(".section-lock-notice").html(""); - $("loaded").find(".section-lock-notice").hide(); - $(".question-form").find("select").removeAttr('disabled'); - $(".question-div").find(".question-readonly").hide(); - $(".question-div").find(".question-form").show(); - - $("#collapse-" + section_id).children(".accordion-inner").find(".loading").hide(); - $("#collapse-" + section_id).children(".accordion-inner").find(".loaded").show(); - $('html, body').animate({ - 'scrollTop': $("#current_question").offset().top - },1000); - },8000); - } - - window.onbeforeunload = function(){ - var message = null; - if ($.fn.is_dirty()) { - var questions = $.fn.get_unsaved_questions(); - message = __('You have unsaved answers in the following sections:') - $.each(questions, function(section_text, question_texts){ - message += "\n\u2022"+section_text; - }); - return message; - } - }; - - //accordion guidance - $('.accordion-guidance-link').on('click', function (e) { - e.stopPropagation(); - var show = true; - var div_to_toggle = $($(this).attr("href")); - if (div_to_toggle.hasClass('in')) { - show = false; - } - $($(this).attr("href")).toggleClass("in"); - if (show) { - $(this).children(".plus-laranja").removeClass("plus-laranja").addClass("minus-laranja"); - } - else { - $(this).children(".minus-laranja").removeClass("minus-laranja").addClass("plus-laranja"); - } - delete show; - delete div_to_toggle; - e.preventDefault(); - }); - - - // Handle section actions on accordion expansion/collapse - $('.section-collapse').on('hide', function(){ - var section = $(this); - var section_id = section.attr("id").split('-')[1]; - if ($.fn.is_dirty(section_id)) { - $('#unsaved-answers-'+section_id).text(""); - $.each($.fn.get_unsaved_questions(section_id), function(index, question_text){ - $('#unsaved-answers-'+section_id).append("
  • "+question_text+"
  • "); - }); - $('#section-' + section_id + '-collapse-alert').modal(); - } - }); - +$(document).ready(function() { + /*---------------- + Popup button listeners for when answers are not saved + ------------------*/ $(".cancel-section-collapse").click(function () { var section_id = $(this).attr('data-section'); $("#collapse-" + section_id).collapse("show"); @@ -160,209 +18,35 @@ $("#collapse-" + section_id).find("input[type='submit']").click(); $('#section-' + section_id + '-collapse-alert').modal("hide"); }); - - // COMMENTS Javascript - - //action for show comment block on the right side of a question - $('.comments_accordion_button').click(function(e){ - var q_id = $(this).closest(".question_right_column_nav").find(".question_id").val(); - $(this).parent().addClass("active"); - $(this).closest(".question_right_column_ul").find(".guidance_tab_class").removeClass("active"); - $('#guidance-question-area-'+ q_id).hide(); - $('#comment-question-area-'+ q_id).show(); + /*---------------- + Listener for clicks in any of the right column of question tabs (e.g. Guidances, Notes) + ------------------*/ + $('.right_column_tab_link').click(function(e){ e.preventDefault(); + // Find current active tab and hide it + var active = $(this).closest('.question_right_column_ul').children().filter('.active'); + active.removeClass('active'); + $(this).closest('.question-area-right-column').find('div.'+active.attr('class')).hide(); + // Select the clicked tab as active and display its content + active = $(this).parent(); + $(this).closest('.question-area-right-column').find('div.'+active.attr('class')).show(); + active.addClass('active'); }); - - //action for show guidance block on the right side of a question - $('.guidance_accordion_button').click(function(e){ - var q_id = $(this).closest(".question_right_column_nav").find(".question_id").val(); - $(this).parent().addClass("active"); - $(this).closest(".question_right_column_ul").find(".comment_tab_class").removeClass("active"); - $('#comment-question-area-'+ q_id).hide(); - $('#guidance-question-area-'+ q_id).show(); + /*---------------- + Accordion toggling for displaying/hiding guidances. + TODO moving to lib/assets/javascripts/annotations when partials for guidances are created + ------------------*/ + $('.accordion-guidance-link').on('click', function (e) { + e.stopPropagation(); e.preventDefault(); + var accordion_body = $($(this).attr("href")); + accordion_body.toggleClass("in"); //adds or removes 'in' class from accordion_body + if(accordion_body.hasClass('in')){ //accordion expanded + $(this).children(".plus-laranja").removeClass("plus-laranja").addClass("minus-laranja"); //display minus + } + else { //accordion collapsed + $(this).children(".minus-laranja").removeClass("minus-laranja").addClass("plus-laranja"); //display plus + } }); }); -$.fn.get_unsaved_questions = function(section_id) { - if (section_id != null) { - var questions = new Array(); - $.each(dirty[section_id], function(question_id,value){ - if (value && question_id != 'undefined') { - questions.push($("label[for='answer-text-"+question_id+"']").text()); - } - }); - return questions; - } - else { - var questions = {}; - $.each(dirty, function(section_id,question_ids){ - var section_text = $("#section-header-"+section_id).clone().children().remove().end().text().trim(); - questions[section_text] = new Array(); - $.each(question_ids, function(question_id,value){ - if (value && question_id != 'undefined') { - questions[section_text].push($("label[for='answer-text-"+question_id+"']").text()); - } - }); - }); - return questions; - } -}; - -$.fn.is_dirty = function(section_id, question_id) { - if (section_id != null) { - if (dirty[section_id] != null) { - if (question_id != null) { - if (dirty[section_id][question_id] != null) { - return dirty[section_id][question_id]; - } - else { - return false; - } - } - else { - var is_dirty = false; - $.each(dirty[section_id], function(question_id, value){ - if (value && question_id != 'undefined') { - is_dirty = true; - } - }); - return is_dirty; - } - } - } - else { - var is_dirty = false; - $.each(dirty, function(section_id, questions){ - $.each(questions, function(question_id, value){ - if (value && question_id != 'undefined') { - is_dirty = true; - } - }); - }); - return is_dirty; - } - return false; -}; - - -$.fn.update_section_progress = function(data) { - s_id = $(this).attr("id").split('-')[0]; - s_qs = data.sections[s_id]["num_questions"]; - question_word = "questions" - if (s_qs == 1) { - question_word = "question"; - } - s_as = data.sections[s_id]["num_answers"]; - $(this).text("("+s_qs+" "+question_word+", "+s_as+" answered)"); - if (s_qs == s_as) { - $(this).removeClass("label-warning"); - $(this).addClass("label-info"); - } -}; - -$.fn.update_plan_progress = function(data) { - $("#questions-progress").css("width", (data.num_answers/data.num_questions*100)+"%"); - $("#questions-progress-title").text(data.num_answers+"/"+data.num_questions + " " + __('questions answered')); - $('#export-progress').css('width', data.space_used + '%'); - $("#export-progress-title").text(__('approx. %{space_used}% of available space used', {space_used: data.space_used})); - if (data.space_used >= 100) { - $('#export-progress').removeClass("space"); - $('#export-progress').addClass("full"); - $('#export-progress-title').addClass("bar-full-text"); - } - else { - $('#export-progress').removeClass("full"); - $('#export-progress').addClass("space"); - $('#export-progress-title').removeClass("bar-full-text"); - } -}; - -$.fn.update_question_timestamp = function(question_id) { - q_status = $('#'+question_id+'-status'); - var t = q_status.children("abbr:first"); - var timestamp = new Date(t.attr('data-time')); - if (timestamp != null) { - timestamp = new Date(Number(timestamp) * 1000); - q_status.text(""); - q_status.append( __('Answered') + " " + __(' by ') + data.questions[question_id]["answered_by"]); - t = q_status.children("abbr:first"); - // Update label to indicate successful submission - q_status.removeClass("label-info label-warning"); - q_status.addClass("label-success"); - // Set timestamp text and data - t.text(timestamp.toUTCString()); - //t.attr('title', timestamp.toISOString()).data("timeago",null).timeago(); - t.attr('data-time', timestamp.toISOString()); - return true; - } - return false; -}; - -$.fn.update_timestamp = function(question_id, data) { - q_status = $('#'+question_id+'-status'); - var t = q_status.children("abbr:first"); - var current_timestamp = new Date(t.attr('data-time')); - var timestamp = data.questions[question_id]["answer_updated_at"]; - if (timestamp != null) { - timestamp = new Date(Number(timestamp) * 1000); - if (timestamp.getTime() != current_timestamp.getTime()) { - q_status.text(""); - q_status.append( __('Answered') + " " + __(' by ') + data.questions[question_id]["answered_by"]); - t = q_status.children("abbr:first"); - // Update label to indicate successful submission - q_status.removeClass("label-info label-warning"); - q_status.addClass("label-success"); - // Set timestamp text and data - t.text(timestamp.toUTCString()); - //t.attr('title', timestamp.toISOString()).data("timeago",null).timeago(); - t.attr('data-time', timestamp.toISOString()); - return true; - } - } - return false; -}; - -// TODO: Should we drop this now that the locking check has been removed? -$.fn.check_section_lock = function() { - var section = $(this); - var section_id = section.attr("id").split('-')[1]; - $.getJSON("locked?section_id="+section_id, function(data) { - if (data.locked) { - section.find(".section-lock-notice").html("

    " + __('This section is locked for editing by ') + data.locked_by + ".

    "); - section.find(".section-lock-notice").show(); - section.find("input").attr('disabled', 'disabled'); - section.find(".question-form").hide(); - section.find("select").attr('disabled', 'disabled'); - section.find(".question-readonly").show(); - } - else { - // LIBDMP-137 - // Changed post request 'lock_section' to 'lock_section.json'. 'lock_section' unnecessary returns a huge html response and takes a quite lot of time to process(3sec) lowering server - // performance when there are large number of concurrent users. - $.post('lock_section', {section_id: section_id} ); - section.find(".section-lock-notice").html(""); - section.find(".section-lock-notice").hide(); - section.find("input").removeAttr('disabled'); - section.find(".question-form").show(); - section.find("select").removeAttr('disabled'); - section.find(".question-readonly").hide(); - } - }); - return true; -}; - -$.fn.toggle_dirty = function(question_id, is_dirty) { - console.log($(this)); - section_id = $(this).attr("id").split('-')[0]; - if (dirty[section_id] == null) { - dirty[section_id] = {}; - } - dirty[section_id][question_id] = is_dirty; - if (is_dirty) { - $("#"+question_id+"-unsaved").show(); - } - else { - $("#"+question_id+"-unsaved").hide(); - } -};