diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index c60fbd3..498603b 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -36,6 +36,41 @@ @answer.update(params[:answer]) end + @section_id = @answer.question.section.id + + # these are used for updating the status line + @username = @answer.user.name + @timestamp = "" + + if @answer.text.present? + @timestamp = @answer.updated_at.iso8601 + end + + + @nquestions = 0 + @nanswers = 0 + @n_section_questions = 0 + @n_section_answers = 0 + + plan = Plan.find(plan_id) + plan.template.phases.each do |phase| + phase.sections.each do |section| + section.questions.each do |question| + @nquestions += 1 + if section.id == @section_id + @n_section_questions += 1 + end + question.answers = question.answers.to_a.select {|answer| answer.plan_id == plan.id} + if question.answers.present? && question.answers.first.text.present? + @nanswers += 1 + if section.id == @section_id + @n_section_answers += 1 + end + end + end + end + end + respond_to do |format| # pass new lock_version back to the client or they'll never save again @lock_version = @answer.lock_version @@ -49,4 +84,5 @@ format.js {} end end + end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 40f5e32..3653f4b 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -2,18 +2,19 @@ after_action :verify_authorized respond_to :html - ## - # POST /notes + require "pp" + def create @note = Note.new user_id = params[:new_note][:user_id] @note.user_id = user_id - answer_id = params[:new_note][:answer_id] question_id = params[:new_note][:question_id] plan_id = params[:new_note][:plan_id] + + # create answer if we dont already have one if answer_id.present? - answer = Answer.find(@note.answer_id) + answer = Answer.find(answer_id) else answer = Answer.new answer.plan_id = plan_id @@ -23,49 +24,53 @@ end @note.answer= answer - @note.text = params["#{params[:new_note][:answer_id]}new_note_text"] + @note.text = params["#{question_id}new_note_text"] authorize @note @plan = answer.plan - @phase = answer.question.section.phase + @notice = "Save failed." + @answer = answer + @question = Question.find(question_id) if @note.save - session[:question_id_notes] = answer.question_id - redirect_to edit_plan_phase_path(@plan, @phase), status: :found, notice: _('Comment was successfully created.') + @status = true + @notice = _('Comment was successfully created.') end + notes = answer.notes.all + @num_notes = notes.count end - ## - # PUT /notes/1 + + def update @note = Note.find(params[:note][:id]) authorize @note @note.text = params["#{params[:note][:id]}_note_text"] - @plan = Plan.find(@note.plan_id) - @project = Project.find(@plan.project_id) + @answer = @note.answer + @question = @answer.question + @plan = @answer.plan if @note.update_attributes(params[:note]) - session[:question_id_notes] = @note.question_id - redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: _('Comment was successfully updated.') + @notice = _('Comment was successfully saved.') end end - ## - # ARCHIVE /notes/1 + + def archive @note = Note.find(params[:note][:id]) authorize @note @note.archived = true @note.archived_by = params[:note][:archived_by] - @plan = Plan.find(@note.plan_id) - @project = Project.find(@plan.project_id) + @answer = @note.answer + @question = @answer.question + @plan = @answer.plan if @note.update_attributes(params[:note]) - session[:question_id_notes] = @note.question_id - redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: _('Comment has been removed.') + @notice = _('Comment removed.') end end end diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index afe9711..f1890ca 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -15,14 +15,22 @@ # the eager_load pulls in ALL answers # need to restrict to just ones for this plan + # at the same time count the questions and answers for the status + @nquestions = 0 + @nanswers = 0 + @plan.template.phases.each do |phase| - phase.sections do |section| + phase.sections.each do |section| section.questions.each do |question| + @nquestions += 1 question.answers = question.answers.to_a.select {|answer| answer.plan_id == @plan.id} + if question.answers.present? && question.answers.first.text.present? + @nanswers += 1 + end end end end - + # Now we need to get all the themed guidance for the plan. # TODO: think this through again, there may be a better way to do this. # diff --git a/app/policies/note_policy.rb b/app/policies/note_policy.rb index 8ffe95a..88a9e11 100644 --- a/app/policies/note_policy.rb +++ b/app/policies/note_policy.rb @@ -13,11 +13,11 @@ end def update? - Plan.find(@note.plan_id).readable_by?(@user.id) + Plan.find(@note.answer.plan_id).readable_by?(@user.id) end def archive? - Plan.find(@note.plan_id).readable_by?(@user.id) + Plan.find(@note.answer.plan_id).readable_by?(@user.id) end end diff --git a/app/views/answers/update.js.erb b/app/views/answers/update.js.erb index 781c176..3ddb49f 100644 --- a/app/views/answers/update.js.erb +++ b/app/views/answers/update.js.erb @@ -3,11 +3,9 @@ // On success this will be "" on error it will be the // conflicting answer -//$("#answer_notice").html("<%= raw @message %>"); - -<%if @message %> - $("#answer_notice-<%=@question.id%>").html(<%= @message %>) %>"); -<% end %> +// go back from "Saving..." message to "Save" button +$("#saving-<%=@question.id%>").hide(); +$("#saving-<%=@question.id%>").prev().show(); <% if @old_answer %> $("#answer_notice_<%=@question.id%>").html("<%= escape_javascript(render partial: '/phases/answer', locals: { question: @question, answer: @old_answer}) %>"); @@ -20,3 +18,24 @@ // this it will fail forever. $("#answer_lock_version-<%=@question.id%>").val(<%= @lock_version %>); + +// update the answer status + +var q_status = $("#<%=@question.id%>-status"); +var timestamp = "<%=@timestamp%>"; + +if( timestamp != "") { + q_status.text(""); + // TODO: i18n this + q_status.append( "Answered \" title=\"<%=@timestamp%>\"><%=@timestamp%> by <%=@username%>"); + $('abbr.timeago').timeago(); +} + + +// update plan progress bar +$(".progress").html("<%= escape_javascript(render :partial => "/plans/progress", locals: {nquestions: @nquestions, nanswers: @nanswers}) %>"); + + +// update the section progress message +//TODO: I18n this +$("#<%=@section_id%>-status").html("(<%=@n_section_questions%> questions, <%=@n_section_answers%> answered)"); diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e8a3467..6afcffb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -62,6 +62,8 @@ <%= render "layouts/header" %> + +
<% if notice %>

