修改项目结构,还有些混乱。

This commit is contained in:
virusdefender
2015-07-31 23:23:15 +08:00
parent c6d6b13072
commit 26dab5bd91
93 changed files with 48009 additions and 10 deletions

View File

@@ -0,0 +1,44 @@
define("login", ["jquery", "validation"], function($){
$("#login-form")
.formValidation({
framework: "bootstrap",
fields: {
username: {
validators: {
notEmpty: {
message: "请填写用户名"
}
}
},
password: {
validators: {
notEmpty: {
message: "请填写密码"
}
}
}
}
}
).on('success.form.fv', function(e) {
e.preventDefault();
var username = $("#username").val();
var password = $("#password").val();
$.ajax({
url: "/api/login/",
data: {username: username, password: password},
dataType: "json",
method: "post",
success: function (data) {
if(!data.code){
window.location.href="/";
}
else{
alert(data.data);
}
}
})
});
});

182
static/src/js/app/admin.js Normal file
View File

@@ -0,0 +1,182 @@
define(["jquery", "avalon", "editor", "uploader", "datetime_picker",
"validation", "dropdown"
],
function ($, avalon, editor, uploader) {
$("#add-contest-form")
.formValidation({
framework: "bootstrap",
fields: {
name: {
validators: {
notEmpty: {
message: "请填写比赛名称"
},
stringLength: {
min: 1,
max: 30,
message: "名称不能超过30个字"
}
}
},
start_time: {
validators: {
notEmpty: {
message: "请填写开始时间"
},
date: {
format: "YYYY-MM-DD h:m",
message: "请输入一个正确的日期格式"
}
}
},
end_time: {
validators: {
notEmpty: {
message: "请填写结束时间"
},
date: {
format: "YYYY-MM-DD h:m",
message: "请输入一个正确的日期格式"
}
}
},
password: {
validators: {
stringLength: {
min: 0,
max: 30,
message: "密码不能超过10个字符"
}
}
},
"problem_name[]": {
validators: {
notEmpty: {
message: "请输入题目名称"
},
stringLength: {
min: 1,
max: 30,
message: "题目不能超过30个字符"
}
}
},
"cpu[]": {
validators: {
notEmpty: {
message: "请输入cpu时间"
},
integer: {
message: "请输入一个合法的数字"
},
between: {
inclusive: true,
min: 1,
max: 5000,
message: "只能在1-5000之间"
}
}
},
"memory[]": {
validators: {
notEmpty: {
message: "请输入内存"
},
integer: {
message: "请输入一个合法的数字"
}
}
}
}
})
.on("success.form.fv", function (e) {
e.preventDefault();
alert("1111");
});
function make_id() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
var editor1 = editor("#editor");
var vm = avalon.define({
$id: "add_contest",
problems: [],
add_problem: function () {
var problem = {};
var problem_id = make_id();
problem["id"] = problem_id;
problem["samples"] = [];
problem["webuploader"] = {};
problem["toggle_string"] = "折叠";
vm.problems.push(problem);
uploader("#problem-" + problem_id + "-uploader");
console.log(vm.problems);
$("#add-contest-form").formValidation('addField', $('[name="problem_name[]"]'));
$("#add-contest-form").formValidation('addField', $('[name="cpu[]"]'));
$("#add-contest-form").formValidation('addField', $('[name="memory[]"]'));
},
del_problem: function (problem) {
if (confirm("你确定要删除么?")) {
vm.problems.remove(problem);
}
},
toggle_problem: function (problem) {
$("#" + "problem-" + problem.id + "-body").toggle();
if (problem["toggle_string"] == "展开") {
problem["toggle_string"] = "折叠";
}
else {
problem["toggle_string"] = "展开";
}
},
add_sample: function (problem) {
problem["samples"].push({"id": make_id(), "toggle_string": "折叠"});
},
del_sample: function (problem, sample) {
if (confirm("你确定要删除么?")) {
problem["samples"].remove(sample);
}
},
toggle_sample: function (problem, sample) {
$("#" + "problem-" + problem.id + "-sampleio-" + sample.id + "-body").toggle();
if (sample["toggle_string"] == "展开") {
sample["toggle_string"] = "折叠";
}
else {
sample["toggle_string"] = "展开";
}
}
});
avalon.scan();
$("#contest_start_time").datetimepicker({
format: "yyyy-mm-dd hh:ii",
minuteStep: 5,
weekStart: 1,
language: "zh-CN"
});
$("#contest_end_time").datetimepicker({
format: "yyyy-mm-dd hh:ii",
minuteStep: 5,
weekStart: 1,
language: "zh-CN"
});
$("#contest_start_time").datetimepicker()
.on("hide", function (ev) {
$("#add-contest-form")
.formValidation("revalidateField", "start_time");
});
$("#contest_end_time").datetimepicker()
.on("hide", function (ev) {
$("#add-contest-form")
.formValidation("revalidateField", "end_time");
});
});

