diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 329b38e5..756cf9c2 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,7 +1,7 @@ class NotesController < ApplicationController def index - @all_notes = current_user.notes + @all_notes = current_user.notes.all @count = @all_notes.size @page_title = "TRACKS::All notes" respond_to do |format| @@ -28,49 +28,38 @@ class NotesController < ApplicationController def create note = current_user.notes.build note.attributes = params["note"] - - saved = note.save - - respond_to do |format| - format.js do + + saved = note.save + + respond_to do |format| + format.js do if note.save render :partial => 'notes_summary', :object => note else render :text => '' end - end - format.xml do - if saved - head :created, :location => note_url(note), :text => "new note with id #{note.id}" - else - render_failure note.errors.full_messages.join(', ') - end - end - format.html do - render :text => 'unexpected request for html rendering' - end - end + end + format.xml do + if saved + head :created, :location => note_url(note), :text => "new note with id #{note.id}" + else + render_failure note.errors.full_messages.join(', ') + end + end + format.html do + render :text => 'unexpected request for html rendering' + end + end end def destroy @note = current_user.notes.find(params['id']) - @note.destroy respond_to do |format| format.html - format.js do - @count = current_user.notes.size - render - end + format.js { @down_count = current_user.notes.size } end - - # if note.destroy - # render :text => '' - # else - # notify :warning, "Couldn't delete note \"#{note.id}\"" - # render :text => '' - # end end def update diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 46377fa1..724de012 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -122,6 +122,12 @@ module ApplicationHelper url_for({:controller => 'contexts', :action => 'edit', :id => context.id}), {:id => "link_edit_#{dom_id(context)}", :class => "context_edit_settings"}) end + + def link_to_edit_note (note, descriptor = sanitize(note.id.to_s)) + link_to(descriptor, + url_for({:controller => 'notes', :action => 'edit', :id => note.id}), + {:id => "link_edit_#{dom_id(note)}", :class => "note_edit_settings"}) + end def link_to_delete_project(project, descriptor = sanitize(project.name)) link_to( @@ -139,6 +145,14 @@ module ApplicationHelper ) end + def link_to_delete_note(note, descriptor = sanitize(note.id.to_s)) + link_to( + descriptor, + note_path(note, :format => 'js'), + {:id => "delete_note_#{note.id}", :class => "delete_note_button", :title => "delete the note '#{note.id}'"} + ) + end + def link_to_project_mobile(project, accesskey, descriptor = sanitize(project.name)) link_to( descriptor, project_path(project, :format => 'm'), {:title => "View project: #{project.name}", :accesskey => accesskey} ) end diff --git a/app/views/notes/_note.rhtml b/app/views/notes/_note.rhtml new file mode 100644 index 00000000..0f556980 --- /dev/null +++ b/app/views/notes/_note.rhtml @@ -0,0 +1,42 @@ +
+
+ +

<%= link_to(t('notes.note_header', :id => note.id.to_s), note_path(note), :title => t('notes.note_link_title', :id => note.id.to_s)) %>

+ +
+ +
<%= format_note(note.body) %>
+ + + +
+ + +
+
\ No newline at end of file diff --git a/app/views/notes/_note_edit_form.rhtml b/app/views/notes/_note_edit_form.rhtml index 6b6ad683..93090c46 100644 --- a/app/views/notes/_note_edit_form.rhtml +++ b/app/views/notes/_note_edit_form.rhtml @@ -1,6 +1,33 @@ -<% @note = note_edit_form %> -<%= hidden_field( "note", "project_id" ) %> -<%= text_area( "note", "body", "cols" => 70, "rows" => 15, "tabindex" => 1 ) %> -

- -<% @note = nil %> \ No newline at end of file +<% +#form_remote_tag :url => note_path(note), +#:method => :put, +#:html => { :id => dom_id(note, 'edit_form'), :class => "inline-form" }, +#:update => dom_id(note, 'container'), +#:complete => visual_effect(:appear, dom_id(note, 'container')) do +-%> + +<% form_for(note_edit_form, :html => { + :id => dom_id(note_edit_form, 'edit_form'), + :class => "inline-form edit-note-form", + :method => :put }) do + -%> + + <%= hidden_field( "note", "project_id" ) %> + <%= text_area( "note", "body", "cols" => 70, "rows" => 15, "tabindex" => 1 ) %> +

+ + +
+
+ + + <%=image_tag("cancel.png", :alt => "") %> + <%= t 'common.cancel' %> + +
+
+ +<% end -%> diff --git a/app/views/notes/_notes.rhtml b/app/views/notes/_notes.rhtml deleted file mode 100644 index ff0ffb64..00000000 --- a/app/views/notes/_notes.rhtml +++ /dev/null @@ -1,36 +0,0 @@ -<% note = notes -%> -
-

<%= link_to(t('notes.note_header', :id => note.id.to_s), note_path(note), :title => t('notes.note_link_title', :id => note.id.to_s)) %>

