diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 756cf9c2..e4f39cd4 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -63,13 +63,12 @@ class NotesController < ApplicationController end def update - note = current_user.notes.find(params['id']) - note.attributes = params["note"] - if note.save - render :partial => 'notes', :object => note - else - notify :warning, "Couldn't update note \"#{note.id}\"" - render :text => '' + @note = current_user.notes.find(params['id']) + @note.attributes = params["note"] + @saved = @note.save + respond_to do |format| + format.html + format.js end end diff --git a/app/views/layouts/standard.html.erb b/app/views/layouts/standard.html.erb index 745a71d3..3b55b3c4 100644 --- a/app/views/layouts/standard.html.erb +++ b/app/views/layouts/standard.html.erb @@ -2,7 +2,7 @@ - <%= stylesheet_link_tag 'standard','superfish','niftyCorners', 'jquery-ui-1.8.5.custom', :cache => true %> + <%= stylesheet_link_tag 'standard','superfish','niftyCorners', 'jquery-ui-1.8.6.custom', :cache => true %> <%= stylesheet_link_tag "print", :media => "print" %> <%= javascript_include_tag 'jquery-1.4.4.min', 'jquery-ui-1.8.6.custom.min', 'jquery.truncator', 'jquery.jeditable.mini', 'jquery.cookie', 'jquery.blockUI', 'jquery.form', :cache => 'jquery-all' %> diff --git a/app/views/notes/_note.rhtml b/app/views/notes/_note.rhtml index 0f556980..f41ab2ab 100644 --- a/app/views/notes/_note.rhtml +++ b/app/views/notes/_note.rhtml @@ -4,39 +4,12 @@

<%= 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) %>
- - - + <%= render :partial => "notes/note_details", :object => note %>
- \ No newline at end of file diff --git a/app/views/notes/_note_details.rhtml b/app/views/notes/_note_details.rhtml new file mode 100644 index 00000000..bd95a8ad --- /dev/null +++ b/app/views/notes/_note_details.rhtml @@ -0,0 +1,16 @@ +<% note = note_details -%> +
<%= format_note(note.body) %>
+ + diff --git a/app/views/notes/_note_edit_form.rhtml b/app/views/notes/_note_edit_form.rhtml index 93090c46..5ad8d16d 100644 --- a/app/views/notes/_note_edit_form.rhtml +++ b/app/views/notes/_note_edit_form.rhtml @@ -1,21 +1,13 @@ -<% -#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 + :method => :put }) do |f| -%> - <%= hidden_field( "note", "project_id" ) %> - <%= text_area( "note", "body", "cols" => 70, "rows" => 15, "tabindex" => 1 ) %> -

- +
<%= error_messages_for("note") %>
+ + <%= f.hidden_field( "project_id" ) %> + <%= f.text_area( "body", "cols" => 70, "rows" => 15, "tabindex" => 1 ) %>
@@ -23,11 +15,13 @@ <%=image_tag("accept.png", :alt => "") %> <%= t 'common.update' %> - + <%=image_tag("cancel.png", :alt => "") %> <%= t 'common.cancel' %>
-<% end -%> +