<%= notice %>

diff --git a/app/views/notes/archive.js.erb b/app/views/notes/archive.js.erb new file mode 100644 index 0000000..f2687fa --- /dev/null +++ b/app/views/notes/archive.js.erb @@ -0,0 +1,29 @@ + +// remove all tinymce explicitly or re-init will not work later +tinymce.remove(".tinymce"); + +// render the list of notes and invisible view and edit sections +<% listlabel = "#comment-question-area-#{@question.id}" %> +$("<%=listlabel%>").html( + "<%= escape_javascript( render partial: '/phases/note', locals: {question: @question, answer: @answer, plan: @plan } ) %>" +); + +// TODO: this duplicates what is in the .yml file +// DRY it out! +tinymce.init({ + selector: ".tinymce", + statusbar: false, + menubar: false, + toolbar: "bold italic | bullist numlist | link | table", + plugins: [ "table", "link", "paste" ], + target_list: false, + autoresize_min_height: 130, + extended_valid_elements: [ "a[href|target=_blank]" ], + paste_auto_cleanup_on_paste : true, + paste_remove_styles: true, + paste_retain_style_properties: "none", + paste_convert_middot_lists: true, + paste_remove_styles_if_webkit: true, + paste_remove_spans: true, + paste_strip_class_attributes: "all" +}); diff --git a/app/views/notes/create.js.erb b/app/views/notes/create.js.erb new file mode 100644 index 0000000..4cd1b85 --- /dev/null +++ b/app/views/notes/create.js.erb @@ -0,0 +1,31 @@ + +// rewrite the number of notes heading e.g. Notes(3) +<% noteslabel = "#notes_number_#{@question.id}" %> +$("<%=noteslabel%>").html("Notes (<%= @num_notes %>)"); + +// need to remove the existing tinymce editor otherwise +tinymce.remove(".tinymce"); + +// render the list of notes and invisible view and edit sections +<% listlabel = "#comment-question-area-#{@question.id}" %> +$("<%=listlabel%>").html( + "<%= escape_javascript( render partial: '/phases/note', locals: {question: @question, answer: @answer, plan: @plan } ) %>" +); + +tinymce.init({ + selector: ".tinymce", + statusbar: false, + menubar: false, + toolbar: "bold italic | bullist numlist | link | table", + plugins: [ "table", "link", "paste" ], + target_list: false, + autoresize_min_height: 130, + extended_valid_elements: [ "a[href|target=_blank]" ], + paste_auto_cleanup_on_paste : true, + paste_remove_styles: true, + paste_retain_style_properties: "none", + paste_convert_middot_lists: true, + paste_remove_styles_if_webkit: true, + paste_remove_spans: true, + paste_strip_class_attributes: "all" +}); diff --git a/app/views/notes/update.js.erb b/app/views/notes/update.js.erb new file mode 100644 index 0000000..45c5eb5 --- /dev/null +++ b/app/views/notes/update.js.erb @@ -0,0 +1,27 @@ + +// need to remove the existing tinymce editor otherwise +tinymce.remove(".tinymce"); + +// render the list of notes and invisible view and edit sections +<% listlabel = "#comment-question-area-#{@question.id}" %> +$("<%=listlabel%>").html( + "<%= escape_javascript( render partial: '/phases/note', locals: {question: @question, answer: @answer, plan: @plan } ) %>" +); + +tinymce.init({ + selector: ".tinymce", + statusbar: false, + menubar: false, + toolbar: "bold italic | bullist numlist | link | table", + plugins: [ "table", "link", "paste" ], + target_list: false, + autoresize_min_height: 130, + extended_valid_elements: [ "a[href|target=_blank]" ], + paste_auto_cleanup_on_paste : true, + paste_remove_styles: true, + paste_retain_style_properties: "none", + paste_convert_middot_lists: true, + paste_remove_styles_if_webkit: true, + paste_remove_spans: true, + paste_strip_class_attributes: "all" +}); diff --git a/app/views/orgs/admin_show.html.erb b/app/views/orgs/admin_show.html.erb index fe91c9c..fffd4ef 100644 --- a/app/views/orgs/admin_show.html.erb +++ b/app/views/orgs/admin_show.html.erb @@ -54,7 +54,7 @@ <% if @org.org_type != 0 then %> <%= _('Organisation type') %> - <%= @org.organisation_type %> + <%= @org.type %> <% end %> diff --git a/app/views/phases/_add_note.html.erb b/app/views/phases/_add_note.html.erb index 190f89b..cc367af 100644 --- a/app/views/phases/_add_note.html.erb +++ b/app/views/phases/_add_note.html.erb @@ -1,25 +1,28 @@ - <% new_note = Note.new - answerid = answer.id + questionid = question.id %> -<%= form_for :new_note, - :url => {:controller => :notes, :action => :create }, - :html=>{:method=>:post, :id => "new_note_form_#{answerid}", :class => "add_note_form"} do |f| %> - <%= f.hidden_field :user_id, :value => current_user.id %> - <%= f.hidden_field :answer_id, :value => answerid %> - <%= f.hidden_field :question_id, :value => question.id %> - <%= f.hidden_field :plan_id, :value => plan_id %> +<%= form_for( :new_note, + url: notes_path, + remote: true, + method: :post, + id: "new_note_form_#{questionid}", + class: "add_note_form") 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 %> - <%= text_area_tag("#{answerid}new_note_text".to_sym, "" , class: "tinymce") %> + <%= text_area_tag "#{questionid}new_note_text", nil, class: "tinymce" %> + <%= tinymce %>
- <%= f.submit _('Save'), :class => "btn btn-primary new_comment_submit_button" %> + <%= f.submit _('Save'), class: "btn btn-primary new_comment_submit_button" %>

