diff --git a/app/controllers/admin/seminar_signups_controller.rb b/app/controllers/admin/seminar_signups_controller.rb index 5f1e989..c6a2e14 100644 --- a/app/controllers/admin/seminar_signups_controller.rb +++ b/app/controllers/admin/seminar_signups_controller.rb @@ -2,12 +2,21 @@ class Admin::SeminarSignupsController < OrbitAdminController include Admin::SeminarsHelper before_action ->(module_app = @app_title) { set_variables module_app } - + before_action :check_manager_for_seminar def initialize super @app_title = "seminar" end - + def check_manager_for_seminar + OrbitHelper.set_params(params,current_user) + access_level = OrbitHelper.user_access_level? + if (access_level.nil? || access_level == "user") + @seminar = SeminarSignup.find(params[:id]).seminar_main rescue nil + if (@seminar.organizer_id != current_user.member_profile_id rescue true) + render_401 + end + end + end def edit OrbitHelper.set_params(params,current_user) params[:controller] = "admin/seminars" @@ -29,6 +38,15 @@ class Admin::SeminarSignupsController < OrbitAdminController field_value = r.last[:id].present? @custom_field_value = SeminarSignupValue.put_field_values(@seminar_signup, r.last, r.last[:id], field_value) end + seminar_reviews = SeminarReview.where(:seminar_main_id=>@seminar_signup.seminar_main_id).to_a + seminar_reviews.each{|sr| sr.save} + @seminar = @seminar_signup.seminar_main + unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s} + @seminar.seminar_reviews.each do |sr| + unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids + end + @seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids + @seminar.save end redirect_to "/admin/seminars/#{@seminar_signup.seminar_main_id}/seminar_signup" diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index ad7f4c9..6c16491 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -2,10 +2,13 @@ class Admin::SeminarsController < OrbitAdminController require 'axlsx' + include Admin::SeminarsHelper helper Admin::SeminarsFieldHelper before_action ->(module_app = @app_title) { set_variables module_app } - before_action :set_seminar, only: [:edit, :set_write_off, :seminar_signup, :destroy] - + before_action :set_seminar, only: [:edit, :set_write_off, :seminar_signup, :destroy,:seminar_signup_admin_setting,:update_seminar_signup_admin_setting,:get_reviewer_block,:get_session_block,:update_seminar_review,:update_seminar_session,:reviewer_setting,:update_reviewer_setting] + before_action :set_seminar_signup_admin_setting, only: [:seminar_signup,:seminar_signup_admin_setting,:update_seminar_signup_admin_setting,:get_reviewer_block,:get_session_block] + before_action :check_permission_for_seminar, only: [:seminar_signup,:get_reviewer_block,:get_session_block] + before_action :check_manager_for_seminar, only: [:seminar_signup_admin_setting,:update_seminar_signup_admin_setting,:update_seminar_review,:update_seminar_session,:reviewer_setting,:update_reviewer_setting] def initialize super @app_title = "seminar" @@ -16,7 +19,229 @@ class Admin::SeminarsController < OrbitAdminController :category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}} } end + def check_manager_for_seminar + OrbitHelper.set_params(params,current_user) + access_level = OrbitHelper.user_access_level? + if (access_level.nil? || access_level == "user") && (@seminar.organizer_id != current_user.member_profile_id rescue true) + render_401 + end + end + def check_permission_for_seminar + OrbitHelper.set_params(params,current_user) + access_level = OrbitHelper.user_access_level? + if (access_level.nil? || access_level == "user") + unless (@seminar.reviewer_ids.include?(current_user.member_profile_id.to_s) rescue false) || (@seminar.organizer_id == current_user.member_profile_id rescue false) + render_401 + else + @user_authenticated_categories = ['all'] + end + end + end + def reviewer_setting + @seminar_reviews = @seminar.seminar_reviews + @fields = [] + @fields_translations = [] + access_markup = ["select","radio_button","checkbox"] + @fields_values = [] + @seminar.seminar_signup_fields.each do |f| + next if f.disabled + if access_markup.include?(f.markup) + @fields << "seminar_signup_fields.#{f.id}" + @fields_translations << f.title + @fields_values << f.option_list + end + end + @seminar.seminar_submission_fields.each do |f| + next if f.disabled + if access_markup.include?(f.markup) + @fields << "seminar_submission_fields.#{f.id}" + @fields_translations << f.title + @fields_values << f.option_list + end + end + if @seminar.enable_summary_choice + @fields << "seminar_signup_contributes.description" + begin + data2 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0] + name2 = data2['name'][I18n.locale] + @fields_translations << (name2.present? ? name2 : I18n.t("seminar_signup.description")) + rescue + @fields_translations << I18n.t("seminar_signup.description") + end + @fields_values << @seminar.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 + seminar_params[:seminar_reviews_attributes].keys.each do |i| + if seminar_params[:seminar_reviews_attributes][i][:default_topics].present? + seminar_params[:seminar_reviews_attributes][i][:default_topics] = [] if seminar_params[:seminar_reviews_attributes][i][:default_topics].nil? + default_topics_values = [] + (0...seminar_params[:seminar_reviews_attributes][i][:default_topics].count).each do |ii| + default_topics_values << (Array(seminar_params[:seminar_reviews_attributes][i][:default_topics_values][ii.to_s]) rescue []) + end + seminar_params[:seminar_reviews_attributes][i][:default_topics_values] = default_topics_values + else + seminar_params[:seminar_reviews_attributes][i][:default_topics] = [] + seminar_params[:seminar_reviews_attributes][i][:default_topics_values] = [] + end + end + #render :html => seminar_params and return + @seminar.update_attributes(seminar_params) + unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s} + unassigned_mode_1_seminar_signup_ids = unassigned_seminar_signup_ids.dup + @seminar.seminar_reviews.each do |sr| + unassigned_mode_1_seminar_signup_ids = unassigned_mode_1_seminar_signup_ids - sr.get_all_seminar_signup_ids(1) + unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids + end + @seminar.unassigned_mode_1_seminar_signup_ids = unassigned_mode_1_seminar_signup_ids + @seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids + @seminar.save + redirect_to admin_seminars_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 && SeminarMain.where(:reviewer_ids=>reviewer_id).count == 0 && SeminarMain.where(:organizer_id=>reviewer_id).count == 0 + render_401 and return + end + @seminar_signup_admin_setting = SeminarSignupAdminSetting.where(:seminar_main_id=>"enquiry_for_applicants").first + if @seminar_signup_admin_setting.nil? + @seminar_signup_admin_setting = SeminarSignupAdminSetting.create(:seminar_main_id=>"enquiry_for_applicants") + end + if params[:name].present? + @seminar_signups = SeminarSignup.where(:name => /#{params[:name]}/).sort_ordered.page(params[:page]).per(10) + else + @seminar_signups = [] + end + unless @can_edit + if @seminar_signups.class != Array + seminar_review = SeminarReview.where(:reviewer_id=>reviewer_id) + seminar_signup_ids = seminar_review.pluck(:seminar_signup_ids).flatten + remove_seminar_signup_ids = seminar_review.pluck(:remove_seminar_signup_ids).flatten + assign_ids = [] + seminars = SeminarMain.where(:id.in => seminar_review.pluck(:seminar_main_id)) + final_assign_signup_ids = SeminarSession.where(:id.in=>seminar_review.pluck(:seminar_session_ids).flatten,:seminar_main_id.in=>seminars.where(:assign_mode=>1).pluck(:id)).pluck(:seminar_signup_ids).flatten + default_seminar_signup_ids = seminar_review.where(:seminar_main_id.in=>seminars.where(:assign_mode=>0).pluck(:id)).pluck(:default_seminar_signup_ids).flatten + all_seminar_signup_ids = seminar_signup_ids - remove_seminar_signup_ids + final_assign_signup_ids + default_seminar_signup_ids + + ids2 = SeminarSignup.where(:seminar_main_id.in=> SeminarMain.where(:organizer_id=>current_user.member_profile_id).pluck(:id)).pluck(:id) + + @seminar_signups = @seminar_signups.where(:id.in=>all_seminar_signup_ids + ids2).sort_ordered.page(params[:page]).per(10) + end + end + end + def get_hide_session + seminar_main = SeminarMain.find(params[:id]) rescue nil + if seminar_main.nil? + render :nothing => true + else + @seminar = seminar_main + @seminar_sessions = @seminar.seminar_sessions + @hide_session_ids = (0...seminar_main.summary_chioices.count).to_a - Array(seminar_main.session_show_ids) + @hide_sessions = @hide_session_ids.zip(seminar_main.summary_chioices[Range.new(@hide_session_ids[0],@hide_session_ids[-1])]).to_h + render :layout => false + end + end + def get_hide_reviewer + seminar_main = SeminarMain.find(params[:id]) rescue nil + if seminar_main.nil? + render :nothing => true + else + @hide_reviewer_ids = Array(seminar_main.reviewer_ids) - Array(seminar_main.reviewer_show_ids) + @hide_reviewers = MemberProfile.where(:id.in=>@hide_reviewer_ids) + @reviewers = seminar_main.seminar_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 + unless (@seminar.session_show_ids.include?(@session_id) rescue false) + @seminar.session_show_ids << @session_id + @seminar.save + end + render :layout => false + end + def get_reviewer_block + @reviewer_id = params[:reviewer_id] + unless (@seminar.reviewer_show_ids.include?(@reviewer_id) rescue false) + @seminar.reviewer_show_ids << @reviewer_id + @seminar.save + end + render :layout => false + end + def update_seminar_session + if @seminar.nil? + render :json => {:success => false} + else + seminar_main = @seminar + session_id = params[:session_id].to_i + seminar_main.save + seminar_session = @seminar.seminar_sessions.where(:key=>session_id).first + if params[:mode] == "append" + @seminar_signup.update(:final_session=>session_id) + seminar_session.seminar_signup_ids << @seminar_signup.id.to_s + @seminar_signup.update(:seminar_session_id=>seminar_session.id) + seminar_main.assign_mode = 1 + seminar_session.save + seminar_main.unassigned_mode_1_seminar_signup_ids.delete(@seminar_signup.id.to_s) + elsif params[:mode] == "remove" + @seminar_signup.update(:final_session=>nil) + seminar_session.seminar_signup_ids.delete(@seminar_signup.id.to_s) + @seminar_signup.update(:seminar_session_id=>nil) + seminar_session.save + seminar_main.assign_mode = 0 if seminar_main.seminar_sessions.where(:seminar_signup_ids.ne=>[]).count == 0 + seminar_main.unassigned_mode_1_seminar_signup_ids << @seminar_signup.id.to_s + elsif params[:mode] == "hide" + if seminar_main.session_show_ids.nil? + seminar_main.session_show_ids = (0...seminar_main.summary_chioices.count).to_a[0..1] + end + seminar_main.session_show_ids.delete(session_id) + elsif params[:mode] == "show" + seminar_main.session_show_ids = seminar_main.session_show_ids.to_a + Array(session_id) + else + render :json => {:success => false} and return + end + seminar_main.save + render :json => {:success => true} + end + end + def update_seminar_review + if @seminar_review.nil? + render :json => {:success => false} + else + seminar_main = @seminar_review.seminar_main + if params[:mode] == "append" + @seminar_review.seminar_signup_ids << params[:signup_id] + @seminar_review.remove_seminar_signup_ids.delete(params[:signup_id]) + seminar_main.unassigned_seminar_signup_ids.delete(params[:signup_id]) + seminar_main.unassigned_mode_1_seminar_signup_ids.delete(params[:signup_id]) + elsif params[:mode] == "remove" + @seminar_review.seminar_signup_ids.delete(params[:signup_id]) + @seminar_review.remove_seminar_signup_ids << params[:signup_id] + seminar_main.unassigned_seminar_signup_ids << params[:signup_id] + seminar_main.unassigned_mode_1_seminar_signup_ids << params[:signup_id] + elsif params[:mode] == "hide" + if seminar_main.reviewer_show_ids.nil? + seminar_main.reviewer_show_ids = seminar_main.reviewer_ids[0..1] + end + seminar_main.reviewer_show_ids = seminar_main.reviewer_show_ids - Array(@seminar_review.reviewer_id).flatten + elsif params[:mode] == "show" + seminar_main.reviewer_show_ids = seminar_main.reviewer_show_ids.to_a + Array(@seminar_review.reviewer_id).flatten + else + render :json => {:success => false} and return + end + seminar_main.save + @seminar_review.save + render :json => {:success => true} + end + end def index @categories = @module_app.categories.enabled @filter_fields = filter_fields(@categories) @@ -31,13 +256,24 @@ class Admin::SeminarsController < OrbitAdminController sort = {params[:sort].to_sym=>params[:order]} end else - sort = {:signup_start_date=>"desc"} + sort = {:signup_start_date=>"desc",:created_at=>"desc"} end @seminars = SeminarMain.all.order_by(sort).with_categories(filters("category")) @seminars = search_data(@seminars,[:title]).page(params[:page]).per(10) - + 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 + reviewer_id = current_user.member_profile_id.to_s + ids1 = @seminars.where(:reviewer_ids=>reviewer_id).pluck(:id) + ids2 = @seminars.where(:organizer_id=>current_user.member_profile_id).pluck(:id) + @seminars = @seminars.where(:id.in=>ids1+ids2) + end if request.xhr? render :partial => "index" end @@ -49,14 +285,31 @@ class Admin::SeminarsController < OrbitAdminController @seminar = SeminarMain.find(params[:id]) @seminar_signups = SeminarSignup.where(:seminar_main_id => params[:id]) filename = @seminar.title.parameterize.underscore + "_export.xlsx" - respond_to do |format| - format.xlsx { - response.headers['Content-Disposition'] = 'attachment; filename="' + filename + '"' - } + if can_see_seminar_signup(@seminar) + if !admin_for_seminar(@seminar) + @seminar_review = @seminar.seminar_reviews.where(:reviewer_id => current_user.member_profile_id.to_s).first + @seminar_signups = @seminar_signups.where(:id.in=>@seminar_review.get_all_seminar_signup_ids) rescue [] + end + @seminar_signups = @seminar_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 + @seminar = SeminarMain.find(params[:id]).clone_new + @member = MemberProfile.where(:id.in=>@seminar.reviewer_ids).to_a + @email_set = @seminar.seminar_email_sets + @signup_sets = @seminar.seminar_signup_field_sets + @submission_set = @seminar.seminar_submission_field_sets + @custom_set = @seminar.seminar_signup_field_customs + @seminar_items = SeminarItem.all + @review = @seminar.seminar_reviews.first + end def new @member = nil @seminar = SeminarMain.new @@ -79,21 +332,43 @@ class Admin::SeminarsController < OrbitAdminController seminar_signup_set_params = seminar_main_params['seminar_signup_field_sets'] seminar_submission_set_params = seminar_main_params['seminar_submission_field_sets'] seminar_email_sets_params = seminar_main_params['seminar_email_sets'] + seminar_signup_field_customs_params = seminar_main_params["seminar_signup_field_customs"].to_hash + seminar_main_params["seminar_signup_field_customs"].each do |k,v| + v.delete "title" + end seminar_main_params.delete(:seminar_signup_field_sets) seminar_main_params.delete(:seminar_submission_field_sets) seminar_main_params.delete(:seminar_email_sets) seminar = SeminarMain.new(seminar_main_params) seminar.create_user_id = current_user.id seminar.update_user_id = current_user.id + if seminar.copy_id && params["clone_signups"].blank? + seminar.except_clone_relations = ["seminar_signups","seminar_signup_values","seminar_signup_contributes","seminar_submission_values"] + end seminar.save - seminar_signup_set_params.each do |key,value| - seminar.seminar_signup_field_sets.create(value) - end - seminar_submission_set_params.each do |key,value| - seminar.seminar_submission_field_sets.create(value) - end - seminar_email_sets_params.each do |key,value| - seminar.seminar_email_sets.create(value) + if seminar.copy_id + seminar_signup_set_params.each do |key,value| + seminar.seminar_signup_field_sets[key.to_i].update_attributes(value) rescue nil + end + seminar_submission_set_params.each do |key,value| + seminar.seminar_submission_field_sets[key.to_i].update_attributes(value) rescue nil + end + seminar_email_sets_params.each do |key,value| + seminar.seminar_email_sets[key.to_i].update_attributes(value) rescue nil + end + seminar_signup_field_customs_params.each_with_index do |(key,value),i| + seminar.seminar_signup_field_customs[i].update(:seminar_signup_field_id => seminar.seminar_signup_fields.where(:title=>value["title"]).first.id) rescue nil + end + else + seminar_signup_set_params.each do |key,value| + seminar.seminar_signup_field_sets.create(value) + end + seminar_submission_set_params.each do |key,value| + seminar.seminar_submission_field_sets.create(value) + end + seminar_email_sets_params.each do |key,value| + seminar.seminar_email_sets.create(value) + end end redirect_to params['referer_url'] @@ -121,22 +396,22 @@ class Admin::SeminarsController < OrbitAdminController @signup_sets = @seminar.seminar_signup_field_sets @submission_set = @seminar.seminar_submission_field_sets @custom_set = @seminar.seminar_signup_field_customs - if @seminar.seminar_reviews.first.nil? - @review = @seminar.seminar_reviews.new() + @member = MemberProfile.where(:id.in=>@seminar.reviewer_ids).to_a rescue [] + if (@seminar.organizer_id == current_user.member_profile_id rescue false) + @user_authorized_categories = @module_app.categories.enabled.to_a else - @review = @seminar.seminar_reviews.first + @user_authorized_categories = nil end - @member = MemberProfile.find(@review.reviewer_id) rescue nil end def update - params[:seminar_main][:registration_status] = (params[:seminar_main][:registration_status] ? params[:seminar_main][:registration_status] : []) uid = params[:id].split('-').last @seminar = SeminarMain.find_by(:uid=>uid) - + seminar_params["reviewer_ids"] = [] if seminar_params["reviewer_ids"].nil? + seminar_params["organizer_id"] = nil if seminar_params["organizer_id"].nil? if params[:seminar_main][:seminar_signup_fields] seminar_params[:seminar_signup_fields].each do |a| @field_name = 'seminar_main' @@ -209,15 +484,61 @@ class Admin::SeminarsController < OrbitAdminController end def seminar_signup - - if !params[:search].blank? - @seminar_signups = SeminarSignup.where(:seminar_main_id => @seminar.id, :name=>params[:search]).page(params[:page]).per(10) + @seminar_signups = [] + if params[:type] == "table" + if params[:search].to_i != 0 + @seminar_signups = @seminar.seminar_signups.where(:serial_number=>params[:search].to_i) + else + @seminar_signups = @seminar.seminar_signups.where(:name=>/#{params[:search]}/) + end + elsif params[:type] == "session" + @seminar_signups = @seminar.seminar_signups.where(:final_session => nil, :name=>/#{params[:search]}/) else - @seminar_signups = SeminarSignup.where(:seminar_main_id => @seminar.id).page(params[:page]).per(10) + unassigned_seminar_signup_ids = @seminar.unassigned_seminar_signup_ids + if @seminar.assign_mode == 1 + unassigned_seminar_signup_ids = @seminar.unassigned_mode_1_seminar_signup_ids + end + @seminar_signups = @seminar.seminar_signups.where(:id.in => unassigned_seminar_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 = (@seminar.organizer_id == current_user.member_profile_id rescue false) + end + unless @can_edit + @seminar_review = @seminar.seminar_reviews.where(:reviewer_id => current_user.member_profile_id.to_s).first + @seminar_signups = @seminar.seminar_signups.where(:id.in=>@seminar_review.get_all_seminar_signup_ids) + end + @seminar_signups = @seminar_signups.sort_ordered.page(params[:page]).per(10) + if request.xhr? + render :layout => false + end + end + def seminar_signup_admin_setting + if @seminar.nil? && params[:id] != "enquiry_for_applicants" + redirect_to admin_seminars_path + end + end + def update_seminar_signup_admin_setting + @seminar_signup_admin_setting.update_attributes(params.require(:seminar_signup_admin_setting).permit!) + if params[:id] != "enquiry_for_applicants" + redirect_to seminar_signup_admin_seminar_path(params[:id]) + "?type=#{params[:page]}" + else + redirect_to admin_seminar_enquiry_for_applicants_path + end + end + def set_seminar_signup_admin_setting + page = params[:type] || params[:page] + page = nil if page.blank? + @seminar_signup_admin_setting = SeminarSignupAdminSetting.where(:seminar_main_id=>params[:id],:page=>page).first + if @seminar_signup_admin_setting.nil? + @seminar_signup_admin_setting = SeminarSignupAdminSetting.create(:seminar_main_id=>params[:id],:page=>page) end - end - def edit_seminar_signup @seminar_signup = SeminarSignup.find(params[:id]) @seminar = SeminarMain.find(@seminar_signup.seminar_main_id) @@ -237,7 +558,13 @@ class Admin::SeminarsController < OrbitAdminController private def set_seminar - @seminar = SeminarMain.find(params[:id]) + @seminar = SeminarMain.find(params[:id]) rescue nil + if params[:action] == "update_seminar_review" + @seminar_review = SeminarReview.find(params[:id]) rescue nil + @seminar = @seminar_review.seminar_main + elsif params[:action] == "update_seminar_session" + @seminar_signup = SeminarSignup.find(params[:signup_id]) rescue nil + end end def seminar_params @@ -245,7 +572,7 @@ class Admin::SeminarsController < OrbitAdminController end def create_set (save_flag) SeminarSignup.attribute_names.each do |attr_signup| - if !(['_id', 'created_at', 'updated_at','seminar_main_id'].include? attr_signup) + if !(['_id', 'created_at', 'updated_at','seminar_main_id','final_session','seminar_session_id'].include? attr_signup) signup_set = @seminar.seminar_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 diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index 968a28d..657bd18 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -148,15 +148,32 @@ class SeminarsController < ApplicationController field_value = r.last[:id].present? @custom_field_value = SeminarSignupValue.put_field_values(@seminar_signup, r.last, r.last[:seminar_signup_field_id], field_value) end + seminar_reviews = SeminarReview.where(:seminar_main_id=>@seminar.id).to_a + seminar_reviews.each{|sr| sr.save} + @seminar = @seminar_signup.seminar_main + unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s} + unassigned_seminar_signup_ids.push(@seminar_signup.id.to_s) + seminar_reviews = SeminarReview.where(:seminar_main_id=>@seminar.id).to_a + seminar_reviews.each do |sr| + unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids + end + @seminar.unassigned_seminar_signup_ids << @seminar_signup.id.to_s + @seminar.unassigned_mode_1_seminar_signup_ids << @seminar_signup.id.to_s + @seminar.save + else + @seminar.unassigned_seminar_signup_ids << @seminar_signup.id.to_s + @seminar.unassigned_mode_1_seminar_signup_ids << @seminar_signup.id.to_s + @seminar.save end + extra_text = "
#{I18n.t('seminar_signup.serial_number')}: #{@seminar_signup.display_serial_number}" if params['seminar_signup']['status']=='C' status_param = '&status=' - send_mail('submission',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id]) + send_mail('submission',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id],extra_text) else status_param = '' - send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id]) + send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id],extra_text) end - redirect_to "#{params[:referer_url]}/?method=signup_ok#{status_param}" + redirect_to "#{params[:referer_url]}/?method=signup_ok#{status_param}&serial_number=#{@seminar_signup.display_serial_number}" else if !@signup.blank? redirect_to "#{params[:referer_url]}", :notice => 'mail已存在' @@ -171,6 +188,8 @@ class SeminarsController < ApplicationController end def signup_ok + params = OrbitHelper.params + {"serial_number"=> params[:serial_number]} end def add_file_proc @@ -203,6 +222,15 @@ class SeminarsController < ApplicationController seminar_id = signup.seminar_main_id @seminar = SeminarMain.where(id:seminar_id).first send_mail('add_file',signup.email,seminar_id) + seminar_reviews = SeminarReview.where(:seminar_main_id=>signup.seminar_main_id).to_a + seminar_reviews.each{|sr| sr.save} + @seminar = signup.seminar_main + unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s} + @seminar.seminar_reviews.each do |sr| + unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids + end + @seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids + @seminar.save redirect_to "#{params[:referer_url]}/?method=con_upload" else redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') @@ -237,6 +265,15 @@ class SeminarsController < ApplicationController seminar_id = signup.seminar_main_id @seminar = SeminarMain.where(id:seminar_id).first send_mail('edit_file',signup.email,seminar_id) + seminar_reviews = SeminarReview.where(:seminar_main_id=>signup.seminar_main_id).to_a + seminar_reviews.each{|sr| sr.save} + @seminar = signup.seminar_main + unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s} + @seminar.seminar_reviews.each do |sr| + unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids + end + @seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids + @seminar.save redirect_to "#{params[:referer_url]}/?method=con_upload" else redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') @@ -250,9 +287,18 @@ class SeminarsController < ApplicationController # seminar_signup = SeminarSignup.find_by(_id: con.seminar_signup_id ) # seminar = SeminarMain.find_by(_id: seminar_signup.seminar_main_id ) - + signup = con.seminar_signup con.destroy + seminar_reviews = SeminarReview.where(:seminar_main_id=>signup.seminar_main_id).to_a + seminar_reviews.each{|sr| sr.save} + @seminar = SeminarMain.find(signup.seminar_main_id) + unassigned_seminar_signup_ids = @seminar.seminar_signup_ids.map{|s| s.to_s} + @seminar.seminar_reviews.each do |sr| + unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids + end + @seminar.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids + @seminar.save redirect_to "#{params[:referer_url]}/?method=con_upload" end @@ -375,7 +421,7 @@ class SeminarsController < ApplicationController def seminar_signup_values_params params.require(:seminar_signup_values).permit! end - def send_mail(field_name,email,seminar_id) + def send_mail(field_name,email,seminar_id,extra_text="") email_set = @seminar.seminar_email_sets.select{|v| v.field_name == field_name} if email_set.length==0 mail = Email.create(mail_to:[email], @@ -383,14 +429,14 @@ class SeminarsController < ApplicationController template:"email/#{field_name}_email.html.erb", mail_sentdate:Time.current, mail_subject: t("seminar.email_#{field_name}_success"), - template_data:{'seminar_id'=>seminar_id,'locale'=>I18n.locale}) + template_data:{'seminar_id'=>seminar_id,'locale'=>I18n.locale,'extra_text'=> extra_text}) elsif !(email_set[0].disabled) mail = Email.create(mail_to:[email], module_app_key:"seminar", template:"email/#{field_name}_email.html.erb", mail_sentdate:Time.current, mail_subject: email_set[0].title[I18n.locale], - template_data:{'seminar_id'=>seminar_id,'locale'=>I18n.locale}) + template_data:{'seminar_id'=>seminar_id,'locale'=>I18n.locale,'extra_text'=> extra_text}) end begin mail.deliver diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index f3d385c..3ac3c1e 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -39,12 +39,12 @@ module Admin::SeminarsFieldHelper add_ext= @attribute_value.address_key[key] rescue {} - result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][county]",add_ext["county"],:class=>"county_#{key}") - result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][street_address]",add_ext["street_address"],:class=>"street_address_#{key}") - result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][city]",add_ext["city"],:class=>"city_#{key}") - result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][zip]",add_ext["zip"],:class=>"zip_#{key}") - result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][country]",add_ext["country"],:class=>"country_#{key}") - result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][indicator]",add_ext["indicator"],:class=>"indicator_#{key}") + result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][county]",add_ext["county"],:class=>"county_#{key}", :id=>nil) + result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][street_address]",add_ext["street_address"],:class=>"street_address_#{key}", :id=>nil) + result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][city]",add_ext["city"],:class=>"city_#{key}", :id=>nil) + result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][zip]",add_ext["zip"],:class=>"zip_#{key}", :id=>nil) + result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][country]",add_ext["country"],:class=>"country_#{key}", :id=>nil) + result << hidden_field_tag(get_basic_field_name_base+"[address_key][#{key}][indicator]",add_ext["indicator"],:class=>"indicator_#{key}", :id=>nil) end end @@ -52,7 +52,7 @@ module Admin::SeminarsFieldHelper @prefiled_value ||=[] control_group_wrapper do a = self.typeE[:option_list].collect do |key,value| - label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", true , (@prefiled_value.include?(key) ? true : false), { :id=>"#{get_basic_field_name_org}_#{self.id}"})+value[I18n.locale.to_s],@markup_options.merge(:class=>"checkbox inline")) + label_tag("#{get_basic_field_name_org}_#{self.id}_#{key}",check_box_tag(get_field_name_base+"[#{key}]", true , (@prefiled_value.include?(key) ? true : false), { :id=>"#{get_basic_field_name_org}_#{self.id}_#{key}"})+value[I18n.locale.to_s],@markup_options.merge(:class=>"checkbox inline")) end.join.html_safe rescue "" end end @@ -138,7 +138,7 @@ module Admin::SeminarsFieldHelper @prefiled_value ||=[] control_group_wrapper do self.typeE[:option_list].collect do |key,value| - label_tag(key,radio_button_tag(get_field_name_base, key , (@prefiled_value.include?(key) ? true : false), {:required=>@require})+value[I18n.locale.to_s],@markup_options.merge(:class=>"radio inline")) + label_tag("#{get_basic_field_name_org}_#{self.id}_#{key}",radio_button_tag(get_field_name_base, key , (@prefiled_value.include?(key) ? true : false), {:required=>@require,:id=>"#{get_basic_field_name_org}_#{self.id}_#{key}"})+value[I18n.locale.to_s],@markup_options.merge(:class=>"radio inline")) end.join.html_safe end end @@ -195,7 +195,7 @@ protected if self.markup=='text_area' #or self.markup=='address' tmp1 = valid_locales.collect do |key| if !@prefiled_value.nil? - value = @prefiled_value[key] rescue nil + value = @prefiled_value[key] || @prefiled_value[key.to_s] rescue nil else value = nil end @@ -203,7 +203,6 @@ protected div_class_ary = ["tab-pane" ,"fade"] if @show_set_field && @markup=='text_area' div_id = "ckeditor_#{get_pairing_tab_class({})}_#{key}" - puts 'ckeditor_' else div_id = "#{get_pairing_tab_class({})}_#{key}" end @@ -245,7 +244,7 @@ protected content_tag :div,:class=> "tab-content" do buff = valid_locales.collect do |key| - value = @prefiled_value[key] rescue nil + value = @prefiled_value[key] || @prefiled_value[key.to_s] rescue nil # div_class_ary = ["tab-pane" ,"fade","#{get_pairing_tab_class({})}_#{key}"] div_class_ary = ["tab-pane" ,"fade"] @@ -380,8 +379,8 @@ protected temp_field_name = get_basic_field_name_base + '[temp]' add_more = content_tag :p,:class=> 'add-btn' do content = link_to (content_tag :i,I18n.t(:add),:class=>"icon-plus"),"#","data-roles"=>"role_a",:class=>"trigger #{can_muti_lang_input? ? 'textLengInput' : 'textInput' } btn btn-small btn-primary" - content << hidden_field_tag("#{temp_field_name}[count]",@attribute_value.add_more_counter ,:class=>"list_count") - content << hidden_field_tag("#{temp_field_name}[count]",get_basic_field_name_base,:class=>"field_name") + content << hidden_field_tag("#{temp_field_name}[count]",@attribute_value.add_more_counter ,:class=>"list_count", :id=>nil) + content << hidden_field_tag("#{temp_field_name}[count]",get_basic_field_name_base,:class=>"field_name", :id=>nil) content end # of div # add_more = content_tag :div,:class=> 'controls' do @@ -396,9 +395,9 @@ protected def end_block if @new_attribute - hidden_field_tag(get_basic_field_name_base+"[#{get_basic_field_name}_id]",id,:for=>"field_#{@index}") + hidden_field_tag(get_basic_field_name_base+"[#{get_basic_field_name}_id]",id,:for=>"field_#{@index}", :id=>nil) else - hidden_field_tag(get_basic_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}") + hidden_field_tag(get_basic_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}", :id=>nil) end end @@ -495,8 +494,12 @@ protected '' end def self.end_block - hidden_field_tag("seminar_main[#{@key_field}][#{@key_index}]"+"[id]", - @attribute_value.id,:for=>"field_#{@key_index}") + unless @attribute_value.new_record? + hidden_field_tag("seminar_main[#{@key_field}][#{@key_index}]"+"[id]", + @attribute_value.id,:for=>"field_#{@key_index}", :id=>nil) + else + "" + end end @key_field = key_field @field = field diff --git a/app/helpers/admin/seminars_helper.rb b/app/helpers/admin/seminars_helper.rb index 3aeed66..15f3dfd 100644 --- a/app/helpers/admin/seminars_helper.rb +++ b/app/helpers/admin/seminars_helper.rb @@ -1,4 +1,7 @@ module Admin::SeminarsHelper + def display_format_string(num, str_length) + return format("%0#{str_length}d", num % (10^str_length)) + end def page_for_seminar(seminar) ann_page = nil pages = Page.where(:module=>'seminar') @@ -24,7 +27,18 @@ module Admin::SeminarsHelper ann_page = pages.first if ann_page.nil? request.protocol+(request.host_with_port+ann_page.url+'/'+seminar.to_param).gsub('//','/') rescue "/" end - + def can_see_seminar_signup(seminar) + if can_edit_or_delete?(seminar) + return true + elsif (seminar.organizer_id == current_user.member_profile_id rescue false) + return true + else + return seminar.reviewer_ids.to_a.include?(current_user.member_profile_id.to_s) + end + end + def admin_for_seminar(seminar) + return can_edit_or_delete?(seminar) || (seminar.organizer_id == current_user.member_profile_id rescue false) + end def page_for_seminar_url page = Pag.where(:module => 'seminar').first return request.protocol+(request.host_with_port+"/#{I18n.locale}#{page.url}").gsub('//','/') rescue "/" diff --git a/app/models/seminar_main.rb b/app/models/seminar_main.rb index 7626c28..92f60e9 100644 --- a/app/models/seminar_main.rb +++ b/app/models/seminar_main.rb @@ -1,4 +1,5 @@ class SeminarMain + require 'fileutils' include Mongoid::Document include Mongoid::Timestamps @@ -6,13 +7,21 @@ class SeminarMain # encoding: utf-8 include OrbitCategory::Categorizable include Slug - + ChoiceTypes = ["checkbox","radio","select"] + field :copy_id + field :except_clone_relations, :type=>Array, :default => [] field :signup_note, localize: true field :title, as: :slug_title, type: String, localize: true field :speaker, localize: true field :content, localize: true field :act_place, localize: true - + field :enable_summary_choice, :type => Boolean, :default => false + field :summary_chioice_type, :type => String, :default => "checkbox" + field :summary_chioices, :type => Array, :default => ["A. Energy Conversion","B. Biocatalysis","C. Electrocatalysis", + "D. Photocatalysis","E. Catalytic and Porous Materials", + "F. Environmental and Reaction Engineering","G. Industrial Applications", + "H. Student Oral Presentation Contest (in English)","I. Student Poster Competition" + ] field :seminar_start_date, :type => Date, :default => Time.now field :seminar_end_date, :type => Date, :default => Time.now @@ -28,9 +37,18 @@ class SeminarMain field :create_user_id field :update_user_id - + field :reviewer_ids + field :reviewer_show_ids + field :session_show_ids + field :unassigned_seminar_signup_ids + field :unassigned_mode_1_seminar_signup_ids + field :review_start_date, :type => Date + field :review_end_date, :type => Date + field :last_serial_number, :type => Integer, :default => 0 + field :assign_mode, :type => Integer, :default => 0 # 0 => 用default signup ids來分配 ,1 => 用final_session來分配 belongs_to :seminar_item - + belongs_to :organizer , :class_name=>"MemberProfile", :foreign_key => :organizer_id + has_many :seminar_sessions, :autosave => true, :dependent => :destroy has_many :seminar_links, :autosave => true, :dependent => :destroy has_many :seminar_files, :autosave => true, :dependent => :destroy has_many :seminar_item_contents, :autosave => true, :dependent => :destroy @@ -42,6 +60,7 @@ class SeminarMain has_many :seminar_submission_field_sets, autosave: true, dependent: :destroy has_many :seminar_email_sets, autosave: true, dependent: :destroy has_many :seminar_signup_field_customs, :autosave => true, :dependent => :destroy + accepts_nested_attributes_for :seminar_sessions, :allow_destroy => true accepts_nested_attributes_for :seminar_links, :allow_destroy => true accepts_nested_attributes_for :seminar_files, :allow_destroy => true accepts_nested_attributes_for :seminar_item_contents, :allow_destroy => true @@ -53,6 +72,144 @@ class SeminarMain accepts_nested_attributes_for :seminar_submission_field_sets, :allow_destroy => true accepts_nested_attributes_for :seminar_email_sets, :allow_destroy => true accepts_nested_attributes_for :seminar_signup_field_customs, :allow_destroy => true + before_save do + module_app_key = "seminar" + add_module_app_member_ids = [] + remove_module_app_member_ids = [] + if self.reviewer_ids_changed? && (self.copy_id.nil? || !self.new_record?) + new_reviewer_ids = self.reviewer_ids.to_a - self.reviewer_ids_was.to_a + remove_reviewer_ids = self.reviewer_ids_was.to_a - self.reviewer_ids.to_a + new_reviewer_ids.each do |reviewer_id| + SeminarReview.create(:reviewer_id=>reviewer_id,:seminar_main=>self) + add_module_app_member_ids << reviewer_id + end + remove_reviewer_ids.each do |reviewer_id| + SeminarReview.where(:reviewer_id=>reviewer_id,:seminar_main=>self).destroy + remove_module_app_member_ids << reviewer_id + end + unassigned_seminar_signup_ids = self.seminar_signup_ids.map{|s| s.to_s} + seminar_reviews = self.seminar_reviews + unassigned_mode_1_seminar_signup_ids = unassigned_seminar_signup_ids.dup + seminar_reviews.each do |sr| + unassigned_mode_1_seminar_signup_ids = unassigned_mode_1_seminar_signup_ids - sr.get_all_seminar_signup_ids(1) + unassigned_seminar_signup_ids = unassigned_seminar_signup_ids - sr.all_seminar_signup_ids + end + self.unassigned_mode_1_seminar_signup_ids = unassigned_mode_1_seminar_signup_ids + self.unassigned_seminar_signup_ids = unassigned_seminar_signup_ids + end + if self.organizer_id_changed? + if self.organizer_id_was.present? + remove_module_app_member_ids << self.organizer_id_was + end + if self.organizer_id.present? + add_module_app_member_ids << self.organizer_id + end + end + remove_module_app_member_ids.delete(self.organizer_id) + self.reviewer_ids.each{|r| remove_module_app_member_ids.delete(r)} rescue nil + remove_module_app_member_ids.each do |m_id| + user = User.where(:member_profile_id=>m_id).first + begin + user.extra_link_module_app_keys.delete(module_app_key) + user.save + rescue + next + end + end + add_module_app_member_ids.each do |m_id| + user = User.where(:member_profile_id=>m_id).first + begin + user.extra_link_module_app_keys << module_app_key + user.save + rescue + next + end + end + if self.enable_summary_choice + (0...self.summary_chioices.count).to_a.each do |i| + seminar_session = self.seminar_sessions.where(:key=>i).first + if seminar_session.nil? + self.seminar_sessions << SeminarSession.new(:key=>i) + end + end + (self.summary_chioices.count...self.summary_chioices_was.to_a.count).to_a.each do |i| + self.seminar_sessions.where(:key=>i).destroy + end + end + end + before_create do + self.unassigned_seminar_signup_ids = [] + self.unassigned_mode_1_seminar_signup_ids = [] + if self.copy_id.present? + clone_new(true) + self.created_at = DateTime.now + self.updated_at = DateTime.now + end + end + after_create do + if self.copy_id.present? + self.seminar_signup_fields.each do |seminar_signup_field| + seminar_signup_field.seminar_signup_values.update_all(:key=>seminar_signup_field.key) + end + self.seminar_submission_fields.each do |seminar_submission_field| + seminar_submission_field.seminar_submission_values.update_all(:key=>seminar_submission_field.key) + end + current_reviewer_ids = self.reviewer_ids.to_a + self.seminar_reviews.where(:reviewer_id.nin=>current_reviewer_ids).destroy + module_app_key = "seminar" + current_reviewer_ids.each do |reviewer_id| + seminar_review = self.seminar_reviews.select{|sr| sr.reviewer_id == reviewer_id}.first + if seminar_review.nil? + self.seminar_reviews << SeminarReview.create(:reviewer_id=>reviewer_id,:seminar_main=>self) + user = User.where(:member_profile_id=>reviewer_id).first + if user.present? + user.extra_link_module_app_keys << module_app_key + user.save + end + end + end + end + end + after_initialize do + unless self.new_record? + save_flag = false + seminar_reviews = self.seminar_reviews + if seminar_reviews.present? + if self["reviewer_ids"].nil? + self["reviewer_ids"] = seminar_reviews.pluck(:reviewer_id).flatten.select{|s| !s.nil?}.to_a + save_flag = true + end + if seminar_reviews.count != 0 && self.review_start_date.nil? && self.review_end_date.nil? + review_start_date = seminar_reviews.pluck(:review_start_date).select{|t| t.present?}.first.to_datetime rescue nil + review_end_date = seminar_reviews.pluck(:review_end_date).select{|t| t.present?}.first.to_datetime rescue nil + self.review_start_date = review_start_date + self.review_end_date = review_end_date + if (self.review_start_date_changed? || self.review_end_date_changed?) + save_flag = true + end + end + end + if self.unassigned_seminar_signup_ids.nil? + self.unassigned_seminar_signup_ids = self.seminar_signup_ids.map{|s| s.to_s} + save_flag = true + end + if self.unassigned_mode_1_seminar_signup_ids.nil? + self.unassigned_mode_1_seminar_signup_ids = self.seminar_signup_ids.map{|s| s.to_s} + save_flag = true + end + unless self.last_serial_number_changed_from_default? + self.seminar_signups.sort_ordered.each do |ss| + if ss.serial_number.nil? + self.last_serial_number += 1 + ss.serial_number = self.last_serial_number + ss.save(:validate=>false) + save_flag = true + end + end + end + self.save(:validate=>false) if save_flag + end + end def self.time_range(date1 = null, date2 = null) if !date1.blank? @@ -84,5 +241,212 @@ class SeminarMain value = values.detect {|value| value.seminar_signup_field_id == field_id} rescue nil value ? value : nil end + def clone_new(clone_mode=false) + @records_all = {} + if clone_mode + clone_target = self.class.find(object.copy_id) rescue nil + else + clone_target = self + end + seminar,clone_target = clone_new_for_object(self,clone_target,clone_mode) + if clone_mode + copy_settings = SeminarSignupAdminSetting.where(:seminar_main_id=>clone_target.id.to_s).to_a + copy_settings.each do |setting| + new_setting = setting.dup + new_setting.seminar_main_id = seminar.id.to_s + new_setting.save + end + count_array = (0...self.seminar_sessions.to_a.count).to_a + count_array.each do |i| + seminar_session = self.seminar_sessions[i] + seminar_session.seminar_signup_ids = map_seminar_signup_ids(seminar_session.seminar_signup_ids) + end + self.unassigned_seminar_signup_ids = map_seminar_signup_ids(clone_target.unassigned_seminar_signup_ids) + self.unassigned_mode_1_seminar_signup_ids = map_seminar_signup_ids(clone_target.unassigned_mode_1_seminar_signup_ids) + need_change_seminar_signups = self.seminar_signups.where(:seminar_session_id.ne=>nil).to_a + count_array = (0...need_change_seminar_signups.count).to_a + count_array.each do |i| + seminar_signup = need_change_seminar_signups[i] + if seminar_signup.seminar_session_id.present? + seminar_signup.seminar_session_id = @records_all["seminar_session_ids"][seminar_signup.seminar_session_id] rescue nil + end + end + count_array = (0...self.seminar_reviews.to_a.count).to_a + change_fields = [:seminar_signup_ids, :remove_seminar_signup_ids, :default_seminar_signup_ids] + count_array.each do |i| + seminar_review = self.seminar_reviews[i] + change_fields.each do |f| + seminar_review.send("#{f}=",map_seminar_signup_ids( seminar_review.send(f))) + end + seminar_review.seminar_session_ids = seminar_review.seminar_session_ids.map{|seminar_session_id| @records_all["seminar_session_ids"][seminar_session_id] rescue nil}.select{|id| !id.nil?} + seminar_review.default_topics = seminar_review.default_topics.map do |default_topic| + fn,id = default_topic.split(".") + if fn == "seminar_signup_fields" + id = @records_all["seminar_signup_field_ids"][BSON::ObjectId(id)].to_s rescue nil + elsif fn == "seminar_submission_fields" + id = @records_all["seminar_submission_field_ids"][BSON::ObjectId(id)].to_s rescue nil + end + "#{fn}.#{id}" + end + end + end + seminar + end end +def map_seminar_signup_ids(old_seminar_signup_ids) + if @records_all["seminar_signup_ids"].present? + old_seminar_signup_ids.map{|seminar_signup_id| @records_all["seminar_signup_ids"][BSON::ObjectId(seminar_signup_id)].to_s rescue ""}.select{|t| t.present?} + else + [] + end +end +def clone_new_for_object(object,clone_target=nil,clone_mode=false) + if clone_mode + new_object = object + clone_target = object.class.find(object.copy_id) rescue nil if clone_target.nil? + else + clone_target = object if clone_target.nil? + new_object = object.dup + end + return if self.except_clone_relations.to_s.include?(new_object.class.to_s.underscore) + @records_all["#{new_object.class.to_s.underscore.singularize}_ids"] = {} if @records_all["#{new_object.class.to_s.underscore.singularize}_ids"].nil? + begin + @records_all["#{new_object.class.to_s.underscore.singularize}_ids"][clone_target.id] = object.id + rescue + nil + end + if !clone_target.nil? && !new_object.nil? + initialize_fields = ["uid","created_at","updated_at"] + initialize_fields.each do |f| + new_object.send("#{f}=",nil) if new_object.fields.keys.include?(f) + end + relations_fields = clone_target.relations.except("impressions").keys + all_fields = clone_target.fields.keys - relations_fields + all_fields = all_fields - relations_fields.map{|k| "#{k}_id"} + all_fields = all_fields - relations_fields.map{|k| "#{k.singularize}_ids"} + new_object_class_name = new_object.class.to_s.underscore + relations_fields = clone_target.relations.except("impressions").keys + unsort_relation_keys = clone_target.relations.keys + unless @parent_level + fields_to_delete = [new_object_class_name] + tmp_relations_fields = [new_object_class_name] + while relations_fields.count > 0 + tmp_singularize_relations_fields = tmp_relations_fields.map{|f| f.singularize} + approve_append = nil + relations_fields.each do |k| + belongs_to_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro == :belongs_to}.keys + has_many_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro == :has_many}.keys + if (belongs_to_class - tmp_singularize_relations_fields).count == 0 + other_has_many_class = (has_many_class - unsort_relation_keys) + if other_has_many_class.count == 0 + tmp_relations_fields << k + else + result = other_has_many_class.map do |k| + belongs_to_class = k.classify.constantize.relations.select{|kk,v| v.macro == :belongs_to}.keys + has_many_class = k.classify.constantize.relations.select{|kk,v| v.macro == :has_many}.keys + if (belongs_to_class - tmp_singularize_relations_fields).count == 0 + true + else + fields_to_delete = fields_to_delete.concat(belongs_to_class) + tmp_relations_fields.concat(belongs_to_class) + false + end + end + if result.select{|t| !t}.count == 0 + if (fields_to_delete.map{|f| f.pluralize} - tmp_relations_fields).count == 0 + tmp_relations_fields << k + elsif clone_target.relations[k].class_name.constantize.fields.keys.include?("key") + tmp_relations_fields << k + elsif (clone_target.relations[k].class_name.constantize.relations.keys.map{|f| f.singularize} & fields_to_delete).count != 0 + approve_append = k + end + end + end + elsif !unsort_relation_keys.include?(clone_target.relations[k].class_name.underscore) && !unsort_relation_keys.include?(clone_target.relations[k].class_name.underscore.pluralize) + tmp_relations_fields << k + end + end + tmp_relations_fields << approve_append if approve_append.present? + approve_append = nil + relations_fields = relations_fields - tmp_relations_fields + end + relations_fields = tmp_relations_fields + fields_to_delete.each{|f| relations_fields.delete(f)} + @clone_mode = clone_mode + end + @parent_level = true + if clone_mode + all_fields.each do |f| + next if f == "uid" + unless new_object.send("#{f}_changed?") && new_object.send("#{f}_changed_from_default?") + new_object.send("#{f}=",clone_target.send(f)) + end + end + end + relations_fields.each do |f| + no_dup_flag = false + if clone_target.relations[f].macro == :belongs_to + no_dup_flag = new_object.send(f).present? + elsif clone_target.relations[f].macro == :has_many + no_dup_flag = new_object.send(f).to_a.count != 0 + end + if clone_target.relations[f].macro == :belongs_to || clone_target.relations[f].class_name == "MemberProfile" + if @records_all["#{f}_ids"].nil? + new_object.send("#{f}_id=",clone_target.send("#{f}_id")) + else + new_object.send("#{f}_id=",(@records_all["#{f}_ids"][clone_target.send("#{f}_id")])) + end + elsif clone_target.relations[f].macro == :has_many + next if self.except_clone_relations.to_s.include?(f) + clone_relations = [] + need_clone_relations = clone_target.send(f).asc(:_id).to_a + file_flag = false + need_clone_relations.each_with_index do |r,i| + clone_relation = new_object.send(f)[i] + clone_relation = r.dup if clone_relation.nil? + initialize_fields.each do |f| + clone_relation.send("#{f}=",nil) if clone_relation.fields.keys.include?(f) + end + check_fields = clone_relation.fields.except(initialize_fields) + check_fields.keys.each do |f| + if (clone_relation.send(f).class.to_s.match(/uploader/i) rescue false) + if clone_relation[f].blank? && (clone_relation.send(f).file.nil? rescue true) + clone_relation[f] = r[f] + source_filepath = r.send(f).file.file + if @clone_mode + dest_filepath = clone_relation.send(f).file.file + FileUtils.mkdir_p(File.dirname(dest_filepath)) + FileUtils.cp(source_filepath,dest_filepath) + end + elsif (clone_relation.send(f).file rescue nil) + clone_relation[f] = File.basename(clone_relation.send(f).file.file.to_s) + end + file_flag = true + end + end + clone_relations << clone_relation + end + if !no_dup_flag || (no_dup_flag && file_flag) + new_object_relations = new_object.send(f).to_a + if new_object_relations.count != 0 + if clone_relations.count > new_object_relations.count + clone_relations = clone_relations[0...new_object_relations.count] + else + clone_relations = clone_relations.concat(new_object.send(f)[clone_relations.count...new_object_relations.count]) + end + new_object.send("#{f}=",clone_relations) + else + new_object.send("#{f}=",clone_relations) + end + end + count_array = (0...new_object.send(f).to_a.count).to_a + count_array.each do |i| + clone_new_for_object(new_object.send(f)[i],need_clone_relations[i],true) + end + end + end + new_object.copy_id = clone_target.id if new_object.fields.keys.include?("copy_id") + return new_object, clone_target + end +end \ No newline at end of file diff --git a/app/models/seminar_review.rb b/app/models/seminar_review.rb index 8ed7aee..1f98da5 100644 --- a/app/models/seminar_review.rb +++ b/app/models/seminar_review.rb @@ -5,8 +5,90 @@ class SeminarReview include Mongoid::Document include Mongoid::Timestamps - field :review_start_date, :type => Date, :default => Time.now - field :review_end_date, :type => Date, :default => Time.now + field :review_start_date, :type => Date, :default => Time.now #Already move to seminar_main + field :review_end_date, :type => Date, :default => Time.now #Already move to seminar_main field :reviewer_id + field :seminar_signup_ids, :type => Array, :default => [] + field :remove_seminar_signup_ids, :type => Array, :default => [] + field :default_seminar_signup_ids, :type => Array, :default => [] + field :default_topics, :type => Array, :default => [] + field :default_topics_values, :type => Array, :default => [] + field :final_session + field :session_ids + field :seminar_session_ids belongs_to :seminar_main + after_initialize do + unless self.new_record? + save_flag = false + if (self.reviewer_id.class == Array rescue false) + reviewer_ids = self.reviewer_id[1..-1] + reviewer_ids.each do |reviewer_id| + self.class.create(:reviewer_id=>reviewer_id,:seminar_main=>self.seminar_main) + end + self.reviewer_id = self.reviewer_id.first + save_flag = true + end + if (self.session_ids.nil? rescue true) + session_ids = [] + self.default_topics.each_with_index do |t,i| + next if t != "seminar_signup_contributes.description" + session_ids << self.default_topics_values[i] + end + session_ids = session_ids.flatten.map{|i| i.to_i} + self.session_ids = session_ids + save_flag = true + end + if self.seminar_session_ids.nil? && self.session_ids.class == Array + self.seminar_session_ids = self.seminar_main.seminar_sessions.where(:key.in=>self.session_ids).pluck(:id) rescue nil + save_flag = true + end + self.save(:validate=>false) if save_flag + end + end + before_save do + default_seminar_signup_ids = [] + self.session_ids = [] + self.default_topics.each_with_index do |topic,i| + fn,id = (topic.split(".") rescue []) + next if fn.nil? + if fn == "seminar_signup_fields" + default_seminar_signup_ids += SeminarSignupValue.where(:seminar_signup_field_id=>id,:val.in=>self.default_topics_values[i].to_a).pluck(:seminar_signup_id) + elsif fn == "seminar_submission_fields" + seminar_signup_contribute_ids = SeminarSubmissionValue.where(:seminar_submission_field_id=>id,:val.in=>self.default_topics_values[i].to_a).pluck(:seminar_signup_contribute) + default_seminar_signup_ids += SeminarSignupContribute.where(:id.in=>seminar_signup_contribute_ids).pluck(:seminar_signup_id) + elsif fn == "seminar_signup_contributes" + seminar_signup_ids_from_contribute = SeminarSignupContribute.where(:description.in=>self.default_topics_values[i].to_a).pluck(:seminar_signup_id) + seminar_signup_ids_from_contribute = seminar_signup_ids_from_contribute & (self.seminar_main.seminar_signups.pluck(:id) rescue []) + default_seminar_signup_ids += seminar_signup_ids_from_contribute + self.session_ids = self.session_ids.concat(self.default_topics_values[i].map{|v| v.to_i}) + end + end + self.seminar_session_ids = self.seminar_main.seminar_sessions.where(:key.in=>self.session_ids.to_a).pluck(:id) rescue [] + default_seminar_signup_ids.uniq! + default_seminar_signup_ids = default_seminar_signup_ids.map{|s| s.to_s} + self.default_seminar_signup_ids = default_seminar_signup_ids + end + def review + MemberProfile.find(self.reviewer_id) rescue nil + end + def get_all_seminar_signup_ids(mode = nil) + if (self.default_topics.include?("seminar_signup_contributes.description") && self.seminar_main.assign_mode == 1) || mode == 1 + final_assign_signup_ids = SeminarSession.where(:id.in=>self.seminar_session_ids).pluck(:seminar_signup_ids).flatten.map{|id| id.to_s} rescue [] + result = final_assign_signup_ids + self.seminar_signup_ids - self.remove_seminar_signup_ids + result = result.uniq + else + result = all_seminar_signup_ids + end + result + end + def all_seminar_signup_ids + result = self.seminar_signup_ids - self.remove_seminar_signup_ids + self.default_seminar_signup_ids + result.uniq + end + def append_default_signup_id(signup_id) + sid = signup_id.to_s + unless self.default_seminar_signup_ids.include?(sid) + self.default_seminar_signup_ids << sid + end + end end diff --git a/app/models/seminar_session.rb b/app/models/seminar_session.rb new file mode 100644 index 0000000..c31521e --- /dev/null +++ b/app/models/seminar_session.rb @@ -0,0 +1,13 @@ +# encoding: utf-8 +class SeminarSession + + include Mongoid::Document + include Mongoid::Timestamps + + field :key + belongs_to :seminar_main + field :seminar_signup_ids, :type => Array, :default => [] + def seminar_signups + SeminarSignup.where(:id.in=>seminar_signup_ids) + end +end diff --git a/app/models/seminar_signup.rb b/app/models/seminar_signup.rb index 9f40877..5bfa754 100644 --- a/app/models/seminar_signup.rb +++ b/app/models/seminar_signup.rb @@ -14,14 +14,54 @@ class SeminarSignup field :address, localize: true field :password field :note, localize: true - + field :serial_number + field :final_session belongs_to :seminar_main - - has_many :seminar_signup_values - has_many :seminar_signup_contributes + field :seminar_session_id + has_many :seminar_signup_values, :autosave => true, :dependent => :destroy + has_many :seminar_signup_contributes, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :seminar_signup_values, allow_destroy: true accepts_nested_attributes_for :seminar_signup_contributes, allow_destroy: true + scope :sort_ordered, ->{ order_by(:created_at=>1) } - + before_create do + unit = self.unit_translations.values.select{|v| v.present?}.first + self.unit_translations = I18n.available_locales.map{|l| [l.to_s,unit]}.to_h + if self.serial_number.nil? + s = SeminarMain.find(self.seminar_main) + s.last_serial_number += 1 + self.serial_number = s.last_serial_number + s.save(:validate=>false) + end + end + after_destroy do + seminar_main = self.seminar_main + if seminar_main.present? + seminar_reviews = seminar_main.seminar_reviews + id = self.id.to_s + seminar_reviews.each do |sr| + if sr.all_seminar_signup_ids.include?(id) + sr.seminar_signup_ids.delete(id) + sr.remove_seminar_signup_ids.delete(id) + sr.default_seminar_signup_ids.delete(id) + sr.save + end + end + if seminar_main.unassigned_seminar_signup_ids.delete(id) + seminar_main.save + end + end + seminar_session = SeminarSession.where(:id=>self.seminar_session_id).first + if seminar_session + seminar_session.seminar_signup_ids.delete(self.id.to_s) + seminar_session.save + end + end + def display_serial_number + display_format_string(self.serial_number,4) + end + def display_format_string(num, str_length) + return format("%0#{str_length}d", num) + end end diff --git a/app/models/seminar_signup_admin_setting.rb b/app/models/seminar_signup_admin_setting.rb new file mode 100644 index 0000000..1d54992 --- /dev/null +++ b/app/models/seminar_signup_admin_setting.rb @@ -0,0 +1,8 @@ +# encoding: utf-8 +class SeminarSignupAdminSetting + include Mongoid::Document + include Mongoid::Timestamps + field :display_field , type: Array , default: [] + field :seminar_main_id + field :page +end \ No newline at end of file diff --git a/app/models/seminar_signup_field_custom.rb b/app/models/seminar_signup_field_custom.rb index ac322db..658cc5e 100644 --- a/app/models/seminar_signup_field_custom.rb +++ b/app/models/seminar_signup_field_custom.rb @@ -5,4 +5,7 @@ class SeminarSignupFieldCustom field :seminar_signup_field_id field :hidden, type: Boolean, default: true belongs_to :seminar_main + def seminar_signup_field + SeminarSignupField.find(self.seminar_signup_field_id) rescue nil + end end diff --git a/app/models/seminar_signup_value.rb b/app/models/seminar_signup_value.rb index f477f67..bc36467 100644 --- a/app/models/seminar_signup_value.rb +++ b/app/models/seminar_signup_value.rb @@ -46,25 +46,30 @@ class SeminarSignupValue end def get_field_value - if (self.seminar_signup_field.markup.eql?("text_field") || self.seminar_signup_field.markup.eql?("text_area")) + seminar_signup_field = self.seminar_signup_field + if (seminar_signup_field.markup.eql?("text_field") || seminar_signup_field.markup.eql?("text_area")) + if self.value.class == String + field_value = self.value + else field_value = self.value[I18n.locale] - elsif (self.seminar_signup_field.markup.eql?("select") || self.seminar_signup_field.markup.eql?("radio_button")) - field_value = self.seminar_signup_field.markup_value["#{self.value}"][I18n.locale] rescue nil - elsif self.seminar_signup_field.markup.eql?("address") - field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ') - elsif self.seminar_signup_field.markup.eql?("date") - case self.seminar_signup_field.typeC['format'] - when 'format1' - field_value = self.value.to_date.strftime("%Y/%m/%d") - when 'format2' - field_value = self.value.to_date.strftime("%Y/%m/%d") - when 'format3' - field_value = self.value.to_date.strftime("%Y/%m") - when 'format4' - field_value = self.value.to_date.strftime("%Y") - end - elsif self.seminar_signup_field.markup.eql?("checkbox") - field_value = self.value.map {|v| self.seminar_signup_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil + end + elsif (seminar_signup_field.markup.eql?("select") || seminar_signup_field.markup.eql?("radio_button")) + field_value = seminar_signup_field.markup_value["#{self.value}"][I18n.locale] rescue nil + elsif seminar_signup_field.markup.eql?("address") + field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ') + elsif seminar_signup_field.markup.eql?("date") + case seminar_signup_field.typeC['format'] + when 'format1' + field_value = self.value.to_date.strftime("%Y/%m/%d") + when 'format2' + field_value = self.value.to_date.strftime("%Y/%m/%d") + when 'format3' + field_value = self.value.to_date.strftime("%Y/%m") + when 'format4' + field_value = self.value.to_date.strftime("%Y") + end + elsif seminar_signup_field.markup.eql?("checkbox") + field_value = self.value.map {|v| seminar_signup_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil end field_value = (field_value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{field_value}" : field_value @@ -72,15 +77,15 @@ class SeminarSignupValue if !field_value.blank? { - "key" => self.seminar_signup_field.key, - "title" => self.seminar_signup_field.title, + "key" => seminar_signup_field.key, + "title" => seminar_signup_field.title, "value" => field_value, "val" => field_value = self.value } else { - "key" => self.seminar_signup_field.key, - "title" => self.seminar_signup_field.title, + "key" => seminar_signup_field.key, + "title" => seminar_signup_field.title, "value" => "", "val" => field_value = self.value } @@ -88,29 +93,30 @@ class SeminarSignupValue end def get_value_by_locale(locale,add_more_index=nil) - case self.seminar_signup_field.markup + seminar_signup_field = self.seminar_signup_field + case seminar_signup_field.markup when "text_field" - case self.seminar_signup_field.add_more - when true - if self.seminar_signup_field.locale - add_more_index.nil? ? self.value.collect{|t| t[locale.to_s]}.join(",") : self.value(add_more_index)[locale] - else - add_more_index.nil? ? self.value.join(",") : self.value(add_more_index) - end - - when false - self.seminar_signup_field.locale ? self[locale.to_s] : self.value + case seminar_signup_field.add_more + when true + if seminar_signup_field.locale + add_more_index.nil? ? self.value.collect{|t| t[locale.to_s]}.join(",") : self.value(add_more_index)[locale] + else + add_more_index.nil? ? self.value.join(",") : self.value(add_more_index) + end + + when false + seminar_signup_field.locale ? self[locale.to_s] : self.value end when "select" - markup_values = self.seminar_signup_field.self_defined_markup_options? ? self.seminar_signup_field.markup_value : self.seminar_signup_field.markup_value + markup_values = seminar_signup_field.self_defined_markup_options? ? seminar_signup_field.markup_value : self.seminar_signup_field.markup_value markup_values[self.value][locale.to_s] rescue 'NoData' when "text_area" - self.seminar_signup_field.locale ? self[locale.to_s] : self.value + seminar_signup_field.locale ? self[locale.to_s] : self.value when "date" - if self.seminar_signup_field.date_is_range? + if seminar_signup_field.date_is_range? get_date_by_format(:from) + ' ~ ' + get_date_by_format(:to) # self.value["from"] + ' ~ ' + self.value["to"] else @@ -122,17 +128,17 @@ class SeminarSignupValue self.value[locale.to_s] when "radio_button" - markup_values = self.seminar_signup_field.markup_value + markup_values = seminar_signup_field.markup_value markup_values[self.value][locale.to_s] when "checkbox" - markup_values = self.seminar_signup_field.markup_value + markup_values = seminar_signup_field.markup_value self.value.collect{|key| markup_values["#{key}"][I18n.locale]}.join(",") when "date_durnation" self.value else - self.seminar_signup_field.locale ? self[locale.to_s] : self.value + seminar_signup_field.locale ? self[locale.to_s] : self.value end end @@ -174,18 +180,19 @@ def unset_all_lang_values end def data_proc + seminar_signup_field = self.seminar_signup_field unless self[:temp_data].nil? - case self.seminar_signup_field.markup + case seminar_signup_field.markup when "address" self["val"] = self["temp_data"] when 'text_field','text_area' - if self.seminar_signup_field.add_more + if seminar_signup_field.add_more self["val"] = self["temp_data"] else # if not add_more - if self.seminar_signup_field.can_muti_lang_input? + if seminar_signup_field.can_muti_lang_input? self[:temp_data].each do |key,val| self[key] = val - end if(!self.seminar_signup_field.get_data[:cross_lang]) + end if(!seminar_signup_field.get_data[:cross_lang]) else self["val"] = self[:temp_data] end @@ -202,7 +209,14 @@ def unset_all_lang_values end #of data_proc def check_key - self.key = self.seminar_signup_field.key + if self.seminar_signup_field_id.present? && self.seminar_signup_field.nil? + begin + self.seminar_signup_field = SeminarSignupField.find(self.seminar_signup_field_id) + rescue + nil + end + end + self.key = self.seminar_signup_field.key rescue nil end def method_missing(*field) diff --git a/app/models/seminar_submission_value.rb b/app/models/seminar_submission_value.rb index b04aea8..5119fce 100644 --- a/app/models/seminar_submission_value.rb +++ b/app/models/seminar_submission_value.rb @@ -45,25 +45,30 @@ class SeminarSubmissionValue end def get_field_value - if (self.seminar_submission_field.markup.eql?("text_field") || self.seminar_submission_field.markup.eql?("text_area")) + seminar_submission_field = self.seminar_submission_field + if (seminar_submission_field.markup.eql?("text_field") || seminar_submission_field.markup.eql?("text_area")) + if self.value.class == String + field_value = self.value + else field_value = self.value[I18n.locale] - elsif (self.seminar_submission_field.markup.eql?("select") || self.seminar_submission_field.markup.eql?("radio_button")) - field_value = self.seminar_submission_field.markup_value["#{self.value}"][I18n.locale] rescue nil - elsif self.seminar_submission_field.markup.eql?("address") - field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ') - elsif self.seminar_submission_field.markup.eql?("date") - case self.seminar_submission_field.typeC['format'] - when 'format1' - field_value = self.value.to_date.strftime("%Y/%m/%d") - when 'format2' - field_value = self.value.to_date.strftime("%Y/%m/%d") - when 'format3' - field_value = self.value.to_date.strftime("%Y/%m") - when 'format4' - field_value = self.value.to_date.strftime("%Y") - end - elsif self.seminar_submission_field.markup.eql?("checkbox") - field_value = self.value.map {|v| self.seminar_submission_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil + end + elsif (seminar_submission_field.markup.eql?("select") || seminar_submission_field.markup.eql?("radio_button")) + field_value = seminar_submission_field.markup_value["#{self.value}"][I18n.locale] rescue nil + elsif seminar_submission_field.markup.eql?("address") + field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ') + elsif seminar_submission_field.markup.eql?("date") + case seminar_submission_field.typeC['format'] + when 'format1' + field_value = self.value.to_date.strftime("%Y/%m/%d") + when 'format2' + field_value = self.value.to_date.strftime("%Y/%m/%d") + when 'format3' + field_value = self.value.to_date.strftime("%Y/%m") + when 'format4' + field_value = self.value.to_date.strftime("%Y") + end + elsif seminar_submission_field.markup.eql?("checkbox") + field_value = self.value.map {|v| seminar_submission_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil end field_value = (field_value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{field_value}" : field_value @@ -71,15 +76,15 @@ class SeminarSubmissionValue if !field_value.blank? { - "key" => self.seminar_submission_field.key, - "title" => self.seminar_submission_field.title, + "key" => seminar_submission_field.key, + "title" => seminar_submission_field.title, "value" => field_value, "val" => field_value = self.value } else { - "key" => self.seminar_submission_field.key, - "title" => self.seminar_submission_field.title, + "key" => seminar_submission_field.key, + "title" => seminar_submission_field.title, "value" => "", "val" => field_value = self.value } @@ -87,29 +92,30 @@ class SeminarSubmissionValue end def get_value_by_locale(locale,add_more_index=nil) - case self.seminar_submission_field.markup + seminar_submission_field = self.seminar_submission_field + case seminar_submission_field.markup when "text_field" - case self.seminar_submission_field.add_more - when true - if self.seminar_submission_field.locale - add_more_index.nil? ? self.value.collect{|t| t[locale.to_s]}.join(",") : self.value(add_more_index)[locale] - else - add_more_index.nil? ? self.value.join(",") : self.value(add_more_index) - end - - when false - self.seminar_submission_field.locale ? self[locale.to_s] : self.value + case seminar_submission_field.add_more + when true + if seminar_submission_field.locale + add_more_index.nil? ? self.value.collect{|t| t[locale.to_s]}.join(",") : self.value(add_more_index)[locale] + else + add_more_index.nil? ? self.value.join(",") : self.value(add_more_index) + end + + when false + seminar_submission_field.locale ? self[locale.to_s] : self.value end when "select" - markup_values = self.seminar_submission_field.self_defined_markup_options? ? self.seminar_submission_field.markup_value : self.seminar_submission_field.markup_value + markup_values = seminar_submission_field.self_defined_markup_options? ? seminar_submission_field.markup_value : self.seminar_submission_field.markup_value markup_values[self.value][locale.to_s] rescue 'NoData' when "text_area" - self.seminar_submission_field.locale ? self[locale.to_s] : self.value + seminar_submission_field.locale ? self[locale.to_s] : self.value when "date" - if self.seminar_submission_field.date_is_range? + if seminar_submission_field.date_is_range? get_date_by_format(:from) + ' ~ ' + get_date_by_format(:to) # self.value["from"] + ' ~ ' + self.value["to"] else @@ -121,17 +127,17 @@ class SeminarSubmissionValue self.value[locale.to_s] when "radio_button" - markup_values = self.seminar_submission_field.markup_value + markup_values = seminar_submission_field.markup_value markup_values[self.value][locale.to_s] when "checkbox" - markup_values = self.seminar_submission_field.markup_value + markup_values = seminar_submission_field.markup_value self.value.collect{|key| markup_values["#{key}"][I18n.locale]}.join(",") when "date_durnation" self.value else - self.seminar_submission_field.locale ? self[locale.to_s] : self.value + seminar_submission_field.locale ? self[locale.to_s] : self.value end end @@ -167,22 +173,23 @@ class SeminarSubmissionValue protected def unset_all_lang_values - VALID_LOCALES.each{|t| self.unset t} - end + VALID_LOCALES.each{|t| self.unset t} +end def data_proc + seminar_submission_field = self.seminar_submission_field unless self[:temp_data].nil? - case self.seminar_submission_field.markup + case seminar_submission_field.markup when "address" self["val"] = self["temp_data"] when 'text_field','text_area' - if self.seminar_submission_field.add_more + if seminar_submission_field.add_more self["val"] = self["temp_data"] else # if not add_more - if self.seminar_submission_field.can_muti_lang_input? + if seminar_submission_field.can_muti_lang_input? self[:temp_data].each do |key,val| self[key] = val - end if(!self.seminar_submission_field.get_data[:cross_lang]) + end if(!seminar_submission_field.get_data[:cross_lang]) else self["val"] = self[:temp_data] end @@ -199,7 +206,14 @@ def unset_all_lang_values end #of data_proc def check_key - self.key = self.seminar_submission_field.key + if self.seminar_submission_field_id.present? && self.seminar_submission_field.nil? + begin + self.seminar_submission_field = SeminarSubmissionField.find(self.seminar_submission_field_id) + rescue + nil + end + end + self.key = self.seminar_submission_field.key rescue nil end def method_missing(*field) diff --git a/app/models/seminar_user.rb b/app/models/seminar_user.rb new file mode 100644 index 0000000..d130630 --- /dev/null +++ b/app/models/seminar_user.rb @@ -0,0 +1,13 @@ +class SeminarUser + include Mongoid::Document + include Mongoid::Timestamps + field :user_name + field :password + belongs_to :seminar_main + # belongs_to :user + # before_save do + # if self.new_record? + # self.user = User.find() + # end + # end +end \ No newline at end of file diff --git a/app/views/admin/seminars/_form.html.erb b/app/views/admin/seminars/_form.html.erb index 378188f..dcf6be6 100644 --- a/app/views/admin/seminars/_form.html.erb +++ b/app/views/admin/seminars/_form.html.erb @@ -1,5 +1,6 @@ <% multi_helper = Admin::SeminarsHelper::MultiLang + new_record = @seminar.new_record? && @seminar.copy_id.nil? %> <% content_for :page_specific_css do %> <%= stylesheet_link_tag "lib/main-forms" %> @@ -54,17 +55,30 @@
- <%= f.datetime_picker :seminar_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @seminar.new_record? %> + <%= f.datetime_picker :seminar_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
- <%= f.datetime_picker :seminar_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @seminar.new_record? %> + <%= f.datetime_picker :seminar_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
- +
+ +
+ <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'seminar_main[organizer_id]', email_members:Array(f.object.organizer), index: "1", select_name: 'organizer_id'} %> +
+
+ <% if params[:action] == "copy" %> +
+ +
+ <%= check_box_tag("clone_signups",true) %> +
+
+ <% end %> @@ -87,14 +101,14 @@
- <%= f.datetime_picker :signup_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @seminar.new_record? %> + <%= f.datetime_picker :signup_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
- <%= f.datetime_picker :signup_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @seminar.new_record? %> + <%= f.datetime_picker :signup_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
@@ -102,14 +116,14 @@
- <%= f.datetime_picker :contribute_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @seminar.new_record? %> + <%= f.datetime_picker :contribute_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
- <%= f.datetime_picker :contribute_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @seminar.new_record? %> + <%= f.datetime_picker :contribute_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
@@ -131,30 +145,28 @@
- <%= f.fields_for :seminar_reviews,@review do |seminar_reviews_form| %>
<% if !@member.nil? %> - <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'seminar_main[seminar_reviews_attributes][0][reviewer_id][]', email_members:@member} %> + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'seminar_main[reviewer_ids][]', email_members:@member, index: "2", select_name: 'reviewer_ids'} %> <% else %> - <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'seminar_main[seminar_reviews_attributes][0][reviewer_id][]', email_members:[]} %> + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'seminar_main[reviewer_ids][]', email_members:[], index: "2", select_name: 'reviewer_ids'} %> <% end %>
-
+
- <%= seminar_reviews_form.datetime_picker :review_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @seminar.new_record? %> + <%= f.datetime_picker :review_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
-
- -
- <%= seminar_reviews_form.datetime_picker :review_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @seminar.new_record? %> -
-
- <% end %> +
+ +
+ <%= f.datetime_picker :review_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %> +
+
@@ -230,6 +242,27 @@ <% end %> +
+
<%=t('seminar_signup.enable_summary_choice')%>
+
<%= f.check_box :enable_summary_choice %>
+
+ <% hidden_style = (f.object.enable_summary_choice) ? "" : "style=display:none" %> +
> +
<%=t('seminar_signup.summary_choice_type')%>
+
<%= f.select :summary_chioice_type,f.object.class::ChoiceTypes.map{|c| [t("seminar_signup.#{c}"),c]} %>
+
+
> +
<%=t('seminar_signup.choices')%>
+
+ <% f.object.summary_chioices.each do |choice| %> +
+ X + <%= text_field_tag "seminar_main[summary_chioices][]",choice, {:id=>nil} %> +
+ <% end %> + +
+
@@ -248,7 +281,11 @@ <%= check_box_tag("seminar_main[seminar_signup_field_customs][#{custom_index}][hidden]", true ,attr_custom.hidden) %> - + <% if !attr_custom.new_record? %> + + <% elsif f.object.copy_id.present? %> + + <% end %> <% end %> @@ -433,7 +470,7 @@

