diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index 2330bd8..ee20348 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -6,65 +6,83 @@
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]
+ @note.user_id = params[:note][:user_id]
# create answer if we dont already have one
- if answer_id.present?
- answer = Answer.find(answer_id)
+ if params[:note][:answer_id].present?
+ @answer = Answer.find(params[:note][:answer_id])
else
- answer = Answer.new
- answer.plan_id = plan_id
- answer.question_id = question_id
- answer.user_id = user_id
- answer.save!
+ @answer = Answer.new
+ @answer.plan_id = params[:note][:plan_id]
+ @answer.question_id = params[:note][:question_id]
+ @answer.user_id = @note.user_id
+ @answer.save!
end
- @note.answer= answer
- @note.text = params["#{question_id}new_note_text"]
+ @note.answer = @answer
+ @note.text = params[:note][:text]
authorize @note
- @plan = answer.plan
- @answer = answer
- @question = Question.find(question_id)
+ @plan = @answer.plan
+
+ @question = Question.find(params[:note][:question_id])
if @note.save
@status = true
@notice = success_message(_('comment'), _('created'))
+ render(json: {
+ "notes" => {
+ "id" => params[:note][:question_id],
+ "html" => render_to_string(partial: 'layout', locals: {plan: @plan, question: @question, answer: @answer }, formats: [:html])
+ },
+ "title" => {
+ "id" => params[:note][:question_id],
+ "html" => render_to_string(partial: 'title', locals: { answer: @answer}, formats: [:html])
+ }
+ }.to_json, status: :created)
else
@status = false
@notice = failed_create_error(@note, _('note'))
+ render json: {
+ "msg" => @notice
+ }.to_json, status: :bad_request
end
- notes = answer.notes.all
- @num_notes = notes.count
end
-
-
def update
- @note = Note.find(params[:note][:id])
+ @note = Note.find(params[:id])
authorize @note
- @note.text = params["#{params[:note][:id]}_note_text"]
+ @note.text = params[:note][:text]
@answer = @note.answer
@question = @answer.question
@plan = @answer.plan
+ question_id = @note.answer.question_id.to_s
+
if @note.update_attributes(params[:note])
@notice = success_message(_('comment'), _('saved'))
+ render(json: {
+ "notes" => {
+ "id" => question_id,
+ "html" => render_to_string(partial: 'layout', locals: {plan: @plan, question: @question, answer: @answer }, formats: [:html])
+ },
+ "title" => {
+ "id" => question_id,
+ "html" => render_to_string(partial: 'title', locals: { answer: @answer}, formats: [:html])
+ }
+ }.to_json, status: :ok)
else
@notice = failed_update_error(@note, _('note'))
+ render json: {
+ "msg" => @notice
+ }.to_json, status: :bad_request
end
end
-
-
def archive
- @note = Note.find(params[:note][:id])
+ @note = Note.find(params[:id])
authorize @note
@note.archived = true
@note.archived_by = params[:note][:archived_by]
@@ -73,10 +91,25 @@
@question = @answer.question
@plan = @answer.plan
+ question_id = @note.answer.question_id.to_s
+
if @note.update_attributes(params[:note])
@notice = success_message(_('comment'), _('removed'))
+ render(json: {
+ "notes" => {
+ "id" => question_id,
+ "html" => render_to_string(partial: 'layout', locals: {plan: @plan, question: @question, answer: @answer }, formats: [:html])
+ },
+ "title" => {
+ "id" => question_id,
+ "html" => render_to_string(partial: 'title', locals: { answer: @answer}, formats: [:html])
+ }
+ }.to_json, status: :ok)
else
@notice = failed_destroy_error(@note, _('note'))
+ render json: {
+ "msg" => @notice
+ }.to_json, status: :bad_request
end
end
end
diff --git a/app/models/answer.rb b/app/models/answer.rb
index f44987b..4458ef6 100644
--- a/app/models/answer.rb
+++ b/app/models/answer.rb
@@ -70,4 +70,12 @@
return false
end
end
+ # Returns all the notes for an instance answer whose archived is nil or false. The Array is ordered by updated_at (descending)
+ def non_archived_notes
+ answer = Answer.includes(:notes).where({ id: self.id, notes: { archived: [nil, false] } }).order('notes.updated_at DESC').first
+ if !answer.nil?
+ return answer.notes.to_a
+ end
+ return []
+ end
end
diff --git a/app/views/annotations/_show.html.erb b/app/views/annotations/_show.html.erb
index e5f122b..792a720 100644
--- a/app/views/annotations/_show.html.erb
+++ b/app/views/annotations/_show.html.erb
@@ -2,16 +2,12 @@
<%= (plan.template.org.abbreviation.present? ? plan.template.org.abbreviation : plan.template.org.name) %>
- <% if annotation.example_answer? %>
- <%= _('Example Answer') %>
- <% else %>
- <%= _('Guidance') %>
- <% end %>
+ <%= _('Guidance') %>
diff --git a/app/views/layouts/_es5_scripts.html.erb b/app/views/layouts/_es5_scripts.html.erb
index e575d54..6045c17 100644
--- a/app/views/layouts/_es5_scripts.html.erb
+++ b/app/views/layouts/_es5_scripts.html.erb
@@ -31,10 +31,6 @@
<%= javascript_include_tag 'views/guidances/admin_edit.js' %>
<%= javascript_include_tag 'views/home/index.js' %>
- <%= javascript_include_tag 'views/notes/add.js' %>
- <%= javascript_include_tag 'views/notes/archive.js' %>
- <%= javascript_include_tag 'views/notes/edit.js' %>
- <%= javascript_include_tag 'views/notes/show.js' %>
<%= javascript_include_tag 'views/orgs/admin_edit.js' %>
<%= javascript_include_tag 'views/orgs/shibboleth_ds.js' %>
<%= javascript_include_tag 'views/plans/available_templates.js' %>
diff --git a/app/views/notes/_add.html.erb b/app/views/notes/_add.html.erb
deleted file mode 100644
index acdc83b..0000000
--- a/app/views/notes/_add.html.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-<%
- new_note = Note.new
-%>
-<%= form_for( :new_note,
- url: notes_path,
- remote: true,
- html: {method: :post, class: "add_note_form roadmap-form"},
- id: "new_note_form_#{question.id}") do |f| %>
- <%= f.hidden_field :user_id, value: current_user.id %>
- <%= f.hidden_field :question_id, value: question.id %>
- <%= f.hidden_field :answer_id, value: answer.id %>
- <%= f.hidden_field :plan_id, value: plan_id %>
-
-
-<% end %>
diff --git a/app/views/notes/_archive.html.erb b/app/views/notes/_archive.html.erb
index 9bc0bc6..ec8c78a 100644
--- a/app/views/notes/_archive.html.erb
+++ b/app/views/notes/_archive.html.erb
@@ -1,20 +1,13 @@
-<%= 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'), class: "btn btn-primary archive_comment_submit_button", role:"button" %>
- <%= link_to _('Cancel'), "#", onclick: "dmproadmap.notes.archive.cancel(event,#{note.id})", class: "cancel_archive_comment btn cancel", role:"button" %>
-
-
-<% end %>
+<% if !note.nil? %>
+ <%= form_for(note, url: archive_note_path(note), method: :patch, html: { class: 'archive_note' }) do |f| %>
+ <%= f.hidden_field :archived_by, :value => current_user.id %>
+
+ <%= render partial: "notes/show", locals: { note: note }, formats: [:html] %>
+
+
<%= _('Are you sure you want to remove this note?')%>
+
+ <%= f.button(_('Destroy'), class: "btn btn-default", type: "submit") %>
+ <%= f.button(_('Cancel'), class: "btn btn-default", type: "button") %>
+
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/notes/_edit.html.erb b/app/views/notes/_edit.html.erb
index d942e6e..dbbcf4e 100644
--- a/app/views/notes/_edit.html.erb
+++ b/app/views/notes/_edit.html.erb
@@ -1,14 +1,10 @@
-
-
-<%= 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| %>
-
-
-<%end%>
+
+<% if !note.nil? %>
+ <%= form_for(note, url: note_path(note), method: :put) do |f| %>
+
+ <%= f.label(:text, _('Edit comment to share with collaborators')) %>
+ <%= f.text_area(:text, class: 'form-control note', id: "note-#{note.id}") %>
+
+ <%= f.button(_('Update'), class: "btn btn-default", type: "submit") %>
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/notes/_layout.html.erb b/app/views/notes/_layout.html.erb
new file mode 100644
index 0000000..3b541ce
--- /dev/null
+++ b/app/views/notes/_layout.html.erb
@@ -0,0 +1,21 @@
+
+<% notes = answer.non_archived_notes %>
+
+
+
+ <%= link_to(_('Add a Comment'), "#note_new#{question.id}", class: "btn btn-default note_new_link", role: "button") %>
+
+
+
+
+
+ <%= render partial: "/notes/list", locals: {question_id: question.id, notes: notes, plan: plan}, formats: [:html] %>
+
+
+
+
+
" style="display: none">
+ <%= render partial: "/notes/new", locals: { question: question, answer: answer, plan: plan }, formats: [:html] %>
+
+
+
\ No newline at end of file
diff --git a/app/views/notes/_list.html.erb b/app/views/notes/_list.html.erb
index cac55f5..7d5bf7e 100644
--- a/app/views/notes/_list.html.erb
+++ b/app/views/notes/_list.html.erb
@@ -1,78 +1,57 @@
-
-
-
-
-
-
- <% notes.each do |note|%>
-
- |
- <% user = note.user.name %>
- <%= user %>
- (<%= l note.updated_at, format: :custom %>)
- |
-
-
- <% if note.archived %>
-
- <% if note.archived_by == current_user.id %>
- <%= _('Comment removed by you')%>
- <% else %>
- <% archived_by_user = User.find(note.archived_by) %>
- <%= _('Comment removed by')%> <%= archived_by_user.name %>
- <%end%>
-
- <%else%>
-
- <%= link_to _('View'),"#question-form-#{question_id}", onclick: "dmproadmap.notes.show(#{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: "dmproadmap.notes.edit(#{note.id}, #{question_id})", :class => "dmp_table_link edit_comment_button" %>
- <%= link_to _('Remove'),"#question-form-#{question_id}", onclick: "dmproadmap.notes.archive(#{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: "dmproadmap.notes.archive(#{note.id}, #{question_id})", :class => "dmp_table_link archive_comment_button" %>
- <% end%>
- <%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%>
-
-<%end%>
-
-<%notes.each do |note|%>
-
-
-
-
-
-
-
-
-
-<%end%>
+<% notes.each do |note| %>
+ <% if !note.archived %>
+
+
+
+ -
+
+
+ - <%= note.user.name %>
+ - (<%= l note.updated_at, format: :custom %>)
+
+
+
+
+ - <%= link_to(_('Show'), "#note_show#{note.id}", class: 'note_show_link') %>
+ <% if current_user.id == note.user_id %>
+ - <%= link_to(_('Edit'), "#note_edit#{note.id}", class: 'note_edit_link') %>
+ - <%= link_to(_('Remove'), "#note_archive#{note.id}", class: 'note_archive_link') %>
+ <% else %>
+ <% if plan.administerable_by?(current_user.id) %>
+ - <%= link_to(_('Remove'), "#note_archive#{note.id}", class: 'note_archive_link') %>
+ <% end %>
+ <% end %>
+
+
+
+
+
+
+
+ <% end %>
+<% end %>
+<% notes.each do |note| %>
+ <% if !note.archived %>
+
+
+
" style="display:none;">
+ <%= render partial: "/notes/show", locals: { note: note }, formats: [:html] %>
+
+
+
+
+
+
" style="display:none;">
+ <%= render partial: "/notes/edit", locals: { note: note }, formats: [:html] %>
+
+
+
+
+
+
" style="display:none;">
+ <%= render partial: "/notes/archive", locals: { note: note }, formats: [:html] %>
+
+
+
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/notes/_new.html.erb b/app/views/notes/_new.html.erb
new file mode 100644
index 0000000..502740b
--- /dev/null
+++ b/app/views/notes/_new.html.erb
@@ -0,0 +1,12 @@
+
+<%= form_for(Note.new, url: notes_path) do |f| %>
+ <%= f.hidden_field :user_id, value: current_user.id %>
+ <%= f.hidden_field :question_id, value: question.id %>
+ <%= f.hidden_field :answer_id, value: answer.id %>
+ <%= f.hidden_field :plan_id, value: plan.id %>
+
+ <%= f.label(:text, _('Add comments to share with collaborators')) %>
+ <%= f.text_area(:text, class: 'form-control note', id: "note-#{question.id}") %>
+
+ <%= f.button(_('Create'), class: "btn btn-default", type: "submit") %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/notes/_show.html.erb b/app/views/notes/_show.html.erb
new file mode 100644
index 0000000..e9e0b9f
--- /dev/null
+++ b/app/views/notes/_show.html.erb
@@ -0,0 +1,12 @@
+
+<% if !note.nil? %>
+ <% user = User.find(note.user_id) %>
+
+ - <%= raw note.text %>
+ -
+
+ <%= "#{user.name} at #{l(note.updated_at, format: :custom)}" %>
+
+
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/notes/_title.html.erb b/app/views/notes/_title.html.erb
new file mode 100644
index 0000000..7b23543
--- /dev/null
+++ b/app/views/notes/_title.html.erb
@@ -0,0 +1,3 @@
+
+<% notes = answer.non_archived_notes %>
+<%= _('Comments') %><%= notes.length > 0 ? " (#{notes.length})" : '' %>
\ No newline at end of file
diff --git a/app/views/notes/_view.html.erb b/app/views/notes/_view.html.erb
deleted file mode 100644
index efe24d2..0000000
--- a/app/views/notes/_view.html.erb
+++ /dev/null
@@ -1,11 +0,0 @@
-
-<% user = User.find(note.user_id) %>
-
-
-
-
- <%= _('Comment from:')%>
- - <%= user.name%> (<%= l note.updated_at, format: :custom %>)
- - <%= raw note.text %>
-
-
diff --git a/app/views/notes/archive.js.erb b/app/views/notes/archive.js.erb
deleted file mode 100644
index 1419296..0000000
--- a/app/views/notes/archive.js.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-dmproadmap.utils.tinymce.destroyEditorsByClassName('tinymce_notes');
-// 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 } ) %>"
-);
-dmproadmap.utils.tinymce.init({ selector: '.tinymce_notes'});
diff --git a/app/views/notes/create.js.erb b/app/views/notes/create.js.erb
deleted file mode 100644
index d36a72c..0000000
--- a/app/views/notes/create.js.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
-// rewrite the number of notes heading e.g. Notes(3)
-<% noteslabel = "#notes_number_#{@question.id}" %>
-$("<%=noteslabel%>").html("Comments (<%= @num_notes %>)");
-
-dmproadmap.utils.tinymce.destroyEditorsByClassName('tinymce_notes');
-
-// 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 } ) %>"
-);
-dmproadmap.utils.tinymce.init({ selector: '.tinymce_notes'});
diff --git a/app/views/notes/update.js.erb b/app/views/notes/update.js.erb
deleted file mode 100644
index 1419296..0000000
--- a/app/views/notes/update.js.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-dmproadmap.utils.tinymce.destroyEditorsByClassName('tinymce_notes');
-// 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 } ) %>"
-);
-dmproadmap.utils.tinymce.init({ selector: '.tinymce_notes'});
diff --git a/app/views/phases/_edit_plan_answers.html.erb b/app/views/phases/_edit_plan_answers.html.erb
index 1a9d52e..e40c52d 100644
--- a/app/views/phases/_edit_plan_answers.html.erb
+++ b/app/views/phases/_edit_plan_answers.html.erb
@@ -73,8 +73,8 @@
-
- <%= render partial: 'guidance_section', locals: {plan: @plan, question: question, answer: answer, question_guidances: @question_guidances} %>
+
+ <%= render partial: 'guidances_notes', locals: {plan: @plan, question: question, answer: answer, question_guidance: @question_guidance} %>
<% end %>
@@ -82,9 +82,5 @@
<% end %>
-
\ No newline at end of file
diff --git a/app/views/phases/_guidance_section.html.erb b/app/views/phases/_guidance_section.html.erb
deleted file mode 100644
index 837f1d4..0000000
--- a/app/views/phases/_guidance_section.html.erb
+++ /dev/null
@@ -1,81 +0,0 @@
-