首页 > 代码库 > 动态添加

动态添加

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>排课登记</title>
</head>
<link rel="stylesheet" type="text/css" href="http://www.mamicode.com/${StaticResourceContextPath}/lib/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://www.mamicode.com/${StaticResourceContextPath}/lib/jstree/3.2.1/dist/themes/default/style.min.css">
<link rel="stylesheet" type="text/css" href="http://www.mamicode.com/${StaticResourceContextPath}/school/attendance/css/index.css">
<link rel="stylesheet" type="text/css" href="http://www.mamicode.com/${StaticResourceContextPath}/school/attendance/css/course.css">
<body>
<%--start second tree--%>
<div class="second-trees">
<div id="second-tree" class="T30"></div>
</div>
<%--end second tree--%>
<%--start right_pannel--%>
<div class="right-pannel">
<%--start right-pannel-header--%>
<div class="right-pannel-header">
<input type="button" value="http://www.mamicode.com/添加" id="add_submit" class="add_submit">
<label style="margin-left: 20px;">选择校历</label>
<select id="school_calender"></select>
</div>
<%--end right-pannel-header--%>
<div class="right-pannel-body">
<div class="course_info">
<%--<label>输入课程名</label>--%>
<%--<select>--%>
<%--<option>数学</option>--%>
<%--<option>语文</option>--%>
<%--</select><br>--%>
<%--<label>输入科任老师姓名</label>--%>
<%--<select>--%>
<%--<option>张</option>--%>
<%--<option>李</option>--%>
<%--</select><br>--%>
<label style="float: left;">上课地点</label>
<select id="building" style="float: left;"></select>
<select id="story" class="none" style="float: left;"></select>
<select id="classRoom" class="none" style="float: left;"></select>
<br><br><br>
<div style="clear: both;">
<label>选择周数:</label>
<div class="weekend-value-area"></div>
<div class="weekend-choose">
<input type="button" name="single" class="single" id="single" value="http://www.mamicode.com/单周">
<input type="button" name="double" class="double" id="double" value="http://www.mamicode.com/双周">
<input type="button" name="checkall" class="checkall" id="checkall" value="http://www.mamicode.com/全选">
<input type="button" name="cancel" class="cancel" id="cancel" value="http://www.mamicode.com/取消">
<input type="button" name="ok" class="ok" id="ok" value="http://www.mamicode.com/选择">
<table border="1" cellpadding="0" cellspacing="0" id="weekend-chooses" class="weekend-chooses" width="240" height="160">
<%--<tr>--%>
<%--<td>1</td>--%>
<%--<td>2</td>--%>
<%--<td>3</td>--%>
<%--<td>4</td>--%>
<%--<td>5</td>--%>
<%--<td>6</td>--%>
<%--</tr>--%>
<%--<tr>--%>
<%--<td>7</td>--%>
<%--<td>8</td>--%>
<%--<td>9</td>--%>
<%--<td>10</td>--%>
<%--<td>11</td>--%>
<%--<td>12</td>--%>
<%--</tr>--%>
<%--<tr>--%>
<%--<td>13</td>--%>
<%--<td>14</td>--%>
<%--<td>15</td>--%>
<%--<td>16</td>--%>
<%--<td>17</td>--%>
<%--<td>18</td>--%>
<%--</tr>--%>
<%--<tr>--%>
<%--<td>19</td>--%>
<%--<td>20</td>--%>
<%--<td>21</td>--%>
<%--<td>22</td>--%>
<%--<td>23</td>--%>
<%--<td>24</td>--%>
<%--</tr>--%>
</table>
</div>
<label>选择上课时间:</label><br>
<select>
<option>周一</option>
<option>周二</option>
<option>周三</option>
<option>周四</option>
<option>周五</option>
<option>周六</option>
<option>周日</option>
</select>
<select>
<option>一</option>
<option>二</option>
<option>三</option>
<option>四</option>
<option>五</option>
<option>六</option>
<option>七</option>
<option>八</option>
<option>九</option>
<option>十</option>
<option>十一</option>
<option>十二</option>
<option>十三</option>
<option>十四</option>
</select>
<select>
<option>一</option>
<option>二</option>
<option>三</option>
<option>四</option>
<option>五</option>
<option>六</option>
<option>七</option>
<option>八</option>
<option>九</option>
<option>十</option>
<option>十一</option>
<option>十二</option>
<option>十三</option>
<option>十四</option>
</select>
</div>
<div class="copy"> </div>
<div><input type="button" value="http://www.mamicode.com/添加更多课程时间" class="copy_btn"></div>
</div>
</div>
</div>
<%--end right_pannel--%>
</body>
<script type="text/javascript" src="http://www.mamicode.com/${StaticResourceContextPath}/lib/jquery/2.1.1/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="http://www.mamicode.com/${StaticResourceContextPath}/lib/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://www.mamicode.com/${StaticResourceContextPath}/lib/jstree/3.2.1/dist/jstree.min.js"></script>
<script type="text/javascript" src="http://www.mamicode.com/${StaticResourceContextPath}/school/attendance/js/public.js"></script>
<script>
$(function(){
/*定义body-pannel高度*/
var body_pannel = window.screen.availHeight-120 ;
var right_pannel_width = window.screen.availWidth-330;
$(‘.second-trees‘).css({height:body_pannel});
/*楼*/
loadBuilding();

// /*对周数选择进行操作*/
$(".weekend-chooses").find(‘td‘).bind(‘click‘,function(){
$(this).removeClass(‘td-bg-white‘);
$(this).addClass(‘td-bg-blue‘);
}
);

$(".weekend-chooses tr td").bind(‘dblclick‘,function(){
$(this).removeClass(‘td-bg-blue‘);
$(this).addClass(‘td-bg-white‘);
});

$(".single").click(function(){
$(".weekend-chooses").find(‘td‘).each(function(i){
if((i+1)%2==1){
$(this).removeClass(‘td-bg-white‘);
$(this).addClass(‘td-bg-blue‘);
}
else{
$(this).removeClass(‘td-bg-blue‘);
$(this).addClass(‘td-bg-white‘);
}
});
});

$(".double").click(function(){
$(".weekend-chooses").find(‘td‘).each(function(i){
if((i+1)%2==0){
$(this).removeClass(‘td-bg-white‘);
$(this).addClass(‘td-bg-blue‘);
}
else{
$(this).removeClass(‘td-bg-blue‘);
$(this).addClass(‘td-bg-white‘);
}
});
});

$(".cancel").click(function(){
$(".weekend-chooses").find(‘td‘).each(function(i){
$(this).removeClass(‘td-bg-blue‘);
$(this).addClass(‘td-bg-white‘);
$(‘.weekend-value-area‘).empty();
});
});

$(".checkall").click(function(){
$(".weekend-chooses").find(‘td‘).each(function(i){
$(this).removeClass(‘td-bg-white‘);
$(this).addClass(‘td-bg-blue‘);
});
});

$(".ok").click(function(){
var allTd = document.querySelectorAll( ‘.td-bg-blue‘);
for(var i=0;i<allTd.length;i++)
{
var td_value = http://www.mamicode.com/allTd[i].innerHTML;
$(‘.weekend-value-area‘).append(td_value+‘&nbsp;‘);
}
});

$(‘.copy_btn‘).click(function(){
$(this).parent().parent().find(‘.copy‘).before("<br><br><div><label>选择周数:</label><div class=‘weekend-value-areas‘></div><div class=‘weekend-choose‘><input type=‘button‘ value=http://www.mamicode.com/‘单周‘ onclick=‘single(this)‘>
123456
7 8 9 101112
131415161718
192021222324

");
});

$(‘.add_submit‘).click(function(){
location.href="http://www.mamicode.com/course_info.jsp";
});

});
/*加载楼*/
var ip = ‘<%=request.getServerName()%>‘;
var port = ‘<%=request.getServerPort()%>‘;
var url = "http://"+ip+":"+port;
function loadBuilding(){
$.get(url+‘/root/api/build‘,{},
function(data){
if(data.success) {
var building =document.getElementById(‘building‘);
var story = document.getElementById(‘story‘);
var classRoom =document.getElementById(‘classRoom‘);
building.options.length=0;
story.options.length=0;
classRoom.options.length=0;
for (var i = 0; i < data.resultData.length; i++) {
var buildind_value = http://www.mamicode.com/data.resultData[i].area_name;
building.options.add(new Option(buildind_value));//创造option
}
$(‘#building‘).change(function(){
$(‘#building option:selected‘).each(function(){
var index = building.selectedIndex;
var building_selected_text = $(this).val();
var building_pk_area = data.resultData[index].pk_area;
story.options.length=0;
classRoom.options.length=0;
/*加载层*/
$(‘#story‘).removeClass(‘none‘).addClass(‘block‘);
$.get(url+‘/root/api/story‘,{pk_area:building_pk_area},
function(data){
if(data.success) {
for (var j = 0; j < data.resultData.length; j++) {
var story_value = http://www.mamicode.com/data.resultData[j].area_name;
story.options.add(new Option(story_value));//创造option
}
$(‘#story‘).change(function(){
$(‘#story option:selected‘).each(function(){
var indexTwo = story.selectedIndex;
var story_pk_area = data.resultData[indexTwo].pk_area;
classRoom.options.length=0;
/*加载教室*/
$(‘#classRoom‘).removeClass(‘none‘).addClass(‘block‘);
$.get(url+‘/root/api/classroom‘,{pk_area:story_pk_area},
function(data){
if(data.success) {
// alert(JSON.stringify(data.resultData));
for (var k = 0; k < data.resultData.length; k++) {
var classRoom_value = http://www.mamicode.com/data.resultData[k].area_name;
classRoom.options.add(new Option(classRoom_value));//创造option
}
}
else{
alert(data.msg);
}
}
);
/*加载教室*/
});
});
}
else{
alert(data.msg);
}
}
);
/*加载层*/
});
});
}
else{
alert(data.msg);
}

}
);
}