- <%= hidden_field_tag 'seminar_file_field_count', @seminar.seminar_files.count %> + <%= hidden_field_tag 'seminar_file_field_count', @seminar.seminar_files.to_a.count %> <%= t(:add) %>

@@ -491,7 +528,26 @@ $(this).parents('.start-line').hide(); } }); - + $(document).on('click','#add_summary_choice',function(){ + $(this).before("
X
") + }) + $(document).on('click','.remove_btn',function(){ + $(this).parent().remove(); + }) + $("input[name=\"seminar_main[enable_summary_choice]\"]").change(function(){ + if($(this).prop("checked")){ + $(".summary_choice_block").css("display",""); + }else{ + $(".summary_choice_block").css("display","none"); + } + }) }); -<% end %> \ No newline at end of file +<% end %> + \ No newline at end of file diff --git a/app/views/admin/seminars/_form_file.html.erb b/app/views/admin/seminars/_form_file.html.erb index a1ab19a..6d21d14 100644 --- a/app/views/admin/seminars/_form_file.html.erb +++ b/app/views/admin/seminars/_form_file.html.erb @@ -1,11 +1,24 @@ -<% if form_file.new_record? %> +<% new_record = form_file.new_record? && form_file["file"].blank? %> +<% if new_record %>
<% else %>
- <% if form_file.file.blank? %> + <% if form_file.file.blank? && form_file["file"].blank? %> <%= t(:no_file) %> <% else %> - <%= link_to content_tag(:i) + form_file.file_identifier, form_file.file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %> + <% belongs_to_record = form_file.relations.select{|k,v| v.macro == :belongs_to}.first[0] rescue nil %> + <% url = form_file.file.url %> + <% if belongs_to_record.present? && (form_file.send(belongs_to_record).copy_id.present? rescue false) %> + <% begin + belongs_to_record = belongs_to_record.classify.constantize.find(form_file.send(belongs_to_record).copy_id) + target_form_files = belongs_to_record.send(form_file.class.to_s.underscore+"s") + target_form_file = target_form_files.select{|ff| ff["file"] == form_file["file"]}.first + url = target_form_file.file.url + rescue + nil + end %> + <% end %> + <%= link_to content_tag(:i) + form_file.file_identifier, url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %> <% end %> <% end %>
@@ -16,7 +29,7 @@
- <%= (form_file.new_record? || form_file.file.blank?) ? t(:select_file) : t(:change_file) %> + <%= (new_record) ? t(:select_file) : t(:change_file) %>
@@ -40,13 +53,13 @@ <% end %> - <% if form_file.new_record? %> + <% if new_record %> <% else %> - <%= f.hidden_field :id %> + <%= f.hidden_field :id unless form_file.new_record?%> <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> diff --git a/app/views/admin/seminars/_get_display_fields.html.erb b/app/views/admin/seminars/_get_display_fields.html.erb new file mode 100644 index 0000000..f66e307 --- /dev/null +++ b/app/views/admin/seminars/_get_display_fields.html.erb @@ -0,0 +1,126 @@ +<% @field_names = [] %> +<% @field_name_translations = [] %> +<% default_hidden = [] %> +<% + default_seminar_signup_fields = ["serial_number"] + default_seminar_signup_fields.each do |f| + @field_names << "seminar_signup.#{f}" + @field_name_translations << t("seminar_signup.#{f}") + end +%> +<% if @seminar.present? %> + <% if @seminar.seminar_signup_field_sets.count != 0 %> + <% @seminar.seminar_signup_field_sets.each do |field_set| %> + <% default_hidden << "seminar_signup_field_set.#{field_set.field_name}" if (field_set.hidden) %> + <% @field_names << "seminar_signup_field_set.#{field_set.field_name}" %> + <% @field_name_translations << field_set.name[I18n.locale] %> + <% end %> + <% else %> + <% ['seminar_signup.name','seminar_signup.tel','seminar.registration_status'].each do |th| %> + <% @field_names << "default.#{th}" %> + <% @field_name_translations << t(th) %> + <% end %> + <% end %> + <% if @seminar.seminar_signup_field_customs.count != 0 %> + <% @seminar.seminar_signup_field_customs.each do |field_set| %> + <% s = SeminarSignupField.where(id:field_set.seminar_signup_field_id).first %> + <% title = s.title rescue '' %> + <% next if title.blank? %> + <% next if s.key.blank? %> + <% default_hidden << "seminar_signup_field_custom.#{s.key}" if (field_set.hidden) %> + <% @field_names << "seminar_signup_field_custom.#{s.key}" %> + <% @field_name_translations << (title)%> + <% end %> + <% end %> + <% @seminar.seminar_signup_fields.each do |s| %> + <% default_hidden << "seminar_signup_fields.#{s.key}" %> + <% @field_names << "seminar_signup_fields.#{s.key}" %> + <% @field_name_translations << s.title %> + <% end %> + <% if @seminar.seminar_submission_field_sets.count != 0 %> + <% show1 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0].hidden) + show2 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0].hidden) + show3 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0].hidden) + %> + <% else %> + <% show1 = true + show2 = true + show3 = true + %> + <% end %> + <% default_hidden << "seminar_signup_contributes.title" if !show1 %> + <% @field_names << 'seminar_signup_contributes.title' %> + <% @field_name_translations << t('seminar_signup.title') %> + + <% default_hidden << "seminar_signup_contributes.file" if !show2 %> + <% @field_names << 'seminar_signup_contributes.file' %> + <% @field_name_translations << t('seminar_signup.file') %> + + <% default_hidden << "seminar_signup_contributes.description" if !show3 %> + <% @field_names << 'seminar_signup_contributes.description' %> + <% @field_name_translations << t('seminar_signup.description') %> + <% @seminar.seminar_submission_fields.each do |s| %> + <% @field_names << "seminar_submission_fields.#{s.key}" %> + <% @field_name_translations << s.title %> + <% end %> + <% @display_field = @seminar_signup_admin_setting.display_field %> + <% if @display_field.blank? + @display_field = @field_names - default_hidden + end %> +<% else %> + <% @field_names = [] %> + <% @field_name_translations = [] %> + <% default_show = [] %> + <% seminar_signup_field_sets = SeminarSignupFieldSet.all.uniq{|s| s.field_name} %> + <% if seminar_signup_field_sets.count != 0 %> + <% seminar_signup_field_sets.each do |field_set| %> + <% default_show << "seminar_signup_field_set.#{field_set.field_name}" if !(field_set.hidden) %> + <% @field_names << "seminar_signup_field_set.#{field_set.field_name}" %> + <% @field_name_translations << field_set.name[I18n.locale] %> + <% end %> + <% else %> + <% ['seminar_signup.name','seminar_signup.tel','seminar.registration_status'].each do |th| %> + <% @field_names << "default.#{th}" %> + <% @field_name_translations << t(th) %> + <% end %> + <% end %> + <% seminar_signup_field_customs = SeminarSignupFieldCustom.all.map{|field_set| SeminarSignupField.where(id: field_set.seminar_signup_field_id).first}.select{|s| !s.nil?}.uniq{|s| s.key } %> + <% if seminar_signup_field_customs.count != 0 %> + <% seminar_signup_field_customs.each do |s| %> + <% title = s.title rescue '' %> + <% next if title.blank? %> + <% next if s.key.blank? %> + <% @field_names << "seminar_signup_field_custom.#{s.key}" %> + <% @field_name_translations << (title)%> + <% end %> + <% end %> + <% seminar_signup_fields = SeminarSignupField.all.uniq{|s| s.key} %> + <% seminar_signup_fields.each do |s| %> + <% @field_names << "seminar_signup_fields.#{s.key}" %> + <% @field_name_translations << s.title %> + <% end %> + <% show1 = true + show2 = true + show3 = true + %> + <% default_show << "seminar_signup_contributes.title" if show1 %> + <% @field_names << 'seminar_signup_contributes.title' %> + <% @field_name_translations << t('seminar_signup.title') %> + + <% default_show << "seminar_signup_contributes.file" if show2 %> + <% @field_names << 'seminar_signup_contributes.file' %> + <% @field_name_translations << t('seminar_signup.file') %> + + <% default_show << "seminar_signup_contributes.description" if show3 %> + <% @field_names << 'seminar_signup_contributes.description' %> + <% @field_name_translations << t('seminar_signup.description') %> + <% seminar_submission_fields = SeminarSignupField.all.uniq{|s| s.key} %> + <% seminar_submission_fields.each do |s| %> + <% @field_names << "seminar_submission_fields.#{s.key}" %> + <% @field_name_translations << s.title %> + <% end %> + <% @display_field = @seminar_signup_admin_setting.display_field %> + <% if @display_field.blank? + @display_field = default_show + end %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/seminars/_index.html.erb b/app/views/admin/seminars/_index.html.erb index cb0b6b4..4d46839 100644 --- a/app/views/admin/seminars/_index.html.erb +++ b/app/views/admin/seminars/_index.html.erb @@ -22,11 +22,13 @@ <%= seminar.title %>
@@ -34,8 +36,19 @@ <%= SeminarMain.time_range(seminar.seminar_start_date, seminar.seminar_end_date) %> <%= SeminarMain.time_range(seminar.signup_start_date, seminar.signup_end_date) %> - <%= seminar.seminar_signups.count %> - <%= t('seminar.export') %> + + <% @seminar_review = seminar.seminar_reviews.where(:reviewer_id => current_user.member_profile_id.to_s).first %> + <% if @seminar_review.present? && !@can_edit %> + <%= @seminar_review.get_all_seminar_signup_ids.count %> + <% else %> + <%= seminar.seminar_signups.count %> + <% end %> + + + <% if can_see_seminar_signup(seminar) %> + <%= t('seminar.export') %> + <% end %> + <% end %> diff --git a/app/views/admin/seminars/_seminar_signup_dashboard.html.erb b/app/views/admin/seminars/_seminar_signup_dashboard.html.erb new file mode 100644 index 0000000..571a652 --- /dev/null +++ b/app/views/admin/seminars/_seminar_signup_dashboard.html.erb @@ -0,0 +1,299 @@ +