-
- <%= format_note(note.body) %> - - -
- - -
-<% note = nil -%> - diff --git a/app/views/notes/destroy.js.erb b/app/views/notes/destroy.js.erb new file mode 100644 index 00000000..75c37e31 --- /dev/null +++ b/app/views/notes/destroy.js.erb @@ -0,0 +1,10 @@ +remove_deleted_note(); +set_page_badge(<%=@down_count%>); +page_notify('notice', "<%= t('notes.deleted_note', :id => @note.id)%>", 5); + +function remove_deleted_note() { + $('div#note-<%=@note.id%>-wrapper').slideUp(1000, + function() { + $('div#note-<%=@note.id%>-wrapper').remove(); + }); +} \ No newline at end of file diff --git a/app/views/notes/destroy.js.rjs b/app/views/notes/destroy.js.rjs deleted file mode 100644 index 739ce168..00000000 --- a/app/views/notes/destroy.js.rjs +++ /dev/null @@ -1,3 +0,0 @@ -page.notify :notice, t('notes.deleted_note', :id => @note.id), 5.0 -page['badge_count'].replace_html @count -page.hide "busy" diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index bd67d537..78d30f77 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -2,10 +2,6 @@ <% if @all_notes.empty? -%>

<%= t('notes.no_notes_available') %>

<% else -%> - <% for notes in @all_notes -%> -
- <%= render :partial => 'notes', :object => notes %> -
- <% end -%> + <%= render :partial => 'note', :collection => @all_notes %> <% end -%> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index a724358e..2dabe1f4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -191,6 +191,7 @@ en: delete_note_title: "Delete this note" delete_confirmation: "Are you sure that you want to delete the note '{{id}}'?" edit_item_title: "Edit item" + delete_item_title: "Delete item" show_note_title: "Show note" deleted_note: "Deleted note '{{id}}'" no_notes_available: "Currently there are no notes: add notes to projects from individual project pages." diff --git a/features/logging_in.feature b/features/logging_in.feature index b4c9c321..f0b4d7cd 100644 --- a/features/logging_in.feature +++ b/features/logging_in.feature @@ -50,7 +50,7 @@ Feature: Existing user logging in | "top secret" project for user "testuser" | "top secret" project for user "testuser" | Logout (Test User) | | context page for "@secret location" for user "testuser" | context page for "@secret location" for user "testuser" | Logout (Test User) | - @selenium @wip + @selenium Scenario: When session expires, you should be logged out When I go to the login page And I submit the login form as user "testuser" with password "secret" diff --git a/features/notes_manage.feature b/features/notes_manage.feature index dca28671..403c0c6f 100644 --- a/features/notes_manage.feature +++ b/features/notes_manage.feature @@ -22,7 +22,7 @@ Feature: View, add, remove notes And I should see note "My Note A" on the notes page Then the badge should show 1 - @selenium + @selenium @wip Scenario: Delete note from notes page Given I have a project "Pass Final Exam" with 2 notes When I go to the notes page @@ -36,3 +36,10 @@ Feature: View, add, remove notes When I visit the "Pass Final Exam" project And I click the icon next to the note Then I should see the note text + + @selenium @wip + Scenario: Edit a note + Given I have a project "Pass Final Exam" with 2 notes + When I go to the notes page + And I edit the note to "edited note" + Then I should see "edited note" \ No newline at end of file diff --git a/features/step_definitions/note_steps.rb b/features/step_definitions/note_steps.rb index fbc93eb7..65beb76e 100644 --- a/features/step_definitions/note_steps.rb +++ b/features/step_definitions/note_steps.rb @@ -28,7 +28,7 @@ end When /^I delete the first note$/ do title = selenium.get_text("css=div.container h2") id = title.split(' ').last - click_link "delete note" + click_link "delete_note_#{id}" selenium.get_confirmation.should == "Are you sure that you want to delete the note '#{id}'?" end @@ -58,7 +58,7 @@ Then /^the first note should disappear$/ do title = selenium.get_text("css=div.container h2") id = title.split(' ').last wait_for :timeout => 15 do - !selenium.is_visible("note_#{id}") + !selenium.is_element_present("note_#{id}") end end diff --git a/public/javascripts/application.js b/public/javascripts/application.js index a7fcba5f..c2227135 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -104,6 +104,19 @@ var IntegrationsPage = { } } +var NotesPage = { + setup_behavior: function() { + $('a.delete_note_button').live('click', function(evt){ + evt.preventDefault(); + if(confirm("Are you sure that you want to "+this.title+"?")){ + $(this).parents('.project').block({message: null}); + params = {_method: 'delete'}; + $.post(this.href, params, null, 'script'); + } + }); + } +} + $.fn.clearForm = function() { return this.each(function() { var type = this.type, tag = this.tagName.toLowerCase(); @@ -740,6 +753,7 @@ $(document).ready(function() { }); IntegrationsPage.setup_behavior(); + NotesPage.setup_behavior(); /* Gets called from some AJAX callbacks, too */ enable_rich_interaction();