parent
c9d91b02d3
commit
08a4357405
@ -0,0 +1,5 @@
|
||||
class SubjectLevelSystem < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
has_many :subjects
|
||||
|
||||
end
|
@ -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") %>")
|
@ -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…
Reference in new issue