<%= @seminar.title %>

+
+<% org_seminar_signups = @seminar_signups %> +
+

<%= t("seminar.reviewer") %>

+ <% reviewer_show_ids = @seminar.reviewer_show_ids %> + <% if reviewer_show_ids.nil? + reviewer_show_ids = @seminar.reviewer_ids[0..1] + @seminar.update(:reviewer_show_ids=>reviewer_show_ids) + end + %> + <% count = 0 %> + <% reviewer_show_ids.each do |reviewer_id| %> + <% seminar_review = @seminar.seminar_reviews.where(:reviewer_id => reviewer_id.to_s).first %> + <% next if seminar_review.nil? %> + <% count += 1 %> +
+
<%= MemberProfile.find(reviewer_id).name rescue "" %>
+ - + <% @seminar_signups = SeminarSignup.where(:id.in=>seminar_review.get_all_seminar_signup_ids).sort_ordered %> + <% @seminar_signups = @seminar_signups.page(params["page_no#{count}"]).per(5) %> + <% @seminar_signups = @seminar_signups.page(0) if @seminar_signups.to_a.count == 0 %> + <%= render :partial => "seminar_signup_render_table",:locals=>{:@seminar_signups=>@seminar_signups,:@drag => true,:@include_blank=>true,:@reviewer_id=>seminar_review.id.to_s} %> + <% + pagination_html = content_tag :div, class: "bottomnav clearfix", style: "position: static;" do + content_tag :div, paginate(@seminar_signups), class: "pagination pagination-centered" + end + %> + <%= pagination_html.gsub(/page_no#{count}=\d*/,"").gsub('&&','&').gsub(/page=(\d*)/m){|ff| ff.gsub("page=#{$1}","page=#{params[:page]}&page_no#{count}=#{$1}")}.html_safe %> +
+ <% end %> + <% if count != 2 && @seminar.seminar_reviews.count >= 2 %> + <% (0...(2-count)).each do |i| %> +
+ +
+ <% end %> + <% end %> +
+<% @seminar_signups = org_seminar_signups + @include_blank = false + @reviewer_id = nil +%> +
+
+
<%= t('seminar.submitter_without_reviewer') %>
+ <%= render :partial => "seminar_signup_render_table" %> +
+<%= + content_tag :div, class: "bottomnav clearfix", style: "position: static;" do + content_tag :div, paginate(@seminar_signups), class: "pagination pagination-centered" + end +%> +
+<% unless request.xhr? %> +
" style="display: none;"> +
+
+ +
+
+
+
+ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t("seminar.field_display_setting"), seminar_signup_admin_setting_admin_seminar_path(params[:id]), :class => 'btn btn-primary' %> +
+
+ + +<% end %> \ No newline at end of file diff --git a/app/views/admin/seminars/_seminar_signup_render_table.html.erb b/app/views/admin/seminars/_seminar_signup_render_table.html.erb new file mode 100644 index 0000000..e8f7001 --- /dev/null +++ b/app/views/admin/seminars/_seminar_signup_render_table.html.erb @@ -0,0 +1,156 @@ + + + + <% render :partial => "get_display_fields" %> + <% if @seminar.nil? %> + + <% end %> + <% if @drag%> + + <% end %> + <% @field_name_translations.each_with_index do |trans,i|%> + <% next unless @display_field.include?(@field_names[i]) %> + + <% end %> + + + > + <% display_title = @seminar.nil? %> + <% @seminar_signups.each do |seminar_signup| %> + <% @seminar = seminar_signup.seminar_main if display_title %> + <% len = seminar_signup.seminar_signup_contributes.count %> + <% rowspan = "rowspan=#{len==0? 1 : len}" %> + <% vals = [] %> + + <% if @drag%> + + <% end %> + <% vals << seminar_signup.seminar_main.title if display_title %> + <% @display_field.each_with_index do |fn,i|%> + <% names = fn.split(".") %> + <% val = "" %> + <% if names[0] == "seminar_signup_field_set" %> + <% if names[1] == "name" %> + <% val = seminar_signup.name + val += "
+ +
" + %> + <% elsif names[1] == 'status' %> + <% val = t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> + <% elsif names[1] != 'recaptcha' %> + <% val = seminar_signup.send("#{names[1]}") %> + <% end %> + <% elsif names[0] == "default" %> + <% if names[2] == "name" %> + <% val = seminar_signup.name + val += "
+ +
" + %> + <% elsif names[2] == "tel" %> + <% val = seminar_signup.tel %> + <% elsif names[2] == "registration_status" %> + <% val = t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> + <% end %> + <% elsif names[0] == "seminar_signup_field_custom" || names[0] == "seminar_signup_fields" %> + <% val = seminar_signup.seminar_signup_values.where(:key=>names[1]).first.get_value_by_locale(I18n.locale) rescue "" %> + <% elsif names[0] == "seminar_signup_contributes" %> + <% if names[1] == "file" %> + <% val = seminar_signup.seminar_signup_contributes.to_a %> + <% else %> + <% if names[1] == "description" %> + <% descriptions = seminar_signup.seminar_signup_contributes.collect{|s| s.send(names[1])} %> + <% if @seminar.enable_summary_choice + descriptions = descriptions.map do |description| + if (description.to_s.to_i.to_s == description) + description = @seminar.summary_chioices[description.to_i] rescue description + else + description = description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
") rescue description + end + end + end %> + <% val = descriptions %> + <% else %> + <% val = seminar_signup.seminar_signup_contributes.collect{|s| s.send(names[1]).to_s} %> + <% end %> + <% end %> + <% elsif names[0] == "seminar_submission_fields" %> + <% val = seminar_signup.seminar_signup_contributes.collect{|s| (s.seminar_submission_values.where(:key=>names[1]).first.get_value_by_locale(I18n.locale) rescue "")} %> + <% elsif names[0] == "seminar_signup" %> + <% val = (seminar_signup.send("display_"+names[1]) rescue seminar_signup.send(names[1])) rescue nil %> + <% end %> + <% vals << val %> + <% end %> + <% count = 0 %> + <% indices = [] %> + <% vals.each_with_index do |val,i| %> + <% if val.class == Array %> + <% count = val.count - 1 %> + <% indices << i%> + + <% else %> + + <% end %> + <% end %> + <% (0...count).each do |i|%> + + <% indices.each do |index| %> + + <% end %> + + <% end %> + + <% end %> + <% if @include_blank %> + + <% if @drag %> + + <% end %> + <% (0...@display_field.count).each do |f| %> + + <% end %> + + <% end %> + +
<%= t('seminar.title') %><%= trans %>
> + <% if val[0].class == SeminarSignupContribute #File %> + <% seminar_signup_contribute = val[0] %> + <% description = seminar_signup_contribute.description.to_s %> + <% if @seminar.enable_summary_choice + if (seminar_signup_contribute.description.to_s.to_i.to_s == seminar_signup_contribute.description) + description = @seminar.summary_chioices[seminar_signup_contribute.description.to_i] rescue seminar_signup_contribute.description + else + description = seminar_signup_contribute.description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
") rescue seminar_signup_contribute.description + end + end %> + <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text} if seminar_signup_contribute.file.file %> + <% else %> + <%= val[0].html_safe.to_s rescue "" %> + <% end %> +
><%= val.to_s.html_safe %>
+ <% if vals[index][i].class == SeminarSignupContribute #File %> + <% seminar_signup_contribute = vals[index][i] %> + <% description = seminar_signup_contribute.description.to_s %> + <% if @seminar.enable_summary_choice + if (seminar_signup_contribute.description.to_s.to_i.to_s == seminar_signup_contribute.description) + description = @seminar.summary_chioices[seminar_signup_contribute.description.to_i] rescue seminar_signup_contribute.description + else + description = seminar_signup_contribute.description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
") rescue seminar_signup_contribute.description + end + end %> + <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text} if seminar_signup_contribute.file.file %> + <% else %> + <%= vals[index][i].html_safe.to_s rescue "" %> + <% end %> +
\ No newline at end of file diff --git a/app/views/admin/seminars/_seminar_signup_session_dashboard.html.erb b/app/views/admin/seminars/_seminar_signup_session_dashboard.html.erb new file mode 100644 index 0000000..ea7428c --- /dev/null +++ b/app/views/admin/seminars/_seminar_signup_session_dashboard.html.erb @@ -0,0 +1,286 @@ +

<%= @seminar.title %>

+
+<% org_seminar_signups = @seminar_signups %> +<% session_translation = (@seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0]['name'][I18n.locale] rescue "Session") %> +
+

