From 12b9e91751713d91da04af88667f970793f55bab Mon Sep 17 00:00:00 2001 From: Bohung Date: Sun, 22 Aug 2021 16:48:49 +0800 Subject: [PATCH] Fix known bug. --- ...n.js => seminar-field-forms-submission.js} | 0 ...{field-forms.js => seminar-field-forms.js} | 4 +- app/controllers/admin/seminars_controller.rb | 143 +++++++++--------- .../seminars/seminar_signup_field.html.erb | 2 +- .../seminar_submission_field.html.erb | 2 +- 5 files changed, 78 insertions(+), 73 deletions(-) rename app/assets/javascripts/{field-forms-submission.js => seminar-field-forms-submission.js} (100%) rename app/assets/javascripts/{field-forms.js => seminar-field-forms.js} (99%) diff --git a/app/assets/javascripts/field-forms-submission.js b/app/assets/javascripts/seminar-field-forms-submission.js similarity index 100% rename from app/assets/javascripts/field-forms-submission.js rename to app/assets/javascripts/seminar-field-forms-submission.js diff --git a/app/assets/javascripts/field-forms.js b/app/assets/javascripts/seminar-field-forms.js similarity index 99% rename from app/assets/javascripts/field-forms.js rename to app/assets/javascripts/seminar-field-forms.js index 1c62186..455fad3 100644 --- a/app/assets/javascripts/field-forms.js +++ b/app/assets/javascripts/seminar-field-forms.js @@ -286,6 +286,9 @@ $(function() { }; attributesHeaderLength = $('.attributes:not(:hidden)').length+1; attributesLength = $('#attributes-area .attributes').length; + if(templateType == null){ + templateType = "typeA"; + } $("#template-attributes").tmpl(setData(attributesLength, templateType, appendIndex)).appendTo( "#attributes-area" ); $('.toggle-check').togglebox(); }); @@ -434,7 +437,6 @@ $(function() { // appendIndex = appendIndex.split("]["); // appendIndex = parseInt(appendIndex[appendIndex.length-2])+1; appendIndex = parseInt(appendIndex.match(/[^[\D\]]+(?=])/g)[1])+1; - console.log(appendIndex) attributeIndex = $(this).closest('.attributes').index(); templateType = $(this).closest('.attributes').find('.dataType').children("option:selected").attr('ref'); $("#template-input-append").tmpl(setData(attributeIndex, templateType, appendIndex)).appendTo($(this).closest('.controls').find('.add-target')); diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index de32149..dce2089 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -531,82 +531,85 @@ class Admin::SeminarsController < OrbitAdminController 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' - field_status = a.last[:id].present? - @attribute_field = SeminarSignupField.add_seminar_signup_field(@seminar, a.last, a.last[:id], field_status) - @attribute = @seminar + @seminar_params = seminar_params rescue {} + if @seminar_params.count != 0 + @seminar_params[:registration_status] = (@seminar_params[:registration_status] ? @seminar_params[:registration_status] : []) + uid = params[:id].split('-').last + @seminar = SeminarMain.find_by(:uid=>uid) + if @seminar_params.has_key?("title_translations") + @seminar_params["reviewer_ids"] = [] if @seminar_params["reviewer_ids"].nil? + @seminar_params["organizer_id"] = nil if @seminar_params["organizer_id"].nil? end - flash.now[:notice] = "Updated Fields" - @seminar.seminar_signup_fields.each{|t| t.destroy if t["to_delete"] == true} - - redirect_to admin_seminars_path - elsif params[:seminar_main][:seminar_submission_fields] - params[:seminar_main][:seminar_submission_fields].each do |a| - @field_name = 'seminar_main' - field_status = a.last[:id].present? - @attribute_field = SeminarSubmissionField.add_seminar_signup_field(@seminar, a.last, a.last[:id], field_status) - @attribute = @seminar - 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 + if @seminar_params[:seminar_signup_fields] + @seminar_params[:seminar_signup_fields].each do |a| + @field_name = 'seminar_main' + field_status = a.last[:id].present? + @attribute_field = SeminarSignupField.add_seminar_signup_field(@seminar, a.last, a.last[:id], field_status) + @attribute = @seminar 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 - - if !seminar_params['seminar_links_attributes'].nil? - seminar_params['seminar_links_attributes'].each do |idx,link| - seminar_params['seminar_links_attributes'].delete(idx.to_s) if link['url'].blank? - end - end - - @seminar.update_user_id = current_user.id - if @seminar.update_attributes(seminar_params) + flash.now[:notice] = "Updated Fields" @seminar.seminar_signup_fields.each{|t| t.destroy if t["to_delete"] == true} - redirect_to params['referer_url'] + + redirect_to admin_seminars_path and return + elsif @seminar_params[:seminar_submission_fields] + params[:seminar_main][:seminar_submission_fields].each do |a| + @field_name = 'seminar_main' + field_status = a.last[:id].present? + @attribute_field = SeminarSubmissionField.add_seminar_signup_field(@seminar, a.last, a.last[:id], field_status) + @attribute = @seminar + 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 and return else - flash.now[:error] = t('update.error.category') - render action: :edit + + if !seminar_params['seminar_links_attributes'].nil? + seminar_params['seminar_links_attributes'].each do |idx,link| + seminar_params['seminar_links_attributes'].delete(idx.to_s) if link['url'].blank? + end + end + + @seminar.update_user_id = current_user.id + if @seminar.update_attributes(seminar_params) + @seminar.seminar_signup_fields.each{|t| t.destroy if t["to_delete"] == true} + redirect_to params['referer_url'] and return + else + flash.now[:error] = t('update.error.category') + render action: :edit and return + end end end - + redirect_to admin_seminars_path end def set_write_off diff --git a/app/views/admin/seminars/seminar_signup_field.html.erb b/app/views/admin/seminars/seminar_signup_field.html.erb index 330b6f4..9fe7b3c 100644 --- a/app/views/admin/seminars/seminar_signup_field.html.erb +++ b/app/views/admin/seminars/seminar_signup_field.html.erb @@ -7,7 +7,7 @@ <% content_for :page_specific_javascript do -%> <%= javascript_include_tag "lib/jquery.tmpl.min.js" %> - <%= javascript_include_tag "field-forms.js" %> + <%= javascript_include_tag "seminar-field-forms.js" %> <% end -%> <%= form_for @attribute,:url => admin_seminar_path(@attribute) , :html => { :class=> "form-horizontal main-forms" } do |f| %> diff --git a/app/views/admin/seminars/seminar_submission_field.html.erb b/app/views/admin/seminars/seminar_submission_field.html.erb index c4063b1..37b57d5 100644 --- a/app/views/admin/seminars/seminar_submission_field.html.erb +++ b/app/views/admin/seminars/seminar_submission_field.html.erb @@ -7,7 +7,7 @@ <% content_for :page_specific_javascript do -%> <%= javascript_include_tag "lib/jquery.tmpl.min.js" %> - <%= javascript_include_tag "field-forms-submission.js" %> + <%= javascript_include_tag "seminar-field-forms-submission.js" %> <% end -%> <%= form_for @attribute,:url => admin_seminar_path(@attribute) , :html => { :class=> "form-horizontal main-forms" } do |f| %> <% if flash.now[:notice].present? %>