diff --git a/app/controllers/admins/disciplines_controller.rb b/app/controllers/admins/disciplines_controller.rb index 9094eca2c..7681bea42 100644 --- a/app/controllers/admins/disciplines_controller.rb +++ b/app/controllers/admins/disciplines_controller.rb @@ -20,7 +20,15 @@ class Admins::DisciplinesController < Admins::BaseController name = params[:discipline][:name].to_s.strip current_discipline.update_attributes!(name: name) else - current_discipline.update_attributes!(setting_params) + ActiveRecord::Base.transaction do + current_discipline.update_attributes!(setting_params) + current_discipline.sub_disciplines.each do |sub| + sub.tag_disciplines.each do |tag| + tag.update_attributes!(setting_params) + end + sub.update_attributes!(setting_params) + end + end end @disciplines = Discipline.all end diff --git a/app/controllers/admins/sub_disciplines_controller.rb b/app/controllers/admins/sub_disciplines_controller.rb index 64b6f1292..25c268ca6 100644 --- a/app/controllers/admins/sub_disciplines_controller.rb +++ b/app/controllers/admins/sub_disciplines_controller.rb @@ -21,7 +21,12 @@ class Admins::SubDisciplinesController < Admins::BaseController name = params[:sub_discipline][:name].to_s.strip current_sub_discipline.update_attributes!(name: name) else - current_sub_discipline.update_attributes!(setting_params) + ActiveRecord::Base.transaction do + current_sub_discipline.update_attributes!(setting_params) + current_sub_discipline.tag_disciplines.each do |tag| + tag.update_attributes!(setting_params) + end + end end @sub_disciplines = current_sub_discipline.discipline&.sub_disciplines end diff --git a/app/models/tag_discipline.rb b/app/models/tag_discipline.rb index 2f279aafd..07faca5c3 100644 --- a/app/models/tag_discipline.rb +++ b/app/models/tag_discipline.rb @@ -1,3 +1,7 @@ class TagDiscipline < ApplicationRecord belongs_to :sub_discipline + + def discipline + sub_discipline&.discipline + end end diff --git a/app/views/admins/sub_disciplines/shared/_list.html.erb b/app/views/admins/sub_disciplines/shared/_list.html.erb index 1ffeeb090..a56c856f2 100644 --- a/app/views/admins/sub_disciplines/shared/_list.html.erb +++ b/app/views/admins/sub_disciplines/shared/_list.html.erb @@ -17,9 +17,9 @@ <%= link_to sub.name, admins_tag_disciplines_path(sub_discipline_id: sub), :title => sub.name %> - <%= check_box_tag :subject,!sub.subject,sub.subject,remote:true,data:{id:sub.id},class:"sub-discipline-source-form" %> - <%= check_box_tag :shixun,!sub.shixun,sub.shixun,remote:true,data:{id:sub.id},class:"sub-discipline-source-form" %> - <%= check_box_tag :question,!sub.question,sub.question,remote:true,data:{id:sub.id},class:"sub-discipline-source-form" %> + <%= check_box_tag :subject,!sub.subject,sub.subject,disabled:!sub.discipline&.subject,remote:true,data:{id:sub.id},class:"sub-discipline-source-form" %> + <%= check_box_tag :shixun,!sub.shixun,sub.shixun,disabled:!sub.discipline&.shixun,remote:true,data:{id:sub.id},class:"sub-discipline-source-form" %> + <%= check_box_tag :question,!sub.question,sub.question,disabled:!sub.discipline&.question,remote:true,data:{id:sub.id},class:"sub-discipline-source-form" %> <%= link_to '编辑', edit_admins_sub_discipline_path(sub), remote: true, class: 'action' %> <%= delete_link '删除', admins_sub_discipline_path(sub, element: ".sub-discipline-item-#{sub.id}"), class: 'delete-sub-discipline-action' %> diff --git a/app/views/admins/tag_disciplines/shared/_list.html.erb b/app/views/admins/tag_disciplines/shared/_list.html.erb index c28c32b96..f6d92d366 100644 --- a/app/views/admins/tag_disciplines/shared/_list.html.erb +++ b/app/views/admins/tag_disciplines/shared/_list.html.erb @@ -15,9 +15,18 @@ <%= index + 1 %> <%= tag.name %> - <%= check_box_tag :subject,!tag.subject,tag.subject,remote:true,data:{id:tag.id},class:"tag-discipline-source-form" %> - <%= check_box_tag :shixun,!tag.shixun,tag.shixun,remote:true,data:{id:tag.id},class:"tag-discipline-source-form" %> - <%= check_box_tag :question,!tag.question,tag.question,remote:true,data:{id:tag.id},class:"tag-discipline-source-form" %> + + <% disabled = !(tag.sub_discipline&.subject && tag.discipline&.subject) %> + <%= check_box_tag :subject,!tag.subject,tag.subject,disabled:disabled,remote:true,data:{id:tag.id},class:"tag-discipline-source-form" %> + + + <% disabled = !(tag.sub_discipline&.shixun && tag.discipline&.shixun) %> + <%= check_box_tag :shixun,!tag.shixun,tag.shixun,disabled:disabled,remote:true,data:{id:tag.id},class:"tag-discipline-source-form" %> + + + <% disabled = !(tag.sub_discipline&.question && tag.discipline&.question) %> + <%= check_box_tag :question,!tag.question,tag.question,disabled:disabled,remote:true,data:{id:tag.id},class:"tag-discipline-source-form" %> + <%= link_to '编辑', edit_admins_tag_discipline_path(tag), remote: true, class: 'action' %> <%= delete_link '删除', admins_tag_discipline_path(tag, element: ".tag-discipline-item-#{tag.id}"), class: 'delete-tag-discipline-action' %>