<%= session_translation %>

+ <% session_show_ids = @seminar.session_show_ids %> + <% if session_show_ids.nil? + session_show_ids = (0...@seminar.summary_chioices.count).to_a[0..1] + @seminar.update(:session_show_ids=>session_show_ids) + end + %> + <% count = 0 %> + <% session_show_ids.each do |session_id| %> + <% next if session_id >= @seminar.summary_chioices.count %> + <% count += 1 %> +
+
<%= @seminar.summary_chioices[session_id] %>
+ - + <% seminar_session = @seminar.seminar_sessions.where(:key=>session_id).first %> + <% @seminar_signups = seminar_session.seminar_signups.sort_ordered %> + <% @seminar_signups = @seminar_signups.page(params["page_no#{count}"]).per(5) %> + <% @seminar_signups = @seminar_signups.page(0) if @seminar_signups.to_a.count == 0 %> + <%= render :partial => "seminar_signup_render_table",:locals=>{:@seminar_signups=>@seminar_signups,:@drag => true,:@include_blank=>true,:@reviewer_id=>session_id} %> + <% + pagination_html = content_tag :div, class: "bottomnav clearfix", style: "position: static;" do + content_tag :div, paginate(@seminar_signups), class: "pagination pagination-centered" + end + %> + <%= pagination_html.gsub(/page_no#{count}=\d*/,"").gsub('&&','&').gsub(/page=(\d*)/m){|ff| ff.gsub("page=#{$1}","page=#{params[:page]}&page_no#{count}=#{$1}")}.html_safe %> +
+ <% end %> + <% if count != 2 && @seminar.summary_chioices.count >= 2 %> + <% (0...(2-count)).each do |i| %> +
+ +
+ <% end %> + <% end %> +
+<% @seminar_signups = org_seminar_signups + @include_blank = false + @reviewer_id = nil +%> +
+
+
<%= t('seminar.unassigned_session_signups',{:session=>session_translation}) %>
+ <%= render :partial => "seminar_signup_render_table" %> +
+<%= + content_tag :div, class: "bottomnav clearfix", style: "position: static;" do + content_tag :div, paginate(@seminar_signups), class: "pagination pagination-centered" + end +%> +
+<% unless request.xhr? %> +
session_translation}) %>" style="display: none;"> +
+
+ +
+
+
+
+ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t("seminar.field_display_setting"), seminar_signup_admin_setting_admin_seminar_path(params[:id]) + "?page=session", :class => 'btn btn-primary' %> +
+
+ + +<% end %> \ No newline at end of file diff --git a/app/views/admin/seminars/_seminar_signup_table.html.erb b/app/views/admin/seminars/_seminar_signup_table.html.erb new file mode 100644 index 0000000..29387f1 --- /dev/null +++ b/app/views/admin/seminars/_seminar_signup_table.html.erb @@ -0,0 +1,22 @@ +
+
+ + +
+
+ + +

