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? %>
- <%= 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" %>
+
- <%= 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" %>