2014-05-08 07:33:39 +00:00
|
|
|
class Admin::FaqsController < OrbitAdminController
|
|
|
|
|
|
|
|
before_filter :setup_vars
|
|
|
|
|
2014-05-05 07:57:25 +00:00
|
|
|
def index
|
2014-05-13 07:30:44 +00:00
|
|
|
@table_fields = ["status","category","title","tags"]
|
2014-05-08 07:33:39 +00:00
|
|
|
@categories = @module_app.categories
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@filter_fields = {
|
|
|
|
:status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}],
|
|
|
|
:category=>@categories.map{|c| {:title=>c.title, :id=>c.id}},
|
|
|
|
:tags=>@tags.map{|tag| {:title=>tag.name, :id=>tag.id}}
|
|
|
|
}
|
|
|
|
status = params[:filters][:status].blank? ? [] : params[:filters][:status] rescue []
|
|
|
|
categories = params[:filters][:category].blank? ? [] : params[:filters][:category] rescue []
|
|
|
|
tags = params[:filters][:tags].blank? ? [] : params[:filters][:tags] rescue []
|
|
|
|
|
2014-05-21 07:56:06 +00:00
|
|
|
@qas = Qa.order_by(sort).with_categories(categories).with_tags(tags).with_status(status).page(params[:page]).per(10)
|
2014-05-08 07:33:39 +00:00
|
|
|
|
|
|
|
if request.xhr?
|
|
|
|
render :partial => "index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sort
|
|
|
|
unless params[:sort].blank?
|
|
|
|
case params[:sort]
|
|
|
|
when "status"
|
|
|
|
@sort = [[:is_top, params[:order]],
|
|
|
|
[:is_hot, params[:order]],
|
|
|
|
[:is_hidden,params[:order]]]
|
|
|
|
when "category"
|
|
|
|
@sort = {:category_id=>params[:order]}
|
|
|
|
when "title"
|
|
|
|
@sort = {:title=>params[:order]}
|
|
|
|
when "last_modified"
|
|
|
|
@sort = {:update_user_id=>params[:order]}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@sort = {:created_at=>'desc'}
|
|
|
|
end
|
|
|
|
@sort
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
@qa = Qa.new
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # new.html.erb
|
|
|
|
format.xml { render :xml => @qa }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@qa = Qa.new(create_params)
|
|
|
|
@qa.create_user_id = current_user.id
|
|
|
|
@qa.update_user_id = current_user.id
|
|
|
|
@qa.save
|
2014-08-05 06:39:47 +00:00
|
|
|
redirect_to params['referer_url']
|
2014-05-08 07:33:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@qa = Qa.find(params[:id])
|
2014-07-31 12:41:24 +00:00
|
|
|
if can_edit_or_delete?(@qa)
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories
|
|
|
|
else
|
|
|
|
render_401
|
|
|
|
end
|
2014-05-08 07:33:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@qa = Qa.find(params[:id])
|
|
|
|
@qa.update_attributes(create_params)
|
|
|
|
@qa.update_user_id = current_user.id
|
|
|
|
@qa.save
|
2014-08-05 06:39:47 +00:00
|
|
|
redirect_to params['referer_url']
|
2014-05-08 07:33:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@qa = Qa.find(params[:id])
|
|
|
|
@qa.destroy
|
|
|
|
redirect_to admin_faqs_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def setup_vars
|
|
|
|
@module_app = ModuleApp.where(:key => "faq").first
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_params
|
|
|
|
params.require(:qa).permit!
|
2014-05-05 07:57:25 +00:00
|
|
|
end
|
|
|
|
end
|