<%= @seminar.title %>

+ +<%= render :partial => "seminar_signup_render_table" %> + +
+ + <% if @can_edit %> +
+ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t("seminar.field_display_setting"), seminar_signup_admin_setting_admin_seminar_path(params[:id]) + "?page=table", :class => 'btn btn-primary' %> +
+ <% end %> +
+ +<%= render 'layouts/delete_modal', delete_options: @delete_options %> \ No newline at end of file diff --git a/app/views/admin/seminars/copy.html.erb b/app/views/admin/seminars/copy.html.erb new file mode 100644 index 0000000..5bf7358 --- /dev/null +++ b/app/views/admin/seminars/copy.html.erb @@ -0,0 +1,6 @@ +<%= form_for @seminar, url: admin_seminars_path, html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= f.hidden_field :copy_id %> + <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/seminars/enquiry_for_applicants.html.erb b/app/views/admin/seminars/enquiry_for_applicants.html.erb new file mode 100644 index 0000000..391eec0 --- /dev/null +++ b/app/views/admin/seminars/enquiry_for_applicants.html.erb @@ -0,0 +1,33 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> +
+ 查詢報名人 +
+
+ +
+ + +
+
+
+
+<%= render :partial => "seminar_signup_render_table" %> +<% if @can_edit %> +
+ +
+ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t("seminar.field_display_setting"), seminar_signup_admin_setting_admin_seminar_path("enquiry_for_applicants"), :class => 'btn btn-primary' %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/admin/seminars/export.xlsx.axlsx b/app/views/admin/seminars/export.xlsx.axlsx index 340998f..15b7269 100644 --- a/app/views/admin/seminars/export.xlsx.axlsx +++ b/app/views/admin/seminars/export.xlsx.axlsx @@ -6,6 +6,8 @@ wb.add_worksheet(name: (@seminar.title.to_s[0..27]+'...')) do |sheet| row = [t('seminar_signup.signup_time')] + row << t('seminar_signup.serial_number') + row << t('seminar_signup.name') row << t('seminar_signup.unit') @@ -34,11 +36,13 @@ wb.add_worksheet(name: (@seminar.title.to_s[0..27]+'...')) do |sheet| sheet.add_row row - @seminar.seminar_signups.each do |signup| - + @seminar_signups.each do |signup| + types = {} row2 = [] row2 << "#{signup.created_at} " + types[1] = :string + row2 << "#{signup.display_serial_number}" row2 << "#{signup[:name]} " row2 << "#{signup.unit} " row2 << "#{signup[:tel]} " @@ -57,8 +61,8 @@ wb.add_worksheet(name: (@seminar.title.to_s[0..27]+'...')) do |sheet| row2 << nl2br(show_attribute_value(@seminar.get_attribute_value(rf,signup.id).get_value_by_locale(I18n.locale))) rescue ' ' end end - - sheet.add_row row2 + types = (0...row2.count).map{|i| types[i]} + sheet.add_row row2 , :types => types end diff --git a/app/views/admin/seminars/get_hide_reviewer.html.erb b/app/views/admin/seminars/get_hide_reviewer.html.erb new file mode 100644 index 0000000..ad34c50 --- /dev/null +++ b/app/views/admin/seminars/get_hide_reviewer.html.erb @@ -0,0 +1,26 @@ +
    + <% @hide_reviewers.each do |member|%> + <% reviewer = @reviewers.select{|r| r.reviewer_id == member.id.to_s}.first %> + <% member_name = member.name %> + <% member_id = member.id.to_s %> + <% member_pic_url = ((member.avatar.file.present? rescue false) ? member.avatar.url : "/assets/member-pic.png") %> +
  • + + +
  • + <% end %> +
