2022-03-10 02:11:18 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
class Admin::ApplicationFormsController < OrbitAdminController
|
|
|
|
|
|
|
|
require 'axlsx'
|
|
|
|
include Admin::ApplicationFormsHelper
|
|
|
|
helper Admin::ApplicationFormsFieldHelper
|
2022-05-21 13:48:39 +00:00
|
|
|
layout :compute_layout
|
|
|
|
def compute_layout
|
|
|
|
if action_name=='print'
|
|
|
|
false
|
|
|
|
else
|
|
|
|
'back_end'
|
|
|
|
end
|
|
|
|
end
|
2022-03-10 02:11:18 +00:00
|
|
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
|
|
|
before_action :set_application_form, only: [:edit, :set_write_off, :application_form_signup, :destroy,:application_form_signup_admin_setting,:update_application_form_signup_admin_setting,:get_reviewer_block,:get_session_block,:update_application_form_review,:update_application_form_session,:reviewer_setting,:update_reviewer_setting,:template_setting,:update_template_setting,:sub_page_setting]
|
|
|
|
before_action :set_application_form_signup_admin_setting, only: [:application_form_signup,:application_form_signup_admin_setting,:update_application_form_signup_admin_setting,:get_reviewer_block,:get_session_block]
|
|
|
|
before_action :check_permission_for_application_form, only: [:application_form_signup,:get_reviewer_block,:get_session_block]
|
|
|
|
before_action :check_manager_for_application_form, only: [:application_form_signup_admin_setting,:update_application_form_signup_admin_setting,:update_application_form_review,:update_application_form_session,:reviewer_setting,:update_reviewer_setting,:template_setting,:update_template_setting]
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "application_form"
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_fields(categories)
|
|
|
|
{
|
|
|
|
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
def check_manager_for_application_form
|
|
|
|
OrbitHelper.set_params(params,current_user)
|
|
|
|
OrbitHelper.set_this_module_app("application_form")
|
|
|
|
access_level = OrbitHelper.user_access_level?
|
|
|
|
if (access_level.nil? || access_level == "user") && (@application_form.organizer_id != current_user.member_profile_id rescue true)
|
|
|
|
render_401
|
|
|
|
elsif access_level == "sub_manager" && @application_form && !(OrbitHelper.user_can_edit(@application_form))
|
|
|
|
render_401
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def check_permission_for_application_form
|
|
|
|
OrbitHelper.set_params(params,current_user)
|
|
|
|
OrbitHelper.set_this_module_app("application_form")
|
|
|
|
access_level = OrbitHelper.user_access_level?
|
|
|
|
if (access_level.nil? || access_level == "user")
|
|
|
|
unless (@application_form.reviewer_ids.include?(current_user.member_profile_id.to_s) rescue false) || (@application_form.organizer_id == current_user.member_profile_id rescue false)
|
|
|
|
render_401
|
|
|
|
else
|
|
|
|
@user_authenticated_categories = ['all']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def template_setting
|
|
|
|
@application_form_template_setting = @application_form.application_form_template_setting
|
|
|
|
if @application_form_template_setting.nil?
|
|
|
|
@application_form_template_setting = ApplicationFormTemplateSetting.create(:application_form_main=>@application_form)
|
|
|
|
end
|
|
|
|
@application_form_page_root = Page.where(:parent_page_id=>params[:id]).first
|
|
|
|
display_menu = []
|
|
|
|
if @application_form_page_root
|
|
|
|
default_display_menu = ApplicationFormTemplateSetting::DefaultMenu
|
|
|
|
default_display_menu.each do |page_id|
|
|
|
|
page = @application_form_page_root.child_page.where(:page_id=>page_id).first
|
|
|
|
if page
|
|
|
|
display_menu << page_id if page.enabled_for.length != 0
|
|
|
|
else
|
|
|
|
display_menu << page_id if page_id != "registered_participants"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@application_form_template_setting.update(:display_menu=>display_menu)
|
|
|
|
if (CustomBulletinConfig.where(:module=>"application_form").count == 0 rescue false)
|
|
|
|
CustomBulletinConfig.create(:module=>"application_form",:bind_model=>"ApplicationFormMain",:custom_record_callback=>"manage_announcement_count")
|
|
|
|
end
|
|
|
|
if (CustomAlbumConfig.where(:module=>"application_form").count == 0 rescue false)
|
|
|
|
CustomAlbumConfig.create(:module=>"application_form",:bind_model=>"ApplicationFormMain",:custom_record_callback=>"manage_album_count")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def update_template_setting
|
|
|
|
@application_form_template_setting = ApplicationFormTemplateSetting.find(params[:id])
|
|
|
|
@application_form_template_setting.update_attributes(application_form_template_setting_params)
|
|
|
|
redirect_to admin_application_forms_path
|
|
|
|
end
|
|
|
|
def sub_page_setting
|
|
|
|
@application_form_page_root = Page.where(:parent_page_id=>params[:id]).first
|
|
|
|
available_locales = Site.first.in_use_locales rescue I18n.available_locales
|
|
|
|
available_locales = available_locales.map{|l| l.to_s}
|
|
|
|
if @application_form_page_root.nil?
|
|
|
|
@application_form_page_root = Page.create(:parent_page_id=>params[:id],:module=>"application_forms_home",:name_translations=>@application_form.title_translations,:url=>"/home",:page_id=>"home",:enabled_for=>available_locales,:bind_uid=>@application_form.uid,:bind_module_app=>"application_form",:bind_model=>"ApplicationFormMain",:menu_enabled_for=>available_locales)
|
|
|
|
else
|
|
|
|
@application_form_page_root.update(:name_translations=>@application_form.title_translations,:module=>"application_forms_home",:url=>"/home",:page_id=>"home",:enabled_for=>available_locales,:bind_uid=>@application_form.uid,:bind_module_app=>"application_form",:bind_model=>"ApplicationFormMain",:menu_enabled_for=>available_locales)
|
|
|
|
end
|
|
|
|
pages_info = ApplicationFormTemplateSetting::PagesInfo
|
|
|
|
relation_model = {"news" => "CustomBulletin","album"=>"CustomAlbum"}
|
|
|
|
pages_info.each do |page_id , page_module|
|
|
|
|
application_form_page = @application_form_page_root.child_page.where(:page_id=>page_id).first
|
|
|
|
page_trans = available_locales.map{|l| [l,I18n.with_locale(l){I18n.t("application_form.menu.#{page_id}")}]}.to_h
|
|
|
|
available_locales_tmp = available_locales.clone
|
|
|
|
if relation_model[page_id]
|
|
|
|
relation = relation_model[page_id].constantize rescue nil
|
|
|
|
if relation
|
|
|
|
if relation.where(:bind_uid=>@application_form.uid).count == 0
|
|
|
|
available_locales_tmp = []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if application_form_page.nil?
|
|
|
|
application_form_page = @application_form_page_root.child_page.create(:name_translations=>page_trans,:page_id=>page_id,:url=>"/home/#{page_id}",:enabled_for=>available_locales_tmp,:module=>page_module,:menu_enabled_for=>available_locales_tmp)
|
|
|
|
else
|
|
|
|
application_form_page.update(:name_translations=>page_trans,:page_id=>page_id,:url=>"/home/#{page_id}",:module=>page_module)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@items = @application_form_page_root.child_page
|
|
|
|
@parent_pages = []
|
|
|
|
# exceptions = ["personal_book","personal_conference","personal_diploma","personal_experience","personal_journal","personal_lab","personal_patent","personal_project","personal_research"]
|
|
|
|
exceptions = []
|
|
|
|
@modules = ModuleApp.where(:key.nin => exceptions).frontend_enabled.order_by(:key=>'asc')
|
|
|
|
@searchfilter = @modules.collect{|m|[t('module_name.'+m.key),m.key]}
|
|
|
|
end
|
|
|
|
def reviewer_setting
|
|
|
|
@application_form_reviews = @application_form.application_form_reviews
|
|
|
|
@fields = []
|
|
|
|
@fields_translations = []
|
|
|
|
access_markup = ["select","radio_button","checkbox"]
|
|
|
|
@fields_values = []
|
|
|
|
@application_form.application_form_signup_fields.each do |f|
|
|
|
|
next if f.disabled
|
|
|
|
if access_markup.include?(f.markup)
|
|
|
|
@fields << "application_form_signup_fields.#{f.id}"
|
|
|
|
@fields_translations << f.title
|
|
|
|
@fields_values << f.option_list
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@application_form.application_form_submission_fields.each do |f|
|
|
|
|
next if f.disabled
|
|
|
|
if access_markup.include?(f.markup)
|
|
|
|
@fields << "application_form_submission_fields.#{f.id}"
|
|
|
|
@fields_translations << f.title
|
|
|
|
@fields_values << f.option_list
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if @application_form.enable_summary_choice
|
|
|
|
@fields << "application_form_signup_contributes.description"
|
|
|
|
begin
|
|
|
|
data2 = @application_form.application_form_submission_field_sets.select{|v| v.field_name=='description'}[0]
|
|
|
|
name2 = data2['name'][I18n.locale]
|
|
|
|
@fields_translations << (name2.present? ? name2 : I18n.t("application_form_signup.description"))
|
|
|
|
rescue
|
|
|
|
@fields_translations << I18n.t("application_form_signup.description")
|
|
|
|
end
|
|
|
|
@fields_values << @application_form.summary_chioices.map.with_index{|v,i| [i.to_s,{I18n.locale=>v}]}.to_h
|
|
|
|
end
|
|
|
|
@fields_values = @fields_values.collect.with_index{|fields_values,i| [i, fields_values.values.map{|v| v[I18n.locale]} ] }.to_h
|
|
|
|
end
|
|
|
|
def update_reviewer_setting
|
2022-05-21 13:48:39 +00:00
|
|
|
application_form_main_params = application_form_params
|
|
|
|
application_form_main_params[:application_form_reviews_attributes].keys.each do |i|
|
|
|
|
if application_form_main_params[:application_form_reviews_attributes][i][:default_topics].present?
|
|
|
|
application_form_main_params[:application_form_reviews_attributes][i][:default_topics] = [] if application_form_main_params[:application_form_reviews_attributes][i][:default_topics].nil?
|
2022-03-10 02:11:18 +00:00
|
|
|
default_topics_values = []
|
2022-05-21 13:48:39 +00:00
|
|
|
(0...application_form_main_params[:application_form_reviews_attributes][i][:default_topics].count).each do |ii|
|
|
|
|
default_topics_values << (Array(application_form_main_params[:application_form_reviews_attributes][i][:default_topics_values][ii.to_s]) rescue [])
|
2022-03-10 02:11:18 +00:00
|
|
|
end
|
2022-05-21 13:48:39 +00:00
|
|
|
application_form_main_params[:application_form_reviews_attributes][i][:default_topics_values] = default_topics_values
|
2022-03-10 02:11:18 +00:00
|
|
|
else
|
2022-05-21 13:48:39 +00:00
|
|
|
application_form_main_params[:application_form_reviews_attributes][i][:default_topics] = []
|
|
|
|
application_form_main_params[:application_form_reviews_attributes][i][:default_topics_values] = []
|
2022-03-10 02:11:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
#render :html => application_form_params and return
|
2022-05-21 13:48:39 +00:00
|
|
|
@application_form.update_attributes(application_form_main_params)
|
2022-03-10 02:11:18 +00:00
|
|
|
unassigned_application_form_signup_ids = @application_form.application_form_signup_ids.map{|s| s.to_s}
|
|
|
|
unassigned_mode_1_application_form_signup_ids = unassigned_application_form_signup_ids.dup
|
|
|
|
@application_form.application_form_reviews.each do |sr|
|
|
|
|
unassigned_mode_1_application_form_signup_ids = unassigned_mode_1_application_form_signup_ids - sr.get_all_application_form_signup_ids(1)
|
|
|
|
unassigned_application_form_signup_ids = unassigned_application_form_signup_ids - sr.all_application_form_signup_ids
|
|
|
|
end
|
|
|
|
@application_form.unassigned_mode_1_application_form_signup_ids = unassigned_mode_1_application_form_signup_ids
|
|
|
|
@application_form.unassigned_application_form_signup_ids = unassigned_application_form_signup_ids
|
|
|
|
@application_form.save
|
|
|
|
redirect_to admin_application_forms_path
|
|
|
|
end
|
|
|
|
def enquiry_for_applicants
|
|
|
|
OrbitHelper.set_params(params,current_user)
|
|
|
|
@access_level = OrbitHelper.user_access_level?
|
|
|
|
@can_edit = true
|
|
|
|
if @access_level == "user" || @access_level.nil?
|
|
|
|
@can_edit = false
|
|
|
|
end
|
|
|
|
reviewer_id = current_user.member_profile_id.to_s
|
|
|
|
if !@can_edit && ApplicationFormMain.where(:reviewer_ids=>reviewer_id).count == 0 && ApplicationFormMain.where(:organizer_id=>reviewer_id).count == 0
|
|
|
|
render_401 and return
|
|
|
|
end
|
|
|
|
|
|
|
|
@application_form_signup_admin_setting = ApplicationFormSignupAdminSetting.where(:application_form_main_id=>"enquiry_for_applicants").first
|
|
|
|
if @application_form_signup_admin_setting.nil?
|
|
|
|
@application_form_signup_admin_setting = ApplicationFormSignupAdminSetting.create(:application_form_main_id=>"enquiry_for_applicants")
|
|
|
|
end
|
|
|
|
if params[:name].present?
|
|
|
|
@application_form_signups = ApplicationFormSignup.where(:name => /#{params[:name]}/).sort_ordered.page(params[:page]).per(10)
|
|
|
|
else
|
|
|
|
@application_form_signups = []
|
|
|
|
end
|
|
|
|
unless @can_edit
|
|
|
|
if @application_form_signups.class != Array
|
|
|
|
application_form_review = ApplicationFormReview.where(:reviewer_id=>reviewer_id)
|
|
|
|
application_form_signup_ids = application_form_review.pluck(:application_form_signup_ids).flatten
|
|
|
|
application_form_sessions = ApplicationFormSession.where(:id.in=>application_form_review.pluck(:application_form_session_ids))
|
|
|
|
remove_application_form_signup_ids = application_form_review.pluck(:remove_application_form_signup_ids).flatten
|
|
|
|
assign_ids = []
|
|
|
|
application_forms = ApplicationFormMain.where(:id.in => application_form_review.pluck(:application_form_main_id))
|
|
|
|
final_assign_signup_ids = ApplicationFormSession.where(:id.in=>application_form_review.pluck(:application_form_session_ids).flatten,:application_form_main_id.in=>application_forms.where(:assign_mode.in=>[1,2]).pluck(:id)).pluck(:application_form_signup_ids,:default_application_form_signup_ids).flatten
|
|
|
|
default_application_form_signup_ids = application_form_review.where(:application_form_main_id.in=>application_forms.where(:assign_mode=>0).pluck(:id)).pluck(:default_application_form_signup_ids).flatten
|
|
|
|
all_application_form_signup_ids = application_form_signup_ids - remove_application_form_signup_ids + final_assign_signup_ids + default_application_form_signup_ids
|
|
|
|
|
|
|
|
ids2 = ApplicationFormSignup.where(:application_form_main_id.in=> ApplicationFormMain.where(:organizer_id=>current_user.member_profile_id).pluck(:id)).pluck(:id)
|
|
|
|
|
|
|
|
@application_form_signups = @application_form_signups.where(:id.in=>all_application_form_signup_ids + ids2).sort_ordered.page(params[:page]).per(10)
|
|
|
|
@preferred_sessions = application_form_review.pluck(:session_ids).flatten
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def get_hide_session
|
|
|
|
application_form_main = ApplicationFormMain.find(params[:id]) rescue nil
|
|
|
|
if application_form_main.nil?
|
|
|
|
render :nothing => true
|
|
|
|
else
|
|
|
|
@application_form = application_form_main
|
|
|
|
@application_form_sessions = @application_form.application_form_sessions
|
|
|
|
@hide_session_ids = (0...application_form_main.summary_chioices.count).to_a - Array(application_form_main.session_show_ids)
|
|
|
|
@hide_sessions = @hide_session_ids.zip(@hide_session_ids.map{|idx| application_form_main.summary_chioices[idx]}).to_h
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def get_hide_reviewer
|
|
|
|
application_form_main = ApplicationFormMain.find(params[:id]) rescue nil
|
|
|
|
if application_form_main.nil?
|
|
|
|
render :nothing => true
|
|
|
|
else
|
|
|
|
@hide_reviewer_ids = Array(application_form_main.reviewer_ids) - Array(application_form_main.reviewer_show_ids)
|
|
|
|
@hide_reviewers = MemberProfile.where(:id.in=>@hide_reviewer_ids)
|
|
|
|
@reviewers = application_form_main.application_form_reviews.where(:reviewer_id.in=>@hide_reviewer_ids).to_a
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def get_session_block
|
|
|
|
@session_id = params[:session_id].to_i
|
|
|
|
@application_form_session = @application_form.application_form_sessions.where(:key=>@session_id).first
|
|
|
|
unless (@application_form.session_show_ids.include?(@session_id) rescue false)
|
|
|
|
@application_form.session_show_ids << @session_id
|
|
|
|
@application_form.save
|
|
|
|
end
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
def get_reviewer_block
|
|
|
|
@reviewer_id = params[:reviewer_id]
|
|
|
|
unless (@application_form.reviewer_show_ids.include?(@reviewer_id) rescue false)
|
|
|
|
@application_form.reviewer_show_ids << @reviewer_id
|
|
|
|
@application_form.save
|
|
|
|
end
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
def update_application_form_session
|
|
|
|
if @application_form.nil?
|
|
|
|
render :json => {:success => false}
|
|
|
|
else
|
|
|
|
application_form_main = @application_form
|
|
|
|
session_id = params[:session_id].to_i
|
|
|
|
application_form_main.save
|
|
|
|
application_form_session = @application_form.application_form_sessions.where(:key=>session_id).first
|
|
|
|
@application_form_submission_value = nil
|
|
|
|
extra_infos = {}
|
|
|
|
if params[:contribute_id].present?
|
|
|
|
application_form_signup_contribute = ApplicationFormSignupContribute.find(params[:contribute_id])
|
|
|
|
application_form_submission_field = application_form_main.application_form_submission_fields.where(:markup=>"application_form_preferred_session").last
|
|
|
|
if application_form_submission_field
|
|
|
|
@application_form_submission_value = application_form_signup_contribute.application_form_submission_values.where(:application_form_submission_field_id=>application_form_submission_field.id).last
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if params[:mode] == "append"
|
|
|
|
if @application_form_submission_value
|
|
|
|
@application_form_submission_value.val = session_id.to_s
|
|
|
|
@application_form_submission_value.save
|
|
|
|
extra_infos = {"edit" => {"target"=>"[data-id=\"#{@application_form_submission_value.id}\"]","text"=>@application_form_submission_value.get_value_by_locale(I18n.locale)}}
|
|
|
|
else
|
|
|
|
@application_form_signup.final_sessions << session_id
|
|
|
|
@application_form_signup.application_form_session_ids << application_form_session.id
|
|
|
|
@application_form_signup.application_form_session_ids = @application_form_signup.application_form_session_ids.uniq
|
|
|
|
@application_form_signup.save
|
|
|
|
application_form_session.application_form_signup_contribute_ids.append(params[:contribute_id])
|
|
|
|
application_form_signup_contribute.update(:final_session=>session_id) rescue nil
|
|
|
|
application_form_session.application_form_signup_ids << @application_form_signup.id.to_s
|
|
|
|
application_form_main.assign_mode = 1 if application_form_main.assign_mode != 2
|
|
|
|
application_form_session.save
|
|
|
|
application_form_main.unassigned_mode_1_application_form_signup_ids.delete(@application_form_signup.id.to_s)
|
|
|
|
end
|
|
|
|
elsif params[:mode] == "remove_contribute"
|
|
|
|
if @application_form_submission_value
|
|
|
|
@application_form_submission_value.val = nil
|
|
|
|
@application_form_submission_value.save
|
|
|
|
extra_infos = {"edit" => {"target"=>"[data-id=\"#{@application_form_submission_value.id}\"]","text"=>""}}
|
|
|
|
else
|
|
|
|
application_form_session.application_form_signup_contribute_ids.delete(params[:contribute_id])
|
|
|
|
application_form_signup_contribute.update(:final_session=>nil) rescue nil
|
|
|
|
application_form_session.save
|
|
|
|
end
|
|
|
|
elsif params[:mode] == "remove"
|
|
|
|
if @application_form_submission_value
|
|
|
|
@application_form_submission_value.val = nil
|
|
|
|
@application_form_submission_value.save
|
|
|
|
extra_infos = {"edit" => {"target"=>"[data-id=\"#{@application_form_submission_value.id}\"]","text"=>""}}
|
|
|
|
else
|
|
|
|
@application_form_signup.final_sessions.delete(session_id)
|
|
|
|
@application_form_signup.application_form_session_ids.delete(application_form_session.id)
|
|
|
|
application_form_session.application_form_signup_ids.delete(@application_form_signup.id.to_s)
|
|
|
|
application_form_session.application_form_signup_contribute_ids.delete(params[:contribute_id])
|
|
|
|
application_form_signup_contribute.update(:final_session=>nil) rescue nil
|
|
|
|
@application_form_signup.save
|
|
|
|
application_form_session.save
|
|
|
|
application_form_main.assign_mode = 0 if application_form_main.application_form_sessions.where(:application_form_signup_ids.ne=>[]).count == 0 && application_form_main.assign_mode != 2
|
|
|
|
application_form_main.unassigned_mode_1_application_form_signup_ids << @application_form_signup.id.to_s
|
|
|
|
end
|
|
|
|
elsif params[:mode] == "hide"
|
|
|
|
if application_form_main.session_show_ids.nil?
|
|
|
|
application_form_main.session_show_ids = (0...application_form_main.summary_chioices.count).to_a[0..1]
|
|
|
|
end
|
|
|
|
application_form_main.session_show_ids.delete(session_id)
|
|
|
|
elsif params[:mode] == "show"
|
|
|
|
application_form_main.session_show_ids = application_form_main.session_show_ids.to_a + Array(session_id)
|
|
|
|
else
|
|
|
|
render :json => {:success => false} and return
|
|
|
|
end
|
|
|
|
application_form_main.save
|
|
|
|
render :json => {:success => true}.merge(extra_infos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def update_application_form_review
|
|
|
|
if @application_form_review.nil?
|
|
|
|
render :json => {:success => false}
|
|
|
|
else
|
|
|
|
application_form_main = @application_form_review.application_form_main
|
|
|
|
if params[:mode] == "append"
|
|
|
|
@application_form_review.application_form_signup_ids << params[:signup_id]
|
|
|
|
@application_form_review.remove_application_form_signup_ids.delete(params[:signup_id])
|
|
|
|
application_form_main.unassigned_application_form_signup_ids.delete(params[:signup_id])
|
|
|
|
application_form_main.unassigned_mode_1_application_form_signup_ids.delete(params[:signup_id])
|
|
|
|
if(params[:contribute_id].present?)
|
|
|
|
@application_form_review.application_form_signup_contribute_ids << params[:contribute_id]
|
|
|
|
@application_form_review.remove_application_form_signup_contribute_ids.delete(params[:contribute_id])
|
|
|
|
end
|
|
|
|
elsif params[:mode] == "remove"
|
|
|
|
@application_form_review.application_form_signup_ids.delete(params[:signup_id])
|
|
|
|
@application_form_review.remove_application_form_signup_ids << params[:signup_id]
|
|
|
|
application_form_main.unassigned_application_form_signup_ids << params[:signup_id]
|
|
|
|
application_form_main.unassigned_mode_1_application_form_signup_ids << params[:signup_id]
|
|
|
|
if(params[:contribute_id].present?)
|
|
|
|
@application_form_review.application_form_signup_contribute_ids.delete(params[:contribute_id])
|
|
|
|
@application_form_review.remove_application_form_signup_contribute_ids << params[:contribute_id]
|
|
|
|
end
|
|
|
|
elsif params[:mode] == "remove_contribute"
|
|
|
|
if(params[:contribute_id].present?)
|
|
|
|
@application_form_review.application_form_signup_contribute_ids.delete(params[:contribute_id])
|
|
|
|
@application_form_review.remove_application_form_signup_contribute_ids << params[:contribute_id]
|
|
|
|
end
|
|
|
|
elsif params[:mode] == "hide"
|
|
|
|
if application_form_main.reviewer_show_ids.nil?
|
|
|
|
application_form_main.reviewer_show_ids = application_form_main.reviewer_ids[0..1]
|
|
|
|
end
|
|
|
|
application_form_main.reviewer_show_ids = application_form_main.reviewer_show_ids - Array(@application_form_review.reviewer_id).flatten
|
|
|
|
elsif params[:mode] == "show"
|
|
|
|
application_form_main.reviewer_show_ids = application_form_main.reviewer_show_ids.to_a + Array(@application_form_review.reviewer_id).flatten
|
|
|
|
else
|
|
|
|
render :json => {:success => false} and return
|
|
|
|
end
|
|
|
|
application_form_main.save
|
|
|
|
@application_form_review.save
|
|
|
|
render :json => {:success => true}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def index
|
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories)
|
2022-03-10 04:40:11 +00:00
|
|
|
@table_fields = [:category, 'application_form.title', 'application_form.event_during', 'application_form.signup_count', 'application_form.export']
|
2022-03-10 02:11:18 +00:00
|
|
|
|
|
|
|
if !params[:sort].blank?
|
|
|
|
if params[:sort] == 'event_during'
|
|
|
|
sort = {:application_form_start_date.to_sym=>params[:order]}
|
|
|
|
elsif params[:sort] == 'signup_during'
|
2022-05-21 13:48:39 +00:00
|
|
|
sort = {:application_form_start_date.to_sym=>params[:order]}
|
2022-03-10 02:11:18 +00:00
|
|
|
else
|
|
|
|
sort = {params[:sort].to_sym=>params[:order]}
|
|
|
|
end
|
|
|
|
else
|
2022-05-21 13:48:39 +00:00
|
|
|
sort = {:application_form_start_date=>"desc",:created_at=>"desc"}
|
2022-03-10 02:11:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@application_forms = ApplicationFormMain.all.order_by(sort).with_categories(filters("category"))
|
|
|
|
|
|
|
|
@application_forms = search_data(@application_forms,[:title]).page(params[:page]).per(10)
|
|
|
|
OrbitHelper.set_params(params,current_user)
|
|
|
|
OrbitHelper.set_this_module_app("application_form")
|
|
|
|
@access_level = OrbitHelper.user_access_level?
|
|
|
|
@can_edit = true
|
|
|
|
if @access_level == "user" || @access_level.nil?
|
|
|
|
@can_edit = false
|
|
|
|
end
|
|
|
|
unless @can_edit
|
|
|
|
reviewer_id = current_user.member_profile_id.to_s
|
|
|
|
ids1 = @application_forms.where(:reviewer_ids=>reviewer_id).pluck(:id)
|
|
|
|
ids2 = @application_forms.where(:organizer_id=>current_user.member_profile_id).pluck(:id)
|
|
|
|
@application_forms = @application_forms.where(:id.in=>ids1+ids2)
|
|
|
|
end
|
|
|
|
if request.xhr?
|
|
|
|
render :partial => "index"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def export
|
|
|
|
|
|
|
|
@application_form = ApplicationFormMain.find(params[:id])
|
|
|
|
@application_form_signups = ApplicationFormSignup.where(:application_form_main_id => params[:id])
|
|
|
|
filename = @application_form.title.parameterize.underscore + "_export.xlsx"
|
|
|
|
if can_see_application_form_signup(@application_form)
|
|
|
|
if !admin_for_application_form(@application_form)
|
|
|
|
@application_form_review = @application_form.application_form_reviews.where(:reviewer_id => current_user.member_profile_id.to_s).first
|
|
|
|
@application_form_signups = @application_form_signups.where(:id.in=>@application_form_review.get_all_application_form_signup_ids) rescue []
|
|
|
|
end
|
|
|
|
@application_form_signups = @application_form_signups.sort_ordered
|
|
|
|
respond_to do |format|
|
|
|
|
format.xlsx {
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename="' + filename + '"'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render :nothing => true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def copy
|
|
|
|
@application_form = ApplicationFormMain.find(params[:id]).clone_new
|
2022-05-21 13:48:39 +00:00
|
|
|
@members = @application_form.reviewer_ids_list.collect{|r_ids| MemberProfile.where(:id.in=>Array(r_ids)).to_a}
|
2022-03-10 05:54:53 +00:00
|
|
|
|
2022-03-10 02:11:18 +00:00
|
|
|
@email_set = @application_form.application_form_email_sets
|
|
|
|
@signup_sets = @application_form.application_form_signup_field_sets
|
|
|
|
@submission_set = @application_form.application_form_submission_field_sets
|
|
|
|
@custom_set = @application_form.application_form_signup_field_customs
|
|
|
|
@application_form_items = ApplicationFormItem.all
|
|
|
|
@review = @application_form.application_form_reviews.first
|
|
|
|
end
|
|
|
|
def new
|
|
|
|
@application_form = ApplicationFormMain.new
|
2022-06-14 13:19:52 +00:00
|
|
|
@application_form_setting = ApplicationFormSetting.first
|
2022-05-21 13:48:39 +00:00
|
|
|
|
|
|
|
@members = (0...@application_form_setting.reviewer_length).collect{nil}
|
2022-03-10 02:11:18 +00:00
|
|
|
create_set (false)
|
|
|
|
@signup_sets = @application_form.application_form_signup_field_sets
|
|
|
|
@submission_set = @application_form.application_form_submission_field_sets
|
|
|
|
@custom_set = @application_form.application_form_signup_field_customs
|
|
|
|
@application_form_items = ApplicationFormItem.all
|
|
|
|
@review = @application_form.application_form_reviews.new()
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2022-05-21 13:48:39 +00:00
|
|
|
application_form_main_params = application_form_params
|
|
|
|
if !application_form_main_params['application_form_links_attributes'].nil?
|
|
|
|
application_form_main_params['application_form_links_attributes'].each do |idx,link|
|
|
|
|
application_form_main_params['application_form_links_attributes'].delete(idx.to_s) if link['url'].blank?
|
2022-03-10 02:11:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
application_form_signup_set_params = application_form_main_params['application_form_signup_field_sets']
|
|
|
|
application_form_email_sets_params = application_form_main_params['application_form_email_sets']
|
|
|
|
application_form_signup_field_customs_params = application_form_main_params["application_form_signup_field_customs"].to_h rescue {}
|
|
|
|
application_form_main_params["application_form_signup_field_customs"].to_h.each do |k,v|
|
|
|
|
v.delete "title"
|
|
|
|
end
|
|
|
|
application_form_main_params.delete(:application_form_signup_field_sets)
|
|
|
|
application_form_main_params.delete(:application_form_email_sets)
|
|
|
|
application_form = ApplicationFormMain.new(application_form_main_params)
|
|
|
|
application_form.create_user_id = current_user.id
|
|
|
|
application_form.update_user_id = current_user.id
|
|
|
|
if application_form.copy_id && params["clone_signups"].blank?
|
|
|
|
application_form.except_clone_relations = ["application_form_signups","application_form_signup_values","application_form_signup_contributes","application_form_submission_values"]
|
|
|
|
end
|
|
|
|
application_form.save
|
|
|
|
if application_form.copy_id
|
|
|
|
application_form_signup_set_params.each do |key,value|
|
|
|
|
application_form.application_form_signup_field_sets[key.to_i].update_attributes(value) rescue nil
|
|
|
|
end
|
|
|
|
application_form_email_sets_params.each do |key,value|
|
|
|
|
application_form.application_form_email_sets[key.to_i].update_attributes(value) rescue nil
|
|
|
|
end
|
|
|
|
application_form_signup_field_customs_params.each_with_index do |(key,value),i|
|
|
|
|
application_form.application_form_signup_field_customs[i].update(:application_form_signup_field_id => application_form.application_form_signup_fields.where(:title=>value["title"]).first.id) rescue nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
application_form_signup_set_params.each do |key,value|
|
|
|
|
application_form.application_form_signup_field_sets.create(value)
|
|
|
|
end
|
|
|
|
application_form_email_sets_params.each do |key,value|
|
|
|
|
application_form.application_form_email_sets.create(value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to params['referer_url']
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2022-05-21 13:48:39 +00:00
|
|
|
def setting
|
2022-06-14 13:19:52 +00:00
|
|
|
@application_form_setting = ApplicationFormSetting.first
|
2022-05-21 13:48:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_setting
|
2022-06-14 13:19:52 +00:00
|
|
|
@application_form_setting = ApplicationFormSetting.first
|
2022-05-21 13:48:39 +00:00
|
|
|
tmp = params.require(:application_form_setting).permit!
|
|
|
|
@application_form_setting.update_attributes(tmp)
|
|
|
|
redirect_to admin_application_forms_path
|
|
|
|
end
|
|
|
|
|
2022-03-10 02:11:18 +00:00
|
|
|
def edit
|
|
|
|
@application_form_items = ApplicationFormItem.all
|
2022-06-14 13:19:52 +00:00
|
|
|
@application_form_setting = ApplicationFormSetting.first
|
2022-03-10 02:11:18 +00:00
|
|
|
@application_form = ApplicationFormMain.where(id: params[:id]).first
|
|
|
|
create_set (true)
|
|
|
|
@signup_sets = @application_form.application_form_signup_field_sets
|
|
|
|
@submission_set = @application_form.application_form_submission_field_sets
|
|
|
|
@custom_set = @application_form.application_form_signup_field_customs
|
2022-05-21 13:48:39 +00:00
|
|
|
@members = @application_form.reviewer_ids_list.collect{|r_ids| MemberProfile.where(:id.in=>Array(r_ids)).to_a}
|
2022-03-10 02:11:18 +00:00
|
|
|
if (@application_form.organizer_id == current_user.member_profile_id rescue false)
|
|
|
|
@user_authorized_categories = @module_app.categories.enabled.to_a
|
|
|
|
else
|
|
|
|
@user_authorized_categories = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2022-05-21 13:48:39 +00:00
|
|
|
@application_form_params = application_form_params
|
2022-03-10 02:11:18 +00:00
|
|
|
if @application_form_params.count != 0
|
|
|
|
@application_form_params[:registration_status] = (@application_form_params[:registration_status] ? @application_form_params[:registration_status] : [])
|
|
|
|
uid = params[:id].split('-').last
|
|
|
|
@application_form = ApplicationFormMain.find_by(:uid=>uid)
|
|
|
|
if @application_form_params.has_key?("title_translations")
|
|
|
|
@application_form_params["organizer_id"] = nil if @application_form_params["organizer_id"].nil?
|
|
|
|
end
|
|
|
|
if @application_form_params[:application_form_signup_fields]
|
|
|
|
@application_form_params[:application_form_signup_fields].each do |a|
|
|
|
|
@field_name = 'application_form_main'
|
|
|
|
field_status = a.last[:id].present?
|
|
|
|
@attribute_field = ApplicationFormSignupField.add_application_form_signup_field(@application_form, a.last, a.last[:id], field_status)
|
|
|
|
@attribute = @application_form
|
|
|
|
end
|
|
|
|
flash.now[:notice] = "Updated Fields"
|
|
|
|
@application_form.application_form_signup_fields.each{|t| t.destroy if t["to_delete"] == true}
|
|
|
|
|
|
|
|
redirect_to admin_application_forms_path and return
|
|
|
|
elsif @application_form_params[:application_form_submission_fields]
|
|
|
|
params[:application_form_main][:application_form_submission_fields].each do |a|
|
|
|
|
@field_name = 'application_form_main'
|
|
|
|
field_status = a.last[:id].present?
|
|
|
|
@attribute_field = ApplicationFormSubmissionField.add_application_form_signup_field(@application_form, a.last, a.last[:id], field_status)
|
|
|
|
@attribute = @application_form
|
|
|
|
end
|
|
|
|
flash.now[:notice] = "Updated Fields"
|
|
|
|
@application_form.application_form_submission_fields.each{|t| t.destroy if t["to_delete"] == true}
|
|
|
|
if @application_form.application_form_submission_fields.select{|sf| sf.markup == "application_form_preferred_session"}.count != 0
|
|
|
|
@application_form.update(:assign_mode => 2)
|
|
|
|
default_sort_number = ApplicationFormSignup.fields['sort_number'].options[:default]
|
|
|
|
ApplicationFormSignup.where(:sort_number=>nil).update_all(:sort_number=>default_sort_number)
|
|
|
|
ApplicationFormSignupContribute.where(:sort_number=>nil).update_all(:sort_number=>default_sort_number)
|
|
|
|
preferred_session_field = @application_form.application_form_submission_fields.select{|sf| sf.markup == "application_form_preferred_session"}.first
|
|
|
|
if preferred_session_field.application_form_submission_values.count != 0
|
|
|
|
application_form_submission_values = preferred_session_field.application_form_submission_values.to_a
|
|
|
|
application_form_submission_values.each do |v|
|
|
|
|
if v.application_form_signup_contribute.nil?
|
|
|
|
v.destroy
|
|
|
|
next
|
|
|
|
end
|
|
|
|
next if v.val.to_i.to_s != v.val
|
|
|
|
application_form_session = @application_form.application_form_sessions.where(:key=>v.val.to_i).first
|
|
|
|
application_form_session.default_application_form_signup_ids << v.application_form_signup_contribute.application_form_signup_id.to_s
|
|
|
|
application_form_session.default_application_form_signup_ids = application_form_session.default_application_form_signup_ids.uniq
|
|
|
|
application_form_session.save
|
|
|
|
end
|
|
|
|
Thread.new do
|
|
|
|
ApplicationFormMain.where(:update_old_flag=>false).each{|s| s.fix_old_data}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if @application_form.application_form_sessions.where(:application_form_signup_ids.ne=>[]).count == 0
|
|
|
|
@application_form.update(:assign_mode => 0)
|
|
|
|
else
|
|
|
|
@application_form.update(:assign_mode => 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to admin_application_forms_path and return
|
|
|
|
else
|
|
|
|
|
2022-05-21 13:48:39 +00:00
|
|
|
if !@application_form_params['application_form_links_attributes'].nil?
|
|
|
|
@application_form_params['application_form_links_attributes'].each do |idx,link|
|
|
|
|
@application_form_params['application_form_links_attributes'].delete(idx.to_s) if link['url'].blank?
|
2022-03-10 02:11:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@application_form.update_user_id = current_user.id
|
2022-05-21 13:48:39 +00:00
|
|
|
if @application_form.update_attributes(@application_form_params)
|
2022-03-10 02:11:18 +00:00
|
|
|
@application_form.application_form_signup_fields.each{|t| t.destroy if t["to_delete"] == true}
|
|
|
|
redirect_to params['referer_url'] and return
|
|
|
|
else
|
|
|
|
flash.now[:error] = t('update.error.category')
|
|
|
|
render action: :edit and return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to admin_application_forms_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_write_off
|
|
|
|
|
|
|
|
@application_form.donation_write_off_status = true
|
|
|
|
@application_form.save
|
|
|
|
|
|
|
|
redirect_to "/admin/application_forms?page=#{params['page']}"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
|
|
|
@application_form.destroy
|
|
|
|
redirect_to "/admin/application_forms"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def application_form_signup_field
|
|
|
|
@field_name = 'application_form_main'
|
|
|
|
@attribute = ApplicationFormMain.find(params[:id])
|
|
|
|
@attribute_type = 'application_form'
|
|
|
|
@class = 'application_forms'
|
|
|
|
end
|
|
|
|
|
|
|
|
def application_form_submission_field
|
|
|
|
@field_name = 'application_form_main'
|
|
|
|
@attribute = ApplicationFormMain.find(params[:id])
|
|
|
|
@attribute_type = 'application_form'
|
|
|
|
@class = 'application_forms'
|
|
|
|
end
|
|
|
|
|
|
|
|
def application_form_signup
|
|
|
|
@application_form_signups = []
|
|
|
|
@filter_fields = {}
|
|
|
|
@summary_chioices = @application_form.enable_summary_choice ? @application_form.summary_chioices : []
|
|
|
|
@enable_review_result = @application_form.enable_review_result
|
|
|
|
if @enable_review_result
|
|
|
|
@filter_fields["application_form.assigned_session"] = @summary_chioices.map.with_index{|summary_chioice,i| {:title=>summary_chioice, :id=>i}} rescue []
|
|
|
|
end
|
|
|
|
if params[:type] == "table"
|
|
|
|
if params[:search].to_i != 0
|
|
|
|
@application_form_signups = @application_form.application_form_signups.where(:serial_number=>params[:search].to_i)
|
|
|
|
else
|
|
|
|
@application_form_signups = @application_form.application_form_signups.where(:name=>/#{params[:search]}/)
|
|
|
|
end
|
|
|
|
elsif params[:type] == "session"
|
|
|
|
assigned_application_form_signups = @application_form.application_form_sessions.pluck(:application_form_signup_ids,:default_application_form_signup_ids).flatten
|
|
|
|
@application_form_signups = @application_form.application_form_signups.where(:id.nin=>assigned_application_form_signups)
|
|
|
|
else
|
|
|
|
unassigned_application_form_signup_ids = @application_form.unassigned_application_form_signup_ids
|
|
|
|
if @application_form.assign_mode != 0
|
|
|
|
unassigned_application_form_signup_ids = @application_form.unassigned_mode_1_application_form_signup_ids
|
|
|
|
end
|
|
|
|
@application_form_signups = @application_form.application_form_signups.where(:id.in => unassigned_application_form_signup_ids, :name=>/#{params[:search]}/)
|
|
|
|
end
|
|
|
|
OrbitHelper.set_params(params,current_user)
|
|
|
|
@access_level = OrbitHelper.user_access_level?
|
|
|
|
@can_edit = true
|
|
|
|
if @access_level == "user" || @access_level.nil?
|
|
|
|
@can_edit = false
|
|
|
|
end
|
|
|
|
unless @can_edit
|
|
|
|
@can_edit = (@application_form.organizer_id == current_user.member_profile_id rescue false)
|
|
|
|
end
|
|
|
|
unless @can_edit
|
|
|
|
@application_form_review = @application_form.application_form_reviews.where(:reviewer_id => current_user.member_profile_id.to_s).first
|
|
|
|
@application_form_signups = @application_form.application_form_signups.where(:id.in=>@application_form_review.get_all_application_form_signup_ids)
|
|
|
|
@preferred_sessions = @application_form_review.session_ids
|
|
|
|
if @enable_review_result
|
|
|
|
@filter_fields["application_form.assigned_session"] = @filter_fields["application_form.assigned_session"].select{|h| @preferred_sessions.include?(h[:id])} rescue []
|
|
|
|
end
|
|
|
|
@append_contribute_ids = @application_form_review.application_form_signup_contribute_ids
|
|
|
|
@remove_contribute_ids = @application_form_review.remove_application_form_signup_contribute_ids
|
|
|
|
end
|
|
|
|
if params[:filters] && params[:filters][:assigned_session].present?
|
|
|
|
@preferred_sessions = params[:filters][:assigned_session].map{|s| s.to_i}
|
|
|
|
@application_form_signups = @application_form_signups.where(:preferred_sessions.in=> @preferred_sessions)
|
|
|
|
end
|
|
|
|
@application_form_signups = @application_form_signups.sort_ordered.page(params[:page]).per(10)
|
|
|
|
if request.xhr?
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def application_form_signup_admin_setting
|
|
|
|
if @application_form.nil? && params[:id] != "enquiry_for_applicants"
|
|
|
|
redirect_to admin_application_forms_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def update_application_form_signup_admin_setting
|
|
|
|
@application_form_signup_admin_setting.update_attributes(params.require(:application_form_signup_admin_setting).permit!)
|
|
|
|
if params[:id] != "enquiry_for_applicants"
|
|
|
|
redirect_to application_form_signup_admin_application_form_path(params[:id]) + "?type=#{params[:page]}"
|
|
|
|
else
|
|
|
|
redirect_to admin_application_form_enquiry_for_applicants_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def set_application_form_signup_admin_setting
|
|
|
|
page = params[:type] || params[:page]
|
|
|
|
if params[:action] == "application_form_signup"
|
|
|
|
page = params[:type]
|
|
|
|
end
|
|
|
|
page = nil if page.blank?
|
|
|
|
@application_form_signup_admin_setting = ApplicationFormSignupAdminSetting.where(:application_form_main_id=>params[:id],:page=>page).first
|
|
|
|
if @application_form_signup_admin_setting.nil?
|
|
|
|
@application_form_signup_admin_setting = ApplicationFormSignupAdminSetting.create(:application_form_main_id=>params[:id],:page=>page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def edit_application_form_signup
|
|
|
|
@application_form_signup = ApplicationFormSignup.find(params[:id])
|
|
|
|
@application_form = ApplicationFormMain.find(@application_form_signup.application_form_main_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_application_form_signup
|
|
|
|
|
|
|
|
@application_form_signup = ApplicationFormSignup.find(params[:id])
|
|
|
|
|
|
|
|
@application_form_id = @application_form_signup.application_form_main_id
|
|
|
|
|
|
|
|
@application_form_signup.destroy
|
|
|
|
|
|
|
|
redirect_to "/admin/application_forms/@application_form_id.to_s/application_form_signup"
|
|
|
|
end
|
|
|
|
|
2022-05-21 13:48:39 +00:00
|
|
|
def print_setting
|
|
|
|
@set = nil
|
|
|
|
@application_form_id = params[:application_form_id]
|
|
|
|
if @application_form_id.blank?
|
|
|
|
@set = ApplicationFormPrintSetting.first
|
|
|
|
else
|
|
|
|
@set = ApplicationFormCategoryPrintSetting.where(:application_form_id=>@application_form_id).first
|
|
|
|
@set = ApplicationFormCategoryPrintSetting.new if @set.nil?
|
|
|
|
end
|
|
|
|
@set = ApplicationFormPrintSetting.create if @set.nil?
|
|
|
|
@url = print_setting_save_admin_application_forms_path
|
|
|
|
end
|
|
|
|
def print_setting_save
|
|
|
|
locale = I18n.locale
|
|
|
|
if params[:application_form_print_setting][:application_form_id].present?
|
|
|
|
set = ApplicationFormCategoryPrintSetting.where(:application_form_id=>params[:application_form_print_setting][:application_form_id]).first
|
|
|
|
set = ApplicationFormCategoryPrintSetting.create(:application_form_id=>params[:application_form_print_setting][:application_form_id]) if set.nil?
|
|
|
|
else
|
|
|
|
set = ApplicationFormPrintSetting.first
|
|
|
|
end
|
|
|
|
set.update_attributes(print_format: params[:application_form_print_setting][:print_format],save_name: params[:application_form_print_setting][:save_name])
|
|
|
|
redirect_to "/#{locale}/admin/application_forms"
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_format_text(text,custom_fields)
|
|
|
|
customs = text.scan(/<tr(?:(?!<tr).)+\{custom\}(?:(?!<tr).)+<\/tr>/m).uniq
|
|
|
|
if customs.length != 0
|
|
|
|
custom_exist_nums = []
|
|
|
|
custom_exists = text.scan(/{custom\d+}/)
|
|
|
|
custom_exists.each do |custom_exist|
|
|
|
|
k = custom_exist[6...-1].to_i - 1
|
|
|
|
custom_exist_nums << k
|
|
|
|
end
|
|
|
|
customs.each do |custom|
|
|
|
|
tmp = custom_fields.keys.collect.with_index do |k,i|
|
|
|
|
if custom_exist_nums.exclude?(i)
|
|
|
|
tp = custom.gsub(/{custom}/,"{custom#{i+1}}")
|
|
|
|
tp = tp.gsub(/{custom_title}/,"{custom#{i+1}_title}")
|
|
|
|
tp
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end.compact.join
|
|
|
|
text = text.gsub(custom,tmp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
format_texts = text.scan(/{\w+\|*\w+}/).uniq
|
|
|
|
format_texts.each do |format_text|
|
|
|
|
if format_text[-7...-1] == '_title'
|
|
|
|
case format_text[1...-7]
|
|
|
|
when /custom\d+/
|
|
|
|
i = format_text.scan(/\d+/)[0].to_i - 1
|
|
|
|
k = custom_fields.keys[i] rescue nil
|
|
|
|
if !k.blank?
|
|
|
|
text_tp = custom_fields[k][I18n.locale] rescue ''
|
|
|
|
text = text.gsub(format_text,text_tp)
|
|
|
|
end
|
|
|
|
when 'title'
|
|
|
|
text = text.gsub(format_text,I18n.t('title'))
|
|
|
|
when 'submission_time'
|
|
|
|
text = text.gsub(format_text,I18n.t('application_form_signup.submission_time'))
|
|
|
|
when 'category'
|
|
|
|
text = text.gsub(format_text,I18n.t('category'))
|
|
|
|
when 'name','email','phone'
|
|
|
|
text = text.gsub(format_text,I18n.t("application_form_signup.#{format_text[1...-7]}"))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
case format_text[1...-1]
|
|
|
|
when 'submission_time'
|
|
|
|
text = text.gsub(format_text,@application_form_signup.created_at.strftime('%Y/%m/%d %H:%M'))
|
|
|
|
when 'title'
|
|
|
|
text = text.gsub(format_text,@application_form_signup.application_form_main.title.to_s)
|
|
|
|
when 'title','name','email','phone'
|
|
|
|
text = text.gsub(format_text,@application_form_signup.send(format_text[1...-1]).to_s)
|
|
|
|
when 'category'
|
|
|
|
cat = @application_form_signup.application_form_main.category.title rescue ''
|
|
|
|
text = text.gsub(format_text,cat)
|
|
|
|
when 'name|mask'
|
|
|
|
name_tp = @application_form_signup.name.to_s
|
|
|
|
if name_tp.length>1
|
|
|
|
name_tp = name_tp[0] + '*'*(name_tp.length-1)
|
|
|
|
end
|
|
|
|
text = text.gsub(format_text,name_tp)
|
|
|
|
when /custom\d+\|format/ #not finish
|
|
|
|
i = format_text.scan(/\d+/)[0].to_i - 1
|
|
|
|
k = custom_fields.keys[i] rescue nil
|
|
|
|
if !k.blank?
|
|
|
|
text_tp = @application_form_signup.application_form_signup_values.select{|v| v.application_form_signup_field_id==k}[0].get_value_by_locale
|
|
|
|
text = text.gsub(format_text,text_tp.to_s)
|
|
|
|
end
|
|
|
|
when /custom\d+/
|
|
|
|
i = format_text.scan(/\d+/)[0].to_i - 1
|
|
|
|
k = custom_fields.keys[i] rescue nil
|
|
|
|
if !k.blank?
|
|
|
|
text_tp = @application_form_signup.application_form_signup_values.select{|v| v.application_form_signup_field_id==k}[0].get_value_by_locale
|
|
|
|
text = text.gsub(format_text,text_tp.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
text
|
|
|
|
end
|
|
|
|
|
|
|
|
def print
|
|
|
|
@application_form_signup = ApplicationFormSignup.find(params[:id])
|
|
|
|
@application_form = @application_form_signup.application_form_main
|
|
|
|
@print_setting = ApplicationFormCategoryPrintSetting.where(application_form_id: @application_form_signup.application_form_main_id.to_s).first
|
|
|
|
@print_setting = ApplicationFormPrintSetting.first if @print_setting.nil?
|
|
|
|
@save_name = @print_setting.save_name rescue ''
|
|
|
|
@print_text = @print_setting.print_format rescue ''
|
|
|
|
custom_fields = @application_form.application_form_signup_fields.order_by({key: :asc}).collect{|v| [v.id,v.title_translations]}.to_h
|
|
|
|
@print_text = process_format_text(@print_text,custom_fields)
|
|
|
|
@save_name = process_format_text(@save_name,custom_fields)
|
|
|
|
end
|
|
|
|
|
2022-03-10 02:11:18 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_application_form
|
|
|
|
@application_form = ApplicationFormMain.find(params[:id]) rescue nil
|
|
|
|
if params[:action] == "update_application_form_review"
|
|
|
|
@application_form_review = ApplicationFormReview.find(params[:id]) rescue nil
|
|
|
|
@application_form = @application_form_review.application_form_main
|
|
|
|
elsif params[:action] == "update_application_form_session"
|
|
|
|
@application_form_signup = ApplicationFormSignup.find(params[:signup_id]) rescue nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def application_form_template_setting_params
|
|
|
|
params.require(:application_form_template_setting).permit!
|
|
|
|
end
|
|
|
|
def application_form_params
|
2022-05-21 13:48:39 +00:00
|
|
|
tmp = params.require(:application_form_main).permit!
|
|
|
|
tmp['reviewer_ids_list'] = tmp['reviewer_enables'].map{|k,i| Array((tmp['reviewer_ids_list'][k] rescue []))}
|
|
|
|
tmp['reviewer_enables'] = tmp['reviewer_enables'].map{|k,v| v.to_i != 0 ? true : false}
|
|
|
|
tmp
|
2022-03-10 02:11:18 +00:00
|
|
|
end
|
|
|
|
def create_set (save_flag)
|
|
|
|
except_attributes = ApplicationFormSignup::HiddenFields
|
2022-06-14 13:19:52 +00:00
|
|
|
if @application_form.application_form_signup_field_sets.where(:field_name.in=>except_attributes).destroy != 0
|
|
|
|
@application_form = @application_form.reload
|
|
|
|
end
|
|
|
|
(ApplicationFormSignup.attribute_names + ['recaptcha']).each do |attr_signup|
|
2022-03-10 02:11:18 +00:00
|
|
|
next if except_attributes.include?(attr_signup)
|
|
|
|
signup_set = @application_form.application_form_signup_field_sets.select{|v| v.field_name==attr_signup }
|
|
|
|
if signup_set.length==0
|
|
|
|
if ApplicationFormSignup::DefaultEnableFields.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("application_form_signup.#{attr_signup}")
|
|
|
|
end
|
|
|
|
I18n.locale = now_locale
|
|
|
|
if save_flag
|
|
|
|
@application_form.application_form_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
|
|
|
|
else
|
|
|
|
@application_form.application_form_signup_field_sets.new(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@application_form.application_form_submission_field_sets.where(:field_name.in=>except_attributes).destroy
|
|
|
|
ApplicationFormSignupContribute.attribute_names.each do |attr_submission|
|
|
|
|
next if except_attributes.include?(attr_submission)
|
|
|
|
signup_set = @application_form.application_form_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("application_form_signup.#{attr_submission}")
|
|
|
|
end
|
|
|
|
I18n.locale = now_locale
|
|
|
|
if save_flag
|
|
|
|
@application_form.application_form_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1)
|
|
|
|
else
|
|
|
|
@application_form.application_form_submission_field_sets.new(field_name:attr_submission,name:name1,placeholder:name1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@application_form.application_form_signup_fields.all.map{|v| v}.each do |field|
|
|
|
|
set = @application_form.application_form_signup_field_customs.select{|v| v.application_form_signup_field_id==field.id}
|
|
|
|
if set.length == 0
|
|
|
|
@application_form.application_form_signup_field_customs.create(application_form_signup_field_id:field.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@email_set = []
|
|
|
|
['signup','submission','add_file','edit_file'].each do |field_name|
|
|
|
|
email_set = @application_form.application_form_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("application_form.email_#{field_name}_success")
|
|
|
|
content[locale] = t("application_form.email_#{field_name}_content")
|
|
|
|
end
|
|
|
|
I18n.locale = now_locale
|
|
|
|
if save_flag
|
|
|
|
email_set = @application_form.application_form_email_sets.create(field_name:field_name,title:title,content:content)
|
|
|
|
else
|
|
|
|
email_set = @application_form.application_form_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
|