4
static/src/js/app/oj.js Normal file
View File

@@ -0,0 +1,4 @@
require(["../config"], function(){
require(["login"])
});

View File

@@ -0,0 +1,32 @@
require(["../../config"], function (config) {
require(["jquery", "avalon", "code_mirror"], function ($, avalon, code_mirror) {
var code_editor = code_mirror($("#code-editor")[0], "text/x-csrc");
$("#language-selector").change(function () {
var language = $("#language-selector").val();
var language_types = {c: "text/x-csrc", cpp: "text/x-c++src", java: "text/x-java"};
code_editor.setOption("mode", language_types[language]);
});
function show_loading(){
$("#submit-code-button").attr("disabled", "disabled");
$("#loading-gif").show();
}
function hide_loading(){
$("#submit-code-button").removeAttr("disabled");
$("#loading-gif").hide();
}
$("#submit-code-button").click(function () {
show_loading();
setTimeout(
function(){
$("#a").animate({opacity:'1'})}
,
3);
})
});
});

42
static/src/js/build.js Normal file
View File

@@ -0,0 +1,42 @@
({
// RequireJS 通过一个相对的路径 baseUrl来加载所有代码。baseUrl通常被设置成data-main属性指定脚本的同级目录。
baseUrl: ".",
//dir: '../built',
// 第三方脚本模块的别名,jquery比libs/jquery-1.11.1.min.js简洁明了
paths: {
//百度webuploader
webuploader: "lib/webuploader/webuploader",
jquery: "empty:",
avalon: "lib/avalon/avalon",
editor: "utils/editor",
uploader: "utils/uploader",
validation: "utils/validation",
code_mirror: "utils/code_mirror",
//formValidation 不要在代码中单独使用而是使用和修改utils/validation
base: "lib/formValidation/base",
helper: "lib/formValidation/helper",
"language/zh_CN": "lib/formValidation/language/zh_CN",
"framework/bootstrap": "lib/formValidation/framework/bootstrap",
"validator/notEmpty": "lib/formValidation/validator/notEmpty",
"validator/stringLength": "lib/formValidation/validator/stringLength",
"validator/date": "lib/formValidation/validator/date",
"validator/integer": "lib/formValidation/validator/integer",
"validator/between": "lib/formValidation/validator/between",
//富文本编辑器
simditor: "lib/simditor/simditor",
"simple-module": "lib/simditor/module",
"simple-hotkeys": "lib/simditor/hotkeys",
"simple-uploader": "lib/simditor/uploader",
//code mirroe 代码编辑器
_code_mirror: "lib/codeMirror/codemirror",
code_mirror_clang: "lib/codeMirror/language/clike"
},
modules: [{name: "app/main1"}],
dir: "app",
findNestedDependencies: true
//wrapShim: true
})

39
static/src/js/config.js Normal file
View File

@@ -0,0 +1,39 @@
require.config({
// RequireJS 通过一个相对的路径 baseUrl来加载所有代码。baseUrl通常被设置成data-main属性指定脚本的同级目录。
baseUrl: "/static/js/lib/",
paths: {
//百度webuploader
webuploader: "webuploader/webuploader",
jquery: "jquery/jquery",
avalon: "avalon/avalon",
editor: "../utils/editor",
uploader: "../utils/uploader",
validation: "../utils/validation",
code_mirror: "../utils/code_mirror",
login: "../app/account/login",
oj: "../app/oj",
//formValidation 不要在代码中单独使用而是使用和修改utils/validation
base: "formValidation/base",
helper: "formValidation/helper",
"language/zh_CN": "formValidation/language/zh_CN",
"framework/bootstrap": "formValidation/framework/bootstrap",
"validator/notEmpty": "formValidation/validator/notEmpty",
"validator/stringLength": "formValidation/validator/stringLength",
"validator/date": "formValidation/validator/date",
"validator/integer": "formValidation/validator/integer",
"validator/between": "formValidation/validator/between",
//富文本编辑器 不要直接使用而是使用上面的editor
simditor: "simditor/simditor",
"simple-module": "simditor/module",
"simple-hotkeys": "simditor/hotkeys",
"simple-uploader": "simditor/uploader",
//code mirroe 代码编辑器
_code_mirror: "codeMirror/codemirror",
code_mirror_clang: "codeMirror/language/clike"
}
});

