实训课程等级系统页面

dev_SaaS
daiao 6 years ago
parent c9d91b02d3
commit 08a4357405

@ -16,6 +16,43 @@ class ManagementsController < ApplicationController
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
# 实训课程等级体系
def subject_level_system
@levels = SubjectLevelSystem.all
end
# 创建课程等级体系
def create_subject_level
raise("名称不能为空") if params[:name].blank?
repeat_name = SubjectLevelSystem.where(name: params[:name]).count
raise("名称不能重复") if repeat_name > 0
level = SubjectLevelSystem.pluck(:level).max.to_i + 1
SubjectLevelSystem.create(name: params[:name], level: level)
redirect_to subject_level_system_managements_path(:format => "js")
end
# 重命名课程等级
def rename_subject_level
raise("名称不能为空!") if params[:name].blank?
repeat_name = SubjectLevelSystem.where("name = ? and id != ?", params[:name], params[:id]).count
raise("名称不能重复") if repeat_name > 0
level = SubjectLevelSystem.find params[:id]
level.update_attribute(:name, params[:name])
redirect_to subject_level_system_managements_path(:format => "js")
end
# 删除课程等级
def delete_subject_level
level = SubjectLevelSystem.find params[:id]
Subject.where(:subject_level_system_id => level).update_all(:subject_level_system_id => nil)
levels = SubjectLevelSystem.where("level > ?", level.level)
levels.each do |l|
l.update_attribute(:level, l.level-1)
end
level.delete
redirect_to subject_level_system_managements_path(:format => "js")
end
# 工程认证视频导入模板
def ec_template
@template = EcTemplate.where(nil)

@ -18,6 +18,7 @@ class Subject < ActiveRecord::Base
has_many :tidings, :as => :container, :dependent => :destroy
belongs_to :repertoire
belongs_to :user
has_one :subject_level_system
scope :visible, lambda{where(status: 2)}

@ -0,0 +1,5 @@
class SubjectLevelSystem < ActiveRecord::Base
# attr_accessible :title, :body
has_many :subjects
end

@ -55,7 +55,7 @@
</li>
<li class="fl edu-admin-nav-li edu-position <%= 'active' if @menu_type == 4 %>" style="width: 100px"><a href="javascript:void(0);" class="edu-admin-nav-a" >实训课程+</a>
<ul class="edu-admin-nav-inner edu-absolute">
<li style="width: 120px"><%= link_to "实训课程等级体系", class_shixuns_managements_path %></li>
<li style="width: 120px"><%= link_to "实训课程等级体系", subject_level_system_managements_path %></li>
<li style="width: 120px"><%= link_to "实训课程列表", class_shixuns_managements_path %></li>
<li style="width: 120px"><%= link_to "实训课程配置", subject_setting_list_managements_path %></li>
<li style="width: 120px"><%= link_to "已发布实训课程", class_publish_shixuns_managements_path %></li>

@ -1,88 +0,0 @@
<div class="mt20" id="levelSystem">
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0">
<thead>
<th width="10%">等级</th>
<th width="15%" class="edu-txt-left">名称</th>
<th width="45" class="edu-txt-left">实训课程数</th>
<th width="15%">创建时间</th>
<th width="15%">操作</th>
</thead>
<tbody>
<tr>
<td class="levelNo">1</td>
<td class="edu-txt-left levelName">初级课程</td>
<td class="edu-txt-left">500</td>
<td>2019-03-02 10:38</td>
<td>
<a href="javascript:void(0)" class="mr15">删除</a>
<a href="javascript:void(0)" class="mr15 renameLine">重命名</a>
</td>
</tr>
<tr>
<td class="levelNo">2</td>
<td class="edu-txt-left levelName">初级课程</td>
<td class="edu-txt-left">--</td>
<td>2019-03-02 10:38</td>
<td>
<a href="javascript:void(0)" class="mr15">删除</a>
<a href="javascript:void(0)" class="mr15 renameLine">重命名</a>
</td>
</tr>
<tr>
<td colspan="5">
<a href="javascript:void(0)" class="color-blue" onclick="createLevel();">+ 新建</a>
</td>
</tr>
</tbody>
</table>
</div>
<script type="text/html" id="template_newForm">
<div class="bor-grey-e mt20 clearfix padding10-20 edu-back-white" id="newForm">
<span class="fl mt3">名称</span>
<input type="text" class="winput-240-35 fl ml20"/>
<li class="fr mt3">
<a href="javascript:void(0)" class="mr15" onclick="cancelNew();">取消</a>
<a href="javascript:void(0)" class="mr15">保存</a>
</li>
</div>
</script>
<script>
//新建
function createLevel(){
if($("#newForm").length==0){
var bt = baidu.template;
bt.LEFT_DELIMITER = '<!';
bt.RIGHT_DELIMITER = '!>';
var html = bt('template_newForm', null);
$("#levelSystem").append(html);
}
}
//新建--取消
function cancelNew(){
$("#newForm").remove();
}
//重命名
var lastHtml="";
$("table").on("click",".renameLine",function(){
var tr=$(this).parents("tr");
lastHtml=$(tr).html();
var value=$(tr).find(".levelName").html();
var No=$(tr).find(".levelNo").html();
var html='<td>'+No+'</td>'+
'<td colspan="4" class="edu-txt-left">'+
'<input type="winput-240-35" name="rename" value="'+value+'"/>'+
'<a href="javascript:void(0)" class="mr15 ml20" onclick="cancelEdit(this);">取消</a>'+
'<a href="javascript:void(0)">保存</a>'+
'</td>';
$(tr).html(html);
})
//重命名--取消
function cancelEdit(item){
$(item).parents("tr").html(lastHtml);
}
</script>

@ -0,0 +1,107 @@
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0">
<thead>
<th width="10%">等级</th>
<th width="15%" class="edu-txt-left">名称</th>
<th width="45" class="edu-txt-left">实训课程数</th>
<th width="15%">创建时间</th>
<th width="15%">操作</th>
</thead>
<tbody>
<% @levels.each do |l| %>
<tr>
<td class="levelNo"><%= l.level %></td>
<td class="edu-txt-left levelName" data-value="<%= l.id %>"><%= l.name %></td>
<td class="edu-txt-left"><%= l.subjects.size %></td>
<td><%= format_time l.created_at %></td>
<td>
<a href="javascript:void(0)" class="mr15" onclick="deleteLevel('<%= l.id %>');">删除</a>
<a href="javascript:void(0)" class="mr15 renameLine">重命名</a>
</td>
</tr>
<% end %>
<tr>
<td colspan="5">
<a href="javascript:void(0)" class="color-blue" onclick="createLevel();">+ 新建</a>
</td>
</tr>
</tbody>
</table>
<script type="text/html" id="template_newForm">
<div class="bor-grey-e mt20 clearfix padding10-20 edu-back-white" id="newForm">
<span class="fl mt3">名称</span>
<input type="text" class="winput-240-35 fl ml20" id="level_name"/>
<li class="fr mt3">
<a href="javascript:void(0)" class="mr15" onclick="cancelNew();">取消</a>
<a href="javascript:void(0)" class="mr15" onclick="createSubjectLevel()">保存</a>
</li>
</div>
</script>
<script>
//新建
function createLevel(){
if($("#newForm").length==0){
var bt = baidu.template;
bt.LEFT_DELIMITER = '<!';
bt.RIGHT_DELIMITER = '!>';
var html = bt('template_newForm', null);
$("#levelSystem").append(html);
}
}
//新建--取消
function cancelNew(){
$("#newForm").remove();
}
//重命名
var lastHtml="";
$("table").on("click",".renameLine",function(){
var tr=$(this).parents("tr");
lastHtml=$(tr).html();
var value=$(tr).find(".levelName").html();
var id = $(tr).find(".levelName").attr("data-value");
var No=$(tr).find(".levelNo").html();
var html='<td>'+No+'</td>'+
'<td colspan="4" class="edu-txt-left">'+
'<input type="winput-240-35" id="rename" name="name" value="'+value+'"/>'+
'<input type="hidden" id="level_id" value="'+id+'"/>'+
'<a href="javascript:void(0)" class="mr15 ml20" onclick="cancelEdit(this);">取消</a>'+
'<a href="javascript:void(0)" onclick="update_level(this);">保存</a>'+
'</td>';
$(tr).html(html);
})
//重命名--取消
function cancelEdit(item){
$(item).parents("tr").html(lastHtml);
}
// 重命名
function update_level(item){
var name = $(item).siblings("#rename").val();
var id = $(item).siblings("#level_id").val();
$.ajax({
url: "<%= rename_subject_level_managements_path %>",
type: "POST",
data:{id: id, name: name}
})
}
function createSubjectLevel(){
var name = $("#level_name").val()
$.ajax({
url: "<%= create_subject_level_managements_path %>",
type: "POST",
data: {name: name}
})
}
function deleteLevel(id){
$.ajax({
url: "<%= delete_subject_level_managements_path %>",
type: "POST",
data: {id: id}
})
}
</script>

@ -0,0 +1,3 @@
<div class="mt20" id="levelSystem">
<%= render :partial => "managements/subject_level_list" %>
</div>

@ -0,0 +1 @@
$("#levelSystem").html("<%= j (render :partial => "subject_level_list") %>")

@ -673,6 +673,10 @@ RedmineApp::Application.routes.draw do
post 'add_course_info_for_school'
get 'ec_template'
post 'add_template'
get 'subject_level_system'
post 'create_subject_level'
post 'rename_subject_level'
post 'delete_subject_level'
end
end
# Enable Grack support

@ -0,0 +1,9 @@
class CreateSubjectLevelSystems < ActiveRecord::Migration
def change
create_table :subject_level_systems do |t|
t.integer :level
t.string :name
t.timestamps
end
end
end

@ -0,0 +1,9 @@
class AddSubjectLevelSystemIdForSubjects < ActiveRecord::Migration
def up
add_column :subjects, :subject_level_system_id, :integer
add_index :subjects, :subject_level_system_id
end
def down
end
end

@ -0,0 +1,5 @@
FactoryGirl.define do
factory :subject_level_system do
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe SubjectLevelSystem, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save