59 lines
1.3 KiB
Ruby
59 lines
1.3 KiB
Ruby
# encoding: utf-8
|
|
class Admin::NewsAdminsController < OrbitAdminController
|
|
def initialize
|
|
super
|
|
@app_title = 'news'
|
|
end
|
|
|
|
def index
|
|
@unit_table_fields = ['news.unit','news.department']
|
|
@unit = Unit.new
|
|
sort = (!params[:sort].blank? ? {params[:sort].to_sym=>params[:order]} : {:id=>"asc"})
|
|
@units = Unit.order_by(sort)
|
|
end
|
|
|
|
def create
|
|
unit = Unit.new(unit_params)
|
|
unit.save
|
|
redirect_to admin_news_admins_path
|
|
end
|
|
|
|
def edit
|
|
@unit = Unit.find(params[:id])
|
|
@unit_table_fields = ['news.unit','news.department']
|
|
sort = (!params[:sort].blank? ? {params[:sort].to_sym=>params[:order]} : {:id=>"asc"})
|
|
@units = Unit.order_by(sort)
|
|
|
|
@url = admin_news_admin_path(@unit)
|
|
end
|
|
|
|
def update
|
|
@unit = Unit.find_by(:uid => params[:id].split("-").last) rescue nil
|
|
@unit.update_attributes(unit_params) if !@unit.nil?
|
|
|
|
redirect_to admin_news_admins_path
|
|
end
|
|
|
|
def destroy
|
|
unit = Unit.find(params[:id])
|
|
unit.destroy
|
|
redirect_to admin_news_admins_path
|
|
end
|
|
|
|
def unit_params
|
|
params.require(:unit).permit!
|
|
end
|
|
|
|
def get_departments
|
|
unit = Unit.find(Sanitize.clean(params[:unit]))
|
|
departments = unit.departments.collect do |d|
|
|
{
|
|
"name" => d.name,
|
|
"id" => d.id.to_s
|
|
}
|
|
end
|
|
render :json => {"departments" => departments}.to_json
|
|
end
|
|
|
|
end
|