Class: Knitkit::ErpApp::Desktop::InquiriesController

Inherits:
AppController
  • Object
show all
Defined in:
app/controllers/knitkit/erp_app/desktop/inquiries_controller.rb

Constant Summary

Constants inherited from AppController

AppController::KNIT_KIT_ROOT

Instance Method Summary collapse

Instance Method Details

#destroyObject



25
26
27
28
29
# File 'app/controllers/knitkit/erp_app/desktop/inquiries_controller.rb', line 25

def destroy
  website_inquiry = WebsiteInquiry.find(params[:id])
  website_inquiry.destroy
  render :json => {:success => true}
end

#indexObject



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

def index
  limit = params[:limit] || 15
  offset = params[:start] || 0

  website = Website.find(params[:website_id])
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
  sort = sort_hash[:property] || 'created_at'
  dir = sort_hash[:direction] || 'DESC'

  total = website.website_inquiries.count

  inquiries = website.website_inquiries.limit(limit).offset(offset).order("#{sort} #{dir}")

  render :json => {:success => true, :total => total, :inquiries => inquiries.collect { |inquiry|
    inquiry.to_hash(:only => [:id, :first_name, :last_name, :message, :email, :created_at],
                    :username => (inquiry.created_by.nil? ? '' : inquiry.created_by.username)) }
  }
end