[项目实训]6.8 contest的add功能最终完成
2017-06-08 20:37
260 查看
在和cxa的共同努力下,contest的add终于实现,我在html 文件中完成了script脚本的编写
<script type="text/javascript">
$(document).ready(function ()
{
$("#show_pass").change(function ()
{
if(!document.getElementById("contest_pass")){
$("#contest_open").after("<div class = \"row\" id=\"contest_pass\">"+
"<label class=\"col-sm-2 control-label\">Password:</label>"+
"<div class=\"col-sm-5\">"+
"<input type=\"password\" class=\"form-control\" name=\"password\">"+
"</div>"+
"</div>")
}
});
$("#hide_pass").change(function ()
{
if(document.getElementById("contest_pass")){
$("div").remove("#contest_pass")
}
})
$("#show_score").change(function()
{
$(".score_input").show();
})
$("#hide_score").change(function()
{
$(".score_input").hide();
})
});
function removeTR(tdobject){
var td=$(tdobject);
td.parents("tr").remove();
}
function addTR(){
$("#probTable").append("<tr><td><select name=\"originoj\" class=\"form-control\" value=\"\" style=\"width:100px;\" ><option value=\"HDU\">HDU</option><option value=\"FZU\">FZU</option><option value=\"ZOJ\">ZOJ</option></select></td><td><input type=\"text\" class=\"form-control\" name=\"prob\" oninput=\"getTitle(event,this)\" onpropertychange=\"getTitle(event,this)\"></td><td><input type=\"text\" class=\"form-control\" value=\"No Such Problem\" name=\"title\" disabled=\"disabled\" style=\"width:200px;\"></td><td hidden=\"hidden\" class=\"score_input\"><input type=\"text\" class=\"form-control\" name=\"score\" value = \"1\" style=\"width:80px;\"></td><td onclick=\"removeTR(this)\"><center><button type=\"button\" class=\"btn btn-danger\">Remove</button></center></td></tr>")
if($("input[name='type']:checked").val() == "custom"){
$(".score_input").show();
}else{
$(".score_input").hide();
}
}
function getTitle(event,inputobject){
var trobject = $(inputobject).parents("tr")
var originoj = $(trobject).children("td").eq(0).children("select").eq(0).val()
var probid = $(inputobject).val()
var title_obj = $(trobject).children("td").eq(2).children("input").eq(0)
$.ajax({
type: 'get',
url: "/contest/addcontest/get_problem_title/?originoj=" + originoj+"&probid="+probid,
success: function (responseData) {
$(title_obj).val(responseData);
}
})
}
function addcontest_submit(){
//author type openness title begin duration
var problems = "$"
var ok = 0
$("#probTable tr").each(function(){
var originoj = $(this).children("td").eq(0).children("select").eq(0).val()
var probid = $(this).children("td").eq(1).children("input").eq(0).val()
var title = $(this).children("td").eq(2).children("input").eq(0).val()
var score = $(this).children("td").eq(3).children("input").eq(0).val()
if(title == "No Such Problem" || isNaN(score)){
//alert(title+"/"+score)
ok = ok + 1
}else{
problems = problems + originoj + "|" + probid + "|" + score + "$"
}
})
//alert(problems)
if(ok < 2){
var pass = ""
var obj = $('input[name="password"]')
if(obj.length != 0){
pass = $('input[name="password"]').val()
}
detail = {
"author" : $('input[name="author"]').val(),
"type" : $('input[name="type"]').val(),
"openness" : $('input[name="openness"]').val(),
"password" : pass,
"title" : $('input[name="title"]').val(),
"begin" : $('input[name="begin"]').val(),
"duration" : $('input[name="duration"]').val(),
"problems" : problems
}
$.ajax({
type : "post",
url : "/contest/addcontest/submit/",
data : detail,
success : function(responseData){
if(responseData == "begin error"){
alert("Please check your begin-time format!")
}else if(responseData == "duration error"){
alert("Please check your duration format!")
}else if(responseData == "error"){
alert("Occur a unexcepted error!")
}else{
window.location.href = responseData;
}
},
error : function(responseData){
alert("Add contest error!")
alert(responseData)
}
})
}else{
alert("Please check your problems!")
}
}
</script>
<script type="text/javascript">
$(document).ready(function ()
{
$("#show_pass").change(function ()
{
if(!document.getElementById("contest_pass")){
$("#contest_open").after("<div class = \"row\" id=\"contest_pass\">"+
"<label class=\"col-sm-2 control-label\">Password:</label>"+
"<div class=\"col-sm-5\">"+
"<input type=\"password\" class=\"form-control\" name=\"password\">"+
"</div>"+
"</div>")
}
});
$("#hide_pass").change(function ()
{
if(document.getElementById("contest_pass")){
$("div").remove("#contest_pass")
}
})
$("#show_score").change(function()
{
$(".score_input").show();
})
$("#hide_score").change(function()
{
$(".score_input").hide();
})
});
function removeTR(tdobject){
var td=$(tdobject);
td.parents("tr").remove();
}
function addTR(){
$("#probTable").append("<tr><td><select name=\"originoj\" class=\"form-control\" value=\"\" style=\"width:100px;\" ><option value=\"HDU\">HDU</option><option value=\"FZU\">FZU</option><option value=\"ZOJ\">ZOJ</option></select></td><td><input type=\"text\" class=\"form-control\" name=\"prob\" oninput=\"getTitle(event,this)\" onpropertychange=\"getTitle(event,this)\"></td><td><input type=\"text\" class=\"form-control\" value=\"No Such Problem\" name=\"title\" disabled=\"disabled\" style=\"width:200px;\"></td><td hidden=\"hidden\" class=\"score_input\"><input type=\"text\" class=\"form-control\" name=\"score\" value = \"1\" style=\"width:80px;\"></td><td onclick=\"removeTR(this)\"><center><button type=\"button\" class=\"btn btn-danger\">Remove</button></center></td></tr>")
if($("input[name='type']:checked").val() == "custom"){
$(".score_input").show();
}else{
$(".score_input").hide();
}
}
function getTitle(event,inputobject){
var trobject = $(inputobject).parents("tr")
var originoj = $(trobject).children("td").eq(0).children("select").eq(0).val()
var probid = $(inputobject).val()
var title_obj = $(trobject).children("td").eq(2).children("input").eq(0)
$.ajax({
type: 'get',
url: "/contest/addcontest/get_problem_title/?originoj=" + originoj+"&probid="+probid,
success: function (responseData) {
$(title_obj).val(responseData);
}
})
}
function addcontest_submit(){
//author type openness title begin duration
var problems = "$"
var ok = 0
$("#probTable tr").each(function(){
var originoj = $(this).children("td").eq(0).children("select").eq(0).val()
var probid = $(this).children("td").eq(1).children("input").eq(0).val()
var title = $(this).children("td").eq(2).children("input").eq(0).val()
var score = $(this).children("td").eq(3).children("input").eq(0).val()
if(title == "No Such Problem" || isNaN(score)){
//alert(title+"/"+score)
ok = ok + 1
}else{
problems = problems + originoj + "|" + probid + "|" + score + "$"
}
})
//alert(problems)
if(ok < 2){
var pass = ""
var obj = $('input[name="password"]')
if(obj.length != 0){
pass = $('input[name="password"]').val()
}
detail = {
"author" : $('input[name="author"]').val(),
"type" : $('input[name="type"]').val(),
"openness" : $('input[name="openness"]').val(),
"password" : pass,
"title" : $('input[name="title"]').val(),
"begin" : $('input[name="begin"]').val(),
"duration" : $('input[name="duration"]').val(),
"problems" : problems
}
$.ajax({
type : "post",
url : "/contest/addcontest/submit/",
data : detail,
success : function(responseData){
if(responseData == "begin error"){
alert("Please check your begin-time format!")
}else if(responseData == "duration error"){
alert("Please check your duration format!")
}else if(responseData == "error"){
alert("Occur a unexcepted error!")
}else{
window.location.href = responseData;
}
},
error : function(responseData){
alert("Add contest error!")
alert(responseData)
}
})
}else{
alert("Please check your problems!")
}
}
</script>
相关文章推荐
- [项目实训]6.4 contest的add功能起步
- 关于研发哲学:项目紧急,先把功能完成还是先修改缺陷
- 技术支持课--项目实训--储蓄综合业务平台(第一期)--开户功能实现--c语言编写
- 以下题目均在bookstore项目上完成(请先运行数据库文件): 1、编写单元测试用例,对用户注册功能的Action层进行测试。(注意:测试用例应考虑成功和失败的情况)
- 【SSH网上商城项目实战26】完成订单支付后的短信发送功能
- 【SSH网上商城项目实战23】完成在线支付功能
- [Symbian项目进展]完成了规则库的增删改的功能
- [项目实训]5.28 contest前端硬苟日志
- 【SSH网上商城项目实战23】完成在线支付功能
- HydroCMS完成项目标签功能和自定义目录修改功能
- 【SSH网上商城项目实战26】完成订单支付后的短信发送功能
- 技术支持课--项目实训--储蓄综合业务平台--完成--C语言编写
- 安卓实训第六天:首先使用AsyncHttpClient来完成网页源代码的显示功能,json数据在服务器端的读取还有安卓上的读取
- 早在2012我完成了对我的BSC荣誉学位,计算最终的项目
- 【SSH网上商城项目实战26】完成订单支付后的短信发送功能
- 项目外包,类似QQ这样界面的客户端,要求界面漂亮,功能是帮助客户完成在线业务的功能。
- 第十一周项目5-大赛计分器 各种功能一身完成
- 第十三周 项目5:(2)阅读程序,完成类似字符串复制的功能
- 【SSH网上商城项目实战26】完成订单支付后的短信发送功能
- 小项目第一天完成了注册功能