diff --git a/admin/views.py b/admin/views.py index 78762c0..b37d22d 100644 --- a/admin/views.py +++ b/admin/views.py @@ -11,4 +11,4 @@ class AdminTemplateView(APIView): try: return HttpResponse(open(path).read(), content_type="text/html") except IOError: - raise Http404 + return HttpResponse(u"模板不存在", content_type="text/html") diff --git a/static/src/css/admin.css b/static/src/css/admin.css index 75fc901..e54f0e3 100644 --- a/static/src/css/admin.css +++ b/static/src/css/admin.css @@ -1,25 +1,15 @@ +@import url("global.css"); @import url("bootstrap/bootstrap.min.css"); @import url("bootstrap/todc-bootstrap.min.css"); @import url("codeMirror/codemirror.css"); @import url("simditor/simditor.css"); @import url("webuploader/webuploader.css"); @import url("datetime_picker/bootstrap-datetimepicker.css"); -html, body { - height: 100%; -} -img { - max-width: 100%; - height: auto; -} - -.footer { - padding-top: 30px; - padding-bottom: 30px; - float: bottom; - bottom: 0; -} - -label { - font-size: 16px; +#loading-gif{ + width: 40px; + height: 40px; + margin: auto; + position: absolute; + top: 0; left: 0; bottom: 0; right: 0; } \ No newline at end of file diff --git a/static/src/css/global.css b/static/src/css/global.css new file mode 100644 index 0000000..c55a0bb --- /dev/null +++ b/static/src/css/global.css @@ -0,0 +1,27 @@ +html{ + height: 100%; +} + +body{ + height:100%; /*使内容高度和body一样*/ + margin-bottom:-80px;/*向上缩减80像素,不至于footer超出屏幕可视范围*/ +} + +.main{ + padding-bottom: 120px; +} + +img { + max-width: 100%; + height: auto; +} + +.footer { + left: 0; + right: 0; + height: 80px +} + +label { + font-size: 16px; +} \ No newline at end of file diff --git a/static/src/css/oj.css b/static/src/css/oj.css index fcf80dd..cc6ac62 100644 --- a/static/src/css/oj.css +++ b/static/src/css/oj.css @@ -1,25 +1,8 @@ +@import url("global.css"); @import url("bootstrap/bootstrap.min.css"); @import url("bootstrap/todc-bootstrap.min.css"); @import url("codeMirror/codemirror.css"); -html, body { - height: 100%; -} -img { - max-width: 100%; - height: auto; -} - -.footer { - padding-top: 30px; - padding-bottom: 30px; - float: bottom; - bottom: 0; -} - -label { - font-size: 16px; -} #language-selector { width: 130px; @@ -47,7 +30,6 @@ label { font-size: 15px; } -/* index css */ .jumbotron { text-align: center; background-color: transparent; diff --git a/static/src/js/app/admin/admin.js b/static/src/js/app/admin/admin.js index d3e30ac..4145a45 100644 --- a/static/src/js/app/admin/admin.js +++ b/static/src/js/app/admin/admin.js @@ -7,25 +7,36 @@ define("admin", ["jquery", "avalon"], function($, avalon){ $(".list-group-item").attr("class", "list-group-item"); } + function show_template(url){ + $("#loading-gif").show(); + vm.template_url = url; + } + + var vm = avalon.define({ + $id: "admin", + template_url: "template/index/index.html", + hide_loading: function(){ + $("#loading-gif").hide(); + } + }); + var hash = window.location.hash.substring(1); if(hash){ - li_active("#li-" + hash); + li_active("#li-" + hash.replace("/", "-")); + show_template("template/" + hash + ".html"); }else { - li_active("#li-index"); + li_active("#li-index-index"); } window.onhashchange = function() { var hash = window.location.hash.substring(1); if(hash){ li_inactive(".list-group-item"); - li_active("#li-" + hash); - vm.template_url = "template/index/" + hash + ".html"; + li_active("#li-" + hash.replace("/", "-")); + show_template("template/" + hash + ".html"); } }; - var vm = avalon.define({ - $id: "admin", - template_url: "template/index/index.html" - }); + }); \ No newline at end of file diff --git a/static/src/js/app/admin/announcement/announcement.js b/static/src/js/app/admin/announcement/announcement.js new file mode 100644 index 0000000..1d3cc28 --- /dev/null +++ b/static/src/js/app/admin/announcement/announcement.js @@ -0,0 +1,154 @@ +require(["jquery", "avalon", "csrf", "bs_alert", "editor", "validation"], function ($, avalon, csrfHeader, bs_alert, editor) { + announcementEditor = editor("#editor"); //创建新建公告的内容编辑器 + editAnnouncementEditor = null; + + if (!avalon.vmodels.announcement) // 防止模式重新定义 + { + // avalon:定义模式 announcement + vm = avalon.define({ + $id: "announcement", + announcement: [], // 公告列表数据项 + previous_page: 0, // 之前的页数 + next_page: 0, // 之后的页数 + page: 1, // 当前页数 + isEditing: 0, // 正在编辑的公告的ID, 为零说明未在编辑 + getState: function (el) { //获取公告当前状态,显示 + if (el.visible) + return "可见"; + else + return "隐藏"; + }, + getNext: function (el) { + if (!vm.next_page) + return; + getPageData(++(vm.page)); + }, + getPrevious: function (el) { + if (!vm.previous_page) + return; + getPageData(--(vm.page)); + }, + getBtnClass: function (btn) { + if (btn) { + return vm.next_page ? "btn btn-primary" : "btn btn-primary disabled"; + } + else { + return vm.previous_page ? "btn btn-primary" : "btn btn-primary disabled"; + } + + }, + enEdit: function (el) { //点击编辑按钮的事件,显示/隐藏编辑区 + $("#newTitle").val(el.title); + if (!editAnnouncementEditor) //初始化编辑器 + editAnnouncementEditor = editor("#editAnnouncementEditor"); + editAnnouncementEditor.setValue(el.content); + if (el.visible == false) + $("#hidden").attr("checked", true); + if (vm.isEditing == el.id) + vm.isEditing = 0; + else + vm.isEditing = el.id; + editAnnouncementEditor.focus(); + }, + disEdit: function () { //收起编辑框 + vm.isEditing = 0; + }, + submitChange: function () { // 处理编辑公告提交事件,顺便验证字段为空 + var title = $("#newTitle").val(), content = editAnnouncementEditor.getValue(), visible = true; + if ($("#hidden").attr("checked") == true) + visible = false; + if (title != "") { + if (content != "") { + $.ajax({ //发送修改公告请求 + beforeSend: csrfHeader, + url: "/api/edit_announcements/", + dataType: "json", + method: "post", + data: {id: vm.isEditing, title: title, content: content, visible: visible}, + success: function (data) { + if (!data.code) { + bs_alert("修改成功"); + vm.isEditing = 0; + } + else { + bs_alert(data.data); + } + } + }); + } + else + bs_alert("公告内容不得为空"); + } + else + bs_alert("公告标题不能为空"); + } + }); + } + + avalon.scan(); + getPageData(1); //公告列表初始化 + vm.page = 1; + vm.isEditing = 0; + //Ajax get数据 + function getPageData(page) { + $.ajax({ + beforeSend: csrfHeader, + url: "/api/announcements/?paging=true&page=" + page + "&page_size=10", + dataType: "json", + method: "get", + success: function (data) { + if (!data.code) { + vm.announcement = data.data.results; + vm.previous_page = data.data.previous_page; + vm.next_page = data.data.next_page; + } + else { + bs_alert(data.data); + } + } + }); + } + + //新建公告表单验证与数据提交 + $("#announcement-form") + .formValidation({ + framework: "bootstrap", + fields: { + title: { + validators: { + notEmpty: { + message: "请填写公告标题" + } + } + } + } + } + ).on('success.form.fv', function (e) { + e.preventDefault(); + var title = $("#title").val(); + var content = announcementEditor.getValue(); + if (content == "") { + bs_alert("请填写公告内容"); + return; + } + $.ajax({ + beforeSend: csrfHeader, + url: "/api/admin/announcement/", + data: {title: title, content: content}, + dataType: "json", + method: "post", + success: function (data) { + if (!data.code) { + bs_alert("提交成功!"); + $("#title").val(""); + announcementEditor.setValue(""); + getPageData(1, function (data) { + }); + } else { + bs_alert(data.data); + } + } + }) + }); + +}); \ No newline at end of file diff --git a/static/src/js/app/admin/contest/contest.js b/static/src/js/app/admin/contest/contest.js index bc13d9d..6cd531d 100644 --- a/static/src/js/app/admin/contest/contest.js +++ b/static/src/js/app/admin/contest/contest.js @@ -2,6 +2,7 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker", "validation" ], function ($, avalon, editor, uploader) { + avalon.vmodels.add_contest = null; $("#add-contest-form") .formValidation({ framework: "bootstrap", diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js index 52c3d36..432ce21 100644 --- a/static/src/js/app/oj/account/register.js +++ b/static/src/js/app/oj/account/register.js @@ -4,7 +4,6 @@ require(["jquery", "bs_alert", "csrf", "validation"], function ($, bs_alert, csr framework: "bootstrap", fields: { username: { - trigger: 'blur', validators: { notEmpty: { message: "请填写用户名" @@ -55,7 +54,6 @@ require(["jquery", "bs_alert", "csrf", "validation"], function ($, bs_alert, csr } }, email: { - trigger: 'blur', validators: { notEmpty: { message: "请填写电子邮箱邮箱地址" diff --git a/static/src/js/lib/formValidation/validator/remote.js b/static/src/js/lib/formValidation/validator/remote.js index e7f8d02..83a6fc5 100755 --- a/static/src/js/lib/formValidation/validator/remote.js +++ b/static/src/js/lib/formValidation/validator/remote.js @@ -35,6 +35,8 @@ method: "post" }); xhr.success(function(response) { + if (response.code == 1) + dfd.resolve($field, 'remote',{valid:true, message:options.msg}); dfd.resolve($field, 'remote',{valid:!response.data, message:options.msg}); }) .error(function(response) { diff --git a/template/admin/admin.html b/template/admin/admin.html index c712084..e3bc97b 100644 --- a/template/admin/admin.html +++ b/template/admin/admin.html @@ -1,5 +1,3 @@ - - @@ -67,23 +65,46 @@ -
+
- + -
+ +
+
diff --git a/template/admin/contest/add_contest.html b/template/admin/contest/add_contest.html index d3fa165..9a789a4 100644 --- a/template/admin/contest/add_contest.html +++ b/template/admin/contest/add_contest.html @@ -1,185 +1,179 @@ -{% extends "admin_base.html" %} -{% block body %} - {% verbatim %} -
+
-
-
-
- + +
+
+ +
+
+
+
-
-
- -
+
+
+ +
+
+
+
-
- +
+
+ +
+
+ +
+
+
+
-
-
- -
-
-
- -
-
- -
-
-
- -
-
-
-
- -
+
+
+
+
+
-
- +
+ +
+
+ +
+
+ +
+
+
+
-
- +
+
+
+ OI + ACM
-
- -
-
-
- -
-
-
-
- OI - ACM -
-
-
-
- 开放排名 -
+
+
+
+ 开放排名
+
-
- - 添加 -
-
-
-
-
- 题目{{$index + 1}} - - {{ problem.toggle_string }} - - - 删除 - +
+ + 添加 +
+
+
+
+ +
+
+
-
-
- -
-
-
- -
+
+
+
-
- +
+
+ +
+
+ +
+
+
+
-
- +
+
+
+
-
-
- -
-
-
-
- -
-
-
+
+
- - - 添加 - + + + 添加 + -
-
-
- 样例{{$index + 1}} +
+
+ +
+
+
-
-
- - +
+
+
-
-
- -
-
-
- -
-
-
- -
+
+
+ +
+
+
+
-
- -
-
-
-
选择文件
+
+
+ +
+
+
+
选择文件
-
- -
- {% endverbatim %} -{% endblock %} -{% block js_block %} - -{% endblock %} \ No newline at end of file +
+ +
+ + \ No newline at end of file diff --git a/template/admin/index/announcement.html b/template/admin/index/announcement.html new file mode 100644 index 0000000..c93b760 --- /dev/null +++ b/template/admin/index/announcement.html @@ -0,0 +1,65 @@ + +

Announcement

+
+ + + + + + + + + + + + + + + + + + + +
编号标题创建时间更新时间创建者状态操作
{{el.id}}{{el.title}}{{el.create_time|date("yyyy-MM-dd HH:mm:ss")}}{{el.last_update_time|date("yyyy-MM-dd HH:mm:ss")}}{{el.created_by.username}}{{getState(el)}} + +
+
+ 页数:{{page}}/{{page+next_page}} + 上一页 + 下一页 +
+ +
+

编辑公告

+ +
+
+
+ + +
+
+ + +
+
+ +
+
+

添加公告

+ +
+
+
+
+ + +
+
+ +
+
+
+ \ No newline at end of file diff --git a/template/oj/account/change_password.html b/template/oj/account/change_password.html index 65de447..dd0d84e 100644 --- a/template/oj/account/change_password.html +++ b/template/oj/account/change_password.html @@ -1,6 +1,6 @@ {% extends "oj_base.html" %} {% block body %} -
+

修改密码

diff --git a/template/oj/account/login.html b/template/oj/account/login.html index e9ddbf2..fb4249b 100644 --- a/template/oj/account/login.html +++ b/template/oj/account/login.html @@ -1,6 +1,6 @@ {% extends "oj_base.html" %} {% block body %} -
+

用户登录

diff --git a/template/oj/account/register.html b/template/oj/account/register.html index 34dc9a4..02d66c8 100644 --- a/template/oj/account/register.html +++ b/template/oj/account/register.html @@ -1,6 +1,6 @@ {% extends "oj_base.html" %} {% block body %} -
+

用户注册

diff --git a/template/oj/contest/problems.html b/template/oj/contest/problems.html index 88dd9d2..450415f 100644 --- a/template/oj/contest/problems.html +++ b/template/oj/contest/problems.html @@ -1,6 +1,6 @@ {% extends "oj_base.html" %} {% block body %} -
+