+ \ No newline at end of file diff --git a/app/views/admin/seminars/get_hide_session.html.erb b/app/views/admin/seminars/get_hide_session.html.erb new file mode 100644 index 0000000..9091136 --- /dev/null +++ b/app/views/admin/seminars/get_hide_session.html.erb @@ -0,0 +1,34 @@ +
    + <% @hide_sessions.each do |i,session|%> + <% seminar_session = @seminar_sessions.where(:key=>i).first %> +
  • + + +
  • +
    + <% end %> +
+ \ No newline at end of file diff --git a/app/views/admin/seminars/get_reviewer_block.html.erb b/app/views/admin/seminars/get_reviewer_block.html.erb new file mode 100644 index 0000000..04393b5 --- /dev/null +++ b/app/views/admin/seminars/get_reviewer_block.html.erb @@ -0,0 +1,14 @@ +<% seminar_review = @seminar.seminar_reviews.where(:reviewer_id => @reviewer_id.to_s).first %> +<% unless seminar_review.nil? %> +
+
<%= MemberProfile.find(@reviewer_id).name rescue "" %>
+ - + <% @seminar_signups = SeminarSignup.where(:id.in=>seminar_review.get_all_seminar_signup_ids).sort_ordered %> + <%= render :partial => "seminar_signup_render_table",:locals=>{:@seminar_signups=>@seminar_signups.page(params[:page]).per(5),:@drag => true,:@include_blank=>true,:@reviewer_id=>seminar_review.id.to_s} %> + <%= + content_tag :div, class: "bottomnav clearfix", style: "position: static;" do + content_tag :div, paginate(@seminar_signups), class: "pagination pagination-centered" + end + %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/seminars/get_session_block.html.erb b/app/views/admin/seminars/get_session_block.html.erb new file mode 100644 index 0000000..528989b --- /dev/null +++ b/app/views/admin/seminars/get_session_block.html.erb @@ -0,0 +1,13 @@ +<% if @session_id < @seminar.summary_chioices.count %> +
+
<%= @seminar.summary_chioices[@session_id] %>
+ - + <% @seminar_signups = @seminar.seminar_signups.where(:final_session=>@session_id).sort_ordered %> + <%= render :partial => "seminar_signup_render_table",:locals=>{:@seminar_signups=>@seminar_signups.page(params[:page]).per(5),:@drag => true,:@include_blank=>true} %> + <%= + content_tag :div, class: "bottomnav clearfix", style: "position: static;" do + content_tag :div, paginate(@seminar_signups), class: "pagination pagination-centered" + end + %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/seminars/reviewer_setting.html.erb b/app/views/admin/seminars/reviewer_setting.html.erb new file mode 100644 index 0000000..2aecffc --- /dev/null +++ b/app/views/admin/seminars/reviewer_setting.html.erb @@ -0,0 +1,99 @@ +<% select_keys = [] %> +<% fields_values = @fields_values.map{|i,fields_values| + "
" + fields_values.map.with_index{|v,ii| "" }.join("") + + "
" +} %> +<%= form_for @seminar, url: update_reviewer_setting_admin_seminar_path(@seminar.id), html: {class: "form-horizontal main-forms"} do |f| %> +
+ <% count = 0 %> + <% @seminar_reviews.each_with_index do |seminar_review,i| %> + <% next if seminar_review.review.nil? %> + <%= f.fields_for :seminar_reviews,seminar_review do |f| %> +

<%= seminar_review.review.name rescue "" %>

+
+ +
+ <% seminar_review.default_topics.each_with_index do |v,ii| %> +
+ X + <%= select_tag("seminar_main[seminar_reviews_attributes][#{count}][default_topics][]" , options_for_select(@fields_translations.zip(@fields),v),{:class=>"select_field_types","data-index"=>count}) %> + <% select_index = @fields.index(v) %> + <% checked_values = seminar_review.default_topics_values[ii] %> +
+ <% @fields_values[select_index].each_with_index do |v,iii| %> + <% checked = checked_values.include?(iii.to_s) rescue false %> + + <% end if select_index.present? %> +
+
+ <% end %> + <% select_keys << select_tag("seminar_main[seminar_reviews_attributes][#{count}][default_topics][]" , options_for_select(@fields_translations.zip(@fields)),{:class=>"select_field_types","data-index"=>count}) %> + +
+
+ <% end %> + <% count += 1 %> + <% end %> +
+ <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), admin_seminars_path, :class=>"btn" %> +
+
+<% end %> + + \ No newline at end of file diff --git a/app/views/admin/seminars/seminar_signup.html.erb b/app/views/admin/seminars/seminar_signup.html.erb index d3bc449..439114a 100644 --- a/app/views/admin/seminars/seminar_signup.html.erb +++ b/app/views/admin/seminars/seminar_signup.html.erb @@ -1,215 +1,32 @@ - - + - - -
-
- -
-
- - -