+ +<% end -%> \ No newline at end of file diff --git a/app/views/notes/update.js.erb b/app/views/notes/update.js.erb new file mode 100644 index 00000000..58735b31 --- /dev/null +++ b/app/views/notes/update.js.erb @@ -0,0 +1,33 @@ +<% if @saved -%> + + page_notify('notice', 'Note <%=@note.id %> saved', 5); + replace_note_form_with_updated_note(); + +<% else -%> + show_errors(); +<% end %> + +function show_errors() { + $('div#edit_error_status').html(html_for_error_messages()); + $('div#edit_error_status').show(); +} + +function replace_note_form_with_updated_note() { + $('#<%= dom_id(@note, 'edit')%>').fadeOut(250, function() { + $('#<%= dom_id(@note, 'edit')%>').html(html_for_updated_note_form()); + $('div.project_notes#<%= dom_id(@note)%>').html(html_for_updated_note_details()); + $('#<%= dom_id(@note)%>').fadeIn(500); + }); +} + +function html_for_error_messages() { + return "<%= escape_javascript(error_messages_for('note')) %>"; +} + +function html_for_updated_note_form(){ + return "<%= escape_javascript(render(:partial => 'note_edit_form', :object => @note)) %>"; +} + +function html_for_updated_note_details(){ + return "<%= escape_javascript(render(:partial => 'note_details', :object => @note)) %>"; +} \ No newline at end of file diff --git a/features/notes_manage.feature b/features/notes_manage.feature index acf4296f..86a3ab47 100644 --- a/features/notes_manage.feature +++ b/features/notes_manage.feature @@ -37,9 +37,9 @@ Feature: View, add, remove notes And I click the icon next to the note Then I should see the note text - @selenium @wip + @selenium 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" + And I edit the first note to "edited note" Then I should see "edited note" \ No newline at end of file diff --git a/features/project_edit.feature b/features/project_edit.feature index 446b7675..8872843f 100644 --- a/features/project_edit.feature +++ b/features/project_edit.feature @@ -62,3 +62,27 @@ Feature: Edit a project Then the badge should show 2 # "manage me" and "test" When I try to edit the project name of "manage me" to "test" Then I should see "Name already exists" + + @selenium @wip + Scenario: I can go to the note of a project + Given I have a project "test" with 2 note + When I visit the "test" project + Then I should see 2 notes + When I click on the first note icon + Then I should go to that note page + + @selenium @wip + Scenario: I can add a note to the project + Given I have a project "test" + When I visit the "test" project + And I add a note "hello I'm testing" + Then I should see one note + + @selenium @wip + Scenario: Long notes in a project are shown cut off + Given I have a project "test" + When I visit the "test" project + And I add a note "test 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234 TOO LONG" + Then I should not see "test 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234 TOO LONG" + And I should see "test 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234" + diff --git a/features/step_definitions/note_steps.rb b/features/step_definitions/note_steps.rb index 5116a4ed..66b1602d 100644 --- a/features/step_definitions/note_steps.rb +++ b/features/step_definitions/note_steps.rb @@ -36,8 +36,12 @@ When /^I click the icon next to the note$/ do click_link "Show note" end -When /^I edit the note to "([^"]*)"$/ do |note_content| - pending # express the regexp above with the code you wish you had +When /^I edit the first note to "([^"]*)"$/ do |note_body| + title = selenium.get_text("css=div.container h2") + id = title.split(' ').last + click_link "link_edit_note_#{id}" + fill_in "note[body]", :with => note_body + click_button "submit_note_#{id}" end Then /^(.*) notes should be visible$/ do |number| @@ -68,4 +72,4 @@ end Then /^I should see the note text$/ do Then "I should see \"after 50 characters\"" -end +end \ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index c2227135..fbd50251 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -106,6 +106,7 @@ var IntegrationsPage = { var NotesPage = { setup_behavior: function() { + /* delete button for note */ $('a.delete_note_button').live('click', function(evt){ evt.preventDefault(); if(confirm("Are you sure that you want to "+this.title+"?")){ @@ -113,7 +114,34 @@ var NotesPage = { params = {_method: 'delete'}; $.post(this.href, params, null, 'script'); } - }); + }); + + /* edit button for note */ + $('a.note_edit_settings').live('click', function(evt){ + evt.preventDefault(); + dom_id = this.id.substr(10); + $('#'+dom_id).toggle(); $('#edit_'+dom_id).show(); $('#edit_form_'+dom_id+' textarea').focus(); + }); + + /* cancel button when editing a note */ + $('.edit-note-form a.negative').live('click', function(){ + dom_id = this.id.substr(14); + $('#'+dom_id).toggle(); $('#edit_'+dom_id).hide(); + return false; + }); + + /* update button when editing a note */ + $("form.edit-note-form button.positive").live('click', function (ev) { + $('form.edit-note-form').ajaxSubmit({ + type: 'POST', + async: true, + buttons_dom_elem: $(this), + beforeSend: function() { + this.buttons_dom_elem.block({message: null});}, + complete: function() {this.buttons_dom_elem.unblock();} + }); + return false; + }); } } @@ -523,11 +551,12 @@ $(document).ready(function() { }); /* for edit project form and edit todo form */ - $('.edit-form a.negative').live('click', function(){ + $('.edit-form a.negative').live('click', function(){ $(this).parents('.edit-form').fadeOut(200, function () { $(this).parents('.list').find('.project').fadeIn(500); $(this).parents('.container').find('.item-show').fadeIn(500); - })}); + }) + }); /* add behavior to clear the date both buttons for show_from and due */ $(".date_clear").live('click', function() {