/*选择校历*/
$.get(url+"/root/api/calendar",{},function(data){
if(data.success){
var school_calendar = document.getElementById(‘school_calender‘);
for(var i=0;i<data.resultData.length;i++){
school_calendar_value = http://www.mamicode.com/data.resultData[i].calendar_name;
school_calendar.options.add(new Option(school_calendar_value));
var start_time = data.resultData[i].action_date;
var end_time = data.resultData[i].end_date;
totalDay = calculateDay(end_time,start_time);
currentWeekday = new Date(start_time).getDay();
switch(currentWeekday){
case 1:
if(totalDay%7 == 0){
totalWeeks = parseInt(totalDay /7);
}
else{
totalWeeks = parseInt(totalDay /7)+1;
}
break;
case 2:
if((totalDay-6)%7==0)
{
totalWeeks = parseInt((totalDay-6)/7)+1;
}
else{
totalWeeks = parseInt((totalDay-6)/7)+2;
}
break;
case 3:
if((totalDay-5)%7==0)
{
totalWeeks = parseInt((totalDay-5)/7)+1;
}
else{
totalWeeks = parseInt((totalDay-5)/7)+2;
}
break;
case 4:
if((totalDay-4)%7==0)
{
totalWeeks = parseInt((totalDay-4)/7)+1;
}
else{
totalWeeks = parseInt((totalDay-4)/7)+2;
}
break;
case 5:
if((totalDay-3)%7==0)
{
totalWeeks = parseInt((totalDay-3)/7)+1;
}
else{
totalWeeks = parseInt((totalDay-3)/7)+2;
}
break;
case 6:
if((totalDay-2)%7==0)
{
totalWeeks = parseInt((totalDay-2)/7)+1;
}
else{
totalWeeks = parseInt((totalDay-2)/7)+2;
}
break;
case 7:
if((totalDay-1)%7==0)
{
totalWeeks = parseInt((totalDay-1)/7)+1;
}
else{
totalWeeks = parseInt((totalDay-1)/7)+2;
}
break;
}

var rows = parseInt(totalWeeks/6);
if(totalWeeks%6==0){
for(var j=1;j<=6;j++){
for(var k=0;k<rows;k++){
// var str = "<tr><td>"+j+"</td></tr>";
// $(‘#weekend-chooses‘).html(str);
var str ="<tr>";
str += "<td>"+j+"</td>";
str += "</tr>";
$(‘#weekend-chooses‘).append(str);

}
}
}
else{
var count = 1;
for(var j=0;j<rows;j++){
str = "<tr>";
for(var k=0;k<6;k++){
str += "<td>";
str += count;
str += "</td>";
count++;
}
str += "</tr>";
}
$(‘#weekend-chooses‘).append(str);
}

}
}
});

/*计算天数*/
function calculateDay($endTime,$startTime){
var endTime = arguments[0],startTime = arguments[1];
endTime = Date.parse(endTime)/1000;
startTime = Date.parse(startTime)/1000;
var time = endTime - startTime;
return (time/(24*60*60));
}
/*单击*/
function single(a){
$(a).parent().find(".weekend-chooses").find(‘td‘).each(function(i,data){
if((i+1)%2==1){
$(this).removeClass(‘td-bg-white‘);
$(this).addClass(‘td-bg-blue‘);
}
else{
$(this).removeClass(‘td-bg-blue‘);
$(this).addClass(‘td-bg-white‘);
}
});
}

function double(b){
$(b).parent().find(".weekend-chooses").find(‘td‘).each(function(i){
if((i+1)%2==0){
$(this).removeClass(‘td-bg-white‘);
$(this).addClass(‘td-bg-blue‘);
}
else{
$(this).removeClass(‘td-bg-blue‘);
$(this).addClass(‘td-bg-white‘);
}
});
}

function cancel(c){
$(c).parent().find(".weekend-chooses").find(‘td‘).each(function(i){
$(this).removeClass(‘td-bg-blue‘);
$(this).addClass(‘td-bg-white‘);
$(c).parent().parent().find(‘.weekend-value-areas‘).empty();
});
}

function checkAll(d){
$(d).parent().find(".weekend-chooses").find(‘td‘).each(function(i){
$(this).removeClass(‘td-bg-white‘);
$(this).addClass(‘td-bg-blue‘);
});
}

function everyTd(e){
$(e).parent().find(".weekend-chooses").find(‘td‘).bind(‘click‘,function(){
$(this).removeClass(‘td-bg-white‘);
$(this).addClass(‘td-bg-blue‘);
});

$(e).parent().find(".weekend-chooses").find("td").bind(‘dblclick‘,function(){
$(this).removeClass(‘td-bg-blue‘);
$(this).addClass(‘td-bg-white‘);
});
}

function choose(g){
$(g).parent().find(‘.weekend-chooses‘).find(‘.td-bg-blue‘).each(function(i){
var td_value = http://www.mamicode.com/$(this).text();
$(g).parent().parent().find(‘.weekend-value-areas‘).append(td_value+‘&nbsp;‘);
});
}

/*jstree define*/
initNavigation($("#teachercode", window.parent.document).val());
function initNavigation(userCode){
//初始化导航树
var ip = ‘<%=request.getServerName()%>‘;
var port = ‘<%=request.getServerPort()%>‘;
var url = "http://"+ip+":"+port;
$.get(url+"/root/api/class",
{
user_code: userCode
},
function (data) //回传函数
{
$(‘#second-tree‘).jstree("destroy");
var treeChildrenData = http://www.mamicode.com/listToTree(data);
var treeData = http://www.mamicode.com/[{
"id": "#",
"text": "",
"children": treeChildrenData,
"state": {
"opened": true
}
}];

$(‘#second-tree‘).jstree({
"core": {
"check_callback": true,
"themes": {
"responsive": true
},
‘strings‘: {
‘Loading ...‘: ‘加载中 ...‘
},
animation: 200,
"multiple": false,
‘data‘: treeData
}
});
$(‘#second-tree‘).on(‘select_node.jstree‘, function (e, data) {

});
}
);
}

/**
* @author andyzhao
* list转化为tree
* @param data
* @param selectedID 当存在selectID时,默认选中id为selectID的节点
* @returns {Array}
*/
function listToTree(data, selectedID) {
var result = [];
$.each(data, function (n, e) {
var cc = [];
if (e.children != null) {
cc = listToTree(e.children, selectedID);
}
var isChecked = false;
if (e.isChecked == "true") {
isChecked = true;
}
if (e.id == selectedID) {
isChecked = true;
}

e.children = cc;
//e.icon = "fa fa-folder icon-state-default";
e.state = {
"opened": true,
//"selected": isChecked
};

result.push(convertItem(e));
});
return result;
}

function convertItem(o) {
o.id = o.deptcode;
o.text = o.deptname;
return o;
}

</script>
</html>




动态添加