<%= @seminar.title %>

- - - - - <% if @seminar.seminar_signup_field_sets.count != 0 %> - <% @seminar.seminar_signup_field_sets.each do |field_set| %> - <% if !(field_set.hidden) %> - - <% end %> - <% end %> - <% else %> - - - - <% end %> - <% if @seminar.seminar_signup_field_customs.count != 0 %> - <% @seminar.seminar_signup_field_customs.each do |field_set| %> - <% if !(field_set.hidden) %> - - <% end %> - <% end %> - <% end %> - <% if @seminar.seminar_submission_field_sets.count != 0 %> - <% show1 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0].hidden) - show2 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0].hidden) - show3 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0].hidden) - %> - <% else %> - <% show1 = true - show2 = true - show3 = true - %> - <% end %> - <% if show1 %> - - <% end %> - <% if show2 %> - - <% end %> - <% if show3 %> - - <% end %> - <% @seminar.seminar_submission_fields.asc(:_id).each do |submission_field| %> - - <% end %> - - - - <% @seminar_signups.each do |seminar_signup| %> - <% len = seminar_signup.seminar_signup_contributes.count %> - - <% if @seminar.seminar_signup_field_sets.count != 0 %> - <% @seminar.seminar_signup_field_sets.each do |field_set| %> - <% if !(field_set.hidden) %> - - <% end %> - <% end %> - <% else %> - - - - <% end %> - <% if @seminar.seminar_signup_field_customs.count != 0 %> - <% @seminar.seminar_signup_field_customs.each do |field_set| %> - <% if !(field_set.hidden) %> - - <% end %> - <% end %> - <% end %> - <% count_set = 0 %> - <% if @seminar.seminar_submission_field_sets.count != 0 %> - <% show1 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0].hidden) - show2 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0].hidden) - show3 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0].hidden) - %> - <% @seminar.seminar_submission_field_sets.each do |field_set| %> - <% if !(field_set.hidden) %> - <% count_set+=1 %> - <% end %> - <% end %> - <% else %> - <% show1 = true - show2 = true - show3 = true - %> - <% count_set = 2 %> - <% end %> - <% if len==0 %> - <% - count_field = @seminar.seminar_submission_fields.count - %> -
    - <% for i in 1..count_field+count_set %> -
- <% end %> - - - <% end %> -
    - <% seminar_signup.seminar_signup_contributes.collect do |seminar_signup_contribute| %> - <% if show1 %> -
