Class: ErpApp::Shared::NotesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/erp_app/shared/notes_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/erp_app/shared/notes_controller.rb', line 26

def create
    content  = params[:content]
    note_type = NoteType.find(params[:note_type_id])
    party = Party.find(params[:party_id])

    note = Note.create(
      :note_type => note_type,
      :content => content,
      :created_by_id => current_user.party.id
    )

    party.notes << note
    party.save

    render :json => {:success => true}
end

#deleteObject



43
44
45
# File 'app/controllers/erp_app/shared/notes_controller.rb', line 43

def delete
    Note.find(params[:id]).destroy ? (render :json => {:success => true}) : (render :json => {:success => false})
end

#note_typesObject



47
48
49
50
51
# File 'app/controllers/erp_app/shared/notes_controller.rb', line 47

def note_types
    NoteType.include_root_in_json = false

    render :json => {:note_types => NoteType.all}
end

#viewObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/erp_app/shared/notes_controller.rb', line 6

def view
    if params[:party_id].to_i == 0
      render :json => {:totalCount => 0, :notes => []}
    else
      sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
      limit = params[:limit] || 30
      start = params[:start] || 0

      sort = sort_hash[:property] || 'created_at'
      dir  = sort_hash[:direction] || 'DESC'

      Note.include_root_in_json = false
			
      party = Party.find(params[:party_id])
      notes = party.notes.order("#{sort} #{dir}").limit(limit).offset(start)
			
      render :inline => "{\"totalCount\":#{party.notes.count}, \"notes\":#{notes.to_json(:only => [:id, :content, :created_at], :methods => [:summary, :note_type_desc, :created_by_username])}}"
    end
end