Class: Knitkit::ErpApp::Desktop::CommentsController

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

Constant Summary

Constants inherited from AppController

AppController::KNIT_KIT_ROOT

Instance Method Summary collapse

Methods inherited from AppController

#available_roles, #websites

Instance Method Details

#approveObject



26
27
28
29
30
31
# File 'app/controllers/knitkit/erp_app/desktop/comments_controller.rb', line 26

def approve
  comment = Comment.find(params[:id])
  comment.approve(current_user)
  
  render :json => {:success => true}
end

#deleteObject



33
34
35
36
37
38
# File 'app/controllers/knitkit/erp_app/desktop/comments_controller.rb', line 33

def delete
  comment = Comment.find(params[:id])
  comment.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
24
# File 'app/controllers/knitkit/erp_app/desktop/comments_controller.rb', line 6

def index
  content = Content.find(params[:content_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'
  limit = params[:limit] || 10
  start = params[:start] || 0

  Comment.class_eval do
    def approved_by_username
      approved_by.nil? ? '' : approved_by.username
    end
  end
  
  #limit and offset are not working rails issue?
  comments = content.comments.order("#{sort} #{dir}").offset(start).limit(limit)
    
  render :inline => "{totalCount:#{comments.count}, comments:#{comments.to_json(:methods => [:approved?, :approved_by_username])}}"
end