Fix known bug.

This commit is contained in:
BoHung Chiu 2021-08-22 16:48:49 +08:00
parent f99f9a199e
commit 12b9e91751
5 changed files with 78 additions and 73 deletions

View File

@ -286,6 +286,9 @@ $(function() {
}; };
attributesHeaderLength = $('.attributes:not(:hidden)').length+1; attributesHeaderLength = $('.attributes:not(:hidden)').length+1;
attributesLength = $('#attributes-area .attributes').length; attributesLength = $('#attributes-area .attributes').length;
if(templateType == null){
templateType = "typeA";
}
$("#template-attributes").tmpl(setData(attributesLength, templateType, appendIndex)).appendTo( "#attributes-area" ); $("#template-attributes").tmpl(setData(attributesLength, templateType, appendIndex)).appendTo( "#attributes-area" );
$('.toggle-check').togglebox(); $('.toggle-check').togglebox();
}); });
@ -434,7 +437,6 @@ $(function() {
// appendIndex = appendIndex.split("]["); // appendIndex = appendIndex.split("][");
// appendIndex = parseInt(appendIndex[appendIndex.length-2])+1; // appendIndex = parseInt(appendIndex[appendIndex.length-2])+1;
appendIndex = parseInt(appendIndex.match(/[^[\D\]]+(?=])/g)[1])+1; appendIndex = parseInt(appendIndex.match(/[^[\D\]]+(?=])/g)[1])+1;
console.log(appendIndex)
attributeIndex = $(this).closest('.attributes').index(); attributeIndex = $(this).closest('.attributes').index();
templateType = $(this).closest('.attributes').find('.dataType').children("option:selected").attr('ref'); 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')); $("#template-input-append").tmpl(setData(attributeIndex, templateType, appendIndex)).appendTo($(this).closest('.controls').find('.add-target'));

View File

@ -531,82 +531,85 @@ class Admin::SeminarsController < OrbitAdminController
end end
def update def update
@seminar_params = seminar_params rescue {}
params[:seminar_main][:registration_status] = (params[:seminar_main][:registration_status] ? params[:seminar_main][:registration_status] : []) if @seminar_params.count != 0
@seminar_params[:registration_status] = (@seminar_params[:registration_status] ? @seminar_params[:registration_status] : [])
uid = params[:id].split('-').last uid = params[:id].split('-').last
@seminar = SeminarMain.find_by(:uid=>uid) @seminar = SeminarMain.find_by(:uid=>uid)
seminar_params["reviewer_ids"] = [] if seminar_params["reviewer_ids"].nil? if @seminar_params.has_key?("title_translations")
seminar_params["organizer_id"] = nil if seminar_params["organizer_id"].nil? @seminar_params["reviewer_ids"] = [] if @seminar_params["reviewer_ids"].nil?
if params[:seminar_main][:seminar_signup_fields] @seminar_params["organizer_id"] = nil if @seminar_params["organizer_id"].nil?
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 end
flash.now[:notice] = "Updated Fields" if @seminar_params[:seminar_signup_fields]
@seminar.seminar_signup_fields.each{|t| t.destroy if t["to_delete"] == true} @seminar_params[:seminar_signup_fields].each do |a|
@field_name = 'seminar_main'
redirect_to admin_seminars_path field_status = a.last[:id].present?
elsif params[:seminar_main][:seminar_submission_fields] @attribute_field = SeminarSignupField.add_seminar_signup_field(@seminar, a.last, a.last[:id], field_status)
params[:seminar_main][:seminar_submission_fields].each do |a| @attribute = @seminar
@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 end
else flash.now[:notice] = "Updated Fields"
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)
@seminar.seminar_signup_fields.each{|t| t.destroy if t["to_delete"] == true} @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 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
end end
redirect_to admin_seminars_path
end end
def set_write_off def set_write_off

View File

@ -7,7 +7,7 @@
<% content_for :page_specific_javascript do -%> <% content_for :page_specific_javascript do -%>
<%= javascript_include_tag "lib/jquery.tmpl.min.js" %> <%= javascript_include_tag "lib/jquery.tmpl.min.js" %>
<%= javascript_include_tag "field-forms.js" %> <%= javascript_include_tag "seminar-field-forms.js" %>
<% end -%> <% end -%>
<%= form_for @attribute,:url => admin_seminar_path(@attribute) , :html => { :class=> "form-horizontal main-forms" } do |f| %> <%= form_for @attribute,:url => admin_seminar_path(@attribute) , :html => { :class=> "form-horizontal main-forms" } do |f| %>

View File

@ -7,7 +7,7 @@
<% content_for :page_specific_javascript do -%> <% content_for :page_specific_javascript do -%>
<%= javascript_include_tag "lib/jquery.tmpl.min.js" %> <%= javascript_include_tag "lib/jquery.tmpl.min.js" %>
<%= javascript_include_tag "field-forms-submission.js" %> <%= javascript_include_tag "seminar-field-forms-submission.js" %>
<% end -%> <% end -%>
<%= form_for @attribute,:url => admin_seminar_path(@attribute) , :html => { :class=> "form-horizontal main-forms" } do |f| %> <%= form_for @attribute,:url => admin_seminar_path(@attribute) , :html => { :class=> "form-horizontal main-forms" } do |f| %>
<% if flash.now[:notice].present? %> <% if flash.now[:notice].present? %>