class NotesController

Public Instance Methods

add_note() click to toggle source
# File app/controllers/notes_controller.rb, line 20
def add_note
  return unless request.post?
  @note = Note.new
  @note.creator_id = @current_user.id
  @note.notes_message = params[:new_notes]
  @note.noteable_id = params[:noteable_id]
  @note.noteable_type = params[:noteable_type]
  unless @note.save
    render 'notes/modal_dialogs/notes_dialog_error.rjs'
  else
    @note.reload
    @number_of_notes_field = params[:number_of_notes_field]
    @highlight_field = params[:highlight_field]
    @number_of_notes = @note.noteable.notes.size
    render 'notes/modal_dialogs/notes_dialog_success.rjs'
  end
end
create() click to toggle source
# File app/controllers/notes_controller.rb, line 51
def create
  @note = Note.new(params[:note])
  @note.noteable_type = params[:noteable_type]
  @note.creator_id = @current_user.id

  if @note.save
    flash[:success] = I18n.t('notes.create.success')
    redirect_to :action => 'index'
  else
    new_retrieve
    render :new
  end
end
destroy() click to toggle source
# File app/controllers/notes_controller.rb, line 99
def destroy
  @note = Note.find(params[:id])
  if @note.user_can_modify?(current_user)
    @note.destroy
    flash[:success] = I18n.t('notes.delete.success')
  else
    flash[:error] = I18n.t('notes.delete.error_permissions')
  end
end
edit() click to toggle source
# File app/controllers/notes_controller.rb, line 87
def edit
end
index() click to toggle source
# File app/controllers/notes_controller.rb, line 38
def index
  @notes = Note.all(:order => "created_at DESC", :include => [:user, :noteable])
  @current_user = current_user
  # Notes are attached to noteables, if there are no noteables, we can't make notes.
  @noteables_available = Note.noteables_exist?
end
new() click to toggle source

gets the objects for groupings on first load.

# File app/controllers/notes_controller.rb, line 46
def new
  new_retrieve
  @note = Note.new
end
new_update_groupings() click to toggle source

Used to update the values in the groupings dropdown in the new note form

# File app/controllers/notes_controller.rb, line 66
def new_update_groupings
  retrieve_groupings(Assignment.find(params[:assignment_id]))
end
noteable_object_selector() click to toggle source

used for RJS call

# File app/controllers/notes_controller.rb, line 71
def noteable_object_selector
  case params[:noteable_type]
    when 'Student'
      @students = Student.all(:order => 'user_name')
    when 'Assignment'
      @assignments = Assignment.all
    when 'Grouping'
      new_retrieve
    else
      # default to groupings if all else fails.
      params[:noteable_type] = 'Grouping'
      flash[:error] = I18n.t('notes.new.invalid_selector')
      new_retrieve
  end
end
notes_dialog() click to toggle source

TODO this method needs explaining ! What is return_id ?

# File app/controllers/notes_controller.rb, line 6
def notes_dialog
  @return_id = params[:id]
  @cls = params[:noteable_type]
  @noteable = Kernel.const_get(@cls).find_by_id(params[:noteable_id])
  @cont = params[:controller_to]
  @action = params[:action_to]
  @highlight_field = params[:highlight_field]
  @number_of_notes_field = params[:number_of_notes_field]

  @notes = Note.all(:conditions => {:noteable_id => @noteable.id,
                                    :noteable_type => @noteable.class.name})
  render :partial => 'notes/modal_dialogs/notes_dialog_script.rjs'
end
update() click to toggle source
# File app/controllers/notes_controller.rb, line 90
def update
  if @note.update_attributes(params[:note])
    flash[:success] = I18n.t('notes.update.success')
    redirect_to :action => 'index'
  else
    render :edit
  end
end