mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-19 16:50:12 +01:00
fix editing a note from the notes page
This commit is contained in:
parent
77e2ff0751
commit
94b5aa2346
10 changed files with 133 additions and 61 deletions
|
|
@ -63,13 +63,12 @@ class NotesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
note = current_user.notes.find(params['id'])
|
@note = current_user.notes.find(params['id'])
|
||||||
note.attributes = params["note"]
|
@note.attributes = params["note"]
|
||||||
if note.save
|
@saved = @note.save
|
||||||
render :partial => 'notes', :object => note
|
respond_to do |format|
|
||||||
else
|
format.html
|
||||||
notify :warning, "Couldn't update note \"#{note.id}\""
|
format.js
|
||||||
render :text => ''
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<%= 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" %>
|
<%= stylesheet_link_tag "print", :media => "print" %>
|
||||||
<%= javascript_include_tag 'jquery-1.4.4.min', 'jquery-ui-1.8.6.custom.min', 'jquery.truncator',
|
<%= 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' %>
|
'jquery.jeditable.mini', 'jquery.cookie', 'jquery.blockUI', 'jquery.form', :cache => 'jquery-all' %>
|
||||||
|
|
|
||||||
|
|
@ -4,39 +4,12 @@
|
||||||
<h2><%= 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)) %></h2>
|
<h2><%= 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)) %></h2>
|
||||||
|
|
||||||
<div class="project_notes" id="<%= dom_id(note) %>">
|
<div class="project_notes" id="<%= dom_id(note) %>">
|
||||||
|
<%= render :partial => "notes/note_details", :object => note %>
|
||||||
<div class="note_boby"><%= format_note(note.body) %></div>
|
|
||||||
|
|
||||||
<div class="note_footer">
|
|
||||||
<% # = link_to_remote(
|
|
||||||
#image_tag("blank.png", :title =>t('notes.delete_note_title'), :class=>"delete_item", :id => "delete_note_"+note.id.to_s),
|
|
||||||
#:url => note_path(note),
|
|
||||||
#:html => {:class => 'delete_note', :title => "delete note"},
|
|
||||||
#:method => :delete,
|
|
||||||
#:confirm => t('notes.delete_confirmation', :id => note.id.to_s),
|
|
||||||
#:before => visual_effect(:fade, dom_id(note, 'container'))) -
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%= link_to_delete_note(note, image_tag( "blank.png",:title => t('notes.delete_item_title'), :class=>"delete_item")) %>
|
|
||||||
<%= link_to_edit_note(note, image_tag( "blank.png", :title => t('notes.edit_item_title'), :class=>"edit_item") ) %>
|
|
||||||
|
|
||||||
<%# link_to_function(image_tag( "blank.png", :title => t('notes.edit_item_title'), :class=>"edit_item"),
|
|
||||||
#"$('##{dom_id(note)}').toggle(); $('##{dom_id(note, 'edit')}').show(); $('##{dom_id(note, 'edit_form')} textarea').focus();" ) + " | "
|
|
||||||
%>
|
|
||||||
|
|
||||||
| <%= link_to("In: " + note.project.name, project_path(note.project), :class=>"footer_link" ) %> |
|
|
||||||
|
|
||||||
<%= Note.human_attribute_name('created_at') %>: <%= format_date(note.created_at) %>
|
|
||||||
|
|
||||||
<% if note.updated_at? -%>
|
|
||||||
| <%= Note.human_attribute_name('updated_at') %>: <%= format_date(note.updated_at) %>
|
|
||||||
<% end -%>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
<div id="<%= dom_id(note, 'edit') %>" class="note-edit-form" style="display:none;">
|
||||||
|
|
||||||
<div id="<%= dom_id(note, 'edit') %>" class="edit-form" style="display:none;">
|
|
||||||
<%= render :partial => "notes/note_edit_form", :object => note %>
|
<%= render :partial => "notes/note_edit_form", :object => note %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
16
app/views/notes/_note_details.rhtml
Normal file
16
app/views/notes/_note_details.rhtml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<% note = note_details -%>
|
||||||
|
<div class="note_boby"><%= format_note(note.body) %></div>
|
||||||
|
|
||||||
|
<div class="note_footer">
|
||||||
|
|
||||||
|
<%= link_to_delete_note(note, image_tag( "blank.png",:title => t('notes.delete_item_title'), :class=>"delete_item")) %>
|
||||||
|
<%= link_to_edit_note(note, image_tag( "blank.png", :title => t('notes.edit_item_title'), :class=>"edit_item") ) %>
|
||||||
|
|
||||||
|
| <%= link_to("In: " + note.project.name, project_path(note.project), :class=>"footer_link" ) %> |
|
||||||
|
|
||||||
|
<%= Note.human_attribute_name('created_at') %>: <%= format_date(note.created_at) %>
|
||||||
|
|
||||||
|
<% if note.updated_at? -%>
|
||||||
|
| <%= Note.human_attribute_name('updated_at') %>: <%= format_date(note.updated_at) %>
|
||||||
|
<% end -%>
|
||||||
|
</div>
|
||||||
|
|
@ -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 => {
|
<% form_for(note_edit_form, :html => {
|
||||||
:id => dom_id(note_edit_form, 'edit_form'),
|
:id => dom_id(note_edit_form, 'edit_form'),
|
||||||
:class => "inline-form edit-note-form",
|
:class => "inline-form edit-note-form",
|
||||||
:method => :put }) do
|
:method => :put }) do |f|
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
<%= hidden_field( "note", "project_id" ) %>
|
<div id="error_status"><%= error_messages_for("note") %></div>
|
||||||
<%= text_area( "note", "body", "cols" => 70, "rows" => 15, "tabindex" => 1 ) %>
|
|
||||||
<br /><br />
|
<%= f.hidden_field( "project_id" ) %>
|
||||||
<input type="submit" value="<%= t('common.update') %>" tabindex="2" />
|
<%= f.text_area( "body", "cols" => 70, "rows" => 15, "tabindex" => 1 ) %>
|
||||||
|
|
||||||
<div class="submit_box">
|
<div class="submit_box">
|
||||||
<div class="widgets">
|
<div class="widgets">
|
||||||
|
|
@ -23,11 +15,13 @@
|
||||||
<%=image_tag("accept.png", :alt => "") %>
|
<%=image_tag("accept.png", :alt => "") %>
|
||||||
<%= t 'common.update' %>
|
<%= t 'common.update' %>
|
||||||
</button>
|
</button>
|
||||||
<a href="" onclick="" class="negative">
|
<a href="" class="negative" id="neg_<%=dom_id(note_edit_form, 'edit_form')%>">
|
||||||
<%=image_tag("cancel.png", :alt => "") %>
|
<%=image_tag("cancel.png", :alt => "") %>
|
||||||
<%= t 'common.cancel' %>
|
<%= t 'common.cancel' %>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
33
app/views/notes/update.js.erb
Normal file
33
app/views/notes/update.js.erb
Normal file
|
|
@ -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)) %>";
|
||||||
|
}
|
||||||
|
|
@ -37,9 +37,9 @@ Feature: View, add, remove notes
|
||||||
And I click the icon next to the note
|
And I click the icon next to the note
|
||||||
Then I should see the note text
|
Then I should see the note text
|
||||||
|
|
||||||
@selenium @wip
|
@selenium
|
||||||
Scenario: Edit a note
|
Scenario: Edit a note
|
||||||
Given I have a project "Pass Final Exam" with 2 notes
|
Given I have a project "Pass Final Exam" with 2 notes
|
||||||
When I go to the notes page
|
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"
|
Then I should see "edited note"
|
||||||
|
|
@ -62,3 +62,27 @@ Feature: Edit a project
|
||||||
Then the badge should show 2 # "manage me" and "test"
|
Then the badge should show 2 # "manage me" and "test"
|
||||||
When I try to edit the project name of "manage me" to "test"
|
When I try to edit the project name of "manage me" to "test"
|
||||||
Then I should see "Name already exists"
|
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"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,12 @@ When /^I click the icon next to the note$/ do
|
||||||
click_link "Show note"
|
click_link "Show note"
|
||||||
end
|
end
|
||||||
|
|
||||||
When /^I edit the note to "([^"]*)"$/ do |note_content|
|
When /^I edit the first note to "([^"]*)"$/ do |note_body|
|
||||||
pending # express the regexp above with the code you wish you had
|
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
|
end
|
||||||
|
|
||||||
Then /^(.*) notes should be visible$/ do |number|
|
Then /^(.*) notes should be visible$/ do |number|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ var IntegrationsPage = {
|
||||||
|
|
||||||
var NotesPage = {
|
var NotesPage = {
|
||||||
setup_behavior: function() {
|
setup_behavior: function() {
|
||||||
|
/* delete button for note */
|
||||||
$('a.delete_note_button').live('click', function(evt){
|
$('a.delete_note_button').live('click', function(evt){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
if(confirm("Are you sure that you want to "+this.title+"?")){
|
if(confirm("Are you sure that you want to "+this.title+"?")){
|
||||||
|
|
@ -114,6 +115,33 @@ var NotesPage = {
|
||||||
$.post(this.href, params, null, 'script');
|
$.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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -527,7 +555,8 @@ $(document).ready(function() {
|
||||||
$(this).parents('.edit-form').fadeOut(200, function () {
|
$(this).parents('.edit-form').fadeOut(200, function () {
|
||||||
$(this).parents('.list').find('.project').fadeIn(500);
|
$(this).parents('.list').find('.project').fadeIn(500);
|
||||||
$(this).parents('.container').find('.item-show').fadeIn(500);
|
$(this).parents('.container').find('.item-show').fadeIn(500);
|
||||||
})});
|
})
|
||||||
|
});
|
||||||
|
|
||||||
/* add behavior to clear the date both buttons for show_from and due */
|
/* add behavior to clear the date both buttons for show_from and due */
|
||||||
$(".date_clear").live('click', function() {
|
$(".date_clear").live('click', function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue