parent
ebfe64b569
commit
24162177fc
@ -0,0 +1,113 @@
|
||||
$(document).on('turbolinks:load', function () {
|
||||
if ($('body.admins-subjects-index-page').length > 0) {
|
||||
var $form = $('.subject-list-form');
|
||||
|
||||
// ************** 学校选择 *************
|
||||
$form.find('.school-select').select2({
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请选择创建者单位',
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/api/schools/search.json',
|
||||
dataType: 'json',
|
||||
data: function (params) {
|
||||
return {keyword: params.term};
|
||||
},
|
||||
processResults: function (data) {
|
||||
return {results: data.schools}
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if (!item.id || item.id === '') return item.text;
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
if (item.id) {
|
||||
}
|
||||
return item.name || item.text;
|
||||
}
|
||||
});
|
||||
|
||||
// 清空
|
||||
$form.on('click', '.clear-btn', function () {
|
||||
$form.find('select[name="status"]').val('');
|
||||
$form.find('.school-select').val('').trigger('change');
|
||||
$form.find('input[name="keyword"]').val('');
|
||||
$form.find('#homepage_show').attr('checked', false);
|
||||
$form.find('#excellent').attr('checked', false);
|
||||
$form.find('input[type="submit"]').trigger('click');
|
||||
})
|
||||
|
||||
// 上传图片
|
||||
$('.modal.admin-upload-file-modal').on('upload:success', function (e, data) {
|
||||
if(data.suffix == '_qrcode'){
|
||||
var $imageElement = $('.subject-weapp-image-' + data.source_id);
|
||||
$imageElement.attr('src', data.url);
|
||||
$imageElement.show();
|
||||
$imageElement.next().html('重新上传');
|
||||
} else {
|
||||
var $imageElement = $('.subject-image-' + data.source_id);
|
||||
$imageElement.attr('src', data.url);
|
||||
$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);
|
||||
}
|
||||
});
|
@ -0,0 +1,71 @@
|
||||
class Admins::SubjectsController < Admins::BaseController
|
||||
def index
|
||||
default_sort('created_at', 'desc')
|
||||
|
||||
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
|
@ -0,0 +1,11 @@
|
||||
module Admins::SubjectsHelper
|
||||
def display_subject_status(subject)
|
||||
style =
|
||||
case subject.status
|
||||
when 0 then 'text-secondary'
|
||||
when 1 then 'text-warning'
|
||||
when 2 then 'text-success'
|
||||
end
|
||||
raw content_tag(:span, t("subject.status.#{subject.status}"), class: style)
|
||||
end
|
||||
end
|
@ -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,41 @@
|
||||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('课程配置') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container subject-list-form">
|
||||
<%= form_tag(admins_subjects_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<div class="form-group mr-1">
|
||||
<label for="status">状态:</label>
|
||||
<% status_options = [['全部', ''], ['编辑中', 'pending'], ['审核中', 'applying'], ['已发布', 'published']] %>
|
||||
<%= select_tag(:status, options_for_select(status_options), class: 'form-control') %>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-12 col-md-3">
|
||||
<label for="school_name">单位:</label>
|
||||
<%= select_tag :school_id, options_for_select([''], params[:school_id]), class: 'form-control school-select flex-1' %>
|
||||
</div>
|
||||
|
||||
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-12 col-md-2 mr-3', placeholder: '创建者/课程名称检索') %>
|
||||
|
||||
<div class="form-check mr-2">
|
||||
<%= hidden_field_tag(:homepage_show, false, id:'') %>
|
||||
<%= check_box_tag(:homepage_show, true, params[:homepage_show].to_s == 'true', class: 'form-check-input') %>
|
||||
<label class="form-check-label" for="homepage_show">只看首页展示</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check mr-2">
|
||||
<%= hidden_field_tag(:excellent, false, id:'') %>
|
||||
<%= check_box_tag(:excellent, true, params[:excellent].to_s == 'true', class: 'form-check-input') %>
|
||||
<label class="form-check-label" for="excellent">只看金课</label>
|
||||
</div>
|
||||
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container subject-list-container">
|
||||
<%= render partial: 'admins/subjects/shared/list', locals: { subjects: @subjects } %>
|
||||
</div>
|
||||
|
||||
<%= render partial: 'admins/shared/modal/upload_file_modal', locals: { title: '上传图片', accept: 'image/*' } %>
|
@ -0,0 +1 @@
|
||||
$('.subject-list-container').html("<%= j( render partial: 'admins/subjects/shared/list', locals: { subjects: @subjects } ) %>");
|
@ -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">×</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>
|
@ -0,0 +1,74 @@
|
||||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="4%">序号</th>
|
||||
<th width="14%" class="text-left">名称</th>
|
||||
<th width="5%">阶段数</th>
|
||||
<th width="5%">实训数</th>
|
||||
<th width="7%">技术体系</th>
|
||||
<th width="7%">等级体系</th>
|
||||
<th width="8%">封面</th>
|
||||
<th width="7%">创建者</th>
|
||||
<th width="10%">单位</th>
|
||||
<th width="6%">开课人数</th>
|
||||
<th width="10%"><%= sort_tag('创建时间', name: 'created_at', path: admins_subjects_path) %></th>
|
||||
<th width="7%">状态</th>
|
||||
<th width="9%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if subjects.present? %>
|
||||
<% subjects.each_with_index do |subject, index| %>
|
||||
<tr class="subject-item-<%= subject.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td class="text-left">
|
||||
<%= link_to(subject.name, "/paths/#{subject.id}", target: '_blank') %>
|
||||
<span class="badge badge-pill badge-success homepage-show-badge" style="<%= subject.homepage_show? ? '' : 'display:none' %>">首页</span>
|
||||
<span class="badge badge-pill badge-info excellent-badge" style="<%= subject.excellent? ? '' : 'display:none' %>">金课</span>
|
||||
</td>
|
||||
<td><%= subject.stages_count %></td>
|
||||
<td><%= subject.shixuns_count %></td>
|
||||
<td><%= display_text subject.repertoire&.name %></td>
|
||||
<td><%= display_text subject.subject_level_system&.name %></td>
|
||||
<td>
|
||||
<% image_exists = Util::FileManage.exists?(subject) %>
|
||||
<%= image_tag(image_exists ? Util::FileManage.source_disk_file_url(subject) : '', height: 40, class: "w-100 preview-image subject-image-#{subject.id}", style: image_exists ? '' : 'display:none') %>
|
||||
<%= javascript_void_link image_exists ? '重新上传' : '上传图片', class: 'action upload-image-action', data: { source_id: subject.id, source_type: 'Subject', toggle: 'modal', target: '.admin-upload-file-modal' } %>
|
||||
</td>
|
||||
<td><%= subject.user.real_name %></td>
|
||||
<td><%= subject.user.school_name %></td>
|
||||
<td><%= subject.student_count %></td>
|
||||
<td><%= subject.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td>
|
||||
<%= display_subject_status(subject) %>
|
||||
</td>
|
||||
<td class="action-container">
|
||||
<%= link_to('编辑', edit_admins_subject_path(subject), remote: true, class: 'edit-action') %>
|
||||
|
||||
<%= 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') %>
|
||||
|
||||
<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', 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_subject_path(subject, element: ".subject-item-#{subject.id}"), class: 'dropdown-item delete-subject-action' %>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: subjects } %>
|
Loading…
Reference in new issue