- <% end %> - <% if show2 %> - - <% end %> - <% if show3 %> - - <% end %> - <% - count_value = seminar_signup_contribute.seminar_submission_values.count - count_field = @seminar.seminar_submission_fields.count - %> - <% if count_value == count_field %> - <% seminar_signup_contribute.seminar_submission_values.asc(:seminar_submission_field_id).each do |value| %> - - <% end %> - <% else %> - <% for i in 1..(count_field-count_value) %> - - <% end %> - <% end %> - - - <% end %> - - +<% if @can_edit %> + <% if params[:type].blank?%> + <% end %> - -
<%= field_set.name[I18n.locale] %><%= t('seminar_signup.name')%><%= t('seminar_signup.tel')%><%= t('seminar.registration_status')%><%= SeminarSignupField.where(id:field_set.seminar_signup_field_id).first.title rescue '' %><%= t('seminar_signup.title')%><%= t('seminar_signup.file')%><%= t('seminar_signup.description')%><%= submission_field.title %>
- <% if field_set.field_name== 'name' %> - <%= seminar_signup.name %> -
- -
- <% elsif field_set.field_name== 'status' %> - <%= t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> - <% elsif field_set.field_name != 'recaptcha' %> - <%= seminar_signup.send("#{field_set.field_name}") %> - <% end %> -
- <%= seminar_signup.name %> -
- -
-
<%= seminar_signup.tel %><%= t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> - - <% seminar_signup.seminar_signup_values.each do |seminar_signup_values| %> - <% if seminar_signup_values.seminar_signup_field_id == field_set.seminar_signup_field_id %> - <% if seminar_signup_values.value.class == String || seminar_signup_values.value.nil? %> - <%= seminar_signup_values.get_value_by_locale(I18n.locale,seminar_signup_values) %> - <% else %> - <% seminar_signup_values.value.each do |key,v| %> - <%= "#{I18n.t(key)}:#{seminar_signup_values.get_value_by_locale(key,seminar_signup_values)}" %> -
- <% end %> - <% end %> - <% end %> - <% end %> -
-
-
  • <%= seminar_signup_contribute.title.to_s %>
  • -
    -
  • - <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(seminar_signup_contribute.description).text} if seminar_signup_contribute.file.file %> -
  • -
    -
  • <%= seminar_signup_contribute.description.to_s.html_safe %>
  • -
    - - <% if value.value.class == String || value.value.nil? %> - <%= value.get_value_by_locale(I18n.locale,value) %> - <% else %> - <% value.value.each do |key,v| %> - <%= "#{I18n.t(key)}:#{value.get_value_by_locale(key,value)}" %> -
    - <% end %> - <% end %> -
    -
    -
    - -<%= - content_tag :div, class: "bottomnav clearfix" do - content_tag :div, paginate(@seminar_signups), class: "pagination pagination-centered" - end -%> -
    - -<%= render 'layouts/delete_modal', delete_options: @delete_options %> + +<% end %> +<% if params[:type] == "table" || (!@can_edit) %> +
    + <%= render :partial => 'seminar_signup_table' %> +<% elsif params[:type] == "session" %> + <%=render :partial => 'seminar_signup_session_dashboard' %> +<% else %> + <%= render :partial => 'seminar_signup_dashboard' %> +<% end %> + diff --git a/app/views/admin/seminars/seminar_signup_admin_setting.html.erb b/app/views/admin/seminars/seminar_signup_admin_setting.html.erb new file mode 100644 index 0000000..1fc797e --- /dev/null +++ b/app/views/admin/seminars/seminar_signup_admin_setting.html.erb @@ -0,0 +1,58 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> +<%= form_for @seminar_signup_admin_setting, url: update_seminar_signup_admin_setting_admin_seminar_path, html: {class: "form-horizontal main-forms"} do |f| %> +

    + <% if @seminar %> + <%= @seminar.title %> + <% else %> + <%= t("seminar.enquiry_for_applicants_display_fields_setting") %> + <% end %> +

    +
    + +
    +

    <%= t('seminar.display_field') %>

    + <% render :partial => "get_display_fields" %> + <% max_length = 10 %> + <% @field_name_translations.each_with_index do |trans,i|%> + <% if i % max_length == 0 %> + + + + + <% else %> + + <% end %> + <% if ((i % max_length) == (max_length - 1) || i == (@field_name_translations.count - 1)) %> + + + + <% @field_names[((i/max_length) *max_length) ..i].each do |fn|%> + + <% end %> + +
    <%= trans %><%= trans %>
    <%= check_box_tag "#{f.object_name}[display_field][]",fn , @display_field.include?(fn) %>
    + <% end %> + <% end %> + <%= hidden_field_tag :id, params[:id] %> + <%= hidden_field_tag :page, params[:page] %> +
    + + +
    + <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), seminar_signup_admin_seminar_path(params[:id]), :class=>"btn" %> +
    +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/seminars/seminar_signup_render_table.html.erb b/app/views/admin/seminars/seminar_signup_render_table.html.erb new file mode 100644 index 0000000..79d184c --- /dev/null +++ b/app/views/admin/seminars/seminar_signup_render_table.html.erb @@ -0,0 +1,103 @@ + + + + <% render :partial => "get_display_fields" %> + <% @field_name_translations.each_with_index do |trans,i|%> + <% next unless @display_field.include?(@field_names[i]) %> + + <% end %> + + + + <% @seminar_signups.each do |seminar_signup| %> + <% len = seminar_signup.seminar_signup_contributes.count %> + <% rowspan = "rowspan=#{len==0? 1 : len}" %> + <% vals = [] %> + + <% @field_names.each_with_index do |fn,i|%> + <% next unless @display_field.include?(fn) %> + <% names = fn.split(".") %> + <% val = "" %> + <% if names[0] == "seminar_signup_field_set" %> + <% if names[1] == "name" %> + <% val = seminar_signup.name + val += "
    + +
    " + %> + <% elsif names[1] == 'status' %> + <% val = t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> + <% elsif names[1] != 'recaptcha' %> + <% val = seminar_signup.send("#{names[1]}") %> + <% end %> + <% elsif names[0] == "default" %> + <% if names[2] == "name" %> + <% val = seminar_signup.name + val += "
    + +
    " + %> + <% elsif names[2] == "tel" %> + <% val = seminar_signup.tel %> + <% elsif names[2] == "registration_status" %> + <% val = t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> + <% end %> + <% elsif names[0] == "seminar_signup_field_custom" || names[0] == "seminar_signup_fields" %> + <% val = seminar_signup.seminar_signup_values.where(:key=>names[1]).first.get_value_by_locale(I18n.locale) rescue "" %> + <% elsif names[0] == "seminar_signup_contributes" %> + <% if names[1] == "file" %> + <% val = seminar_signup.seminar_signup_contributes.to_a %> + <% else %> + <% val = seminar_signup.seminar_signup_contributes.collect{|s| s.send(names[1])} %> + <% end %> + <% elsif names[0] == "seminar_submission_fields" %> + <% val = seminar_signup.seminar_signup_contributes.collect{|s| (s.seminar_submission_values.where(:key=>names[1]).first.get_value_by_locale(I18n.locale) rescue "")} %> + <% end %> + <% vals << val %> + <% end %> + <% count = 0 %> + <% indices = [] %> + <% vals.each_with_index do |val,i| %> + <% if val.class == Array %> + <% count = val.count - 1 %> + <% indices << i%> + + <% else %> + + <% end %> + <% end %> + <% (0...count).each do |i|%> + + <% indices.each do |index| %> + + <% end %> + + <% end %> + + <% end %> + +
    <%= trans %>
    + <% if val[0].class == SeminarSignupContribute #File %> + <% seminar_signup_contribute = val[0] %> + <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(seminar_signup_contribute.description).text} if seminar_signup_contribute.file.file %> + <% else %> + <%= val[0].html_safe.to_s rescue "" %> + <% end %> + ><%= val.to_s.html_safe %>
    + <% if vals[index][i].class == SeminarSignupContribute #File %> + <% seminar_signup_contribute = vals[index][i] %> + <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(seminar_signup_contribute.description).text} if seminar_signup_contribute.file.file %> + <% else %> + <%= vals[index][i].html_safe.to_s rescue "" %> + <% end %> +
    \ No newline at end of file diff --git a/app/views/email/signup_email.html.erb b/app/views/email/signup_email.html.erb index eb6a9a0..9a0583d 100644 --- a/app/views/email/signup_email.html.erb +++ b/app/views/email/signup_email.html.erb @@ -5,4 +5,5 @@ <% end %> <% else %> <%= t('seminar.email_signup_content') %> -<% end %> \ No newline at end of file +<% end %> +<%= (@data['extra_text'] rescue "").to_s.html_safe %> \ No newline at end of file diff --git a/app/views/email/submission_email.html.erb b/app/views/email/submission_email.html.erb index d3b4041..a0f31c2 100644 --- a/app/views/email/submission_email.html.erb +++ b/app/views/email/submission_email.html.erb @@ -5,4 +5,5 @@ <% end %> <% else %> <%= t('seminar.email_submission_content') %> -<% end %> \ No newline at end of file +<% end %> +<%= (@data['extra_text'] rescue "").to_s.html_safe %> \ No newline at end of file diff --git a/app/views/seminars/_contribute_form.html.erb b/app/views/seminars/_contribute_form.html.erb new file mode 100644 index 0000000..997e844 --- /dev/null +++ b/app/views/seminars/_contribute_form.html.erb @@ -0,0 +1,139 @@ +
    + <% unless f.object.new_record? %> + <%= f.hidden_field :id %> + <% end %> + <% if @seminar.seminar_submission_field_sets.count != 0 + data1 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0] + data2 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0] + data3 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0] + show1 = !(data1.disabled) + show2 = !(data2.disabled) + show3 = !(data3.disabled) + name1 = data1['name'][I18n.locale] + name2 = data2['name'][I18n.locale] + name3 = data3['name'][I18n.locale] + plc1 = data1['placeholder'][I18n.locale] + plc2 = data2['placeholder'][I18n.locale]==t('seminar_signup.description') ? '' : data2['placeholder'][I18n.locale] + plc3 = data3['placeholder'][I18n.locale]==t('seminar_signup.file') ? '' : data3['placeholder'][I18n.locale] + else + show1 = true + show2 = true + show3 = true + name1 = t('seminar_signup.title') + name2 = t('seminar_signup.description') + name3 = t('seminar_signup.file') + plc1 = t('seminar_signup.title') + plc2 = '' + plc3 = '' + end + %> + <% if show1 %> +
    + +
    + <%= f.text_field :title, :class=>"input-medium form-control", :id=>'name', :placeholder=> plc1, :required => true %> +
    +
    + <% end %> + <% if show2 %> +
    + + <% required = @seminar.enable_summary_choice %> + +
    + <%= "(#{plc2})" if !(plc2.to_s.blank?) %> +
    +
    + <% if @seminar.enable_summary_choice %> + <% check_choices = Array(f.object.description) %> + <% if @seminar.summary_chioice_type == "select" %> + <%= f.select :description,options_for_select(@seminar.summary_chioices.map.with_index{|v,i| [v,i]},check_choices),{},{:style=>"float: left;",:required=>"required"} %> + <% else %> + <% multiple = @seminar.summary_chioice_type == "checkbox" %> + <% @seminar.summary_chioices.each_with_index do |c,i| %> + + <% end %> + <% end %> + <% else %> + <%= f.text_area :description, rows: 5, :class=>"ckeditor input-medium form-control", :placeholder=> plc2 %> + <% end %> +
    +
    + <% end %> + <% if show3 %> +
    + + +
    + <%= "(#{plc3})" if !(plc3.to_s.blank?) %> +
    +
    + +
    <%= f.object["file"] if f.object.file.present? %>
    +
    +
    + <% end %> + <% @seminar.seminar_submission_fields.asc(:_id).each do |rf| %> +
    + <%= rf.block_helper(@seminar,@form_index,false,"seminar_signup_contribute",@con, rf.to_require,rf) %> +
    + <% @form_index = @form_index +1 %> + <% end %> +
    +
    + "> + + <%= f.submit "Submit", class: 'btn btn-primary', :id => 'button-mail' %> + <%= f.button "Delete", type: 'reset', class: 'btn' %> +
    +
    +
    + + \ No newline at end of file diff --git a/app/views/seminars/add_file.html.erb b/app/views/seminars/add_file.html.erb index 7b7146d..289f0de 100644 --- a/app/views/seminars/add_file.html.erb +++ b/app/views/seminars/add_file.html.erb @@ -16,83 +16,11 @@ <% if ( @seminar.contribute_file_count.blank? or @seminar_signup.seminar_signup_contributes.count < @seminar.contribute_file_count.to_i ) %> <%= form_for @con, url: add_file_proc_seminars_path, html: {class: "content form-horizontal" , :id=>"new-seminar-signup-contribute"} do |f| %> -
    - <% if @seminar.seminar_submission_field_sets.count != 0 - data1 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0] - data2 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0] - data3 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0] - show1 = !(data1.disabled) - show2 = !(data2.disabled) - show3 = !(data3.disabled) - name1 = data1['name'][I18n.locale] - name2 = data2['name'][I18n.locale] - name3 = data3['name'][I18n.locale] - plc1 = data1['placeholder'][I18n.locale] - plc2 = data2['placeholder'][I18n.locale]==t('seminar_signup.description') ? '' : data2['placeholder'][I18n.locale] - plc3 = data3['placeholder'][I18n.locale]==t('seminar_signup.file') ? '' : data3['placeholder'][I18n.locale] - else - show1 = true - show2 = true - show3 = true - name1 = t('seminar_signup.title') - name2 = t('seminar_signup.description') - name3 = t('seminar_signup.file') - plc1 = t('seminar_signup.title') - plc2 = '' - plc3 = '' - end - %> - <% if show1 %> -
    - -
    - <%= f.text_field :title, :class=>"input-medium form-control", :id=>'name', :placeholder=> plc1, :required => true %> -
    -
    + <% begin %> + <%= render :partial => 'seminars/contribute_form',:locals=>{:f=>f} %> + <%rescue => e%> + <%= e %> <% end %> - <% if show2 %> -
    - - -
    - <%= "(#{plc2})" if !(plc2.to_s.blank?) %> -
    -
    - <%= f.text_area :description, rows: 5, :class=>"ckeditor input-medium form-control", :placeholder=> plc2 %> -
    -
    - <% end %> - <% if show3 %> -
    - - -
    - <%= "(#{plc3})" if !(plc3.to_s.blank?) %> -
    -
    - <%= f.file_field :file, :required => true %> -
    -
    - <% end %> - <% @seminar.seminar_submission_fields.asc(:_id).each do |rf| %> -
    - <%= rf.block_helper(@seminar,@form_index,false,"seminar_signup_contribute",@con, rf.to_require,rf) %> -
    - <% @form_index = @form_index +1 %> - <% end %> -
    -
    - "> - - <%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %> - <%= f.button t('cancel'), type: 'reset', class: 'btn' %> -
    -
    -
    <% end %> <% else %> diff --git a/app/views/seminars/con_login.html.erb b/app/views/seminars/con_login.html.erb index 32f245c..0e37809 100644 --- a/app/views/seminars/con_login.html.erb +++ b/app/views/seminars/con_login.html.erb @@ -24,20 +24,20 @@ <%= form_tag con_login_proc_seminars_path, :class => 'content' do %>
    - <%= text_field_tag :user_name, params[:user_name], :placeholder => t("users.user_id"), :id=>"user_email" %> + <%= text_field_tag :user_name, params[:user_name], :placeholder => t('seminar_signup.email_address'), :id=>"user_email" %>
    <%= password_field_tag :password, nil, :placeholder => t(:dots), :id=>"user_password" %>

    "> - + <% end %>
    @@ -50,4 +50,10 @@ 已截止 -<% end %> \ No newline at end of file +<% end %> + \ No newline at end of file diff --git a/app/views/seminars/con_upload.html.erb b/app/views/seminars/con_upload.html.erb index 1abe351..52532ef 100644 --- a/app/views/seminars/con_upload.html.erb +++ b/app/views/seminars/con_upload.html.erb @@ -6,11 +6,20 @@ @seminar = data["seminar"] @seminar_signup = data["seminar_signup"] @time_now = data["time_now"] + data1 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0] + data2 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0] + data3 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0] + show1 = !(data1.disabled) rescue false + show2 = !(data2.disabled) rescue false + show3 = !(data3.disabled) rescue false + name1 = data1['name'][I18n.locale] + name2 = data2['name'][I18n.locale] + name3 = data3['name'][I18n.locale] %> <% if @seminar.contribute_start_date <= @time_now and ( @seminar.contribute_end_date.nil? or @seminar.contribute_end_date+1 >= @time_now ) %> - + <% begin %> <% if !session[:seminar_signup_id].blank? %> - + <%=t('seminar_signup.serial_number') %>: <%=@seminar_signup.display_serial_number rescue ""%> <%= t('seminar_signup.logout') %> @@ -19,9 +28,15 @@ - - - + <% if show1 %> + + <% end %> + <% if show2 %> + + <% end %> + <% if show3 %> + + <% end %> @@ -31,8 +46,16 @@ %> - - + <% description = seminar_signup_contribute.description.to_s %> + <% if @seminar.enable_summary_choice + if (seminar_signup_contribute.description.to_s.to_i.to_s == seminar_signup_contribute.description) + description = @seminar.summary_chioices[seminar_signup_contribute.description.to_i] rescue seminar_signup_contribute.description + else + description = seminar_signup_contribute.description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
    ") rescue seminar_signup_contribute.description + end + end %> + +
    <%= t('seminar_signup.file_name') %><%= t('seminar_signup.file_note') %><%= t('seminar_signup.files') %><%= name1 %><%= name2 %><%= name3 %><%= t(:action) %>
    <%= seminar_signup_contribute.title %><%= seminar_signup_contribute.description.to_s.html_safe %><%= link_to File.basename(seminar_signup_contribute.file.path), seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(seminar_signup_contribute.description).text} if seminar_signup_contribute.file.file %><%= description.html_safe %><%= link_to File.basename(seminar_signup_contribute.file.path), seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
    "," , ")).text} if seminar_signup_contribute.file.file %>
    <%= link_to t(:edit), OrbitHelper.url_to_show(@seminar.to_param) + '?method=edit_file&con_no=' + seminar_signup_contribute.id, :class => 'btn btn-primary' %>
    @@ -49,7 +72,7 @@ <% if ( @seminar.contribute_file_count.blank? or @seminar_signup.seminar_signup_contributes.count < @seminar.contribute_file_count.to_i ) %> - <%= link_to content_tag(:i, nil, :class => 'icon-plus') +' '+ t('new_'), OrbitHelper.url_to_show(@seminar.to_param) + '?method=add_file', :class => 'btn btn-primary' %> + <%= link_to content_tag(:i, nil, :class => 'icon-plus') +' '+ t('seminar_signup.new_'), OrbitHelper.url_to_show(@seminar.to_param) + '?method=add_file', :class => 'btn btn-primary' %> <% end %>
    @@ -63,7 +86,10 @@ 回列表頁 <% end %> - + <% + rescue => e + puts e + end%> <% else %> 已截止 diff --git a/app/views/seminars/edit_file.html.erb b/app/views/seminars/edit_file.html.erb index 7a1bdbf..303b658 100644 --- a/app/views/seminars/edit_file.html.erb +++ b/app/views/seminars/edit_file.html.erb @@ -14,84 +14,11 @@ <% if !session[:seminar_signup_id].blank? %> <%= form_for @con, url: edit_file_proc_seminars_path, html: {class: "content form-horizontal" , :id=>"new-seminar-signup-contribute"} do |f| %> -
    - <% if @seminar.seminar_submission_field_sets.count != 0 - data1 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0] - data2 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0] - data3 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0] - show1 = !(data1.disabled) - show2 = !(data2.disabled) - show3 = !(data3.disabled) - name1 = data1['name'][I18n.locale] - name2 = data2['name'][I18n.locale] - name3 = data3['name'][I18n.locale] - plc1 = data1['placeholder'][I18n.locale] - plc2 = data2['placeholder'][I18n.locale]==t('seminar_signup.description') ? '' : data2['placeholder'][I18n.locale] - plc3 = data3['placeholder'][I18n.locale]==t('seminar_signup.file') ? '' : data3['placeholder'][I18n.locale] - else - show1 = true - show2 = true - show3 = true - name1 = t('seminar_signup.title') - name2 = t('seminar_signup.description') - name3 = t('seminar_signup.file') - plc1 = t('seminar_signup.title') - plc2 = '' - plc3 = '' - end - %> - <% if show1 %> -
    - -
    - <%= f.text_field :title, :class=>"input-medium form-control", :id=>'name', :placeholder=> plc1, :required => true %> -
    -
    + <% begin %> + <%= render :partial => 'seminars/contribute_form',:locals=>{:f=>f} %> + <%rescue => e%> + <%= e %> <% end %> - <% if show2 %> -
    - - -
    - <%= "(#{plc2})" if !(plc2.to_s.blank?) %> -
    -
    - <%= f.text_area :description, rows: 5, :class=>"ckeditor input-medium form-control", :placeholder=> plc2 %> -
    -
    - <% end %> - <% if show3 %> -
    - - -
    - <%= "(#{plc3})" if !(plc3.to_s.blank?) %> -
    -
    - <%= f.file_field :file %> -
    -
    - <% end %> - <% @seminar.seminar_submission_fields.asc(:_id).each do |rf| %> -
    - <%= rf.block_helper(@seminar,@form_index,false,"seminar_signup_contribute",@con, rf.to_require,rf) %> -
    - <% @form_index = @form_index +1 %> - <% end %> -
    -
    - "> - - - <%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %> - <%= f.button t('cancel'), type: 'reset', class: 'btn' %> -
    -
    -
    <% end %> <% else %> diff --git a/app/views/seminars/index.html.erb b/app/views/seminars/index.html.erb index eba6e34..2c6071b 100644 --- a/app/views/seminars/index.html.erb +++ b/app/views/seminars/index.html.erb @@ -5,7 +5,7 @@ @total_pages = data["total_pages"] @time_now = data["time_now"] %> - +<% begin %>

    <%= t('seminar.seminar') %>

    @@ -23,11 +23,11 @@ <% @seminars.each do |seminar| - if !seminar.registration_status.blank? and seminar.signup_start_date <= @time_now and ( seminar.signup_end_date.nil? or seminar.signup_end_date+1 >= @time_now ) + if !seminar.registration_status.blank? and (seminar.signup_start_date <= @time_now rescue false) and ( seminar.signup_end_date.nil? or seminar.signup_end_date+1 >= @time_now ) sign_up = ('' + t('seminar.signup') + '').html_safe elsif seminar.registration_status.blank? sign_up = t('seminar.sign_up_not_open') - elsif seminar.signup_start_date > @time_now + elsif (seminar.signup_start_date > @time_now rescue false) sign_up = t('seminar.sign_up_not_yet') else sign_up = t('seminar.sign_up_overdue') @@ -42,7 +42,7 @@ <%= sign_up %>
    <%= - if !seminar.registration_status.blank? and seminar.registration_status.include?('C') and seminar.contribute_start_date <= @time_now and ( seminar.contribute_end_date.nil? or seminar.contribute_end_date+1 >= @time_now ) + if !seminar.registration_status.blank? and seminar.registration_status.include?('C') and (seminar.contribute_start_date <= @time_now rescue false) and ( seminar.contribute_end_date.nil? or (seminar.contribute_end_date+1 >= @time_now rescue false) ) if !session[:seminar_signup_id].blank? if session[:seminar_main_id] == seminar.id ('' + t('seminar_signup.uploads') + '').html_safe @@ -59,5 +59,8 @@ <% end %>
    - +<% rescue => e +puts [e,e.backtrace] + end +%> <%= create_pagination(@total_pages).html_safe if @total_pages > 1 %> \ No newline at end of file diff --git a/app/views/seminars/show.html.erb b/app/views/seminars/show.html.erb index f74e5ac..ef3d8bd 100644 --- a/app/views/seminars/show.html.erb +++ b/app/views/seminars/show.html.erb @@ -36,53 +36,37 @@ <% end %> +
    +
    *(<%= t('seminar.required') %>)
    +
    <% if @seminar.seminar_signup_field_sets.count != 0 %> <% @seminar.seminar_signup_field_sets.each do |signup_field| %> - <% if signup_field.field_name == 'name' %> -
    -
    *(<%= t('seminar.required') %>)
    -
    - <% end %> <% if !(signup_field.disabled) && signup_field.field_name != 'recaptcha' %> - -
    -
    *(<%= t('seminar.required') %>)
    -
    @@ -232,10 +212,10 @@
    - "> + "> - <%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %> - <%= f.button t('cancel'), type: 'reset', class: 'btn' %> + <%= f.submit "Submit", class: 'btn btn-primary', :id => 'button-mail' %> + <%= f.button "Delete", type: 'reset', class: 'btn' %>
    @@ -245,6 +225,7 @@