Sha256: d4384c7f9fdc4986483580fdcc63210362cf0edbe0e30e8663909d1eb8fbe644

Contents?: true

Size: 1.33 KB

Versions: 29

Compression:

Stored size: 1.33 KB

Contents

module Knitkit
  module ErpApp
    module Desktop
      class CommentsController < Knitkit::ErpApp::Desktop::AppController
        
        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

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

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

      end#CommentsController
    end#Desktop
  end#ErpApp
end#Knitkit

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
knitkit-3.2.0 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-3.0.0 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.15 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.14 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.13 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.12 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.11 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.10 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.9 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.8 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.7 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.6 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.5 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.4 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.3 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.2 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.1 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.1.0 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.0.11 app/controllers/knitkit/erp_app/desktop/comments_controller.rb
knitkit-2.0.10 app/controllers/knitkit/erp_app/desktop/comments_controller.rb