-<%end%> +<% end %> diff --git a/app/views/phases/_answer_form.html.erb b/app/views/phases/_answer_form.html.erb index 90880c5..16c60e0 100644 --- a/app/views/phases/_answer_form.html.erb +++ b/app/views/phases/_answer_form.html.erb @@ -104,10 +104,10 @@ <% end %>
- <% if answer.nil? || answer.created_at.nil? %> + <% if answer.nil? || !answer.text.present? %> <%= _('Not answered yet') %> <% else %> - <%= _('Answered')%> <%= answer.created_at %><%= _(' by')%> <%= answer.user.name %> + <%= _('Answered')%> <%= answer.updated_at.iso8601 %><%= _(' by')%> <%= answer.user.name %> <% end %> @@ -130,9 +130,9 @@
  • <% if comments.count > 0 then%> <% comments_label_with_count = "#{_('Notes')} (#{comments.count})"%> - <%= link_to comments_label_with_count , "#", :class => "comments_accordion_button" %> + <%= link_to comments_label_with_count , "#", id: "notes_number_#{question_id}", class: "comments_accordion_button" %> <%else%> - <%= link_to _('Share note'), "#", :class => "comments_accordion_button" %> + <%= link_to _('Share note'), "#", id: "notes_number_#{question_id}", class: "comments_accordion_button" %> <%end%>
  • <%else%> @@ -142,9 +142,9 @@
  • <% if comments.count > 0 then%> <% comments_label_with_count = "#{_('Notes')} (#{comments.count})"%> -

    <%= comments_label_with_count %>

    +

    <%= comments_label_with_count %>

    <%else%> -

    <%= _('Share note') %>

    +

    <%= _('Share note') %>

    <%end%>
  • <%end%> @@ -202,7 +202,7 @@
    - <%= render :partial => "note", locals: {question: question, answer: answer, plan: plan }%> + <%= 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 index 26e87e3..0e7b244 100644 --- a/app/views/phases/_archive_note.html.erb +++ b/app/views/phases/_archive_note.html.erb @@ -1,23 +1,21 @@ -<%= form_for(Note.new, :url => {:controller => :notes, :action => :archive } , :html => { :method => :put, :class => "archive_note_form", :id => "archive_note_form_#{note["id"]}"}) do |f| %> - <%= f.hidden_field :id, :value => note["id"] %> +<%= 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 => "view_note", locals: {note: note} %> + <%= render :partial => "/phases/view_note", locals: {note: note} %> - <% if current_user.id == note["user_id"] then %> - <%= _('helpers.notes.archive_own_note_question')%> - <% button_label = _('helpers.notes.archive_own_comment_button_label') %> - <% else%> - <%= _('helpers.notes.archive_note_question')%> - <% button_label = _('helpers.notes.archive_comment_button_label') %> - <%end%> +

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

    - -
    - <%= hidden_field_tag :note_id, note["id"], :class => "comment_id" %> - <%= f.submit button_label, :class => "btn btn-primary archive_comment_submit_button" %> - <%= link_to _('Cancel'), "#", :class => "cancel_archive_comment btn cancel" %> -
    + +
    + <%= 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%> +<% end %> diff --git a/app/views/phases/_edit_note.html.erb b/app/views/phases/_edit_note.html.erb index cc482cc..b0a7bdf 100644 --- a/app/views/phases/_edit_note.html.erb +++ b/app/views/phases/_edit_note.html.erb @@ -1,15 +1,19 @@ -<%= form_for(Note.new, :url => {:controller => :notes, :action => :update } , :html => { :method => :put, :class => "edit_note_form", :id=> "edit_note_form_#{note["id"]}"}) do |f| %> - <%= f.hidden_field :id, :value => note["id"] %> +<%= form_for(note, + url: note_path(note), + remote: true, + method: :put, + class: "edit_note_form", + id: "edit_note_form_#{note.id}") do |f| %> - <%= text_area_tag("#{note["id"]}_note_text".to_sym, note["text"] , class: "tinymce") %> + <%= f.hidden_field :id, :value => note.id %> + + <%= text_area_tag("#{note.id}_note_text".to_sym, note.text , class: "tinymce") %>
    - <%= hidden_field_tag :answer, note["answer_id"], :class => "answer_id" %> - <%= hidden_field_tag :note_id, note["id"], :class => "note_id" %> <%= f.submit _('Save'), :class => "btn btn-primary edit_note_submit_button" %>

    diff --git a/app/views/phases/_list_notes.html.erb b/app/views/phases/_list_notes.html.erb index bd2ae70..56a8b96 100644 --- a/app/views/phases/_list_notes.html.erb +++ b/app/views/phases/_list_notes.html.erb @@ -31,18 +31,16 @@ <%else%> - <%= link_to _('View'),"#", :class => "dmp_table_link view_comment_button" %> - <%= hidden_field_tag :note_id, note.id, :class => "comment_id" %> + <%= 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'),"#", :class => "dmp_table_link edit_comment_button" %> - <%= hidden_field_tag :note_id, note.id, :class => "comment_id" %> - <%= link_to _('Remove'),"#", :class => "dmp_table_link archive_comment_button" %> + <%= 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'),"#", :class => "dmp_table_link archive_comment_button" %> + <%= link_to _('Remove'),"#question-form-#{question_id}", onclick: "archive_note(#{note.id}, #{question_id})", :class => "dmp_table_link archive_comment_button" %> <% end%> <%end%> @@ -57,30 +55,30 @@ <% notes_not_archived = notes.select { |n| n.archived.nil? } %> -<% latest_note = notes_not_archived.sort { |x,y| y.updated_at <=> x.updated_at }.first %> +<% latest_note = notes_not_archived.sort { |x,y| y.updated_at <=> x.updated_at }.first %> <% if !latest_note.nil? then%>
    - <%= render :partial => "view_note", locals: {note: latest_note} %> + <%= render :partial => "/phases/view_note", locals: {note: latest_note} %>
    <%end%> -<%notes.each do |com|%> +<%notes.each do |note|%> -
    " class ="view_comment_class" style="display: none"> - <%= render :partial => "view_note", locals: {note: com} %> + -
    " class ="edit_comment_class" style="display: none"> - <%= render :partial => "edit_note", locals: {note: com} %> + -
    " class ="archive_comment_class" style="display: none"> - <%= render :partial => "archive_note", locals: {note: com} %> + diff --git a/app/views/phases/_note.html.erb b/app/views/phases/_note.html.erb index ce15d4c..95d38ec 100644 --- a/app/views/phases/_note.html.erb +++ b/app/views/phases/_note.html.erb @@ -2,35 +2,32 @@ else display display add note form --> <% if answer.present? && answer.notes.any? %> - <% notes = answer.notes.all.to_a.sort! {|x,y| y["updated_at"] <=> x["updated_at"] } %> - <% answerid = answer.id %> - <%= hidden_field_tag :answer_id, answer.id %> + <% notes = answer.notes.all.to_a.sort! {|x,y| y.updated_at <=> x.updated_at } %> + <% questionid = question.id %> + <%= hidden_field_tag :question_id, questionid, class: "question_id" %> -
    - <%= link_to _('Add note'),'#', :class => "btn btn-primary add_comment_button" %> +
    + <%= link_to _('Add note'), + "#question-form-#{questionid}", + class: "btn btn-primary add_comment_button", + onclick: "add_note_button(#{questionid})" + %>
    - <%= render :partial => "list_notes", locals: {question_id: question.id, notes: notes, plan: plan} %> + <%= render :partial => "/phases/list_notes", locals: {question_id: question.id, notes: notes, plan: plan} %> -
    - - -
    - <%= link_to _('Add note'),'#', :class => "btn btn-primary add_comment_button" %> -
    - <%= render :partial => "/plans/plan_nav_tabs", locals: {plan: @plan, active: @phase.title} %> diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb index dc4bdb2..b852aa9 100644 --- a/app/views/plans/_plan_details.html.erb +++ b/app/views/plans/_plan_details.html.erb @@ -219,7 +219,7 @@ <% phases.each do |phase| %>
    - <%= link_to _('Answer questions'), edit_plan_path(plan), :class => 'btn btn-primary' %> + <%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary' %> <%= _('Export') %>
    <%= render :partial => "plans/export", locals: {plan: plan } %> @@ -272,7 +272,7 @@
    - <%= link_to _('Answer questions'), edit_plan_path(plan), :class => 'btn btn-primary' %> + <%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary' %> <%= _('Export') %>
    <%= render :partial => "plans/export", locals: {plan: plan} %> diff --git a/app/views/plans/_progress.html.erb b/app/views/plans/_progress.html.erb new file mode 100644 index 0000000..9a2fa84 --- /dev/null +++ b/app/views/plans/_progress.html.erb @@ -0,0 +1,5 @@ +<% answered = %(#{nanswers}/#{nquestions})%> +
    + <%= answered -%> <%= _('questions answered')%> + +
    diff --git a/app/views/templates/_show_phases_sections.html.erb b/app/views/templates/_show_phases_sections.html.erb index 1338717..784f16e 100644 --- a/app/views/templates/_show_phases_sections.html.erb +++ b/app/views/templates/_show_phases_sections.html.erb @@ -37,22 +37,24 @@ <% (1..phase_hash[:sections].length).each do |section_no| %> <% section = phase_hash[:sections][section_no] %> - - -

    <%= section[:data].title %>

    - - - <% if section[:questions].present? %> -
      - <% (1..section[:questions].length).each do |question_no|%> -
    • - - <%= raw section[:questions][question_no][:data].text %> -
    • - <% end %> -
    - <% end %> - - + <% if section.present? %> + + +

    <%= section[:data].title %>

    + + + <% if section[:questions].present? %> +
      + <% (1..section[:questions].length).each do |question_no|%> +
    • + - <%= raw section[:questions][question_no][:data].text %> +
    • + <% end %> +
    + <% end %> + + + <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index f86cb56..2db89ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -170,9 +170,9 @@ resources :answers, only: :update - resources :notes, only: [:create, :update] do + resources :notes, only: [:create, :update, :archive] do member do - put 'archive' + patch 'archive' end end diff --git a/db/schema.rb b/db/schema.rb index 7c39b2f..7161ae7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,59 +17,55 @@ enable_extension "plpgsql" create_table "answers", force: :cascade do |t| - t.text "text", limit: 65535 - t.integer "plan_id", limit: 4 - t.integer "user_id", limit: 4 - t.integer "question_id", limit: 4 + t.text "text" + t.integer "plan_id" + t.integer "user_id" + t.integer "question_id" t.datetime "created_at" t.datetime "updated_at" t.integer "lock_version", default: 0 end - add_index "answers", ["plan_id"], name: "fk_rails_84a6005a3e", using: :btree - add_index "answers", ["question_id"], name: "fk_rails_3d5ed4418f", using: :btree - add_index "answers", ["user_id"], name: "fk_rails_584be190c2", using: :btree - create_table "answers_question_options", id: false, force: :cascade do |t| - t.integer "answer_id", limit: 4, null: false - t.integer "question_option_id", limit: 4, null: false + t.integer "answer_id", null: false + t.integer "question_option_id", null: false end add_index "answers_question_options", ["answer_id", "question_option_id"], name: "answer_question_option_index", using: :btree add_index "answers_question_options", ["question_option_id", "answer_id"], name: "question_option_answer_index", using: :btree create_table "exported_plans", force: :cascade do |t| - t.integer "plan_id", limit: 4 - t.integer "user_id", limit: 4 - t.string "format", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + t.integer "plan_id" + t.integer "user_id" + t.string "format" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "file_types", force: :cascade do |t| - t.string "name", limit: 255 - t.string "icon_name", limit: 255 - t.integer "icon_size", limit: 4 - t.string "icon_location", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + t.string "name" + t.string "icon_name" + t.integer "icon_size" + t.string "icon_location" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "file_uploads", force: :cascade do |t| - t.string "name", limit: 255 - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "size", limit: 4 + t.string "name" + t.string "title" + t.text "description" + t.integer "size" t.boolean "published" - t.string "location", limit: 255 - t.integer "file_type_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.string "location" + t.integer "file_type_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", limit: 255, null: false - t.integer "sluggable_id", limit: 4, null: false + t.string "slug", null: false + t.integer "sluggable_id", null: false t.string "sluggable_type", limit: 40 t.datetime "created_at" end @@ -79,115 +75,100 @@ add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree create_table "guidance_groups", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "org_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.string "name" + t.integer "org_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "optional_subset" t.boolean "published" end - add_index "guidance_groups", ["org_id"], name: "fk_rails_819c1dbbc7", using: :btree - create_table "guidances", force: :cascade do |t| - t.text "text", limit: 65535 - t.integer "guidance_group_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" - t.integer "question_id", limit: 4 + t.text "text" + t.integer "guidance_group_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "question_id" t.boolean "published" end - add_index "guidances", ["guidance_group_id"], name: "fk_rails_20d29da787", using: :btree - create_table "identifier_schemes", force: :cascade do |t| - t.string "name", limit: 255 - t.string "description", limit: 255 + t.string "name" + t.string "description" t.boolean "active" t.datetime "created_at" t.datetime "updated_at" end create_table "languages", force: :cascade do |t| - t.string "abbreviation", limit: 255 - t.string "description", limit: 255 - t.string "name", limit: 255 + t.string "abbreviation" + t.string "description" + t.string "name" t.boolean "default_language" end create_table "notes", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.text "text", limit: 65535 + t.integer "user_id" + t.text "text" t.boolean "archived" - t.integer "answer_id", limit: 4 - t.integer "archived_by", limit: 4 + t.integer "answer_id" + t.integer "archived_by" t.datetime "created_at" t.datetime "updated_at" end - add_index "notes", ["answer_id"], name: "fk_rails_907f8d48bf", using: :btree - add_index "notes", ["user_id"], name: "fk_rails_7f2323ad43", using: :btree - create_table "org_token_permissions", force: :cascade do |t| - t.integer "org_id", limit: 4 - t.integer "token_permission_type_id", limit: 4 + t.integer "org_id" + t.integer "token_permission_type_id" t.datetime "created_at" t.datetime "updated_at" end - add_index "org_token_permissions", ["org_id"], name: "fk_rails_e1db1b22c5", using: :btree - add_index "org_token_permissions", ["token_permission_type_id"], name: "fk_rails_2aa265f538", using: :btree - create_table "orgs", force: :cascade do |t| - t.string "name", limit: 255 - t.string "abbreviation", limit: 255 - t.string "target_url", limit: 255 - t.string "wayfless_entity", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" - t.integer "parent_id", limit: 4 + t.string "name" + t.string "abbreviation" + t.string "target_url" + t.string "wayfless_entity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "parent_id" t.boolean "is_other" - t.string "sort_name", limit: 255 - t.text "banner_text", limit: 65535 - t.string "logo_file_name", limit: 255 - t.integer "region_id", limit: 4 - t.integer "language_id", limit: 4 - t.string "logo_uid", limit: 255 - t.string "logo_name", limit: 255 - t.string "contact_email", limit: 255 - t.integer "org_type", limit: 4, default: 0, null: false + t.string "sort_name" + t.text "banner_text" + t.string "logo_file_name" + t.integer "region_id" + t.integer "language_id" + t.string "logo_uid" + t.string "logo_name" + t.string "contact_email" + t.integer "org_type", default: 0, null: false end - add_index "orgs", ["language_id"], name: "fk_rails_5640112cab", using: :btree - add_index "orgs", ["region_id"], name: "fk_rails_5a6adf6bab", using: :btree - create_table "perms", force: :cascade do |t| - t.string "name", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "perms", ["name"], name: "index_perms_on_name", using: :btree add_index "perms", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree create_table "phases", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "number", limit: 4 - t.integer "template_id", limit: 4 + t.string "title" + t.text "description" + t.integer "number" + t.integer "template_id" t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 255 + t.string "slug" t.boolean "modifiable" end - add_index "phases", ["template_id"], name: "fk_rails_0f8036cb2e", using: :btree - create_table "plan_guidance_groups", force: :cascade do |t| - t.integer "plan_id", limit: 4 - t.integer "guidance_group_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "plan_id" + t.integer "guidance_group_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "selected" end @@ -195,232 +176,200 @@ add_index "plan_guidance_groups", ["plan_id"], name: "index_plan_guidance_groups_on_plan_id", using: :btree create_table "plans", force: :cascade do |t| - t.integer "project_id", limit: 4 - t.string "title", limit: 255 - t.integer "template_id", limit: 4 + t.integer "project_id" + t.string "title" + t.integer "template_id" t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 255 - t.string "grant_number", limit: 255 - t.string "identifier", limit: 255 - t.text "description", limit: 65535 - t.string "principal_investigator", limit: 255 - t.string "principal_investigator_identifier", limit: 255 - t.string "data_contact", limit: 255 - t.string "funder_name", limit: 255 - t.integer "visibility", limit: 4, default: 0, null: false + t.string "slug" + t.string "grant_number" + t.string "identifier" + t.text "description" + t.string "principal_investigator" + t.string "principal_investigator_identifier" + t.string "data_contact" + t.string "funder_name" + t.integer "visibility", default: 0, null: false end - add_index "plans", ["template_id"], name: "fk_rails_3424ca281f", using: :btree - create_table "question_formats", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.datetime "created_at" - t.datetime "updated_at" - t.boolean "option_based", default: false + t.string "title" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "option_based", default: false + t.integer "formattype", default: 0 end create_table "question_options", force: :cascade do |t| - t.integer "question_id", limit: 4 - t.string "text", limit: 255 - t.integer "number", limit: 4 + t.integer "question_id" + t.string "text" + t.integer "number" t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" end - add_index "question_options", ["question_id"], name: "fk_rails_b9c5f61cf9", using: :btree - create_table "questions", force: :cascade do |t| - t.text "text", limit: 65535 - t.text "default_value", limit: 65535 - t.text "guidance", limit: 65535 - t.integer "number", limit: 4 - t.integer "section_id", limit: 4 + t.text "text" + t.text "default_value" + t.text "guidance" + t.integer "number" + t.integer "section_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "question_format_id", limit: 4 - t.boolean "option_comment_display", default: true + t.integer "question_format_id" + t.boolean "option_comment_display", default: true t.boolean "modifiable" end - add_index "questions", ["question_format_id"], name: "fk_rails_4fbc38c8c7", using: :btree - add_index "questions", ["section_id"], name: "fk_rails_c50eadc3e3", using: :btree - create_table "questions_themes", id: false, force: :cascade do |t| - t.integer "question_id", limit: 4, null: false - t.integer "theme_id", limit: 4, null: false + t.integer "question_id", null: false + t.integer "theme_id", null: false end add_index "questions_themes", ["question_id", "theme_id"], name: "question_theme_index", using: :btree add_index "questions_themes", ["theme_id", "question_id"], name: "theme_question_index", using: :btree create_table "regions", force: :cascade do |t| - t.string "abbreviation", limit: 255 - t.string "description", limit: 255 - t.string "name", limit: 255 - t.integer "super_region_id", limit: 4 + t.string "abbreviation" + t.string "description" + t.string "name" + t.integer "super_region_id" end create_table "roles", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "plan_id", limit: 4 + t.integer "user_id" + t.integer "plan_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "access", limit: 4, default: 0, null: false + t.integer "access", default: 0, null: false end - add_index "roles", ["plan_id"], name: "fk_rails_a1ce6c2772", using: :btree - add_index "roles", ["user_id"], name: "fk_rails_ab35d699f0", using: :btree - create_table "sections", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "number", limit: 4 + t.string "title" + t.text "description" + t.integer "number" t.datetime "created_at" t.datetime "updated_at" t.boolean "published" - t.integer "phase_id", limit: 4 + t.integer "phase_id" t.boolean "modifiable" end - add_index "sections", ["phase_id"], name: "fk_rails_1853581585", using: :btree - create_table "settings", force: :cascade do |t| - t.string "var", limit: 255, null: false - t.text "value", limit: 65535 - t.integer "target_id", limit: 4, null: false - t.string "target_type", limit: 255, null: false - t.datetime "created_at" - t.datetime "updated_at" + t.string "var", null: false + t.text "value" + t.integer "target_id", null: false + t.string "target_type", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree create_table "splash_logs", force: :cascade do |t| - t.string "destination", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + t.string "destination" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "suggested_answers", force: :cascade do |t| - t.integer "question_id", limit: 4 - t.integer "org_id", limit: 4 - t.text "text", limit: 65535 + t.integer "question_id" + t.integer "org_id" + t.text "text" t.boolean "is_example" t.datetime "created_at" t.datetime "updated_at" end - add_index "suggested_answers", ["org_id"], name: "fk_rails_473de65779", using: :btree - add_index "suggested_answers", ["question_id"], name: "fk_rails_daa60b5b70", using: :btree - create_table "templates", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.string "title" + t.text "description" t.boolean "published" - t.integer "org_id", limit: 4 - t.string "locale", limit: 255 + t.integer "org_id" + t.string "locale" t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" - t.integer "version", limit: 4 - t.integer "visibility", limit: 4 - t.integer "customization_of", limit: 4 - t.integer "dmptemplate_id", limit: 4 + t.integer "version" + t.integer "visibility" + t.integer "customization_of" + t.integer "dmptemplate_id" end - add_index "templates", ["org_id"], name: "fk_rails_481431e1bd", using: :btree - create_table "themes", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.datetime "created_at" - t.datetime "updated_at" - t.string "locale", limit: 255 + t.string "title" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "locale" end create_table "themes_in_guidance", id: false, force: :cascade do |t| - t.integer "theme_id", limit: 4 - t.integer "guidance_id", limit: 4 + t.integer "theme_id" + t.integer "guidance_id" end - add_index "themes_in_guidance", ["guidance_id"], name: "fk_rails_a5ab9402df", using: :btree - add_index "themes_in_guidance", ["theme_id"], name: "fk_rails_7d708f6f1e", using: :btree - create_table "token_permission_types", force: :cascade do |t| - t.string "token_type", limit: 255 - t.text "text_description", limit: 65535 + t.string "token_type" + t.text "text_description" t.datetime "created_at" t.datetime "updated_at" end create_table "user_identifiers", force: :cascade do |t| - t.string "identifier", limit: 255 + t.string "identifier" t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id", limit: 4 - t.integer "identifier_scheme_id", limit: 4 + t.integer "user_id" + t.integer "identifier_scheme_id" end - add_index "user_identifiers", ["identifier_scheme_id"], name: "fk_rails_fe95df7db0", using: :btree - add_index "user_identifiers", ["user_id"], name: "fk_rails_65c9a98cdb", using: :btree - create_table "users", force: :cascade do |t| - t.string "firstname", limit: 255 - t.string "surname", limit: 255 - t.string "email", limit: 255, default: "", null: false - t.string "shibboleth_id", limit: 255 + t.string "firstname" + t.string "surname" + t.string "email", default: "", null: false + t.string "orcid_id" + t.string "shibboleth_id" t.datetime "created_at" t.datetime "updated_at" - t.string "encrypted_password", limit: 255, default: "" - t.string "reset_password_token", limit: 255 + t.string "encrypted_password", default: "" + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", limit: 4, default: 0 + t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip", limit: 255 - t.string "last_sign_in_ip", limit: 255 - t.string "confirmation_token", limit: 255 + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "invitation_token", limit: 255 + t.string "invitation_token" t.datetime "invitation_created_at" t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" - t.string "other_organisation", limit: 255 + t.string "other_organisation" t.boolean "dmponline3" t.boolean "accept_terms" - t.integer "org_id", limit: 4 - t.string "api_token", limit: 255 - t.integer "invited_by_id", limit: 4 - t.string "invited_by_type", limit: 255 - t.integer "language_id", limit: 4 + t.integer "org_id" + t.string "api_token" + t.integer "invited_by_id" + t.string "invited_by_type" + t.integer "language_id" end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree - add_index "users", ["language_id"], name: "fk_rails_45f4f12508", using: :btree - add_index "users", ["org_id"], name: "fk_rails_e73753bccb", using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree - create_table "users_org_roles", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "organisation_id", limit: 4 - t.integer "user_role_type_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + create_table "users_perms", id: false, force: :cascade do |t| + t.integer "user_id" + t.integer "perm_id" end - create_table "users_perms", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "perm_id", limit: 4 - end - - add_index "users_perms", ["perm_id"], name: "fk_rails_457217c31c", using: :btree add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id", using: :btree add_foreign_key "answers", "plans" diff --git a/lib/assets/javascripts/plans.js b/lib/assets/javascripts/plans.js index 3289dae..ebf8d3e 100644 --- a/lib/assets/javascripts/plans.js +++ b/lib/assets/javascripts/plans.js @@ -1,10 +1,79 @@ //= require jquery.timeago.js //= require tinymce +//= require tinymce-jquery 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 @@ -55,16 +124,6 @@ saving_message.show(); s_status = $(this).closest(".accordion-group").find(".section-status:first"); s_status.toggle_dirty(q_id, false); - // Allow quarter of a second for database to update - timeout = setTimeout(function(){ - $.getJSON("status.json", function(data) { - $.fn.update_plan_progress(data); - $.fn.update_timestamp(q_id, data); - s_status.update_section_progress(data); - submit_button.parent().show(); - saving_message.hide(); - }); - },250); }); //accordion guidance @@ -90,40 +149,17 @@ // Handle section actions on accordion expansion/collapse $('.section-collapse').on('show', function() { - var section = $(this); - - $.getJSON("status.json", function(data) { - $.fn.update_plan_progress(data); - $(".section-status").each(function(){ - $(this).update_section_progress(data); - }); - - //For each question in section, check answer timestamp against currently displayed - var section_id = section.attr("id").split('-')[1]; - var num_questions = data.sections[section_id]["questions"].length; - for (var i = 0; i < num_questions; i++) { - question_id = data.sections[section_id]["questions"][i]; - $.fn.update_timestamp(question_id, data) - } - }); + $('abbr.timeago').timeago(); }).on('hide', function(){ - var section = $(this); - // Only attempt unlock if there are forms on the page (not read-only) - if ($('.question-form').length > 0) { - var section_id = section.attr("id").split('-')[1]; - // LIBDMP-137 - // Changed post request 'unlock_section' to 'unlock_section.json'. 'unlock_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('unlock_section.json', {section_id: section_id}); - - if ($.fn.is_dirty(section_id)) { + 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(); - } - } + } }); $(".cancel-section-collapse").click(function () { @@ -168,114 +204,6 @@ $('#guidance-question-area-'+ q_id).show(); e.preventDefault(); }); - - //action for show add comment block - $('.add_comment_button').click(function(e){ - var q_id = $(this).closest(".comment-area").find(".question_id").val(); - $('.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(); - $('#add_comment_block_div_'+ q_id).show(); - e.preventDefault(); - }); - - //submit new comment button - $('.new_comment_submit_button').click(function(e){ - var q_id = $(this).parent().children(".question_id").val(); - var s_id = $(this).parent().children(".section_id").val(); - - $("#collapse-" + s_id).children(".accordion-inner").find(".saving").show(); - $("#collapse-" + s_id).children(".accordion-inner").find(".loaded").hide(); - $(".alert-notice").hide(); - $("#new_comment_form_" + q_id).submit(); - - }); - - //action to view a comment block - $('.view_comment_button').click(function(e){ - var c_id = $(this).next(".comment_id").val(); - var q_id = $(this).closest(".comment-area").find(".question_id").val(); - $('.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_bottom_div_'+ q_id).show(); - $('#add_comment_button_top_div_'+ q_id).show(); - e.preventDefault(); - }); - - //action to edit a comment block - $('.edit_comment_button').click(function(e){ - var c_id = $(this).prev(".comment_id").val(); - var q_id = $(this).closest(".comment-area").find(".question_id").val(); - $('.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_bottom_div_'+ q_id).show(); - $('#add_comment_button_top_div_'+ q_id).show(); - e.preventDefault(); - }); - - //submit edit comment button - $('.edit_comment_submit_button').click(function(e){ - var c_id = $(this).parent().children(".comment_id").val(); - var s_id = $(this).parent().children(".section_id").val(); - - $("#collapse-" + s_id).children(".accordion-inner").find(".saving").show(); - $("#collapse-" + s_id).children(".accordion-inner").find(".loaded").hide(); - $(".alert-notice").hide(); - $("#edit_comment_form_" + c_id).submit(); - - }); - - //action to archive a comment block - $('.archive_comment_button').click(function(e){ - var c_id = $(this).prev(".comment_id").val(); - var q_id = $(this).closest(".comment-area").find(".question_id").val(); - $('.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_bottom_div_'+ q_id).show(); - $('#add_comment_button_top_div_'+ q_id).show(); - e.preventDefault(); - }); - - //submit archived comment button - $('.archive_comment_submit_button').click(function(e){ - var c_id = $(this).parent().children(".comment_id").val(); - var s_id = $(this).parent().children(".section_id").val(); - - $("#collapse-" + s_id).children(".accordion-inner").find(".removing").show(); - $("#collapse-" + s_id).children(".accordion-inner").find(".loaded").hide(); - $(".alert-notice").hide(); - $("#archive_comment_form_" + c_id).submit(); - - }); - - //action to cancel archive block -// $(".cancel_archive_comment").click(function(e){ -// var c_id = $(this).prev(".comment_id").val(); -// $('.archive_comment_class').hide(); -// $('#view_comment_div_'+ c_id).show(); -// e.preventDefault(); -// }); - }); $.fn.get_unsaved_questions = function(section_id) { @@ -301,8 +229,6 @@ }); return questions; } - - }; $.fn.is_dirty = function(section_id, question_id) { @@ -374,6 +300,28 @@ } }; +$.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(""); + // TODO: i18n this + 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"); @@ -383,6 +331,7 @@ timestamp = new Date(Number(timestamp) * 1000); if (timestamp.getTime() != current_timestamp.getTime()) { q_status.text(""); + // TODO: i18n this q_status.append( "Answered" + " " + "by" + " " + data.questions[question_id]["answered_by"]); t = q_status.children("abbr:first"); // Update label to indicate successful submission diff --git a/test/functional/answers_controller_test.rb b/test/functional/answers_controller_test.rb index e8389f0..852504c 100644 --- a/test/functional/answers_controller_test.rb +++ b/test/functional/answers_controller_test.rb @@ -43,7 +43,8 @@ form_attributes = {"answer-text-#{question.id}": "Tested", answer: {user_id: answer.user.id, plan_id: answer.plan.id, - question_id: answer.question.id}} + question_id: answer.question.id, + lock_version: answer.lock_version}} put_answer(answer, form_attributes, referrer) @@ -59,7 +60,12 @@ private def put_answer(answer, attributes, referrer) - put answer_path(answer), attributes, {'HTTP_REFERER': referrer, 'HTTP_ACCEPT': 'text/javascript'} + put answer_path(FastGettext.locale, answer, format: "js"), attributes, {'HTTP_REFERER': referrer} + assert_response :success + assert_equal "text/javascript", @response.content_type + + # last line of JS updates section status with X questions, Y answered + assert_match /status"\).html\("\([0-9]+ questions, [0-9]+ answered/, @response.body end -end \ No newline at end of file +end