admin: edit subject

dev_local_cqdsj
p31729568 5 years ago
parent 6d04519e2b
commit 8e87b085ad

@ -0,0 +1,18 @@
$(document).on('turbolinks:load', function() {
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-subject-modal', function(){
var $modal = $('.modal.admin-edit-subject-modal');
var $form = $modal.find('form.admin-edit-subject-form');
$modal.on('click', '.submit-btn', function(){
$form.find('.error').html('');
var url = $form.attr('action');
$.ajax({
method: 'PATCH',
dataType: 'script',
url: url,
data: $form.serialize()
});
});
})
});

@ -46,5 +46,62 @@ $(document).on('turbolinks:load', function() {
$imageElement.show();
$imageElement.next().html('重新上传');
})
// 定义状态切换监听事件
var defineStatusChangeFunc = function(doElement, undoElement, url, callback){
$('.subject-list-container').on('click', doElement, function(){
var $doAction = $(this);
var $undoAction = $doAction.siblings(undoElement);
var subjectId = $doAction.data('id');
customConfirm({
content: '确认进行该操作吗?',
ok: function(){
$.ajax({
url: '/admins/subjects/' + subjectId + url,
method: 'POST',
dataType: 'json',
success: function() {
show_success_flash();
$doAction.hide();
$undoAction.show();
if(callback && typeof callback === "function"){
callback(subjectId, url);
}
}
});
}
});
});
}
// 隐藏与取消隐藏
defineStatusChangeFunc('.hide-action', '.active-action', '/hide');
defineStatusChangeFunc('.active-action', '.hide-action', '/cancel_hide');
// 首页展示与取消首页展示
var homepageShowCallback = function(subjectId, url){
var $subjectItem = $('.subject-list-container').find('.subject-item-' + subjectId);
if(url === '/homepage_show'){
$subjectItem.find('.homepage-show-badge').show();
} else {
$subjectItem.find('.homepage-show-badge').hide();
}
}
defineStatusChangeFunc('.homepage-show-action', '.homepage-hide-action', '/homepage_show', homepageShowCallback);
defineStatusChangeFunc('.homepage-hide-action', '.homepage-show-action', '/cancel_homepage_show', homepageShowCallback);
// 设为金课与取消金课
var excellentCallback = function(subjectId, url){
var $subjectItem = $('.subject-list-container').find('.subject-item-' + subjectId);
if(url === '/excellent'){
$subjectItem.find('.excellent-badge').show();
} else {
$subjectItem.find('.excellent-badge').hide();
}
}
defineStatusChangeFunc('.excellent-action', '.cancel-excellent-action', '/excellent', excellentCallback);
defineStatusChangeFunc('.cancel-excellent-action', '.excellent-action', '/cancel_excellent', excellentCallback);
}
});