29967
static/src/js/r.js Normal file

File diff suppressed because one or more lines are too long

2090
static/src/js/require.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
define("code_mirror", ["_code_mirror", "code_mirror_clang"], function(CodeMirror){
function code_mirror(selector, language){
return CodeMirror.fromTextArea(selector,
{
indentUnit: 4,
lineNumbers: true,
matchBrackets: true,
mode: language
});
}
return code_mirror;
});

View File

View File

@@ -0,0 +1,22 @@
define("editor", ["simditor"], function(Simditor){
function editor(selector){
return new Simditor({
textarea: $(selector),
toolbar: [
"bold", "color", "ol", "ul", "code", "link", "image"
],
toolbarFloat: false,
defaultImage: null,
upload: {
url: "",
params: null,
fileKey: "image",
connectionCount: 3,
leaveConfirm: "正在上传文件,如果离开上传会自动取消"
},
pasteImage: true,
imageButton: ["upload"]
});
}
return editor;
});

4
static/src/js/utils/html5shiv.min.js vendored Normal file
View File

@@ -0,0 +1,4 @@
/**
* @preserve HTML5 Shiv 3.7.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
*/
!function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x<style>"+b+"</style>",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.2",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="<xyz></xyz>",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b)}(this,document);

View File

@@ -0,0 +1,24 @@
function _notify(notify_type, title, content){
$.notify({
title: title,
message: content
}, {
type: notify_type,
placement: {
from: "top",
align: "center"
},
offset: {
y: 50
},
delay: 3000,
timer: 1000
});
}
function show_info(title, content) {
_notify("info", title, content);
}
function show_warning(title, content) {
_notify("warning", title, content);
}

5
static/src/js/utils/respond.min.js vendored Normal file
View File

@@ -0,0 +1,5 @@
/*! Respond.js v1.4.2: min/max-width media query polyfill * Copyright 2013 Scott Jehl
* Licensed under https://github.com/scottjehl/Respond/blob/master/LICENSE-MIT
* */
!function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='&shy;<style media="'+a+'"> #mq-test-1 { width: 42px; }</style>',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b<s.length;b++){var c=s[b],e=c.href,f=c.media,g=c.rel&&"stylesheet"===c.rel.toLowerCase();e&&g&&!o[e]&&(c.styleSheet&&c.styleSheet.rawCssText?(v(c.styleSheet.rawCssText,e,f),o[e]=!0):(!/^([a-zA-Z:]*\/\/)/.test(e)&&!r||e.replace(RegExp.$1,"").split("/")[0]===a.location.host)&&("//"===e.substring(0,2)&&(e=a.location.protocol+e),d.push({href:e,media:f})))}w()};x(),c.update=x,c.getEmValue=t,a.addEventListener?a.addEventListener("resize",b,!1):a.attachEvent&&a.attachEvent("onresize",b)}}(this);

View File

@@ -0,0 +1,20 @@
define("uploader", ["webuploader"], function(webuploader){
function uploader(selector) {
return webuploader.create({
// swf文件路径
swf: "/js/Uploader.swf",
// 文件接收服务端。
server: "http://webuploader.duapp.com/server/fileupload.php",
// 选择文件的按钮。可选。
// 内部根据当前运行是创建可能是input元素也可能是flash.
pick: selector,
// 不压缩image, 默认如果是jpeg文件上传前会压缩一把再上传
resize: false
});
}
return uploader;
});

View File

@@ -0,0 +1,11 @@
define("validation",
[ 'base',
'helper',
'framework/bootstrap',
'language/zh_CN',
'validator/notEmpty',
'validator/stringLength',
'validator/date',
'validator/integer',
'validator/between'], function () {
});