orbit-basic/vendor/built_in_modules/personal_experience/app/controllers/panel/personal_experience/back_end/experiences_controller.rb

262 lines
7.2 KiB
Ruby

class Panel::PersonalExperience::BackEnd::ExperiencesController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
before_filter :authenticate_user!
before_filter :force_order_for_visitor,:only=>[:index,:show]
before_filter :force_order_for_user,:except => [:index,:show]
# before_filter :for_app_manager,:except => [:index,:show]
before_filter :only => [ :new,:edit,:update] do |controller|
controller.get_categorys('ExperienceCategory')
end
def index
get_plugins
get_categorys("ExperienceCategory",params[:experience_category_ids])
@filter = params[:filter]
new_filter = params[:new_filter]
if @filter && params[:clear]
@filter.delete(params[:type])
elsif @filter && new_filter
if @filter.has_key?(new_filter[:type]) && @filter[new_filter[:type]].include?(new_filter[:id].to_s)
@filter[new_filter[:type]].delete(new_filter[:id].to_s)
elsif @filter.has_key?(new_filter[:type])
@filter[new_filter[:type]] << new_filter[:id].to_s
else
@filter.merge!({new_filter[:type] => [new_filter[:id].to_s]})
end
elsif new_filter
@filter = {new_filter[:type] => [new_filter[:id].to_s]}
end
@experience_categorys = get_categories_for_index("ExperienceCategory")
@experience_category_ids = @experience_categorys.collect{|t| t.id.to_s} + [nil]
@experiences = (params[:sort] || @filter) ? get_sorted_and_filtered("experience",:experience_category_id.in => @experience_category_ids) : get_viewable("experience",:experience_category_id.in => @experience_category_ids)
@tags = get_tags
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @experiences }
format.js
end
end
def experience_setting
get_plugins
@experience_types = ExperienceCategory.all
@tags = get_tags
@set_experience_type = ExperienceCategory.new(:display => 'List')
@experience_type_url = panel_personal_experience_back_end_experiences_path
end
def experience_category_quick_add
@set_experience_type = ExperienceCategory.new(:display => 'List')
@experience_type_url = panel_personal_experience_back_end_experiences_path
@set_experience_type.id = params[:id]
respond_to do |format|
format.js
end
end
def experience_category_quick_edit
@set_experience_type = ExperienceCategory.find(params[:experience_id])
@experience_type_url = panel_personal_experience_back_end_experience_path(@set_experience_type)
respond_to do |format|
format.js
end
end
# GET /experiences/1
# GET /experiences/1.xml
def show
@experience = Experience.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @experience }
end
end
# GET /experiences/new
# GET /experiences/new.xml
def new
get_plugins
@experience = Experience.new
@experience_categorys = ExperienceCategory.all
@tags = get_tags
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @experience }
end
end
# GET /experiences/1/edit
def edit
get_plugins
@experience = Experience.find(params[:id])
@experience_types = ExperienceCategory.all
@tags = get_tags
end
# POST /experiences
# POST /experiences.xml
def create
if params[:experience_category]
@experience_category = ExperienceCategory.new(params[:experience_category])
respond_to do |format|
if @experience_category.save
format.js { render 'create_experience_setting' }
end
end
else
@experience_types = ExperienceCategory.all
@tags = get_tags
@experience = Experience.new(params[:experience])
if params[:experience][:user_id]
@experience.create_user_id = params[:experience][:user_id]
@experience.update_user_id = params[:experience][:user_id]
else
@experience.create_user_id = current_user.id
@experience.update_user_id = current_user.id
end
respond_to do |format|
if @experience.save
if params[:experience][:user_id]
format.html { redirect_to(admin_users_new_interface_url(:id=>params[:experience][:user_id],:show_plugin_profile=>'Experience')) }
else
format.html { redirect_to(panel_personal_experience_back_end_experiences_url) }
end
format.xml { render :xml => @experience, :status => :created, :location => @experience }
else
format.html { render :action => "new" }
format.xml { render :xml => @experience.errors, :status => :unprocessable_entity }
end
end
end
end
# PUT /experiences/1
# PUT /experiences/1.xml
def update
if params[:experience_category]
@experience_category = ExperienceCategory.find(params[:id])
respond_to do |format|
if @experience_category.update_attributes(params[:experience_category])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_experience_setting' }
end
end
else
@experience = Experience.find(params[:id])
@experience.update_user_id = current_user.id
params[:experience][:tag_ids] ||=[]
respond_to do |format|
if @experience.update_attributes(params[:experience])
format.html { redirect_to(panel_personal_experience_back_end_experiences_url) }
# format.js { render 'toggle_enable' }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @experience.errors, :status => :unprocessable_entity }
end
end
end
end
# DELETE /experiences/1
# DELETE /experiences/1.xml
def destroy
@experience = Experience.find(params[:id])
@experience.destroy
respond_to do |format|
format.html { redirect_to(panel_personal_experience_back_end_experiences_url) }
# format.xml { head :ok }
format.js
end
end
def delete
if params[:ids]
experiences = Experience.any_in(:_id => params[:ids]).destroy_all
end
redirect_to panel_personal_experience_back_end_experiences_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
end
protected
# def get_index_categories(id = nil)
# @bulletin_categorys = []
# if(is_manager? || is_admin?)
# @bulletin_categorys = (id ? BulletinCategory.admin_manager_all.find(id).to_a : BulletinCategory.admin_manager_all)
# elsif is_sub_manager?
# @bulletin_categorys = BulletinCategory.all
# end
# @bulletin_categorys
# end
# def get_categorys(id = nil)
# @experience_categorys = []
# if(is_manager? || is_admin?)
# @experience_categorys = (id ? ExperienceCategory.admin_manager_all.find(id).to_a : ExperienceCategory.admin_manager_all))
# elsif is_sub_manager?
# @experience_categorys = ExperienceCategory.all.authed_for_user(current_user,'edit')
# end
# if @experience_categorys.empty? && params[:action] != "index"
# flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
# redirect_to :action => :index
# end
# end
def get_plugins
@plugins = OrbitApp::Plugin::Registration.all
end
end