2005-06-18 13:46:03 +00:00
|
|
|
class NoteController < ApplicationController
|
2005-08-08 01:54:05 +00:00
|
|
|
|
|
|
|
|
model :user
|
|
|
|
|
before_filter :login_required
|
|
|
|
|
|
2005-06-18 13:46:03 +00:00
|
|
|
layout "standard"
|
2005-08-08 01:54:05 +00:00
|
|
|
|
2005-06-18 13:46:03 +00:00
|
|
|
def index
|
2005-08-08 01:54:05 +00:00
|
|
|
@all_notes = @user.notes
|
2005-06-18 13:46:03 +00:00
|
|
|
@page_title = "TRACKS::All notes"
|
|
|
|
|
end
|
2005-08-08 01:54:05 +00:00
|
|
|
|
2005-06-18 13:46:03 +00:00
|
|
|
def show
|
2005-08-08 01:54:05 +00:00
|
|
|
@note = check_user_return_note
|
2005-06-18 13:46:03 +00:00
|
|
|
@page_title = "TRACKS::Note " + @note.id.to_s
|
|
|
|
|
end
|
2005-08-08 01:54:05 +00:00
|
|
|
|
2005-06-18 13:46:03 +00:00
|
|
|
# Add a new note to this project
|
|
|
|
|
#
|
2005-08-08 01:54:05 +00:00
|
|
|
def add
|
|
|
|
|
note = @user.notes.build
|
2006-05-13 13:32:39 +00:00
|
|
|
note.attributes = params["new_note"]
|
2005-06-18 13:46:03 +00:00
|
|
|
|
|
|
|
|
if note.save
|
|
|
|
|
render_partial 'notes_summary', note
|
|
|
|
|
else
|
|
|
|
|
render_text ""
|
|
|
|
|
end
|
|
|
|
|
end
|
2005-08-08 01:54:05 +00:00
|
|
|
|
|
|
|
|
def delete
|
|
|
|
|
note = check_user_return_note
|
2005-06-18 13:46:03 +00:00
|
|
|
if note.destroy
|
|
|
|
|
render_text ""
|
|
|
|
|
else
|
|
|
|
|
flash["warning"] = "Couldn't delete note \"#{note.id.to_s}\""
|
|
|
|
|
render_text ""
|
|
|
|
|
end
|
|
|
|
|
end
|
2005-08-08 01:54:05 +00:00
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
note = check_user_return_note
|
2006-05-13 13:32:39 +00:00
|
|
|
note.attributes = params["note"]
|
2005-06-18 13:46:03 +00:00
|
|
|
if note.save
|
|
|
|
|
render_partial 'notes', note
|
|
|
|
|
else
|
|
|
|
|
flash["warning"] = "Couldn't update note \"#{note.id.to_s}\""
|
|
|
|
|
render_text ""
|
|
|
|
|
end
|
|
|
|
|
end
|
2005-08-08 01:54:05 +00:00
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
|
|
def check_user_return_note
|
2006-05-13 13:32:39 +00:00
|
|
|
note = Note.find_by_id( params['id'] )
|
2006-04-08 17:46:41 +00:00
|
|
|
if @user == note.user
|
2005-08-08 01:54:05 +00:00
|
|
|
return note
|
|
|
|
|
else
|
|
|
|
|
render_text ""
|
|
|
|
|
end
|
|
|
|
|
end
|
2005-06-18 13:46:03 +00:00
|
|
|
end
|