From af0b7aa1a6b4e2f99bc84acd29ede1cb085390e3 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Feb 2020 18:27:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=85=8D=E7=BD=AE=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/subject_settings/index.js | 17 +++++++++++++++++ .../admins/subject_settings_controller.rb | 11 +++++++++++ app/views/admins/subject_settings/mobile.js.erb | 0 .../subject_settings/shared/_list.html.erb | 12 ++++++------ .../admins/subject_settings/shared/_td.html.erb | 4 +++- .../subject_settings/update_mobile_show.js.erb | 1 + config/routes.rb | 4 +++- ...0200222081052_add_show_moblie_to_subjects.rb | 5 +++++ 8 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 app/views/admins/subject_settings/mobile.js.erb create mode 100644 app/views/admins/subject_settings/update_mobile_show.js.erb create mode 100644 db/migrate/20200222081052_add_show_moblie_to_subjects.rb diff --git a/app/assets/javascripts/admins/subject_settings/index.js b/app/assets/javascripts/admins/subject_settings/index.js index 63f76dd6e..80fc91f47 100644 --- a/app/assets/javascripts/admins/subject_settings/index.js +++ b/app/assets/javascripts/admins/subject_settings/index.js @@ -29,6 +29,23 @@ $(document).on('turbolinks:load', function () { } }); + + $(".action-container").on("change", '.subject-mobile-form', function () { + var s_id = $(this).attr("data-id"); + var s_value = $(this).val(); + var s_name = $(this).attr("name"); + var json = {}; + var s_index = $(this).parent("td").siblings(".shixun-line-no").text(); + json[s_name] = s_value; + json["page_no"] = s_index; + $.ajax({ + url: "/admins/subject_settings/update_mobile_show?subject_id=" + s_id, + type: "POST", + dataType:'script', + data: json + }); + }); + $(".subject-setting-list-container").on("change", '.subject-setting-form', function () { var s_id = $(this).attr("data-id"); var s_value = $(this).val(); diff --git a/app/controllers/admins/subject_settings_controller.rb b/app/controllers/admins/subject_settings_controller.rb index 29e4dfd30..10a3139e4 100644 --- a/app/controllers/admins/subject_settings_controller.rb +++ b/app/controllers/admins/subject_settings_controller.rb @@ -8,6 +8,12 @@ class Admins::SubjectSettingsController < Admins::BaseController end def update + # 为了复用代码 + if params["show_moblie"] + subject.find(params[:id]).update_attributes(:show_moblie => params[:show_moblie]) + return + end + sub_discipline_ids = params[:sub_disciplines] || [] sub_ids = sub_discipline_ids.reject(&:blank?).map(&:to_i) old_sub_ids = current_subject.sub_discipline_containers.pluck(:sub_discipline_id) @@ -20,6 +26,11 @@ class Admins::SubjectSettingsController < Admins::BaseController end end + def update_mobile_show + subject = Subject.find(params[:subject_id]) + subject.update_attributes(:show_mobile => params[:show_mobile]) + end + private def current_subject diff --git a/app/views/admins/subject_settings/mobile.js.erb b/app/views/admins/subject_settings/mobile.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/admins/subject_settings/shared/_list.html.erb b/app/views/admins/subject_settings/shared/_list.html.erb index 9f27c084c..79411e892 100644 --- a/app/views/admins/subject_settings/shared/_list.html.erb +++ b/app/views/admins/subject_settings/shared/_list.html.erb @@ -1,14 +1,14 @@ - - - - + + + + - - + + diff --git a/app/views/admins/subject_settings/shared/_td.html.erb b/app/views/admins/subject_settings/shared/_td.html.erb index 6e905d995..ed8216bbb 100644 --- a/app/views/admins/subject_settings/shared/_td.html.erb +++ b/app/views/admins/subject_settings/shared/_td.html.erb @@ -5,7 +5,7 @@ 金课 - + @@ -16,6 +16,8 @@ diff --git a/app/views/admins/subject_settings/update_mobile_show.js.erb b/app/views/admins/subject_settings/update_mobile_show.js.erb new file mode 100644 index 000000000..c95a41ec3 --- /dev/null +++ b/app/views/admins/subject_settings/update_mobile_show.js.erb @@ -0,0 +1 @@ +$.notify({ message: '更新成功' }); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9455f7719..6cf70ac15 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1328,7 +1328,9 @@ Rails.application.routes.draw do post :drag, on: :collection end - resources :subject_settings, only: [:index, :update] + resources :subject_settings, only: [:index, :update] do + post :update_mobile_show, on: :collection + end resources :subjects, only: [:index, :edit, :update, :destroy] do member do diff --git a/db/migrate/20200222081052_add_show_moblie_to_subjects.rb b/db/migrate/20200222081052_add_show_moblie_to_subjects.rb new file mode 100644 index 000000000..05e7a8ea9 --- /dev/null +++ b/db/migrate/20200222081052_add_show_moblie_to_subjects.rb @@ -0,0 +1,5 @@ +class AddShowMoblieToSubjects < ActiveRecord::Migration[5.2] + def change + add_column :subjects, :show_mobile, :boolean, :default => false + end +end
序号名称技术体系等级体系序号名称老版技术体系状态 课程体系 封面开课人数操作开课人数操作
<%= display_text subject.repertoire&.name %><%= display_text subject.subject_level_system&.name %><%= display_text subject.status == 2 ? "已发布" : "未发布" %> <%= select_tag(:sub_disciplines, options_for_select(@sub_disciplines, subject.sub_disciplines.pluck(:id)),multiple:true,class:"form-control subject-setting-form",data:{id:subject.id},id:"tags-chosen-#{subject.id}") %> <%= subject.student_count %> + <%= check_box_tag :show_mobile, !subject.show_mobile, subject.show_mobile, remote: true, + data: {id: subject.id, toggle: "tooltip", placement: "top"}, class: "subject-mobile-form mr10", title: "小程序端显示" %> <%= link_to('编辑', edit_admins_subject_path(subject), remote: true, class: 'edit-action') %>