diff --git a/app/controllers/admin/seminar_review_results_controller.rb b/app/controllers/admin/seminar_review_results_controller.rb new file mode 100644 index 0000000..3ba1d80 --- /dev/null +++ b/app/controllers/admin/seminar_review_results_controller.rb @@ -0,0 +1,53 @@ +# encoding: utf-8 +class Admin::SeminarReviewResultsController < OrbitAdminController + include Admin::SeminarsHelper + before_action ->(module_app = @app_title) { set_variables module_app } + before_action :set_seminar,:check_permission_for_seminar + def initialize + super + @app_title = "seminar" + end + def set_seminar + @seminar_signup_contribute = SeminarSignupContribute.find(params[:id]) rescue nil + @seminar_review_result = @seminar_signup_contribute.seminar_review_result rescue nil + @seminar_review_result = SeminarReviewResult.new if @seminar_review_result.nil? + @seminar = @seminar_signup_contribute.seminar_signup.seminar_main rescue nil + 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") + if (@seminar.organizer_id != current_user.member_profile_id rescue true) + render_401 + end + 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 edit + OrbitHelper.set_params(params,current_user) + @form_index = 0 + params[:controller] = "admin/seminars" + params[:action] = "edit_seminar_review" + end + + def update + @seminar_signup_contribute.update_attributes(seminar_signup_contribute_params) + redirect_to params[:referer_url] + end + + private + + def seminar_signup_contribute_params + params.require(:seminar_signup_contribute).permit! + end +end diff --git a/app/controllers/admin/seminar_submission_values_controller.rb b/app/controllers/admin/seminar_submission_values_controller.rb new file mode 100644 index 0000000..6537fa2 --- /dev/null +++ b/app/controllers/admin/seminar_submission_values_controller.rb @@ -0,0 +1,45 @@ +# encoding: utf-8 +class Admin::SeminarSubmissionValuesController < OrbitAdminController + include Admin::SeminarsHelper + before_action ->(module_app = @app_title) { set_variables module_app } + before_action :set_seminar,:check_manager_for_seminar + def initialize + super + @app_title = "seminar" + end + def set_seminar + @seminar_submission_value = SeminarSubmissionValue.find(params[:id]) rescue nil + @seminar_submission_field = @seminar_submission_value.seminar_submission_field rescue nil + @con = @seminar_submission_value.seminar_signup_contribute rescue nil + @seminar = @seminar_submission_value.seminar_submission_field.seminar_main rescue nil + 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") + if (@seminar.organizer_id != current_user.member_profile_id rescue true) + render_401 + end + end + end + def edit + OrbitHelper.set_params(params,current_user) + @form_index = 0 + render :layout =>false + end + + def update + begin + @seminar_submission_value.update_attributes(seminar_submission_value_params) + render :json => {:success=>true,:val=>@seminar_submission_value.get_value_by_locale(I18n.locale)} + rescue => e + render :json => {:success=>false,:error=>e.to_s} + end + end + + private + + def seminar_submission_value_params + params.require(:seminar_submission_values).permit!.values.first + end +end diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index 6c16491..a0ec7b5 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -124,16 +124,18 @@ class Admin::SeminarsController < OrbitAdminController if @seminar_signups.class != Array seminar_review = SeminarReview.where(:reviewer_id=>reviewer_id) seminar_signup_ids = seminar_review.pluck(:seminar_signup_ids).flatten + seminar_sessions = SeminarSession.where(:id.in=>seminar_review.pluck(:seminar_session_ids)) 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 + final_assign_signup_ids = SeminarSession.where(:id.in=>seminar_review.pluck(:seminar_session_ids).flatten,:seminar_main_id.in=>seminars.where(:assign_mode.in=>[1,2]).pluck(:id)).pluck(:seminar_signup_ids,:default_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) + @preferred_sessions = seminar_review.pluck(:session_ids).flatten end end end @@ -145,7 +147,7 @@ class Admin::SeminarsController < OrbitAdminController @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 + @hide_sessions = @hide_session_ids.zip(@hide_session_ids.map{|idx| seminar_main.summary_chioices[idx]}).to_h render :layout => false end end @@ -162,6 +164,7 @@ class Admin::SeminarsController < OrbitAdminController end def get_session_block @session_id = params[:session_id].to_i + @seminar_session = @seminar.seminar_sessions.where(:key=>@session_id).first unless (@seminar.session_show_ids.include?(@session_id) rescue false) @seminar.session_show_ids << @session_id @seminar.save @@ -184,20 +187,58 @@ class Admin::SeminarsController < OrbitAdminController session_id = params[:session_id].to_i seminar_main.save seminar_session = @seminar.seminar_sessions.where(:key=>session_id).first + @seminar_submission_value = nil + extra_infos = {} + if params[:contribute_id].present? + seminar_signup_contribute = SeminarSignupContribute.find(params[:contribute_id]) + seminar_submission_field = seminar_main.seminar_submission_fields.where(:markup=>"seminar_preferred_session").last + if seminar_submission_field + @seminar_submission_value = seminar_signup_contribute.seminar_submission_values.where(:seminar_submission_field_id=>seminar_submission_field.id).last + end + end 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) + if @seminar_submission_value + @seminar_submission_value.val = session_id.to_s + @seminar_submission_value.save + extra_infos = {"edit" => {"target"=>"[data-id=\"#{@seminar_submission_value.id}\"]","text"=>@seminar_submission_value.get_value_by_locale(I18n.locale)}} + else + @seminar_signup.final_sessions << session_id + @seminar_signup.seminar_session_ids << seminar_session.id + @seminar_signup.seminar_session_ids = @seminar_signup.seminar_session_ids.uniq + @seminar_signup.save + seminar_session.seminar_signup_contribute_ids.append(params[:contribute_id]) + seminar_signup_contribute.update(:final_session=>session_id) rescue nil + seminar_session.seminar_signup_ids << @seminar_signup.id.to_s + seminar_main.assign_mode = 1 if seminar_main.assign_mode != 2 + seminar_session.save + seminar_main.unassigned_mode_1_seminar_signup_ids.delete(@seminar_signup.id.to_s) + end + elsif params[:mode] == "remove_contribute" + if @seminar_submission_value + @seminar_submission_value.val = nil + @seminar_submission_value.save + extra_infos = {"edit" => {"target"=>"[data-id=\"#{@seminar_submission_value.id}\"]","text"=>""}} + else + seminar_session.seminar_signup_contribute_ids.delete(params[:contribute_id]) + seminar_signup_contribute.update(:final_session=>nil) rescue nil + seminar_session.save + end 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 + if @seminar_submission_value + @seminar_submission_value.val = nil + @seminar_submission_value.save + extra_infos = {"edit" => {"target"=>"[data-id=\"#{@seminar_submission_value.id}\"]","text"=>""}} + else + @seminar_signup.final_sessions.delete(session_id) + @seminar_signup.seminar_session_ids.delete(seminar_session.id) + seminar_session.seminar_signup_ids.delete(@seminar_signup.id.to_s) + seminar_session.seminar_signup_contribute_ids.delete(params[:contribute_id]) + seminar_signup_contribute.update(:final_session=>nil) rescue nil + @seminar_signup.save + seminar_session.save + seminar_main.assign_mode = 0 if seminar_main.seminar_sessions.where(:seminar_signup_ids.ne=>[]).count == 0 && seminar_main.assign_mode != 2 + seminar_main.unassigned_mode_1_seminar_signup_ids << @seminar_signup.id.to_s + end 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] @@ -209,7 +250,7 @@ class Admin::SeminarsController < OrbitAdminController render :json => {:success => false} and return end seminar_main.save - render :json => {:success => true} + render :json => {:success => true}.merge(extra_infos) end end def update_seminar_review @@ -222,11 +263,24 @@ class Admin::SeminarsController < OrbitAdminController @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]) + if(params[:contribute_id].present?) + @seminar_review.seminar_signup_contribute_ids << params[:contribute_id] + @seminar_review.remove_seminar_signup_contribute_ids.delete(params[:contribute_id]) + end 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] + if(params[:contribute_id].present?) + @seminar_review.seminar_signup_contribute_ids.delete(params[:contribute_id]) + @seminar_review.remove_seminar_signup_contribute_ids << params[:contribute_id] + end + elsif params[:mode] == "remove_contribute" + if(params[:contribute_id].present?) + @seminar_review.seminar_signup_contribute_ids.delete(params[:contribute_id]) + @seminar_review.remove_seminar_signup_contribute_ids << params[:contribute_id] + end elsif params[:mode] == "hide" if seminar_main.reviewer_show_ids.nil? seminar_main.reviewer_show_ids = seminar_main.reviewer_ids[0..1] @@ -332,8 +386,8 @@ 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| + seminar_signup_field_customs_params = seminar_main_params["seminar_signup_field_customs"].to_h rescue {} + seminar_main_params["seminar_signup_field_customs"].to_h.each do |k,v| v.delete "title" end seminar_main_params.delete(:seminar_signup_field_sets) @@ -377,13 +431,14 @@ class Admin::SeminarsController < OrbitAdminController def edit @seminar_items = SeminarItem.all @seminar = SeminarMain.where(id: params[:id]).first + except_attributes = ["final_sessions","preferred_sessions","seminar_session_ids","preferred_session","final_session","sort_number","abstract_number","presentation_type"] @seminar.seminar_signup_field_sets.each do |signup_field_set| - if !(SeminarSignup.attribute_names.include? signup_field_set.field_name) && signup_field_set.field_name != 'recaptcha' + if (!(SeminarSignup.attribute_names.include? signup_field_set.field_name) && signup_field_set.field_name != 'recaptcha') || except_attributes.include?(signup_field_set.field_name) signup_field_set.delete end end @seminar.seminar_submission_field_sets.each do |submission_field_set| - if !(SeminarSignupContribute.attribute_names.include? submission_field_set.field_name) + if (!(SeminarSignupContribute.attribute_names.include? submission_field_set.field_name)) || except_attributes.include?(submission_field_set.field_name) submission_field_set.delete end end @@ -432,6 +487,36 @@ class Admin::SeminarsController < OrbitAdminController end flash.now[:notice] = "Updated Fields" @seminar.seminar_submission_fields.each{|t| t.destroy if t["to_delete"] == true} + if @seminar.seminar_submission_fields.select{|sf| sf.markup == "seminar_preferred_session"}.count != 0 + @seminar.update(:assign_mode => 2) + default_sort_number = SeminarSignup.fields['sort_number'].options[:default] + SeminarSignup.where(:sort_number=>nil).update_all(:sort_number=>default_sort_number) + SeminarSignupContribute.where(:sort_number=>nil).update_all(:sort_number=>default_sort_number) + preferred_session_field = @seminar.seminar_submission_fields.select{|sf| sf.markup == "seminar_preferred_session"}.first + if preferred_session_field.seminar_submission_values.count != 0 + seminar_submission_values = preferred_session_field.seminar_submission_values.to_a + seminar_submission_values.each do |v| + if v.seminar_signup_contribute.nil? + v.destroy + next + end + next if v.val.to_i.to_s != v.val + seminar_session = @seminar.seminar_sessions.where(:key=>v.val.to_i).first + seminar_session.default_seminar_signup_ids << v.seminar_signup_contribute.seminar_signup_id.to_s + seminar_session.default_seminar_signup_ids = seminar_session.default_seminar_signup_ids.uniq + seminar_session.save + end + Thread.new do + SeminarMain.where(:update_old_flag=>false).each{|s| s.fix_old_data} + end + end + else + if seminar_main.seminar_sessions.where(:seminar_signup_ids.ne=>[]).count == 0 + @seminar.update(:assign_mode => 0) + else + @seminar.update(:assign_mode => 1) + end + end redirect_to admin_seminars_path else @@ -485,6 +570,12 @@ class Admin::SeminarsController < OrbitAdminController def seminar_signup @seminar_signups = [] + @filter_fields = {} + @summary_chioices = @seminar.enable_summary_choice ? @seminar.summary_chioices : [] + @enable_review_result = @seminar.enable_review_result + if @enable_review_result + @filter_fields["seminar.assigned_session"] = @summary_chioices.map.with_index{|summary_chioice,i| {:title=>summary_chioice, :id=>i}} rescue [] + end if params[:type] == "table" if params[:search].to_i != 0 @seminar_signups = @seminar.seminar_signups.where(:serial_number=>params[:search].to_i) @@ -492,10 +583,11 @@ class Admin::SeminarsController < OrbitAdminController @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]}/) + assigned_seminar_signups = @seminar.seminar_sessions.pluck(:seminar_signup_ids,:default_seminar_signup_ids).flatten + @seminar_signups = @seminar.seminar_signups.where(:id.nin=>assigned_seminar_signups) else unassigned_seminar_signup_ids = @seminar.unassigned_seminar_signup_ids - if @seminar.assign_mode == 1 + if @seminar.assign_mode != 0 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]}/) @@ -512,6 +604,16 @@ class Admin::SeminarsController < OrbitAdminController 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) + @preferred_sessions = @seminar_review.session_ids + if @enable_review_result + @filter_fields["seminar.assigned_session"] = @filter_fields["seminar.assigned_session"].select{|h| @preferred_sessions.include?(h[:id])} rescue [] + end + @append_contribute_ids = @seminar_review.seminar_signup_contribute_ids + @remove_contribute_ids = @seminar_review.remove_seminar_signup_contribute_ids + end + if params[:filters] && params[:filters][:assigned_session].present? + @preferred_sessions = params[:filters][:assigned_session].map{|s| s.to_i} + @seminar_signups = @seminar_signups.where(:preferred_sessions.in=> @preferred_sessions) end @seminar_signups = @seminar_signups.sort_ordered.page(params[:page]).per(10) if request.xhr? @@ -533,6 +635,9 @@ class Admin::SeminarsController < OrbitAdminController end def set_seminar_signup_admin_setting page = params[:type] || params[:page] + if params[:action] == "seminar_signup" + page = params[:type] + end 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? @@ -571,7 +676,9 @@ class Admin::SeminarsController < OrbitAdminController params.require(:seminar_main).permit! end def create_set (save_flag) + except_attributes = ["final_sessions","preferred_sessions","seminar_session_ids","preferred_session","final_session","sort_number","abstract_number","presentation_type"] SeminarSignup.attribute_names.each do |attr_signup| + next if except_attributes.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 @@ -616,6 +723,7 @@ class Admin::SeminarsController < OrbitAdminController end end SeminarSignupContribute.attribute_names.each do |attr_submission| + next if except_attributes.include?(attr_submission) if !(['_id', 'created_at', 'updated_at','seminar_signup_id'].include? attr_submission) signup_set = @seminar.seminar_submission_field_sets.select{|v| v.field_name==attr_submission } if signup_set.length==0 diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index 657bd18..fdf0d49 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -178,11 +178,33 @@ class SeminarsController < ApplicationController if !@signup.blank? redirect_to "#{params[:referer_url]}", :notice => 'mail已存在' else - redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') + referer_url = params[:referer_url].to_s + if referer_url.split("/").last.include?("?") + uri_query = referer_url.split("?").last.gsub(/notice=[^&]*/,'') + if uri_query == "" + referer_url = referer_url.split("?")[0...-1].join("?") + "?notice=#{t('recaptcha.errors.verification_failed')}" + else + referer_url = referer_url.split("?")[0...-1].join("?") + "¬ice=#{t('recaptcha.errors.verification_failed')}" + end + else + referer_url = referer_url + "?notice=#{t('recaptcha.errors.verification_failed')}" + end + redirect_to referer_url, :notice => t('recaptcha.errors.verification_failed') end end else - redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') + referer_url = params[:referer_url].to_s + if referer_url.split("/").last.include?("?") + uri_query = referer_url.split("?").last.gsub(/notice=[^&]*/,'') + if uri_query == "" + referer_url = referer_url.split("?")[0...-1].join("?") + "?notice=#{t('recaptcha.errors.verification_failed')}" + else + referer_url = referer_url.split("?")[0...-1].join("?") + "¬ice=#{t('recaptcha.errors.verification_failed')}" + end + else + referer_url = referer_url + "?notice=#{t('recaptcha.errors.verification_failed')}" + end + redirect_to referer_url, :notice => t('recaptcha.errors.verification_failed') end end diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index 3ac3c1e..5d100d9 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -142,7 +142,16 @@ module Admin::SeminarsFieldHelper end.join.html_safe end end - + def render_seminar_preferred_session + @prefiled_value ||=[] + @prefiled_value = Array(@prefiled_value) + control_group_wrapper do + @member.summary_chioices.map.with_index do |value,key| + key = key.to_s + label_tag("#{get_basic_field_name_org}_#{self.id}_#{key}",radio_button_tag(get_field_name_base, key , ((@prefiled_value.include?(key) || @prefiled_value.include?(key.to_i)) ? true : false), {:required=>@require,:id=>"#{get_basic_field_name_org}_#{self.id}_#{key}"})+value,@markup_options.merge(:class=>"radio inline")) + end.join.html_safe + end if @member.enable_summary_choice + end def render_select prompt = @panel_setting["initial"][I18n.locale.to_s] rescue nil @markup_options.merge!(:prompt => prompt) unless prompt.nil? @@ -449,7 +458,7 @@ protected if self.markup == "address" return true else - LIST[:markups][markup]["muti_lang_input_supprt"] and !(get_data["cross_lang"] == "true") + $seminar_list[:markups][markup]["muti_lang_input_supprt"] and !(get_data["cross_lang"] == "true") end end diff --git a/app/helpers/admin/seminars_helper.rb b/app/helpers/admin/seminars_helper.rb index 15f3dfd..d49a841 100644 --- a/app/helpers/admin/seminars_helper.rb +++ b/app/helpers/admin/seminars_helper.rb @@ -1,4 +1,6 @@ module Admin::SeminarsHelper + data = File.open(File.join(File.dirname(__FILE__), '../../../config', 'list.yml')).read + $seminar_list = YAML::load(ERB.new(data).result(binding)).symbolize_keys def display_format_string(num, str_length) return format("%0#{str_length}d", num % (10^str_length)) end diff --git a/app/helpers/admin/seminars_values_helper.rb b/app/helpers/admin/seminars_values_helper.rb index 7743617..f076cd2 100644 --- a/app/helpers/admin/seminars_values_helper.rb +++ b/app/helpers/admin/seminars_values_helper.rb @@ -1,4 +1,8 @@ module Admin::SeminarsValuesHelper + def show_seminar_type_panel(attribute_field,type) + markup = attribute_field.markup + $seminar_list[:markups][markup]["panel"] == type ? type : [type,'hide'].join(" ") + end def show_west_calender(from_to=nil) case from_to when :to diff --git a/app/models/seminar_main.rb b/app/models/seminar_main.rb index 92f60e9..10373dc 100644 --- a/app/models/seminar_main.rb +++ b/app/models/seminar_main.rb @@ -45,7 +45,8 @@ class SeminarMain 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來分配 + field :assign_mode, :type => Integer, :default => 0 # 0 => 用default signup ids來分配 ,1 => 用final_session來分配, 2 => 用final_session來分配(當有preffered session欄位時) + field :update_old_flag, :type => Boolean, :default => false belongs_to :seminar_item belongs_to :organizer , :class_name=>"MemberProfile", :foreign_key => :organizer_id has_many :seminar_sessions, :autosave => true, :dependent => :destroy @@ -178,6 +179,13 @@ class SeminarMain if self["reviewer_ids"].nil? self["reviewer_ids"] = seminar_reviews.pluck(:reviewer_id).flatten.select{|s| !s.nil?}.to_a save_flag = true + else + self["reviewer_ids"].each do |reviewer_id| + seminar_review_to_destroy = seminar_reviews.where(:reviewer_id=>reviewer_id)[1] + if seminar_review_to_destroy + seminar_review_to_destroy.destroy + end + end 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 @@ -264,12 +272,12 @@ class SeminarMain 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 + need_change_seminar_signups = self.seminar_signups.where(:seminar_session_ids.nin=>[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 + if seminar_signup.seminar_session_ids.present? + seminar_signup.seminar_session_ids = seminar_signup.seminar_session_ids.map{|id| @records_all["seminar_session_ids"][id]} rescue [] end end count_array = (0...self.seminar_reviews.to_a.count).to_a @@ -293,118 +301,114 @@ class SeminarMain 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) + 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 - 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 + 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 - 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 + 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 - 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)) + relations_fields.each do |f| + no_dup_flag = false + if clone_target.relations[f].macro == :belongs_to || clone_target.relations[f].macro == :has_one + 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 - 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? + 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_one + next if self.except_clone_relations.to_s.include?(f) + need_clone_relation = clone_target.send(f) + clone_relation = new_object.send(f) + clone_relation = need_clone_relation.dup if clone_relation.nil? initialize_fields.each do |f| clone_relation.send("#{f}=",nil) if clone_relation.fields.keys.include?(f) end @@ -425,28 +429,76 @@ def clone_new_for_object(object,clone_target=nil,clone_mode=false) 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]) + new_object.send("#{f}=",clone_relation) + 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 - new_object.send("#{f}=",clone_relations) - else - new_object.send("#{f}=",clone_relations) + 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 - 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 + new_object.copy_id = clone_target.id if new_object.fields.keys.include?("copy_id") + return new_object, clone_target end - new_object.copy_id = clone_target.id if new_object.fields.keys.include?("copy_id") - return new_object, clone_target + end + def fix_old_data + unless self.update_old_flag + self.seminar_signups.each do |ss| + ss.final_sessions = Array(ss.final_session) + ss.seminar_session_ids = Array(ss.seminar_session_id) + if ss.final_session + ss.seminar_signup_contributes.update_all(:final_session=>final_session) + SeminarSubmissionValue.where(:seminar_signup_contribute_id.in=> ss.seminar_signup_contributes.pluck(:id)).each{|ssv| ssv.save} + end + ss.save + end + self.seminar_sessions.each{|ss| ss.fix_seminar_signup_contribute_ids} + self.update(:update_old_flag=>true) + end + end + def enable_review_result + self.assign_mode == 2 end end \ No newline at end of file diff --git a/app/models/seminar_review.rb b/app/models/seminar_review.rb index 1f98da5..14d52e9 100644 --- a/app/models/seminar_review.rb +++ b/app/models/seminar_review.rb @@ -10,6 +10,8 @@ class SeminarReview field :reviewer_id field :seminar_signup_ids, :type => Array, :default => [] field :remove_seminar_signup_ids, :type => Array, :default => [] + field :seminar_signup_contribute_ids, :type => Array, :default => [] + field :remove_seminar_signup_contribute_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 => [] @@ -72,9 +74,11 @@ class SeminarReview 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 + if (self.default_topics.include?("seminar_signup_contributes.description") && self.seminar_main.assign_mode != 0) || mode != 0 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 + default_seminar_signup_ids = SeminarSession.where(:id.in=>self.seminar_session_ids).pluck(:default_seminar_signup_ids).flatten + default_seminar_signup_ids = SeminarSignup.where(:seminar_session_id=>nil,:id.in=>default_seminar_signup_ids).pluck(:id).map{|id| id.to_s} rescue [] + result = final_assign_signup_ids + default_seminar_signup_ids + self.seminar_signup_ids - self.remove_seminar_signup_ids result = result.uniq else result = all_seminar_signup_ids @@ -91,4 +95,24 @@ class SeminarReview self.default_seminar_signup_ids << sid end end + def fix_assign + seminar_signups = SeminarSignup.where(:id.in=>self.seminar_signup_ids) + self.seminar_signup_ids = seminar_signups.pluck(:id).map{|id| id.to_s} + seminar_signups = seminar_signups.to_a + self.seminar_signup_contribute_ids = seminar_signups.map{|ss| ss.seminar_signup_contribute_ids}.flatten.map{|id| id.to_s} + + remove_seminar_signups = SeminarSignup.where(:id.in=>self.remove_seminar_signup_ids) + self.remove_seminar_signup_ids = remove_seminar_signups.pluck(:id).map{|id| id.to_s} + remove_seminar_signups = remove_seminar_signups.to_a + self.remove_seminar_signup_contribute_ids = remove_seminar_signups.map{|ss| ss.seminar_signup_contribute_ids}.flatten.map{|id| id.to_s} + + self.save + end + def clear_all_assign + self.seminar_signup_ids = [] + self.remove_seminar_signup_ids = [] + self.seminar_signup_contribute_ids = [] + self.remove_seminar_signup_contribute_ids = [] + self.save + end end diff --git a/app/models/seminar_review_result.rb b/app/models/seminar_review_result.rb new file mode 100644 index 0000000..2d69a8f --- /dev/null +++ b/app/models/seminar_review_result.rb @@ -0,0 +1,17 @@ +class SeminarReviewResult + + include Mongoid::Document + include Mongoid::Timestamps + PRESENTATION_TYPES = ["oral" , "poster"] + field :sort_number , type: Integer , default: -1 + field :abstract_number , type: String , default: "" + field :presentation_type , type: String , default: "" #oral , poster + belongs_to :seminar_signup_contribute + before_save do + self.sort_number = self.abstract_number.match(/[-]{0,1}\d+/)[0].to_i rescue -1 + end + after_save do + SeminarSignupContribute.where(:id=>self.seminar_signup_contribute_id).update_all(:sort_number=>self.sort_number,:abstract_number=>self.abstract_number,:presentation_type=>self.presentation_type) + SeminarSignup.where(:id.in=>SeminarSignupContribute.where(:id=>self.seminar_signup_contribute_id).pluck(:seminar_signup_id)).update_all(:sort_number=>self.sort_number) + end +end \ No newline at end of file diff --git a/app/models/seminar_session.rb b/app/models/seminar_session.rb index c31521e..883cbca 100644 --- a/app/models/seminar_session.rb +++ b/app/models/seminar_session.rb @@ -7,7 +7,14 @@ class SeminarSession field :key belongs_to :seminar_main field :seminar_signup_ids, :type => Array, :default => [] + field :seminar_signup_contribute_ids, :type => Array, :default => [] + field :default_seminar_signup_ids, :type => Array, :default => [] def seminar_signups - SeminarSignup.where(:id.in=>seminar_signup_ids) + SeminarSignup.any_of({:id.in=>self.seminar_signup_ids},{:preferred_sessions=>self.key,:seminar_session_ids.in=>[[],nil]}) + end + def fix_seminar_signup_contribute_ids + @seminar_signup_ids = SeminarSignup.where(:id.in=>self.seminar_signup_ids).pluck(:id).map{|id| id.to_s} + self.seminar_signup_contribute_ids = SeminarSignupContribute.where(:seminar_signup_id.in=>@seminar_signup_ids).pluck(:id).map{|id| id.to_s} + self.save end end diff --git a/app/models/seminar_signup.rb b/app/models/seminar_signup.rb index 5bfa754..89ab028 100644 --- a/app/models/seminar_signup.rb +++ b/app/models/seminar_signup.rb @@ -4,6 +4,8 @@ class SeminarSignup include Mongoid::Document include Mongoid::Timestamps + field :sort_number , type: Integer, default: 10000 + field :status field :name # become Last Name for TICC field :tel, type: String # become First Name for TICC @@ -15,15 +17,18 @@ class SeminarSignup field :password field :note, localize: true field :serial_number - field :final_session + field :final_session #only store old data , not used + field :final_sessions + field :preferred_sessions, type: Array, default: [] belongs_to :seminar_main - field :seminar_session_id + field :seminar_session_id #only store old data , not used + field :seminar_session_ids, type: Array, default: [] 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) } + scope :sort_ordered, ->{ order_by(:sort_number=>1,:created_at=>1) } before_create do unit = self.unit_translations.values.select{|v| v.present?}.first @@ -64,4 +69,8 @@ class SeminarSignup def display_format_string(num, str_length) return format("%0#{str_length}d", num) end + def set_preferred_sessions + self.preferred_sessions = self.seminar_signup_contributes.pluck(:preferred_session) + self.save + end end diff --git a/app/models/seminar_signup_contribute.rb b/app/models/seminar_signup_contribute.rb index b282142..6ebb194 100644 --- a/app/models/seminar_signup_contribute.rb +++ b/app/models/seminar_signup_contribute.rb @@ -4,10 +4,40 @@ class SeminarSignupContribute include Mongoid::Timestamps field :title + field :abstract_number , type: String , default: "" + field :presentation_type , type: String , default: "" + field :sort_number , type: Integer, default: 10000 mount_uploader :file, AssetUploader field :description - + field :preferred_session + field :final_session belongs_to :seminar_signup + has_one :seminar_review_result, dependent: :destroy + accepts_nested_attributes_for :seminar_review_result has_many :seminar_submission_values, autosave: true, dependent: :destroy accepts_nested_attributes_for :seminar_submission_values, :allow_destroy => true + scope :sort_ordered, ->{ order_by(:sort_number=>1,:created_at=>1) } + after_destroy do + seminar_signup = self.seminar_signup.reload rescue nil + seminar_signup_id = seminar_signup.id.to_s + seminar_submission_field_ids = seminar_signup.seminar_main.seminar_submission_fields.where(:markup=>"seminar_preferred_session").pluck(:id) rescue [] + if seminar_signup && seminar_submission_field_ids.count != 0 + seminar_signup_contribute_ids = seminar_signup.seminar_signup_contributes.pluck(:id) + seminar_submission_values = SeminarSubmissionValue.where(:seminar_signup_contribute_id.in=>seminar_signup_contribute_ids,:seminar_submission_field_id.in=>seminar_submission_field_ids).to_a + seminar_sessions = seminar_signup.seminar_main.seminar_sessions.to_a + seminar_sessions.each do |ss| + ss.default_seminar_signup_ids.delete(seminar_signup_id) + ss.save(:validate=>false) + end + seminar_submission_value = seminar_submission_values.last + val = seminar_submission_value["val"].to_i rescue nil + unless val.nil? + seminar_session = seminar_sessions.select{|ss| ss.key == val}.first + if seminar_session + seminar_session.default_seminar_signup_ids << seminar_signup_id + seminar_session.save(:validate=>false) + end + end + end + end end \ No newline at end of file diff --git a/app/models/seminar_signup_field.rb b/app/models/seminar_signup_field.rb index ca6c3fb..60ff2d1 100644 --- a/app/models/seminar_signup_field.rb +++ b/app/models/seminar_signup_field.rb @@ -22,7 +22,7 @@ class SeminarSignupField field :typeC, type: Hash, default: {calendar: "west_calendar", format: "format3"} field :typeD, type: Hash, default: {cross_lang: false} field :typeE, type: Hash, default: {} - + field :typeF, type: Hash, default: {} belongs_to :seminar_main has_many :seminar_signup_values, autosave: true, dependent: :destroy accepts_nested_attributes_for :seminar_signup_values, :allow_destroy => true @@ -71,7 +71,7 @@ class SeminarSignupField end def panel - panel = LIST[:markups][self[:markup]]["panel"] + panel = $seminar_list[:markups][self[:markup]]["panel"] end def get_data diff --git a/app/models/seminar_submission_field.rb b/app/models/seminar_submission_field.rb index 07e8e5a..cd6968d 100644 --- a/app/models/seminar_submission_field.rb +++ b/app/models/seminar_submission_field.rb @@ -22,7 +22,7 @@ class SeminarSubmissionField field :typeC, type: Hash, default: {calendar: "west_calendar", format: "format3"} field :typeD, type: Hash, default: {cross_lang: false} field :typeE, type: Hash, default: {} - + field :typeF, type: Hash, default: {cross_lang: "true"} belongs_to :seminar_main has_many :seminar_submission_values, autosave: true, dependent: :destroy accepts_nested_attributes_for :seminar_submission_values, :allow_destroy => true @@ -96,7 +96,7 @@ class SeminarSubmissionField end def panel - panel = LIST[:markups][self[:markup]]["panel"] + panel = $seminar_list[:markups][self[:markup]]["panel"] end def get_data diff --git a/app/models/seminar_submission_value.rb b/app/models/seminar_submission_value.rb index 5119fce..dff233b 100644 --- a/app/models/seminar_submission_value.rb +++ b/app/models/seminar_submission_value.rb @@ -6,12 +6,34 @@ class SeminarSubmissionValue include ::Admin::SeminarsValuesHelper field :key, type: String - + field :val belongs_to :seminar_submission_field belongs_to :seminar_signup_contribute before_save :check_key before_save :data_proc - + after_save do + if (self.seminar_submission_field.markup == "seminar_preferred_session" rescue false) && self.seminar_signup_contribute + val_change = self.val_change + self.seminar_signup_contribute.update(:preferred_session=>val.to_i) + self.seminar_signup_contribute.seminar_signup.set_preferred_sessions + unless val_change.nil? + old_val = val_change[0] + new_val = val_change[1] + seminar_signup_id = self.seminar_signup_contribute.seminar_signup_id.to_s + seminar_sessions = self.seminar_submission_field.seminar_main.seminar_sessions.to_a + old_seminar_session = seminar_sessions.select{|ss| ss.key.to_s == old_val}.first + if old_seminar_session + old_seminar_session.default_seminar_signup_ids.delete seminar_signup_id + old_seminar_session.save + end + new_seminar_session = seminar_sessions.select{|ss| ss.key.to_s == new_val}.first + if new_seminar_session + new_seminar_session.default_seminar_signup_ids << seminar_signup_id + new_seminar_session.save + end + end + end + end def add_more_counter index_max = self["val"].count rescue 0 index_max == 0 ? 1 : index_max @@ -26,7 +48,7 @@ class SeminarSubmissionValue else self.seminar_submission_field.get_data["cross_lang"] =="true" ? self["val"] : Hash[site.valid_locales.collect{|lang| [lang,self[lang.to_sym]]}] end - when 'select','radio_button','address' + when 'select','radio_button','address','seminar_preferred_session' self["val"] when 'date' if !self["val"].blank? and !self["val"]['(1i)'].blank? @@ -54,6 +76,8 @@ class SeminarSubmissionValue 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?("seminar_preferred_session") + field_value = seminar_submission_field.seminar_main.summary_chioices[self.value.to_i] 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") @@ -129,7 +153,8 @@ class SeminarSubmissionValue when "radio_button" markup_values = seminar_submission_field.markup_value markup_values[self.value][locale.to_s] - + when "seminar_preferred_session" + seminar_submission_field.seminar_main.summary_chioices[self.value.to_i] rescue nil when "checkbox" markup_values = seminar_submission_field.markup_value self.value.collect{|key| markup_values["#{key}"][I18n.locale]}.join(",") @@ -195,7 +220,7 @@ end end end # of self.seminar_submission_field.add_more - when 'select','date','radio_button' + when 'select','date','radio_button','seminar_preferred_session' self["val"] = self[:temp_data] when 'checkbox' self["val"] = self[:temp_data].keys diff --git a/app/views/admin/seminar_review_results/edit.html.erb b/app/views/admin/seminar_review_results/edit.html.erb new file mode 100644 index 0000000..8839c84 --- /dev/null +++ b/app/views/admin/seminar_review_results/edit.html.erb @@ -0,0 +1,132 @@ + +<%= form_for @seminar_signup_contribute, url: admin_seminar_review_result_path(@seminar_signup_contribute), html: {class: "form-horizontal main-forms"} do |f| %> + <% seminar_signup = @seminar_signup_contribute.seminar_signup %> + <% referer_url = request.referer %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/seminar_submission_values/edit.html.erb b/app/views/admin/seminar_submission_values/edit.html.erb new file mode 100644 index 0000000..65d6101 --- /dev/null +++ b/app/views/admin/seminar_submission_values/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @seminar_submission_value, url: admin_seminar_submission_value_path(@seminar_submission_value), html: {class: "form-horizontal main-forms",id: "jquery_form"} do |f| %> +