@ -66,9 +66,9 @@ function customConfirm(opts){
return $.confirm($.extend({}, defaultOpts, opts))
}
function show_success_flash(){
function show_success_flash(message){
$.notify({
message: '操作成功'
message: message || '操作成功'
},{
type: 'success'
});

@ -5,4 +5,67 @@ class Admins::SubjectsController < Admins::BaseController
subjects = Admins::SubjectQuery.call(params)
@subjects = paginate subjects.includes(:repertoire, :subject_level_system, user: { user_extension: :school })
end
def edit
@subject = current_subject
end
def update
current_subject.update!(update_params)
flash[:success] = '保存成功'
redirect_to admins_subjects_path
end
def destroy
current_subject.destroy!
render_delete_success
end
# 隐藏
def hide
current_subject.update!(hidden: true)
render_ok
end
# 展示
def cancel_hide
current_subject.update!(hidden: false)
render_ok
end
# 设为主页展示
def homepage_show
current_subject.update!(homepage_show: true)
render_ok
end
# 取消主页展示
def cancel_homepage_show
current_subject.update!(homepage_show: false)
render_ok
end
# 设为金课
def excellent
current_subject.update!(excellent: true)
render_ok
end
# 取消金课
def cancel_excellent
current_subject.update!(excellent: false)
render_ok
end
private
def current_subject
@_current_subject ||= Subject.find(params[:id])
end
def update_params
params.require(:subject).permit(:repertoire_id, :subject_level_system_id, :student_count)
end
end

@ -5,7 +5,7 @@ class Subject < ApplicationRecord
include Searchable::Subject
#status :0 编辑中 1 审核中 2 发布
belongs_to :repertoire
belongs_to :repertoire, optional: true
belongs_to :user
belongs_to :subject_level_system, optional: true

@ -0,0 +1,2 @@
$('.admin-modal-container').html("<%= j( render partial: 'admins/subjects/shared/edit_subject_modal', locals: { subject: @subject } ) %>");
$('.modal.admin-edit-subject-modal').modal('show');

@ -0,0 +1,33 @@
<div class="modal fade admin-edit-subject-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">编辑课程信息</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<%= simple_form_for([:admins, subject], html: { class: 'admin-edit-subject-form' }, defaults: { wrapper_html: { class: 'offset-md-1 col-md-10' } }) do |f| %>
<%= f.input :repertoire_id, label: '技术体系:' do %>
<% repertoire_options = Repertoire.order('CONVERT(name USING gbk) COLLATE gbk_chinese_ci ASC').map{|r| [r.name, r.id]} %>
<%= f.select :repertoire_id, [['请选择', '']] + repertoire_options, {}, class: 'form-control' %>
<% end %>
<%= f.input :subject_level_system_id, label: '等级体系:' do %>
<% level_options = SubjectLevelSystem.all.map{|r| [r.name, r.id]} %>
<%= f.select :subject_level_system_id, [['请选择', '']] + level_options, {}, class: 'form-control' %>
<% end %>
<%= f.input :student_count, as: :integer, label: '开课人数:' %>
<div class="error text-danger"></div>
<% end %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary submit-btn">确认</button>
</div>
</div>
</div>
</div>

@ -7,12 +7,12 @@
<th width="8%">技术体系</th>
<th width="8%">等级体系</th>
<th width="8%">封面</th>
<th width="8%">创建者</th>
<th width="7%">创建者</th>
<th width="10%">单位</th>
<th width="8%">开课人数</th>
<th width="10%"><%= sort_tag('创建时间', name: 'created_at', path: admins_subjects_path) %></th>
<th width="7%">状态</th>
<th width="14%">操作</th>
<th width="15%">操作</th>
</tr>
</thead>
<tbody>
@ -40,26 +40,26 @@
<td>
<%= display_subject_status(subject) %>
</td>
<td>
<%#= javascript_void_link('编辑', class: 'edit-action') %>
<td class="action-container">
<%= link_to('编辑', edit_admins_subject_path(subject), remote: true, class: 'edit-action') %>
<%#= javascript_void_link('隐藏', class: 'hide-action', style: subject.hidden? ? 'display:none' : '') %>
<%#= javascript_void_link('取消隐藏', class: 'active-action', style: subject.hidden? ? '' : 'display:none') %>
<%= javascript_void_link('隐藏', class: 'hide-action', data: { id: subject.id }, style: subject.hidden? ? 'display:none' : '') %>
<%= javascript_void_link('取消隐藏', class: 'active-action', data: { id: subject.id }, style: subject.hidden? ? '' : 'display:none') %>
<%# if subject.published? %>
<!-- <div class="d-inline">-->
<%#= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
<!-- <div class="dropdown-menu more-action-dropdown">-->
<%#= javascript_void_link('首页展示', class: 'dropdown-item homepage-show-action', style: subject.homepage_show? ? 'display:none' : '') %>
<%#= javascript_void_link('取消首页展示', class: 'dropdown-item homepage-hide-action', style: subject.homepage_show? ? '' : 'display:none') %>
<div class="d-inline">
<%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
<div class="dropdown-menu more-action-dropdown">
<% if subject.published? %>
<%= javascript_void_link('首页展示', class: 'dropdown-item homepage-show-action', data: { id: subject.id }, style: subject.homepage_show? ? 'display:none' : '') %>
<%= javascript_void_link('取消首页展示', class: 'dropdown-item homepage-hide-action', data: { id: subject.id }, style: subject.homepage_show? ? '' : 'display:none') %>
<%#= javascript_void_link('选为金课', class: 'dropdown-item excellent-action', style: subject.excellent? ? 'display:none' : '') %>
<%#= javascript_void_link('取消金课', class: 'dropdown-item cancel-excellent-action', style: subject.excellent? ? '' : 'display:none') %>
<%= javascript_void_link('选为金课', class: 'dropdown-item excellent-action', data: { id: subject.id }, style: subject.excellent? ? 'display:none' : '') %>
<%= javascript_void_link('取消金课', class: 'dropdown-item cancel-excellent-action', data: { id: subject.id }, style: subject.excellent? ? '' : 'display:none') %>
<% end %>
<%#= delete_link '删除', admins_subjects_path(subject, element: ".subject-item-#{subject.id}"), class: 'delete-subject-action' %>
<!-- </div>-->
<!-- </div>-->
<%# end %>
<%= delete_link '删除', admins_subject_path(subject, element: ".subject-item-#{subject.id}"), class: 'dropdown-item delete-subject-action' %>
</div>
</div>
</td>
</tr>
<% end %>

@ -1052,7 +1052,16 @@ Rails.application.routes.draw do
post :drag, on: :collection
end
resources :subjects, only: [:index]
resources :subjects, only: [:index, :edit, :update, :destroy] do
member do
post :hide
post :cancel_hide
post :homepage_show
post :cancel_homepage_show
post :excellent
post :cancel_excellent
end
end
end
namespace :cooperative do

File diff suppressed because one or more lines are too long

@ -29898,9 +29898,9 @@ function customConfirm(opts){
return $.confirm($.extend({}, defaultOpts, opts))
}
function show_success_flash(){
function show_success_flash(message){
$.notify({
message: '操作成功'
message: message || '操作成功'
},{
type: 'success'
});
@ -137789,6 +137789,24 @@ $(document).on('turbolinks:load', function() {
});
})
});
$(document).on('turbolinks:load', function() {
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-subject-modal', function(){
var $modal = $('.modal.admin-edit-subject-modal');
var $form = $modal.find('form.admin-edit-subject-form');
$modal.on('click', '.submit-btn', function(){
$form.find('.error').html('');
var url = $form.attr('action');
$.ajax({
method: 'PATCH',
dataType: 'script',
url: url,
data: $form.serialize()
});
});
})
});
$(document).on('turbolinks:load', function() {
var $modal = $('.modal.admin-import-course-member-modal');
if ($modal.length > 0) {
@ -138526,6 +138544,63 @@ $(document).on('turbolinks:load', function() {
$imageElement.show();
$imageElement.next().html('重新上传');
})
// 定义状态切换监听事件
var defineStatusChangeFunc = function(doElement, undoElement, url, callback){
$('.subject-list-container').on('click', doElement, function(){
var $doAction = $(this);
var $undoAction = $doAction.siblings(undoElement);
var subjectId = $doAction.data('id');
customConfirm({
content: '确认进行该操作吗?',
ok: function(){
$.ajax({
url: '/admins/subjects/' + subjectId + url,
method: 'POST',
dataType: 'json',
success: function() {
show_success_flash();
$doAction.hide();
$undoAction.show();
if(callback && typeof callback === "function"){
callback(subjectId, url);
}
}
});
}
});
});
}
// 隐藏与取消隐藏
defineStatusChangeFunc('.hide-action', '.active-action', '/hide');
defineStatusChangeFunc('.active-action', '.hide-action', '/cancel_hide');
// 首页展示与取消首页展示
var homepageShowCallback = function(subjectId, url){
var $subjectItem = $('.subject-list-container').find('.subject-item-' + subjectId);
if(url === '/homepage_show'){
$subjectItem.find('.homepage-show-badge').show();
} else {
$subjectItem.find('.homepage-show-badge').hide();
}
}
defineStatusChangeFunc('.homepage-show-action', '.homepage-hide-action', '/homepage_show', homepageShowCallback);
defineStatusChangeFunc('.homepage-hide-action', '.homepage-show-action', '/cancel_homepage_show', homepageShowCallback);
// 设为金课与取消金课
var excellentCallback = function(subjectId, url){
var $subjectItem = $('.subject-list-container').find('.subject-item-' + subjectId);
if(url === '/excellent'){
$subjectItem.find('.excellent-badge').show();
} else {
$subjectItem.find('.excellent-badge').hide();
}
}
defineStatusChangeFunc('.excellent-action', '.cancel-excellent-action', '/excellent', excellentCallback);
defineStatusChangeFunc('.cancel-excellent-action', '.excellent-action', '/cancel_excellent', excellentCallback);
}
});
$(document).on('turbolinks:load', function() {

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save