venue_management/app/controllers/admin/venue_managements_controlle...

347 lines
14 KiB
Ruby
Raw Permalink Normal View History

2020-05-07 15:26:34 +00:00
# encoding: utf-8
class Admin::VenueManagementsController < OrbitAdminController
require 'axlsx'
helper Admin::VenueManagementsFieldHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy]
def initialize
super
@app_title = "venue_management"
end
def filter_fields(categories)
{
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}}
}
end
def index
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories)
@table_fields = [:category, 'venue_management.title', 'venue_management.event_during', 'venue_management.signup_during', 'venue_management.signup_count', 'venue_management.inviting_hostory', 'venue_management.memorabilia','venue_management.export']
if !params[:sort].blank?
if params[:sort] == 'event_during'
sort = {:venue_management_start_date.to_sym=>params[:order]}
elsif params[:sort] == 'signup_during'
sort = {:signup_start_date.to_sym=>params[:order]}
else
sort = {params[:sort].to_sym=>params[:order]}
end
else
sort = {:signup_start_date=>"desc"}
end
@venue_managements = VenueManagementMain.all.order_by(sort).with_categories(filters("category"))
@venue_managements = search_data(@venue_managements,[:title]).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def export
@venue_management = VenueManagementMain.find(params[:id])
@venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => params[:id])
filename = @venue_management.title.parameterize.underscore + "_export.xlsx"
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="' + filename + '"'
}
end
end
def new
@member = nil
@managers = nil
@contractors = nil
@coordinators = nil
@venue_management = VenueManagementMain.new
create_set (false)
@signup_sets = @venue_management.venue_management_signup_field_sets
@submission_set = @venue_management.venue_management_submission_field_sets
@custom_set = @venue_management.venue_management_signup_field_customs
@venue_management_items = VenueManagementItem.all
@review = @venue_management.venue_management_reviews.new()
end
def create
if !venue_management_params['venue_management_links_attributes'].nil?
venue_management_params['venue_management_links_attributes'].each do |idx,link|
venue_management_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank?
end
end
venue_management_main_params = venue_management_params
venue_management_signup_set_params = venue_management_main_params['venue_management_signup_field_sets']
venue_management_submission_set_params = venue_management_main_params['venue_management_submission_field_sets']
venue_management_email_sets_params = venue_management_main_params['venue_management_email_sets']
venue_management_main_params.delete(:venue_management_signup_field_sets)
venue_management_main_params.delete(:venue_management_submission_field_sets)
venue_management_main_params.delete(:venue_management_email_sets)
venue_management = VenueManagementMain.new(venue_management_main_params)
venue_management.create_user_id = current_user.id
venue_management.update_user_id = current_user.id
venue_management.save
#venue_management_signup_set_params.each do |key,value|
# venue_management.venue_management_signup_field_sets.create(value)
#end
#venue_management_submission_set_params.each do |key,value|
# venue_management.venue_management_submission_field_sets.create(value)
#end
venue_management_email_sets_params.each do |key,value|
venue_management.venue_management_email_sets.create(value)
end
redirect_to params['referer_url']
end
def edit
@venue_management_items = VenueManagementItem.all
@venue_management = VenueManagementMain.where(id: params[:id]).first
@venue_management.venue_management_signup_field_sets.each do |signup_field_set|
if !(VenueManagementSignup.attribute_names.include? signup_field_set.field_name) && signup_field_set.field_name != 'recaptcha'
signup_field_set.delete
end
end
@venue_management.venue_management_submission_field_sets.each do |submission_field_set|
if !(VenueManagementSignupContribute.attribute_names.include? submission_field_set.field_name)
submission_field_set.delete
end
end
@venue_management.venue_management_signup_field_customs.each do |custom_set|
if !(@venue_management.venue_management_signup_fields.collect(&:id).include? custom_set.venue_management_signup_field_id)
custom_set.delete
end
end
create_set (true)
@signup_sets = @venue_management.venue_management_signup_field_sets
@submission_set = @venue_management.venue_management_submission_field_sets
@custom_set = @venue_management.venue_management_signup_field_customs
if @venue_management.venue_management_reviews.first.nil?
@review = @venue_management.venue_management_reviews.new()
else
@review = @venue_management.venue_management_reviews.first
end
@member = MemberProfile.find(@review.reviewer_id) rescue nil
@managers = MemberProfile.find(@venue_management.manager_ids) rescue nil
@contractors = MemberProfile.find(@venue_management.contractor_ids) rescue nil
@coordinators = MemberProfile.find(@venue_management.coordinator_ids) rescue nil
end
def update
params[:venue_management_main][:registration_status] = (params[:venue_management_main][:registration_status] ? params[:venue_management_main][:registration_status] : [])
uid = params[:id].split('-').last
@venue_management = VenueManagementMain.find_by(:uid=>uid)
if params[:venue_management_main][:venue_management_signup_fields]
venue_management_params[:venue_management_signup_fields].each do |a|
@field_name = 'venue_management_main'
field_status = a.last[:id].present?
@attribute_field = VenueManagementSignupField.add_venue_management_signup_field(@venue_management, a.last, a.last[:id], field_status)
@attribute = @venue_management
end
flash.now[:notice] = "Updated Fields"
@venue_management.venue_management_signup_fields.each{|t| t.destroy if t["to_delete"] == true}
redirect_to admin_venue_managements_path
elsif params[:venue_management_main][:venue_management_submission_fields]
params[:venue_management_main][:venue_management_submission_fields].each do |a|
@field_name = 'venue_management_main'
field_status = a.last[:id].present?
@attribute_field = VenueManagementSubmissionField.add_venue_management_signup_field(@venue_management, a.last, a.last[:id], field_status)
@attribute = @venue_management
end
flash.now[:notice] = "Updated Fields"
@venue_management.venue_management_submission_fields.each{|t| t.destroy if t["to_delete"] == true}
redirect_to admin_venue_managements_path
else
if !venue_management_params['venue_management_links_attributes'].nil?
venue_management_params['venue_management_links_attributes'].each do |idx,link|
venue_management_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank?
end
end
@venue_management.update_user_id = current_user.id
if @venue_management.update_attributes(venue_management_params)
@venue_management.venue_management_signup_fields.each{|t| t.destroy if t["to_delete"] == true}
redirect_to params['referer_url']
else
flash.now[:error] = t('update.error.category')
render action: :edit
end
end
end
def set_write_off
@venue_management.donation_write_off_status = true
@venue_management.save
redirect_to "/admin/venue_managements?page=#{params['page']}"
end
def destroy
@venue_management.destroy
redirect_to "/admin/venue_managements"
end
def venue_management_signup_field
@field_name = 'venue_management_main'
@attribute = VenueManagementMain.find(params[:id])
@attribute_type = 'venue_management'
@class = 'venue_managements'
end
def venue_management_submission_field
@field_name = 'venue_management_main'
@attribute = VenueManagementMain.find(params[:id])
@attribute_type = 'venue_management'
@class = 'venue_managements'
end
def venue_management_signup
if !params[:search].blank?
@venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => @venue_management.id, :name=>params[:search]).page(params[:page]).per(10)
else
@venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => @venue_management.id).page(params[:page]).per(10)
end
end
def edit_venue_management_signup
@venue_management_signup = VenueManagementSignup.find(params[:id])
@venue_management = VenueManagementMain.find(@venue_management_signup.venue_management_main_id)
end
def delete_venue_management_signup
@venue_management_signup = VenueManagementSignup.find(params[:id])
@venue_management_id = @venue_management_signup.venue_management_main_id
@venue_management_signup.destroy
redirect_to "/admin/venue_managements/@venue_management_id.to_s/venue_management_signup"
end
private
def set_venue_management
@venue_management = VenueManagementMain.find(params[:id])
end
def venue_management_params
params.require(:venue_management_main).permit!
end
def create_set (save_flag)
VenueManagementSignup.attribute_names.each do |attr_signup|
if !(['_id', 'created_at', 'updated_at','venue_management_main_id'].include? attr_signup)
signup_set = @venue_management.venue_management_signup_field_sets.select{|v| v.field_name==attr_signup }
if signup_set.length==0
if ['status','name','tel','phone','email','password'].include? attr_signup
disabled = false
else
disabled = true
end
if ['status','name','tel'].include? attr_signup
hidden = false
else
hidden = true
end
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("venue_management_signup.#{attr_signup}")
end
I18n.locale = now_locale
if save_flag
@venue_management.venue_management_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
else
@venue_management.venue_management_signup_field_sets.new(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
end
end
end
end
signup_set = @venue_management.venue_management_signup_field_sets.select{|v| v.field_name== 'recaptcha' }
if signup_set.length==0
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("venue_management_signup.recaptcha")
end
I18n.locale = now_locale
if save_flag
@venue_management.venue_management_signup_field_sets.create(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true)
else
@venue_management.venue_management_signup_field_sets.new(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true)
end
end
VenueManagementSignupContribute.attribute_names.each do |attr_submission|
if !(['_id', 'created_at', 'updated_at','venue_management_signup_id'].include? attr_submission)
signup_set = @venue_management.venue_management_submission_field_sets.select{|v| v.field_name==attr_submission }
if signup_set.length==0
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("venue_management_signup.#{attr_submission}")
end
I18n.locale = now_locale
if save_flag
@venue_management.venue_management_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1)
else
@venue_management.venue_management_submission_field_sets.new(field_name:attr_submission,name:name1,placeholder:name1)
end
end
end
end
@venue_management.venue_management_signup_fields.all.map{|v| v}.each do |field|
set = @venue_management.venue_management_signup_field_customs.select{|v| v.venue_management_signup_field_id==field.id}
if set.length == 0
@venue_management.venue_management_signup_field_customs.create(venue_management_signup_field_id:field.id)
end
end
@email_set = []
['signup','submission','add_file','edit_file'].each do |field_name|
email_set = @venue_management.venue_management_email_sets.select{|v| v.field_name==field_name}
if email_set.length==0
title = Hash.new
content = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
title[locale] = t("venue_management.email_#{field_name}_success")
content[locale] = t("venue_management.email_#{field_name}_content")
end
I18n.locale = now_locale
if save_flag
email_set = @venue_management.venue_management_email_sets.create(field_name:field_name,title:title,content:content)
else
email_set = @venue_management.venue_management_email_sets.new(field_name:field_name,title:title,content:content)
end
else
email_set = email_set[0]
end
@email_set << email_set
end
end
end