From 90eaadbb1c1efad809879d404d2df7ff50d45153 Mon Sep 17 00:00:00 2001 From: sxw Date: Mon, 3 Aug 2015 16:34:55 +0800 Subject: [PATCH 01/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B3=A8=E5=86=8C=E9=A1=B5=E9=9D=A2=E5=92=8C=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84urls=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 1 + template/oj/account/register.html | 42 ++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/oj/urls.py b/oj/urls.py index 260a42a..84b1363 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ url(r'^docs/', include('rest_framework_swagger.urls')), url(r'^admin/$', TemplateView.as_view(template_name="admin/index.html"), name="admin_index_page"), url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), + url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="login_api"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="user_login_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), diff --git a/template/oj/account/register.html b/template/oj/account/register.html index 71ce692..a93014c 100644 --- a/template/oj/account/register.html +++ b/template/oj/account/register.html @@ -1,10 +1,34 @@ - - - - - - - +{% extends "oj_base.html" %} +{% block body %} +
+
+

用户注册

- - \ No newline at end of file +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+{% endblock %} +{% block js_block %} + +{% endblock %} \ No newline at end of file From 2454db54b0e725dcfd1b1e502c82da66b0727876 Mon Sep 17 00:00:00 2001 From: sxw Date: Mon, 3 Aug 2015 16:37:20 +0800 Subject: [PATCH 02/99] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E5=92=8Ctab=E6=B7=B7=E5=90=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oj/urls.py b/oj/urls.py index 84b1363..b308320 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -10,7 +10,7 @@ urlpatterns = [ url(r'^docs/', include('rest_framework_swagger.urls')), url(r'^admin/$', TemplateView.as_view(template_name="admin/index.html"), name="admin_index_page"), url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), - url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), + url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="login_api"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="user_login_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), From c72624e2d5e997e18a741d2207694d5c8757b22f Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Tue, 4 Aug 2015 13:22:37 +0800 Subject: [PATCH 03/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20login=5Frequired=20d?= =?UTF-8?q?ecorator=20=E5=92=8C=E5=AF=B9=E5=BA=94=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/decorators.py | 24 +++++++++++++ account/test_urls.py | 12 +++++++ account/tests.py | 79 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 account/decorators.py create mode 100644 account/test_urls.py diff --git a/account/decorators.py b/account/decorators.py new file mode 100644 index 0000000..6b10896 --- /dev/null +++ b/account/decorators.py @@ -0,0 +1,24 @@ +# coding=utf-8 +from django.http import HttpResponse +from django.shortcuts import render + +from utils.shortcuts import error_response +from .models import User + + +def login_required(func): + def check(*args, **kwargs): + # 在class based views 里面,args 有两个元素,一个是self, 第二个才是request, + # 在function based views 里面,args 只有request 一个参数 + request = args[-1] + if request.user.is_authenticated(): + return func(*args, **kwargs) + if request.is_ajax(): + return error_response(u"请先登录") + else: + return render(request, "utils/error.html", {"error": u"请先登录"}) + return check + + +def admin_required(): + pass diff --git a/account/test_urls.py b/account/test_urls.py new file mode 100644 index 0000000..4066721 --- /dev/null +++ b/account/test_urls.py @@ -0,0 +1,12 @@ +# coding=utf-8 +from django.conf.urls import include, url + +from .tests import LoginRequiredCBVTestWithArgs, LoginRequiredCBVTestWithoutArgs + + +urlpatterns = [ + url(r'^test/fbv/1/$', "account.tests.login_required_FBV_test_without_args"), + url(r'^test/fbv/(?P\d+)/$', "account.tests.login_required_FBC_test_with_args"), + url(r'^test/cbv/1/$', LoginRequiredCBVTestWithoutArgs.as_view()), + url(r'^test/cbv/(?P\d+)/$', LoginRequiredCBVTestWithArgs.as_view()), +] diff --git a/account/tests.py b/account/tests.py index 90e5d12..83226b7 100644 --- a/account/tests.py +++ b/account/tests.py @@ -1,10 +1,16 @@ # coding=utf-8 +import json + from django.core.urlresolvers import reverse from django.test import TestCase, Client +from django.http import HttpResponse from rest_framework.test import APITestCase, APIClient +from rest_framework.views import APIView +from rest_framework.response import Response from .models import User +from .decorators import login_required class UserLoginTest(TestCase): @@ -98,4 +104,75 @@ class UserChangePasswordAPITest(APITestCase): def test_username_does_not_exist(self): data = {"username": "test1", "old_password": "aaabbb", "new_password": "aaaddd"} response = self.client.post(self.url, data=data) - self.assertEqual(response.data["code"], 1) \ No newline at end of file + self.assertEqual(response.data["code"], 1) + + +@login_required +def login_required_FBV_test_without_args(request): + return HttpResponse("function based view test1") + + +@login_required +def login_required_FBC_test_with_args(request, problem_id): + return HttpResponse(problem_id) + + +class LoginRequiredCBVTestWithoutArgs(APIView): + @login_required + def get(self, request): + return HttpResponse("class based view login required test1") + +class LoginRequiredCBVTestWithArgs(APIView): + @login_required + def get(self, request, problem_id): + return HttpResponse(problem_id) + + +class LoginRequiredDecoratorTest(TestCase): + urls = 'account.test_urls' + + def setUp(self): + self.client = Client() + user = User.objects.create(username="test") + user.set_password("test") + user.save() + + def test_fbv_without_args(self): + # 没登陆 + response = self.client.get("/test/fbv/1/") + self.assertTemplateUsed(response, "utils/error.html") + + # 登陆后 + self.client.login(username="test", password="test") + response = self.client.get("/test/fbv/1/") + self.assertEqual(response.content, "function based view test1") + + def test_fbv_with_args(self): + # 没登陆 + response = self.client.get("/test/fbv/1024/") + self.assertTemplateUsed(response, "utils/error.html") + + # 登陆后 + self.client.login(username="test", password="test") + response = self.client.get("/test/fbv/1024/") + self.assertEqual(response.content, "1024") + + def test_cbv_without_args(self): + # 没登陆 + response = self.client.get("/test/cbv/1/") + self.assertTemplateUsed(response, "utils/error.html") + + # 登陆后 + self.client.login(username="test", password="test") + response = self.client.get("/test/cbv/1/") + self.assertEqual(response.content, "class based view login required test1") + + def test_cbv_with_args(self): + # 没登陆 + response = self.client.get("/test/cbv/1024/", HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(json.loads(response.content), {"code": 1, "data": u"请先登录"}) + + # 登陆后 + self.client.login(username="test", password="test") + response = self.client.get("/test/cbv/1024/") + self.assertEqual(response.content, "1024") From 3ccb7740f2f671efecc711f35a9d11735d7d6f5d Mon Sep 17 00:00:00 2001 From: sxw Date: Tue, 4 Aug 2015 14:55:38 +0800 Subject: [PATCH 04/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E7=9A=84=E9=A1=B5=E9=9D=A2=E5=92=8C?= =?UTF-8?q?js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 1 + .../src/js/app/oj/account/change_password.js | 89 +++++++++++++++++++ static/src/js/config.js | 1 + .../lib/formValidation/validator/confirm.js | 34 +++++++ template/oj/account/change_password.html | 42 +++++++-- 5 files changed, 158 insertions(+), 9 deletions(-) create mode 100644 static/src/js/app/oj/account/change_password.js create mode 100644 static/src/js/lib/formValidation/validator/confirm.js diff --git a/oj/urls.py b/oj/urls.py index b308320..f9d4cbf 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -11,6 +11,7 @@ urlpatterns = [ url(r'^admin/$', TemplateView.as_view(template_name="admin/index.html"), name="admin_index_page"), url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), + url(r'^change_password/$', TemplateView.as_view(template_name="oj/account/change_password.html"), name="user_change_password_page"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="login_api"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="user_login_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), diff --git a/static/src/js/app/oj/account/change_password.js b/static/src/js/app/oj/account/change_password.js new file mode 100644 index 0000000..035e0d3 --- /dev/null +++ b/static/src/js/app/oj/account/change_password.js @@ -0,0 +1,89 @@ + +require(["jquery", "bs_alert", "validation"], function($, bs_alert){ + + + $("#change_password-form").formValidation({ + framework: "bootstrap", + fields: { + username: { + validators: { + notEmpty: { + message: "请填写用户名" + } + } + }, + password: { + validators: { + notEmpty: { + message: "请填写旧密码" + } + } + }, + new_password: { + validators: { + notEmpty: { + message: "请填写新密码" + }, + stringLength: { + min: 6, + max: 30, + message: '密码长度必须在6到30位之间' + }, + confirm: { + firstPassword: $("#new_password"), + secondPassword: $("#confirm_password"), + message: "两次输入的密码必须一致" + } + }, + onSuccess: function(e, data) { + + if (!data.fv.isValidField('confirm_password')) { + data.fv.revalidateField('confirm_password'); + } + } + + }, + confirm_password: { + validators: { + notEmpty: { + message: "请填写确认密码" + }, + confirm: { + firstPassword: $("#new_password"), + secondPassword: $("#confirm_password"), + message: "两次输入的密码必须一致" + } + }, + onSuccess: function(e, data) { + + if (!data.fv.isValidField('new_password')) { + data.fv.revalidateField('new_password'); + } + } + } + } + } + ).on('success.form.fv', function(e) { + e.preventDefault(); + var username = $("#username").val(); + var new_password = $("#new_password ").val(); + var password = $("#password").val(); + $.ajax({ + url: "/api/change_password/", + data: {username: username, new_password: new_password , old_password : password}, + dataType: "json", + method: "post", + success: function (data) { + + if(!data.code){ + window.location.href="/login/"; + } + else{ + bs_alert(data.data); + } + } + + }) + }); + +}); \ No newline at end of file diff --git a/static/src/js/config.js b/static/src/js/config.js index dc17a5a..fbeaa3a 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -25,6 +25,7 @@ var require = { "validator/date": "lib/formValidation/validator/date", "validator/integer": "lib/formValidation/validator/integer", "validator/between": "lib/formValidation/validator/between", + 'validator/confirm':"lib/formValidation/validator/confirm", //富文本编辑器 不要直接使用,而是使用上面的editor simditor: "lib/simditor/simditor", diff --git a/static/src/js/lib/formValidation/validator/confirm.js b/static/src/js/lib/formValidation/validator/confirm.js new file mode 100644 index 0000000..5d491ee --- /dev/null +++ b/static/src/js/lib/formValidation/validator/confirm.js @@ -0,0 +1,34 @@ +/** + * confirm validator + */ + +(function(root, factory) { + + "use strict"; + + // AMD module is defined + if (typeof define === "function" && define.amd) { + define("validator/confirm", ["jquery", "base"], factory); + } else { + // planted over the root! + factory(root.jQuery, root.FormValidation); + } + +}(this, function ($, FormValidation) { + FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { + 'en_US': { + confirm: { + 'default': 'Please input the same value' + } + } + }); + + FormValidation.Validator.confirm = { + + validate: function(validator, $field, options) { + if (options.firstPassword.val() == options.secondPassword.val() ||options.secondPassword.val()== '') + return true; + return false; + } + }; +})); diff --git a/template/oj/account/change_password.html b/template/oj/account/change_password.html index 71ce692..65de447 100644 --- a/template/oj/account/change_password.html +++ b/template/oj/account/change_password.html @@ -1,10 +1,34 @@ - - - - - - - +{% extends "oj_base.html" %} +{% block body %} +
+
+

修改密码

- - \ No newline at end of file +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+{% endblock %} +{% block js_block %} + +{% endblock %} \ No newline at end of file From 58a664af1b0852b95517c11cf85d8a04bc1e6770 Mon Sep 17 00:00:00 2001 From: sxw Date: Tue, 4 Aug 2015 14:56:17 +0800 Subject: [PATCH 05/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=B3=A8?= =?UTF-8?q?=E5=86=8Cjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/oj/account/register.js | 94 ++++++++++++++++++++++++ static/src/js/utils/validation.js | 5 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 static/src/js/app/oj/account/register.js diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js new file mode 100644 index 0000000..0241698 --- /dev/null +++ b/static/src/js/app/oj/account/register.js @@ -0,0 +1,94 @@ +require(["jquery", "bs_alert", "validation"], function($, bs_alert){ + + $("#register-form") + .formValidation({ + framework: "bootstrap", + fields: { + username: { + validators: { + notEmpty: { + message: "请填写用户名" + }, + stringLength: { + min: 3, + max: 30, + message: '用户名长度必须在3到30位之间' + } + } + }, + password: { + validators: { + notEmpty: { + message: "请填写密码" + }, + stringLength: { + min: 6, + max: 30, + message: '密码长度必须在6到30位之间' + }, + confirm: { + firstPassword: $("#password"), + secondPassword: $("#confirm_password"), + message: "两次输入的密码必须一致" + } + }, + onSuccess: function(e, data) { + + if (!data.fv.isValidField('confirm_password')) { + data.fv.revalidateField('confirm_password'); + } + } + }, + real_name: { + validators: { + notEmpty: { + message: "请填写真实姓名" + } + }, + + }, + confirm_password: { + validators: { + notEmpty: { + message: "请填写确认密码" + }, + confirm: { + firstPassword: $("#password"), + secondPassword: $("#confirm_password"), + message: "两次输入的密码必须一致" + } + + }, + + onSuccess: function(e, data) { + + if (!data.fv.isValidField('password')) { + data.fv.revalidateField('password'); + } + } + } + } + } + ).on('success.form.fv', function(e) { + e.preventDefault(); + var username = $("#username").val(); + var real_name = $("#real_name").val(); + var password = $("#password").val(); + $.ajax({ + url: "/api/register/", + data: {username: username, real_name: real_name, password: password}, + dataType: "json", + method: "post", + success: function (data) { + if(!data.code){ + window.location.href="/login/"; + } + else{ + bs_alert(data.data); + } + } + + }) + }); + +}); \ No newline at end of file diff --git a/static/src/js/utils/validation.js b/static/src/js/utils/validation.js index ab3c2e7..b79bd81 100644 --- a/static/src/js/utils/validation.js +++ b/static/src/js/utils/validation.js @@ -7,5 +7,8 @@ define("validation", 'validator/stringLength', 'validator/date', 'validator/integer', - 'validator/between'], function () { + 'validator/between', + 'validator/confirm'], + function () { + }); \ No newline at end of file From 62a9e050f5ea05cc271edb31c37d505bc08f992e Mon Sep 17 00:00:00 2001 From: sxw Date: Tue, 4 Aug 2015 16:05:40 +0800 Subject: [PATCH 06/99] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=99=BB?= =?UTF-8?q?=E9=99=86=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E4=B8=89=E4=B8=AA=E9=A1=B5=E9=9D=A2=E7=9A=84?= =?UTF-8?q?csrf=EF=BC=9B=20=E6=B7=BB=E5=8A=A0=E4=BA=86usernameCheck?= =?UTF-8?q?=E7=9A=84valuedation=E6=A3=80=E6=B5=8B=E6=96=B9=E6=B3=95;=20url?= =?UTF-8?q?s.py=20=E6=B7=BB=E5=8A=A0=E4=BA=86register=EF=BC=8Cchange=5Fpas?= =?UTF-8?q?sword=E9=A1=B5=E9=9D=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 2 + .../src/js/app/oj/account/change_password.js | 3 +- static/src/js/app/oj/account/login.js | 3 +- static/src/js/app/oj/account/register.js | 6 ++- static/src/js/config.js | 3 +- .../formValidation/validator/usernameCheck.js | 44 +++++++++++++++++++ static/src/js/utils/csrf.js | 16 +++++++ static/src/js/utils/validation.js | 3 +- 8 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 static/src/js/lib/formValidation/validator/usernameCheck.js create mode 100644 static/src/js/utils/csrf.js diff --git a/oj/urls.py b/oj/urls.py index fc652b3..aa35a62 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -10,6 +10,8 @@ urlpatterns = [ url(r'^docs/', include('rest_framework_swagger.urls')), url(r'^admin/$', TemplateView.as_view(template_name="admin/index.html"), name="admin_index_page"), url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), + url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), + url(r'^change_password/$', TemplateView.as_view(template_name="oj/account/change_password.html"), name="user_change_password_page"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="user_login_api"), url(r'^api/register/$', UserRegisterAPIView.as_view(), name="user_register_api"), url(r'^api/change_password/$', UserChangePasswordAPIView.as_view(), name="user_change_password_api"), diff --git a/static/src/js/app/oj/account/change_password.js b/static/src/js/app/oj/account/change_password.js index 035e0d3..ff9bf74 100644 --- a/static/src/js/app/oj/account/change_password.js +++ b/static/src/js/app/oj/account/change_password.js @@ -1,5 +1,5 @@ -require(["jquery", "bs_alert", "validation"], function($, bs_alert){ +require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrfHeader){ $("#change_password-form").formValidation({ @@ -69,6 +69,7 @@ require(["jquery", "bs_alert", "validation"], function($, bs_alert){ var new_password = $("#new_password ").val(); var password = $("#password").val(); $.ajax({ + beforeSend: csrfHeader, url: "/api/change_password/", data: {username: username, new_password: new_password , old_password : password}, dataType: "json", diff --git a/static/src/js/app/oj/account/login.js b/static/src/js/app/oj/account/login.js index b7c23e7..da4416d 100644 --- a/static/src/js/app/oj/account/login.js +++ b/static/src/js/app/oj/account/login.js @@ -1,4 +1,4 @@ -require(["jquery", "bs_alert", "validation"], function($, bs_alert){ +require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrfHeader){ $("#login-form") .formValidation({ framework: "bootstrap", @@ -24,6 +24,7 @@ require(["jquery", "bs_alert", "validation"], function($, bs_alert){ var username = $("#username").val(); var password = $("#password").val(); $.ajax({ + beforeSend: csrfHeader, url: "/api/login/", data: {username: username, password: password}, dataType: "json", diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js index 0241698..4baf334 100644 --- a/static/src/js/app/oj/account/register.js +++ b/static/src/js/app/oj/account/register.js @@ -1,4 +1,4 @@ -require(["jquery", "bs_alert", "validation"], function($, bs_alert){ +require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrfHeader){ $("#register-form") .formValidation({ @@ -13,6 +13,9 @@ require(["jquery", "bs_alert", "validation"], function($, bs_alert){ min: 3, max: 30, message: '用户名长度必须在3到30位之间' + }, + usernameCheck:{ + message: '用户名已存在' } } }, @@ -75,6 +78,7 @@ require(["jquery", "bs_alert", "validation"], function($, bs_alert){ var real_name = $("#real_name").val(); var password = $("#password").val(); $.ajax({ + beforeSend: csrfHeader, url: "/api/register/", data: {username: username, real_name: real_name, password: password}, dataType: "json", diff --git a/static/src/js/config.js b/static/src/js/config.js index fbeaa3a..3907d1c 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -14,6 +14,7 @@ var require = { bs_alert: "utils/bs_alert", submit_code: "app/oj/problem/submit_code", contest: "app/admin/contest/contest", + csrf: "utils/csrf", //formValidation 不要在代码中单独使用,而是使用和修改utils/validation base: "lib/formValidation/base", @@ -26,7 +27,7 @@ var require = { "validator/integer": "lib/formValidation/validator/integer", "validator/between": "lib/formValidation/validator/between", 'validator/confirm':"lib/formValidation/validator/confirm", - + "validator/usernameCheck":"lib/formValidation/validator/usernameCheck", //富文本编辑器 不要直接使用,而是使用上面的editor simditor: "lib/simditor/simditor", "simple-module": "lib/simditor/module", diff --git a/static/src/js/lib/formValidation/validator/usernameCheck.js b/static/src/js/lib/formValidation/validator/usernameCheck.js new file mode 100644 index 0000000..116c1dc --- /dev/null +++ b/static/src/js/lib/formValidation/validator/usernameCheck.js @@ -0,0 +1,44 @@ +/** + * usernameCheck validator + */ + +(function(root, factory) { + + "use strict"; + + // AMD module is defined + if (typeof define === "function" && define.amd) { + define("validator/usernameCheck", ["jquery", "base", "csrf"], factory); + } else { + // planted over the root! + factory(root.jQuery, root.FormValidation); + } + +}(this, function ($, FormValidation, csrfHeader) { + FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { + 'en_US': { + usernameCheck: { + 'default': 'Please input the same value' + } + } + }); + + FormValidation.Validator.usernameCheck = { + + validate: function(validator, $field, options) { + if ($field.val() == '') + return true; + return !$.ajax({ + async: false, + beforeSend: csrfHeader, + url: "/api/username_check/", + data: {username: $field.val()}, + dataType: "json", + method: "post", + + + }).responseJSON.data; + + } + }; +})); diff --git a/static/src/js/utils/csrf.js b/static/src/js/utils/csrf.js new file mode 100644 index 0000000..767542b --- /dev/null +++ b/static/src/js/utils/csrf.js @@ -0,0 +1,16 @@ +define("csrf",function(){ + function get_cookie(cookie_name) { + var name = cookie_name + "="; + var ca = document.cookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1); + if (c.indexOf(name) != -1) return c.substring(name.length, c.length); + } + return ""; + } + function csrfHeader(xhr){ + xhr.setRequestHeader("X-CSRFToken", get_cookie("csrftoken")); + } + return csrfHeader; +}); diff --git a/static/src/js/utils/validation.js b/static/src/js/utils/validation.js index b79bd81..38788f7 100644 --- a/static/src/js/utils/validation.js +++ b/static/src/js/utils/validation.js @@ -8,7 +8,8 @@ define("validation", 'validator/date', 'validator/integer', 'validator/between', - 'validator/confirm'], + 'validator/confirm', + 'validator/usernameCheck'], function () { }); \ No newline at end of file From 006ed117f1cc51704603af47597a40bcc0e34e20 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Tue, 4 Aug 2015 17:38:04 +0800 Subject: [PATCH 07/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E7=9A=84API=E6=8E=A5=E5=8F=A3=E5=92=8C=E7=9B=B8?= =?UTF-8?q?=E5=BA=94=E7=9A=84API=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- announcement/__init__.py | 0 announcement/admin.py | 3 +++ announcement/migrations/__init__.py | 0 announcement/models.py | 20 ++++++++++++++++++++ announcement/serializers.py | 8 ++++++++ announcement/tests.py | 16 ++++++++++++++++ announcement/views.py | 28 ++++++++++++++++++++++++++++ oj/urls.py | 2 ++ 8 files changed, 77 insertions(+) create mode 100644 announcement/__init__.py create mode 100644 announcement/admin.py create mode 100644 announcement/migrations/__init__.py create mode 100644 announcement/models.py create mode 100644 announcement/serializers.py create mode 100644 announcement/tests.py create mode 100644 announcement/views.py diff --git a/announcement/__init__.py b/announcement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/announcement/admin.py b/announcement/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/announcement/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/announcement/migrations/__init__.py b/announcement/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/announcement/models.py b/announcement/models.py new file mode 100644 index 0000000..a47eba6 --- /dev/null +++ b/announcement/models.py @@ -0,0 +1,20 @@ +# coding=utf-8 +from django.db import models + +from account.models import User + + +class Announcement(models.Model): + # 标题 + title = models.CharField(max_length=50) + # 公告的描述 HTML 格式 + description = models.TextField() + # 创建时间 + create_time = models.DateTimeField(auto_now_add=True) + # 这个公告是谁创建的 + created_by = models.ForeignKey(User) + # 是否可见 false的话相当于删除 + visible = models.BooleanField(default=True) + + class Meta: + db_table = "announcement" diff --git a/announcement/serializers.py b/announcement/serializers.py new file mode 100644 index 0000000..a1525b9 --- /dev/null +++ b/announcement/serializers.py @@ -0,0 +1,8 @@ +# coding=utf-8 +from rest_framework import serializers + + +class AnnouncementSerializer(serializers.Serializer): + title = serializers.CharField(max_length=50) + description = serializers.CharField(max_length=10000) + diff --git a/announcement/tests.py b/announcement/tests.py new file mode 100644 index 0000000..ccb8a04 --- /dev/null +++ b/announcement/tests.py @@ -0,0 +1,16 @@ +# coding=utf-8 +from django.core.urlresolvers import reverse + +from rest_framework.test import APITestCase, APIClient + + +class AbstractAnnouncementAPITest(APITestCase): + def setUp(self): + self.client = APIClient() + self.url = reverse("announcement_api") + + def test_invalid_format(self): + # todo 判断用户是否登录 + data = {"title": "test1"} + response = self.client.post(self.url, data=data) + self.assertEqual(response.data["code"], 1) diff --git a/announcement/views.py b/announcement/views.py new file mode 100644 index 0000000..220e806 --- /dev/null +++ b/announcement/views.py @@ -0,0 +1,28 @@ +# coding=utf-8 +from rest_framework.views import APIView + +from utils.shortcuts import serializer_invalid_response, error_response, success_response + +from account.models import User + +from .models import Announcement +from .serializers import AnnouncementSerializer + + +class AnnouncementAPIView(APIView): + # todo 判断用户是否需要登录 + def post(self, request): + """ + 公告发布json api接口 + --- + request_serializer: AnnouncementSerializer + """ + serializer = AnnouncementSerializer(data=request.DATA) + if serializer.is_valid(): + data = serializer.data + Announcement.objects.create(title=data["title"], + description=data["description"], + created_by=request.user) + return success_response(u"公告发布成功!") + else: + return serializer_invalid_response(serializer) \ No newline at end of file diff --git a/oj/urls.py b/oj/urls.py index fc652b3..19da589 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -4,6 +4,7 @@ from django.contrib import admin from django.views.generic import TemplateView from account.views import UserLoginAPIView, UsernameCheckAPIView, UserRegisterAPIView, UserChangePasswordAPIView +from announcement.views import AnnouncementAPIView urlpatterns = [ url("^$", TemplateView.as_view(template_name="oj/index.html"), name="index_page"), @@ -14,6 +15,7 @@ urlpatterns = [ url(r'^api/register/$', UserRegisterAPIView.as_view(), name="user_register_api"), url(r'^api/change_password/$', UserChangePasswordAPIView.as_view(), name="user_change_password_api"), url(r'^api/username_check/$', UsernameCheckAPIView.as_view(), name="username_check_api"), + url(r'^api/admin/announcement/$', AnnouncementAPIView.as_view(), name="announcement_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), url(r'^admin/contest/$', TemplateView.as_view(template_name="admin/contest/add_contest.html"), name="add_contest_page"), From 76aba7f0e7f7b012425f6efcc5bae06daca1f40a Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Tue, 4 Aug 2015 18:38:00 +0800 Subject: [PATCH 08/99] add coverage requirement and run test shell script --- requirements.txt | 3 ++- tools/runserver.sh | 2 ++ tools/runtest.sh | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tools/runserver.sh create mode 100644 tools/runtest.sh diff --git a/requirements.txt b/requirements.txt index 00da332..bb0fce3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ django-redis-sessions djangorestframework django-rest-swagger celery -gunicorn \ No newline at end of file +gunicorn +coverage \ No newline at end of file diff --git a/tools/runserver.sh b/tools/runserver.sh new file mode 100644 index 0000000..d508cfc --- /dev/null +++ b/tools/runserver.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +python manage.py runserver \ No newline at end of file diff --git a/tools/runtest.sh b/tools/runtest.sh new file mode 100644 index 0000000..2fc4d4a --- /dev/null +++ b/tools/runtest.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +coverage run --source='.' manage.py test +nose html +open htmlcov/index.html From 1d4af5cc7cbffbba38ea9bd6ed951e6e10317f3d Mon Sep 17 00:00:00 2001 From: sxw Date: Tue, 4 Aug 2015 19:18:56 +0800 Subject: [PATCH 09/99] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86windows?= =?UTF-8?q?=E4=B8=8B=E7=9A=84runserver=E5=92=8Cruntest=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=20[ci=20sikp]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/runserver.cmd | 5 +++++ tools/runtest.cmd | 12 ++++++++++++ tools/runtest.sh | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tools/runserver.cmd create mode 100644 tools/runtest.cmd diff --git a/tools/runserver.cmd b/tools/runserver.cmd new file mode 100644 index 0000000..b458e55 --- /dev/null +++ b/tools/runserver.cmd @@ -0,0 +1,5 @@ +@echo off +python manage.py runserver +cls +cd.. +python manage.py runserver \ No newline at end of file diff --git a/tools/runtest.cmd b/tools/runtest.cmd new file mode 100644 index 0000000..e6d9ad7 --- /dev/null +++ b/tools/runtest.cmd @@ -0,0 +1,12 @@ +@echo off +coverage run --source='.' manage.py test +coverage html +cd htmlcov +index.html +cls +cd.. +coverage run --source='.' manage.py test +coverage html +cd htmlcov +index.html + diff --git a/tools/runtest.sh b/tools/runtest.sh index 2fc4d4a..87399cc 100644 --- a/tools/runtest.sh +++ b/tools/runtest.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash coverage run --source='.' manage.py test -nose html +coverage html open htmlcov/index.html From 4548ffd61709941267f36a7463ad1fbf5d56b810 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Tue, 4 Aug 2015 19:23:10 +0800 Subject: [PATCH 10/99] =?UTF-8?q?=E6=9B=B4=E6=AD=A3=E5=85=AC=E5=91=8AAPI?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- announcement/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/announcement/tests.py b/announcement/tests.py index ccb8a04..f73805e 100644 --- a/announcement/tests.py +++ b/announcement/tests.py @@ -4,7 +4,7 @@ from django.core.urlresolvers import reverse from rest_framework.test import APITestCase, APIClient -class AbstractAnnouncementAPITest(APITestCase): +class AnnouncementAPITest(APITestCase): def setUp(self): self.client = APIClient() self.url = reverse("announcement_api") From 0b55f6bbf79bf8f66c1ea81931165c5e3464feef Mon Sep 17 00:00:00 2001 From: sxw Date: Tue, 4 Aug 2015 19:54:44 +0800 Subject: [PATCH 11/99] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=AF=86=E7=A0=81=E9=AA=8C=E8=AF=81=E7=9A=84js?= =?UTF-8?q?=EF=BC=8C=E7=B2=BE=E7=AE=80=E4=BB=A3=E7=A0=81=E9=87=8F=EF=BC=8C?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E4=BA=86=E9=87=8D=E5=A4=8D=E7=9A=84=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=EF=BC=8C=E5=87=8F=E5=B0=91=E4=BA=86valuedator?= =?UTF-8?q?=E4=B8=ADconfirm=E7=9A=84=E5=8F=82=E6=95=B0=20[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/js/app/oj/account/change_password.js | 23 +------------------ static/src/js/app/oj/account/register.js | 23 ++----------------- .../lib/formValidation/validator/confirm.js | 10 ++++---- .../formValidation/validator/usernameCheck.js | 21 ++++++----------- static/src/js/utils/validation.js | 1 - 5 files changed, 14 insertions(+), 64 deletions(-) diff --git a/static/src/js/app/oj/account/change_password.js b/static/src/js/app/oj/account/change_password.js index ff9bf74..e3e907f 100644 --- a/static/src/js/app/oj/account/change_password.js +++ b/static/src/js/app/oj/account/change_password.js @@ -1,7 +1,4 @@ - require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrfHeader){ - - $("#change_password-form").formValidation({ framework: "bootstrap", fields: { @@ -28,20 +25,11 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf min: 6, max: 30, message: '密码长度必须在6到30位之间' - }, - confirm: { - firstPassword: $("#new_password"), - secondPassword: $("#confirm_password"), - message: "两次输入的密码必须一致" } }, onSuccess: function(e, data) { - - if (!data.fv.isValidField('confirm_password')) { data.fv.revalidateField('confirm_password'); - } } - }, confirm_password: { validators: { @@ -49,17 +37,10 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf message: "请填写确认密码" }, confirm: { - firstPassword: $("#new_password"), - secondPassword: $("#confirm_password"), + original: $("#new_password"), message: "两次输入的密码必须一致" } }, - onSuccess: function(e, data) { - - if (!data.fv.isValidField('new_password')) { - data.fv.revalidateField('new_password'); - } - } } } } @@ -83,8 +64,6 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf bs_alert(data.data); } } - }) }); - }); \ No newline at end of file diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js index 4baf334..e6b4deb 100644 --- a/static/src/js/app/oj/account/register.js +++ b/static/src/js/app/oj/account/register.js @@ -1,5 +1,4 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrfHeader){ - $("#register-form") .formValidation({ framework: "bootstrap", @@ -28,18 +27,10 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf min: 6, max: 30, message: '密码长度必须在6到30位之间' - }, - confirm: { - firstPassword: $("#password"), - secondPassword: $("#confirm_password"), - message: "两次输入的密码必须一致" - } + } }, onSuccess: function(e, data) { - - if (!data.fv.isValidField('confirm_password')) { data.fv.revalidateField('confirm_password'); - } } }, real_name: { @@ -48,7 +39,6 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf message: "请填写真实姓名" } }, - }, confirm_password: { validators: { @@ -56,18 +46,9 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf message: "请填写确认密码" }, confirm: { - firstPassword: $("#password"), - secondPassword: $("#confirm_password"), + original: $("#password"), message: "两次输入的密码必须一致" } - - }, - - onSuccess: function(e, data) { - - if (!data.fv.isValidField('password')) { - data.fv.revalidateField('password'); - } } } } diff --git a/static/src/js/lib/formValidation/validator/confirm.js b/static/src/js/lib/formValidation/validator/confirm.js index 5d491ee..db5ad3a 100644 --- a/static/src/js/lib/formValidation/validator/confirm.js +++ b/static/src/js/lib/formValidation/validator/confirm.js @@ -22,13 +22,11 @@ } } }); - FormValidation.Validator.confirm = { - validate: function(validator, $field, options) { - if (options.firstPassword.val() == options.secondPassword.val() ||options.secondPassword.val()== '') - return true; - return false; - } + if (options.original.val() == $field.val() || $field.val()== '') + return true; + return false; + } }; })); diff --git a/static/src/js/lib/formValidation/validator/usernameCheck.js b/static/src/js/lib/formValidation/validator/usernameCheck.js index 116c1dc..36a7762 100644 --- a/static/src/js/lib/formValidation/validator/usernameCheck.js +++ b/static/src/js/lib/formValidation/validator/usernameCheck.js @@ -1,7 +1,6 @@ /** * usernameCheck validator */ - (function(root, factory) { "use strict"; @@ -13,7 +12,6 @@ // planted over the root! factory(root.jQuery, root.FormValidation); } - }(this, function ($, FormValidation, csrfHeader) { FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { 'en_US': { @@ -22,23 +20,18 @@ } } }); - FormValidation.Validator.usernameCheck = { - validate: function(validator, $field, options) { if ($field.val() == '') return true; return !$.ajax({ - async: false, - beforeSend: csrfHeader, - url: "/api/username_check/", - data: {username: $field.val()}, - dataType: "json", - method: "post", - - - }).responseJSON.data; - + async: false, + beforeSend: csrfHeader, + url: "/api/username_check/", + data: {username: $field.val()}, + dataType: "json", + method: "post", + }).responseJSON.data; } }; })); diff --git a/static/src/js/utils/validation.js b/static/src/js/utils/validation.js index 38788f7..5fe792f 100644 --- a/static/src/js/utils/validation.js +++ b/static/src/js/utils/validation.js @@ -11,5 +11,4 @@ define("validation", 'validator/confirm', 'validator/usernameCheck'], function () { - }); \ No newline at end of file From 44be61dab6b21553367ea84f60f40e31cb587bf4 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Wed, 5 Aug 2015 08:43:15 +0800 Subject: [PATCH 12/99] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20runtest.sh=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E5=9C=A8=E6=B5=8B=E8=AF=95=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=E6=89=8D=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=A6=86=E7=9B=96=E7=8E=87=E5=88=86=E6=9E=90?= =?UTF-8?q?=E5=92=8C=E6=89=93=E5=BC=80=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/runtest.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/runtest.sh b/tools/runtest.sh index 87399cc..f41a02b 100644 --- a/tools/runtest.sh +++ b/tools/runtest.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash coverage run --source='.' manage.py test -coverage html -open htmlcov/index.html +test_result=$? +if [ "$test_result" -eq 0 ];then + coverage html + open htmlcov/index.html +fi From 8a6093d6457c1e5ddbeacf87575a95fa4ce1d222 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Wed, 5 Aug 2015 08:44:28 +0800 Subject: [PATCH 13/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=87=BD=E6=95=B0=E5=92=8C=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/settings.py | 1 + utils/shortcuts.py | 49 ++++++++++++++++++++++++++++++++++- utils/test_urls.py | 9 +++++++ utils/tests.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 utils/test_urls.py create mode 100644 utils/tests.py diff --git a/oj/settings.py b/oj/settings.py index db9ea8f..793f605 100644 --- a/oj/settings.py +++ b/oj/settings.py @@ -47,6 +47,7 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', 'account', + 'utils', 'rest_framework', 'rest_framework_swagger', diff --git a/utils/shortcuts.py b/utils/shortcuts.py index bd5f286..3d37063 100644 --- a/utils/shortcuts.py +++ b/utils/shortcuts.py @@ -1,4 +1,7 @@ # coding=utf-8 +from django.core.paginator import Paginator + +from rest_framework import pagination from rest_framework.response import Response @@ -11,4 +14,48 @@ def serializer_invalid_response(serializer): def success_response(data): - return Response(data={"code": 0, "data": data}) \ No newline at end of file + return Response(data={"code": 0, "data": data}) + + +def paginate(request, query_set, object_serializer): + """ + 用于分页的函数 + :param query_set 数据库查询结果 + :param object_serializer: 序列化单个object的serializer + :return response + """ + need_paginate = request.GET.get("paging", None) + # 如果请求的参数里面没有paging=true的话 就返回全部数据 + if need_paginate != "true": + return success_response(data=object_serializer(query_set, many=True).data) + + page_size = request.GET.get("page_size", None) + if not page_size: + return error_response(u"参数错误") + + try: + page_size = int(page_size) + except Exception: + return error_response(u"参数错误") + + paginator = Paginator(query_set, page_size) + page = request.GET.get("page", None) + + try: + current_page = paginator.page(page) + except Exception: + return error_response(u"参数错误") + + data = {"results": object_serializer(current_page, many=True).data, "previous_page": None, "next_page": None} + + try: + data["previous_page"] = current_page.previous_page_number() + except Exception: + pass + + try: + data["next_page"] = current_page.next_page_number() + except Exception: + pass + + return success_response(data) \ No newline at end of file diff --git a/utils/test_urls.py b/utils/test_urls.py new file mode 100644 index 0000000..0500d16 --- /dev/null +++ b/utils/test_urls.py @@ -0,0 +1,9 @@ +# coding=utf-8 +from django.conf.urls import include, url + + + +urlpatterns = [ + url(r'^paginate_test/$', "utils.tests.pagination_test_func"), +] + diff --git a/utils/tests.py b/utils/tests.py new file mode 100644 index 0000000..9ab31f9 --- /dev/null +++ b/utils/tests.py @@ -0,0 +1,64 @@ +# coding=utf-8 +from rest_framework.test import APIClient, APITestCase +from rest_framework import serializers +from rest_framework.decorators import api_view + +from account.models import User +from .shortcuts import paginate + + +class PaginationTestSerialiser(serializers.Serializer): + username = serializers.CharField(max_length=100) + + +@api_view(["GET"]) +def pagination_test_func(request): + return paginate(request, User.objects.all(), PaginationTestSerialiser) + + +class PaginatorTest(APITestCase): + urls = "utils.test_urls" + + def setUp(self): + self.client = APIClient() + self.url = "/paginate_test/" + User.objects.create(username="test1") + User.objects.create(username="test2") + + def test_no_paginate(self): + response = self.client.get(self.url) + self.assertEqual(response.data["code"], 0) + self.assertNotIn("next_page", response.data["data"]) + self.assertNotIn("previous_page", response.data["data"]) + + def test_error_parameter(self): + response = self.client.get(self.url + "?paging=true") + self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) + + response = self.client.get(self.url + "?paging=true&limit=-1") + self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) + + response = self.client.get(self.url + "?paging=true&limit=aa") + self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) + + response = self.client.get(self.url + "?paging=true&limit=1&page_size=1&page=-1") + self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) + + response = self.client.get(self.url + "?paging=true&limit=1&page_size=aaa&page=1") + self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) + + response = self.client.get(self.url + "?paging=true&limit=1&page_size=1&page=aaa") + self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) + + def test_correct_paginate(self): + response = self.client.get(self.url + "?paging=true&limit=1&page_size=1&page=1") + self.assertEqual(response.data["code"], 0) + self.assertEqual(response.data["data"]["previous_page"], None) + self.assertEqual(response.data["data"]["next_page"], 2) + self.assertEqual(len(response.data["data"]["results"]), 1) + + response = self.client.get(self.url + "?paging=true&limit=1&page_size=2&page=1") + self.assertEqual(response.data["code"], 0) + self.assertEqual(response.data["data"]["previous_page"], None) + self.assertEqual(response.data["data"]["next_page"], None) + self.assertEqual(len(response.data["data"]["results"]), 2) From 5558600792c66135e97d349e1ee2d88a1324fb4b Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Wed, 5 Aug 2015 08:53:39 +0800 Subject: [PATCH 14/99] =?UTF-8?q?=E8=A1=A5=E5=85=85=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=87=BD=E6=95=B0=E7=9A=84=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E5=92=8C=E7=94=A8=E6=B3=95=EF=BC=9B=E4=BF=AE=E6=94=B9=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/shortcuts.py | 26 +++++++++++++++++++++++++- utils/tests.py | 10 +++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/utils/shortcuts.py b/utils/shortcuts.py index 3d37063..852622f 100644 --- a/utils/shortcuts.py +++ b/utils/shortcuts.py @@ -1,7 +1,6 @@ # coding=utf-8 from django.core.paginator import Paginator -from rest_framework import pagination from rest_framework.response import Response @@ -20,6 +19,31 @@ def success_response(data): def paginate(request, query_set, object_serializer): """ 用于分页的函数 + 如果 url 里面不含有paging=true,那么将返回全部数据。类似 + [ + { + "username": "1111111", + "password": "123456" + } + ] + 如果 url 中有 paging=true 的参数, + 然后还需要读取其余的两个参数,page=[int],需要的页码,p + age_size=[int],一页的数据条数 + 参数错误的时候,返回{"code": 1, "data": u"参数错误"} + 返回的数据格式 + { + "code": 0, + "data": { + "previous_page": null, + "results": [ + { + "username": "1111111", + "password": "123456" + } + ], + "next_page": 2 + } + } :param query_set 数据库查询结果 :param object_serializer: 序列化单个object的serializer :return response diff --git a/utils/tests.py b/utils/tests.py index 9ab31f9..519870c 100644 --- a/utils/tests.py +++ b/utils/tests.py @@ -35,19 +35,19 @@ class PaginatorTest(APITestCase): response = self.client.get(self.url + "?paging=true") self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) - response = self.client.get(self.url + "?paging=true&limit=-1") + response = self.client.get(self.url + "?paging=true&page_size=-1") self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) - response = self.client.get(self.url + "?paging=true&limit=aa") + response = self.client.get(self.url + "?paging=true&page_size=aa") self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) - response = self.client.get(self.url + "?paging=true&limit=1&page_size=1&page=-1") + response = self.client.get(self.url + "?paging=true&page_size=1&page=-1") self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) - response = self.client.get(self.url + "?paging=true&limit=1&page_size=aaa&page=1") + response = self.client.get(self.url + "?paging=true&page_size=aaa&page=1") self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) - response = self.client.get(self.url + "?paging=true&limit=1&page_size=1&page=aaa") + response = self.client.get(self.url + "?paging=true&page_size=1&page=aaa") self.assertEqual(response.data, {"code": 1, "data": u"参数错误"}) def test_correct_paginate(self): From 17b44800ca339d3b5302c1343508f704f17d6614 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Wed, 5 Aug 2015 10:34:00 +0800 Subject: [PATCH 15/99] =?UTF-8?q?=E5=B0=86announcement=20=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=20setings.py=20=E9=87=8C=E9=9D=A2=E7=9A=84=20INSTALLE?= =?UTF-8?q?D=5FAPPS=EF=BC=8C=E5=B9=B6=E4=B8=94=E5=88=9B=E5=BB=BAannounceme?= =?UTF-8?q?nt=E8=BF=99=E5=BC=A0=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- announcement/migrations/0001_initial.py | 29 +++++++++++++++++++++++++ oj/settings.py | 1 + 2 files changed, 30 insertions(+) create mode 100644 announcement/migrations/0001_initial.py diff --git a/announcement/migrations/0001_initial.py b/announcement/migrations/0001_initial.py new file mode 100644 index 0000000..24a1d13 --- /dev/null +++ b/announcement/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Announcement', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('title', models.CharField(max_length=50)), + ('description', models.TextField()), + ('create_time', models.DateTimeField(auto_now_add=True)), + ('visible', models.BooleanField(default=True)), + ('created_by', models.ForeignKey(to=settings.AUTH_USER_MODEL)), + ], + options={ + 'db_table': 'announcement', + }, + ), + ] diff --git a/oj/settings.py b/oj/settings.py index 793f605..910914c 100644 --- a/oj/settings.py +++ b/oj/settings.py @@ -47,6 +47,7 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', 'account', + 'announcement', 'utils', 'rest_framework', From 34ccdd5e0e285dd8bb92ba6bb4fedbf372d58668 Mon Sep 17 00:00:00 2001 From: sxw Date: Wed, 5 Aug 2015 19:38:28 +0800 Subject: [PATCH 16/99] =?UTF-8?q?1.=E4=BB=BF=E7=85=A7=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=87=8D=E5=86=99=E4=BA=86=E5=8E=9FusernameCheck=E7=9A=84valid?= =?UTF-8?q?ator=E3=80=82=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BAremoteCSRF?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E4=BD=BF=E7=94=A8ajax=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E5=90=91=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=94=AF=E4=B8=80=E6=80=A7=E3=80=82=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=BAurl=EF=BC=9A=E8=AF=B7=E6=B1=82=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=EF=BC=8Cfield=EF=BC=9A=E5=90=91=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E5=8F=91=E9=80=81=E7=9A=84=E8=A1=A8=E7=A4=BA=E7=AC=A6?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=EF=BC=9B=202.=E6=B7=BB=E5=8A=A0=E4=BA=86emai?= =?UTF-8?q?lAddress=E7=9A=84validator=E7=9A=84requires.js=E7=9A=84config.?= =?UTF-8?q?=20[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/config.js | 5 +- .../formValidation/validator/remoteCSRF.js | 46 +++++++++++++++++++ .../formValidation/validator/usernameCheck.js | 37 --------------- static/src/js/utils/validation.js | 3 +- 4 files changed, 51 insertions(+), 40 deletions(-) create mode 100644 static/src/js/lib/formValidation/validator/remoteCSRF.js delete mode 100644 static/src/js/lib/formValidation/validator/usernameCheck.js diff --git a/static/src/js/config.js b/static/src/js/config.js index 3907d1c..30f4969 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -26,8 +26,9 @@ var require = { "validator/date": "lib/formValidation/validator/date", "validator/integer": "lib/formValidation/validator/integer", "validator/between": "lib/formValidation/validator/between", - 'validator/confirm':"lib/formValidation/validator/confirm", - "validator/usernameCheck":"lib/formValidation/validator/usernameCheck", + "validator/confirm":"lib/formValidation/validator/confirm", + "validator/remoteCSRF":"lib/formValidation/validator/remoteCSRF", + "validator/emailAddress":"lib/formValidation/validator/emailAddress", //富文本编辑器 不要直接使用,而是使用上面的editor simditor: "lib/simditor/simditor", "simple-module": "lib/simditor/module", diff --git a/static/src/js/lib/formValidation/validator/remoteCSRF.js b/static/src/js/lib/formValidation/validator/remoteCSRF.js new file mode 100644 index 0000000..9cab354 --- /dev/null +++ b/static/src/js/lib/formValidation/validator/remoteCSRF.js @@ -0,0 +1,46 @@ +/** + * remoteCSRF validator + */ +(function(root, factory) { + + "use strict"; + + // AMD module is defined + if (typeof define === "function" && define.amd) { + define("validator/remoteCSRF", ["jquery", "base", "csrf"], factory); + } else { + // planted over the root! + factory(root.jQuery, root.FormValidation); + } +}(this, function ($, FormValidation, csrfHeader) { + FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { + 'en_US': { + remoteCSRF: { + 'default': '' + } + } + }); + FormValidation.Validator.remoteCSRF = { + validate: function(validator, $field, options) { + var dfd = new $.Deferred(), ajaxData = {}; + ajaxData[options.field] = $field.val(); + if ($field.val() === '') + return true; + var url = options.url; + var xhr = $.ajax({ + beforeSend: csrfHeader, + url: url, + dataType: 'json', + data: ajaxData, + method: "post" + }); + xhr.success(function(response) { + dfd.resolve($field, 'remoteCSRF',{valid:!response.data, message:options.msg}); + }) + .error(function(response) { + dfd.resolve($field, 'remoteCSRF', {valid: false}); + }); + return dfd; + } + }; +})); diff --git a/static/src/js/lib/formValidation/validator/usernameCheck.js b/static/src/js/lib/formValidation/validator/usernameCheck.js deleted file mode 100644 index 36a7762..0000000 --- a/static/src/js/lib/formValidation/validator/usernameCheck.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * usernameCheck validator - */ -(function(root, factory) { - - "use strict"; - - // AMD module is defined - if (typeof define === "function" && define.amd) { - define("validator/usernameCheck", ["jquery", "base", "csrf"], factory); - } else { - // planted over the root! - factory(root.jQuery, root.FormValidation); - } -}(this, function ($, FormValidation, csrfHeader) { - FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { - 'en_US': { - usernameCheck: { - 'default': 'Please input the same value' - } - } - }); - FormValidation.Validator.usernameCheck = { - validate: function(validator, $field, options) { - if ($field.val() == '') - return true; - return !$.ajax({ - async: false, - beforeSend: csrfHeader, - url: "/api/username_check/", - data: {username: $field.val()}, - dataType: "json", - method: "post", - }).responseJSON.data; - } - }; -})); diff --git a/static/src/js/utils/validation.js b/static/src/js/utils/validation.js index 5fe792f..45da8f5 100644 --- a/static/src/js/utils/validation.js +++ b/static/src/js/utils/validation.js @@ -9,6 +9,7 @@ define("validation", 'validator/integer', 'validator/between', 'validator/confirm', - 'validator/usernameCheck'], + 'validator/remoteCSRF', + 'validator/emailAddress'], function () { }); \ No newline at end of file From c868441d615e78402bd6b258941305ac52b78a23 Mon Sep 17 00:00:00 2001 From: sxw Date: Wed, 5 Aug 2015 19:40:02 +0800 Subject: [PATCH 17/99] =?UTF-8?q?1.=E5=9C=A8=E7=94=A8=E6=88=B7=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0=E4=BA=86email?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=B9=B6=E9=99=84=E5=B8=A6=E9=AA=8C?= =?UTF-8?q?=E8=AF=81;=202.=E7=BB=9F=E4=B8=80=E4=BA=86username=E5=92=8Cemai?= =?UTF-8?q?l=E5=AD=97=E6=AE=B5=E7=9A=84=E5=94=AF=E4=B8=80=E6=80=A7?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=96=B9=E6=B3=95=E3=80=82=20[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/oj/account/register.js | 22 ++++++++++++++++++++-- template/oj/account/register.html | 4 ++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js index e6b4deb..b9d3468 100644 --- a/static/src/js/app/oj/account/register.js +++ b/static/src/js/app/oj/account/register.js @@ -2,6 +2,11 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf $("#register-form") .formValidation({ framework: "bootstrap", + icon: { + valid: 'glyphicon glyphicon-ok', + invalid: 'glyphicon glyphicon-remove', + validating: 'glyphicon glyphicon-refresh' + }, fields: { username: { validators: { @@ -50,6 +55,21 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf message: "两次输入的密码必须一致" } } + }, + email: { + validators: { + notEmpty: { + message: "请填写电子邮箱邮箱地址" + }, + emailAddress: { + message: "请填写有效的邮箱地址" + }, + remoteCSRF: { + message: "您已经注册过了", + url: "/api/email_check/", + field: 'email' + } + } } } } @@ -72,8 +92,6 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf bs_alert(data.data); } } - }) }); - }); \ No newline at end of file diff --git a/template/oj/account/register.html b/template/oj/account/register.html index a93014c..34dc9a4 100644 --- a/template/oj/account/register.html +++ b/template/oj/account/register.html @@ -14,6 +14,10 @@ +
+ + +
From c5446361db23f10e62257d2128baec6ec0966494 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Wed, 5 Aug 2015 19:45:35 +0800 Subject: [PATCH 18/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=20admin=20spa?= =?UTF-8?q?=20=E7=9A=84=E9=80=9A=E7=94=A8=E4=BB=A3=E7=A0=81[CI=20SKIP]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 4 +- static/src/js/app/admin/admin.js | 31 ++++++++ static/src/js/config.js | 1 + template/admin/admin.html | 122 +++++++++++++++++++++++++++++++ template/admin/index.html | 4 - template/admin/index/index.html | 1 + template/admin_base.html | 8 +- 7 files changed, 162 insertions(+), 9 deletions(-) create mode 100644 static/src/js/app/admin/admin.js create mode 100644 template/admin/admin.html delete mode 100644 template/admin/index.html create mode 100644 template/admin/index/index.html diff --git a/oj/urls.py b/oj/urls.py index 0c8ea51..cc49f42 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -5,11 +5,12 @@ from django.views.generic import TemplateView from account.views import UserLoginAPIView, UsernameCheckAPIView, UserRegisterAPIView, UserChangePasswordAPIView from announcement.views import AnnouncementAPIView +from admin.views import AdminTemplateView urlpatterns = [ url("^$", TemplateView.as_view(template_name="oj/index.html"), name="index_page"), url(r'^docs/', include('rest_framework_swagger.urls')), - url(r'^admin/$', TemplateView.as_view(template_name="admin/index.html"), name="admin_index_page"), + url(r'^admin/$', TemplateView.as_view(template_name="admin/admin.html"), name="admin_spa_page"), url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), url(r'^change_password/$', TemplateView.as_view(template_name="oj/account/change_password.html"), name="user_change_password_page"), @@ -22,4 +23,5 @@ urlpatterns = [ url(r'^admin/contest/$', TemplateView.as_view(template_name="admin/contest/add_contest.html"), name="add_contest_page"), url(r'^problems/$', TemplateView.as_view(template_name="oj/problem/problem_list.html"), name="problem_list_page"), + url(r'^admin/template/(?P\w+)/(?P\w+).html', AdminTemplateView.as_view(), name="admin_template") ] diff --git a/static/src/js/app/admin/admin.js b/static/src/js/app/admin/admin.js new file mode 100644 index 0000000..d3e30ac --- /dev/null +++ b/static/src/js/app/admin/admin.js @@ -0,0 +1,31 @@ +define("admin", ["jquery", "avalon"], function($, avalon){ + function li_active(selector){ + $(selector).attr("class", "list-group-item active"); + } + + function li_inactive(selector){ + $(".list-group-item").attr("class", "list-group-item"); + } + + var hash = window.location.hash.substring(1); + + if(hash){ + li_active("#li-" + hash); + }else { + li_active("#li-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"; + } + }; + + var vm = avalon.define({ + $id: "admin", + template_url: "template/index/index.html" + }); +}); \ No newline at end of file diff --git a/static/src/js/config.js b/static/src/js/config.js index 3907d1c..079e45c 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -15,6 +15,7 @@ var require = { submit_code: "app/oj/problem/submit_code", contest: "app/admin/contest/contest", csrf: "utils/csrf", + admin: "app/admin/admin", //formValidation 不要在代码中单独使用,而是使用和修改utils/validation base: "lib/formValidation/base", diff --git a/template/admin/admin.html b/template/admin/admin.html new file mode 100644 index 0000000..c712084 --- /dev/null +++ b/template/admin/admin.html @@ -0,0 +1,122 @@ + + + + + + + + + + + 在线评测系统 - 后台管理 + + + {% block css_block %}{% endblock %} + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + + +
+ +
+
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/template/admin/index.html b/template/admin/index.html deleted file mode 100644 index df51a66..0000000 --- a/template/admin/index.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "admin_base.html" %} -{% block body %} -Hello world -{% endblock %} \ No newline at end of file diff --git a/template/admin/index/index.html b/template/admin/index/index.html new file mode 100644 index 0000000..6116828 --- /dev/null +++ b/template/admin/index/index.html @@ -0,0 +1 @@ +

Hello world

\ No newline at end of file diff --git a/template/admin_base.html b/template/admin_base.html index 8525b2e..86cf7e2 100644 --- a/template/admin_base.html +++ b/template/admin_base.html @@ -65,14 +65,14 @@ -
+
  • List header
  • -
  • Home
  • -
  • Library
  • +
  • 主页
  • +
  • 公告
  • Applications
  • Another list header
  • Help
  • @@ -108,7 +108,7 @@ {% block js_block %}{% endblock %} From 5eacb9f3d74651cea6f8e6d57dcc246bd5478c11 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Wed, 5 Aug 2015 19:47:49 +0800 Subject: [PATCH 19/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20admin=20=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E8=BF=94=E5=9B=9E=E6=89=A7=E8=A1=8C=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=9A=84=20views=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/views.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/admin/views.py b/admin/views.py index 91ea44a..78762c0 100644 --- a/admin/views.py +++ b/admin/views.py @@ -1,3 +1,14 @@ -from django.shortcuts import render +# coding=utf-8 +from django.conf import settings +from django.http import HttpResponse, Http404 -# Create your views here. +from rest_framework.views import APIView + + +class AdminTemplateView(APIView): + def get(self, request, template_dir, template_name): + path = settings.TEMPLATE_DIRS[0] + "/admin/" + template_dir + "/" + template_name + ".html" + try: + return HttpResponse(open(path).read(), content_type="text/html") + except IOError: + raise Http404 From cbb86d72f1c7a5ab4030a34a8e4c1b9e8688097b Mon Sep 17 00:00:00 2001 From: sxw Date: Wed, 5 Aug 2015 20:01:15 +0800 Subject: [PATCH 20/99] =?UTF-8?q?=E6=9B=B4=E6=AD=A3=E4=BA=86validator?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8CremoteCSR?= =?UTF-8?q?F->remote.=E6=8A=8A=E5=8E=9F=E7=94=9F=E7=9A=84remote=E6=94=B9?= =?UTF-8?q?=E6=88=90=E4=BA=86remotex=E3=80=82=E3=80=82=E3=80=82=20[ci=20sk?= =?UTF-8?q?ip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/oj/account/register.js | 8 +- static/src/js/config.js | 2 +- .../js/lib/formValidation/validator/remote.js | 144 +++-------------- .../formValidation/validator/remoteCSRF.js | 46 ------ .../lib/formValidation/validator/remotex.js | 146 ++++++++++++++++++ static/src/js/utils/validation.js | 2 +- 6 files changed, 175 insertions(+), 173 deletions(-) delete mode 100644 static/src/js/lib/formValidation/validator/remoteCSRF.js create mode 100644 static/src/js/lib/formValidation/validator/remotex.js diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js index b9d3468..a7a3ea1 100644 --- a/static/src/js/app/oj/account/register.js +++ b/static/src/js/app/oj/account/register.js @@ -18,8 +18,10 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf max: 30, message: '用户名长度必须在3到30位之间' }, - usernameCheck:{ - message: '用户名已存在' + remote: { + message: "用户名已存在", + url: "/api/username_check/", + field: 'username' } } }, @@ -64,7 +66,7 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf emailAddress: { message: "请填写有效的邮箱地址" }, - remoteCSRF: { + remote: { message: "您已经注册过了", url: "/api/email_check/", field: 'email' diff --git a/static/src/js/config.js b/static/src/js/config.js index dc8b37c..67bb9b6 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -28,7 +28,7 @@ var require = { "validator/integer": "lib/formValidation/validator/integer", "validator/between": "lib/formValidation/validator/between", "validator/confirm":"lib/formValidation/validator/confirm", - "validator/remoteCSRF":"lib/formValidation/validator/remoteCSRF", + "validator/remote":"lib/formValidation/validator/remote", "validator/emailAddress":"lib/formValidation/validator/emailAddress", //富文本编辑器 不要直接使用,而是使用上面的editor simditor: "lib/simditor/simditor", diff --git a/static/src/js/lib/formValidation/validator/remote.js b/static/src/js/lib/formValidation/validator/remote.js index b0ba1af..e7f8d02 100755 --- a/static/src/js/lib/formValidation/validator/remote.js +++ b/static/src/js/lib/formValidation/validator/remote.js @@ -1,146 +1,46 @@ /** * remote validator - * - * @link http://formvalidation.io/validators/remote/ - * @author https://twitter.com/nghuuphuoc - * @copyright (c) 2013 - 2015 Nguyen Huu Phuoc - * @license http://formvalidation.io/license/ */ - (function(root, factory) { "use strict"; // AMD module is defined if (typeof define === "function" && define.amd) { - define("validator/remote", ["jquery", "base"], factory); + define("validator/remote", ["jquery", "base", "csrf"], factory); } else { // planted over the root! factory(root.jQuery, root.FormValidation); } - -}(this, function ($, FormValidation) { +}(this, function ($, FormValidation, csrfHeader) { FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { 'en_US': { remote: { - 'default': 'Please enter a valid value' + 'default': '' } } }); - FormValidation.Validator.remote = { - html5Attributes: { - message: 'message', - name: 'name', - type: 'type', - url: 'url', - data: 'data', - delay: 'delay' - }, - - /** - * Destroy the timer when destroying the bootstrapValidator (using validator.destroy() method) - */ - destroy: function(validator, $field, options) { - var ns = validator.getNamespace(), - timer = $field.data(ns + '.remote.timer'); - if (timer) { - clearTimeout(timer); - $field.removeData(ns + '.remote.timer'); - } - }, - - /** - * Request a remote server to check the input value - * - * @param {FormValidation.Base} validator Plugin instance - * @param {jQuery} $field Field element - * @param {Object} options Can consist of the following keys: - * - url {String|Function} - * - type {String} [optional] Can be GET or POST (default) - * - data {Object|Function} [optional]: By default, it will take the value - * { - * : - * } - * - delay - * - name {String} [optional]: Override the field name for the request. - * - message: The invalid message - * - headers: Additional headers - * @returns {Deferred} - */ validate: function(validator, $field, options) { - var ns = validator.getNamespace(), - value = validator.getFieldValue($field, 'remote'), - dfd = new $.Deferred(); - if (value === '') { - dfd.resolve($field, 'remote', { valid: true }); - return dfd; - } - - var name = $field.attr('data-' + ns + '-field'), - data = options.data || {}, - url = options.url, - type = options.type || 'GET', - headers = options.headers || {}; - - // Support dynamic data - if ('function' === typeof data) { - data = data.call(this, validator); - } - - // Parse string data from HTML5 attribute - if ('string' === typeof data) { - data = JSON.parse(data); - } - - // Support dynamic url - if ('function' === typeof url) { - url = url.call(this, validator); - } - - data[options.name || name] = value; - function runCallback() { - var xhr = $.ajax({ - type: type, - headers: headers, - url: url, - dataType: 'json', - data: data - }); - - xhr - .success(function(response) { - response.valid = response.valid === true || response.valid === 'true'; - dfd.resolve($field, 'remote', response); - }) - .error(function(response) { - dfd.resolve($field, 'remote', { - valid: false - }); - }); - - dfd.fail(function() { - xhr.abort(); - }); - - return dfd; - } - - if (options.delay) { - // Since the form might have multiple fields with the same name - // I have to attach the timer to the field element - if ($field.data(ns + '.remote.timer')) { - clearTimeout($field.data(ns + '.remote.timer')); - } - - $field.data(ns + '.remote.timer', setTimeout(runCallback, options.delay)); - return dfd; - } else { - return runCallback(); - } + var dfd = new $.Deferred(), ajaxData = {}; + ajaxData[options.field] = $field.val(); + if ($field.val() === '') + return true; + var url = options.url; + var xhr = $.ajax({ + beforeSend: csrfHeader, + url: url, + dataType: 'json', + data: ajaxData, + method: "post" + }); + xhr.success(function(response) { + dfd.resolve($field, 'remote',{valid:!response.data, message:options.msg}); + }) + .error(function(response) { + dfd.resolve($field, 'remote', {valid: false}); + }); + return dfd; } }; - - - return FormValidation.Validator.remote; })); diff --git a/static/src/js/lib/formValidation/validator/remoteCSRF.js b/static/src/js/lib/formValidation/validator/remoteCSRF.js deleted file mode 100644 index 9cab354..0000000 --- a/static/src/js/lib/formValidation/validator/remoteCSRF.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * remoteCSRF validator - */ -(function(root, factory) { - - "use strict"; - - // AMD module is defined - if (typeof define === "function" && define.amd) { - define("validator/remoteCSRF", ["jquery", "base", "csrf"], factory); - } else { - // planted over the root! - factory(root.jQuery, root.FormValidation); - } -}(this, function ($, FormValidation, csrfHeader) { - FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { - 'en_US': { - remoteCSRF: { - 'default': '' - } - } - }); - FormValidation.Validator.remoteCSRF = { - validate: function(validator, $field, options) { - var dfd = new $.Deferred(), ajaxData = {}; - ajaxData[options.field] = $field.val(); - if ($field.val() === '') - return true; - var url = options.url; - var xhr = $.ajax({ - beforeSend: csrfHeader, - url: url, - dataType: 'json', - data: ajaxData, - method: "post" - }); - xhr.success(function(response) { - dfd.resolve($field, 'remoteCSRF',{valid:!response.data, message:options.msg}); - }) - .error(function(response) { - dfd.resolve($field, 'remoteCSRF', {valid: false}); - }); - return dfd; - } - }; -})); diff --git a/static/src/js/lib/formValidation/validator/remotex.js b/static/src/js/lib/formValidation/validator/remotex.js new file mode 100644 index 0000000..b0ba1af --- /dev/null +++ b/static/src/js/lib/formValidation/validator/remotex.js @@ -0,0 +1,146 @@ +/** + * remote validator + * + * @link http://formvalidation.io/validators/remote/ + * @author https://twitter.com/nghuuphuoc + * @copyright (c) 2013 - 2015 Nguyen Huu Phuoc + * @license http://formvalidation.io/license/ + */ + +(function(root, factory) { + + "use strict"; + + // AMD module is defined + if (typeof define === "function" && define.amd) { + define("validator/remote", ["jquery", "base"], factory); + } else { + // planted over the root! + factory(root.jQuery, root.FormValidation); + } + +}(this, function ($, FormValidation) { + FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { + 'en_US': { + remote: { + 'default': 'Please enter a valid value' + } + } + }); + + FormValidation.Validator.remote = { + html5Attributes: { + message: 'message', + name: 'name', + type: 'type', + url: 'url', + data: 'data', + delay: 'delay' + }, + + /** + * Destroy the timer when destroying the bootstrapValidator (using validator.destroy() method) + */ + destroy: function(validator, $field, options) { + var ns = validator.getNamespace(), + timer = $field.data(ns + '.remote.timer'); + if (timer) { + clearTimeout(timer); + $field.removeData(ns + '.remote.timer'); + } + }, + + /** + * Request a remote server to check the input value + * + * @param {FormValidation.Base} validator Plugin instance + * @param {jQuery} $field Field element + * @param {Object} options Can consist of the following keys: + * - url {String|Function} + * - type {String} [optional] Can be GET or POST (default) + * - data {Object|Function} [optional]: By default, it will take the value + * { + * : + * } + * - delay + * - name {String} [optional]: Override the field name for the request. + * - message: The invalid message + * - headers: Additional headers + * @returns {Deferred} + */ + validate: function(validator, $field, options) { + var ns = validator.getNamespace(), + value = validator.getFieldValue($field, 'remote'), + dfd = new $.Deferred(); + if (value === '') { + dfd.resolve($field, 'remote', { valid: true }); + return dfd; + } + + var name = $field.attr('data-' + ns + '-field'), + data = options.data || {}, + url = options.url, + type = options.type || 'GET', + headers = options.headers || {}; + + // Support dynamic data + if ('function' === typeof data) { + data = data.call(this, validator); + } + + // Parse string data from HTML5 attribute + if ('string' === typeof data) { + data = JSON.parse(data); + } + + // Support dynamic url + if ('function' === typeof url) { + url = url.call(this, validator); + } + + data[options.name || name] = value; + function runCallback() { + var xhr = $.ajax({ + type: type, + headers: headers, + url: url, + dataType: 'json', + data: data + }); + + xhr + .success(function(response) { + response.valid = response.valid === true || response.valid === 'true'; + dfd.resolve($field, 'remote', response); + }) + .error(function(response) { + dfd.resolve($field, 'remote', { + valid: false + }); + }); + + dfd.fail(function() { + xhr.abort(); + }); + + return dfd; + } + + if (options.delay) { + // Since the form might have multiple fields with the same name + // I have to attach the timer to the field element + if ($field.data(ns + '.remote.timer')) { + clearTimeout($field.data(ns + '.remote.timer')); + } + + $field.data(ns + '.remote.timer', setTimeout(runCallback, options.delay)); + return dfd; + } else { + return runCallback(); + } + } + }; + + + return FormValidation.Validator.remote; +})); diff --git a/static/src/js/utils/validation.js b/static/src/js/utils/validation.js index 45da8f5..191d585 100644 --- a/static/src/js/utils/validation.js +++ b/static/src/js/utils/validation.js @@ -9,7 +9,7 @@ define("validation", 'validator/integer', 'validator/between', 'validator/confirm', - 'validator/remoteCSRF', + 'validator/remote', 'validator/emailAddress'], function () { }); \ No newline at end of file From 117a6d3525b9a5e3dac0b0c6ce413445bec0af11 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Wed, 5 Aug 2015 20:11:25 +0800 Subject: [PATCH 21/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E4=BF=AE=E6=94=B9=E6=88=90=E5=8A=9F=E7=9A=84?= =?UTF-8?q?API=E6=B5=8B=E8=AF=95=EF=BC=8C=E4=BB=A5=E5=8F=8A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=94=A8=E6=88=B7=E9=82=AE=E7=AE=B1=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=B9=B6=E5=81=9A=E4=BA=86=E7=9B=B8=E5=BA=94=E7=9A=84API?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=8C=E7=9B=AE=E5=89=8D=E7=9A=84account/v?= =?UTF-8?q?iew.py=E6=B5=8B=E8=AF=95=E8=A6=86=E7=9B=96=E7=8E=87=E4=B8=BA100?= =?UTF-8?q?%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/migrations/0003_user_email.py | 19 +++++++++++ account/models.py | 2 ++ account/serializers.py | 5 +++ account/tests.py | 48 ++++++++++++++++++++++++--- account/views.py | 29 ++++++++++++++-- oj/urls.py | 4 ++- 6 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 account/migrations/0003_user_email.py diff --git a/account/migrations/0003_user_email.py b/account/migrations/0003_user_email.py new file mode 100644 index 0000000..780afc3 --- /dev/null +++ b/account/migrations/0003_user_email.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0002_auto_20150731_2310'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='email', + field=models.EmailField(max_length=254, null=True, blank=True), + ), + ] diff --git a/account/models.py b/account/models.py index 1b8636a..1f02eef 100644 --- a/account/models.py +++ b/account/models.py @@ -19,6 +19,8 @@ class User(AbstractBaseUser): username = models.CharField(max_length=30, unique=True) # 真实姓名 real_name = models.CharField(max_length=30, blank=True, null=True) + # 用户邮箱 + email = models.EmailField(max_length=254, blank=True, null=True) admin_group = models.ForeignKey(AdminGroup, null=True, on_delete=models.SET_NULL) USERNAME_FIELD = 'username' diff --git a/account/serializers.py b/account/serializers.py index 41634b7..209e490 100644 --- a/account/serializers.py +++ b/account/serializers.py @@ -11,10 +11,15 @@ class UsernameCheckSerializer(serializers.Serializer): username = serializers.CharField(max_length=30) +class EmailCheckSerializer(serializers.Serializer): + email = serializers.EmailField(max_length=254) + + class UserRegisterSerializer(serializers.Serializer): username = serializers.CharField(max_length=30) real_name = serializers.CharField(max_length=30) password = serializers.CharField(max_length=30, min_length=6) + email = serializers.EmailField(max_length=254) class UserChangePasswordSerializer(serializers.Serializer): diff --git a/account/tests.py b/account/tests.py index 83226b7..76fbec6 100644 --- a/account/tests.py +++ b/account/tests.py @@ -1,6 +1,8 @@ # coding=utf-8 import json +from django.contrib import auth + from django.core.urlresolvers import reverse from django.test import TestCase, Client from django.http import HttpResponse @@ -63,6 +65,26 @@ class UsernameCheckTest(APITestCase): self.assertEqual(response.data, {"code": 0, "data": False}) +class EmailCheckTest(APITestCase): + def setUp(self): + self.client = APIClient() + self.url = reverse("email_check_api") + User.objects.create(email="11@qq.com") + + def test_invalid_data(self): + response = self.client.post(self.url, data={"email000": "11@qq.com"}) + self.assertEqual(response.data["code"], 1) + self.assertEqual(response.data["code"], 1) + + def test_email_exists(self): + response = self.client.post(self.url, data={"email": "11@qq.com"}) + self.assertEqual(response.data, {"code": 0, "data": True}) + + def test_email_does_not_exist(self): + response = self.client.post(self.url, data={"email": "33@qq.com"}) + self.assertEqual(response.data, {"code": 0, "data": False}) + + class UserRegisterAPITest(APITestCase): def setUp(self): self.client = APIClient() @@ -74,22 +96,35 @@ class UserRegisterAPITest(APITestCase): self.assertEqual(response.data["code"], 1) def test_short_password(self): - data = {"username": "test", "real_name": "TT", "password": "qq"} + data = {"username": "test", "real_name": "TT", "password": "qq", "email": "6060@qq.com"} response = self.client.post(self.url, data=data) self.assertEqual(response.data["code"], 1) def test_same_username(self): - User.objects.create(username="aa", real_name="ww") - data = {"username": "aa", "real_name": "ww", "password": "zzzzzzz"} + User.objects.create(username="aa") + data = {"username": "aa", "real_name": "ww", "password": "zzzzzzz", "email": "6060@qq.com"} response = self.client.post(self.url, data=data) self.assertEqual(response.data, {"code": 1, "data": u"用户名已存在"}) + def test_same_email(self): + User.objects.create(username="bb", email="8080@qq.com") + data = {"username": "aa", "real_name": "ww", "password": "zzzzzzz", "email": "8080@qq.com"} + response = self.client.post(self.url, data=data) + self.assertEqual(response.data, {"code": 1, "data": u"该邮箱已被注册,请换其他邮箱进行注册"}) + + def test_success_email(self): + data = {"username": "cc", "real_name": "dd", "password": "xxxxxx", "email": "9090@qq.com"} + response = self.client.post(self.url, data=data) + self.assertEqual(response.data, {"code": 0, "data": u"注册成功!"}) + class UserChangePasswordAPITest(APITestCase): def setUp(self): self.client = APIClient() self.url = reverse("user_change_password_api") - User.objects.create(username="test", password="aaabbb") + user = User.objects.create(username="test") + user.set_password("aaabbb") + user.save() def test_error_old_password(self): data = {"username": "test", "old_password": "aaaccc", "new_password": "aaaddd"} @@ -106,6 +141,11 @@ class UserChangePasswordAPITest(APITestCase): response = self.client.post(self.url, data=data) self.assertEqual(response.data["code"], 1) + def test_success_change_password(self): + data = {"username": "test", "old_password": "aaabbb", "new_password": "aaaccc"} + response = self.client.post(self.url, data=data) + self.assertEqual(response.data, {"code": 0, "data": u"用户密码修改成功!"}) + @login_required def login_required_FBV_test_without_args(request): diff --git a/account/views.py b/account/views.py index dd05874..ea13663 100644 --- a/account/views.py +++ b/account/views.py @@ -7,7 +7,7 @@ from utils.shortcuts import serializer_invalid_response, error_response, success from .models import User from .serializers import UserLoginSerializer, UsernameCheckSerializer, UserRegisterSerializer, \ - UserChangePasswordSerializer + UserChangePasswordSerializer, EmailCheckSerializer class UserLoginAPIView(APIView): @@ -45,7 +45,13 @@ class UserRegisterAPIView(APIView): User.objects.get(username=data["username"]) return error_response(u"用户名已存在") except User.DoesNotExist: - user = User.objects.create(username=data["username"], real_name=data["real_name"]) + pass + try: + User.objects.get(email=data["email"]) + return error_response(u"该邮箱已被注册,请换其他邮箱进行注册") + except User.DoesNotExist: + user = User.objects.create(username=data["username"], real_name=data["real_name"], + email=data["email"]) user.set_password(data["password"]) user.save() return success_response(u"注册成功!") @@ -89,4 +95,21 @@ class UsernameCheckAPIView(APIView): except User.DoesNotExist: return success_response(False) else: - return serializer_invalid_response(serializer) \ No newline at end of file + return serializer_invalid_response(serializer) + +class EmailCheckAPIView(APIView): + def post(self, request): + """ + 检测邮箱是否存在,存在返回True,不存在返回False + --- + request_serializer: EmailCheckSerializer + """ + serializer = EmailCheckSerializer(data=request.DATA) + if serializer.is_valid(): + try: + User.objects.get(email=serializer.data["email"]) + return success_response(True) + except User.DoesNotExist: + return success_response(False) + else: + return serializer_invalid_response(serializer) diff --git a/oj/urls.py b/oj/urls.py index 0c8ea51..b2b3f12 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -3,7 +3,8 @@ from django.conf.urls import include, url from django.contrib import admin from django.views.generic import TemplateView -from account.views import UserLoginAPIView, UsernameCheckAPIView, UserRegisterAPIView, UserChangePasswordAPIView +from account.views import UserLoginAPIView, UsernameCheckAPIView, UserRegisterAPIView, UserChangePasswordAPIView, \ + EmailCheckAPIView from announcement.views import AnnouncementAPIView urlpatterns = [ @@ -17,6 +18,7 @@ urlpatterns = [ url(r'^api/register/$', UserRegisterAPIView.as_view(), name="user_register_api"), url(r'^api/change_password/$', UserChangePasswordAPIView.as_view(), name="user_change_password_api"), url(r'^api/username_check/$', UsernameCheckAPIView.as_view(), name="username_check_api"), + url(r'^api/email_check/$', EmailCheckAPIView.as_view(), name="email_check_api"), url(r'^api/admin/announcement/$', AnnouncementAPIView.as_view(), name="announcement_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), From 98f8b650110d71190f13f92696464f0751c19098 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Wed, 5 Aug 2015 20:23:42 +0800 Subject: [PATCH 22/99] =?UTF-8?q?=E5=9C=A8account/tests.py=E4=B8=AD?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/tests.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/account/tests.py b/account/tests.py index 76fbec6..89410da 100644 --- a/account/tests.py +++ b/account/tests.py @@ -1,8 +1,6 @@ # coding=utf-8 import json -from django.contrib import auth - from django.core.urlresolvers import reverse from django.test import TestCase, Client from django.http import HttpResponse @@ -74,7 +72,6 @@ class EmailCheckTest(APITestCase): def test_invalid_data(self): response = self.client.post(self.url, data={"email000": "11@qq.com"}) self.assertEqual(response.data["code"], 1) - self.assertEqual(response.data["code"], 1) def test_email_exists(self): response = self.client.post(self.url, data={"email": "11@qq.com"}) From 875e3b16717161b3a024a786dbd5f9aaf8fae73d Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 09:43:14 +0800 Subject: [PATCH 23/99] =?UTF-8?q?=E5=B0=86=E6=B3=A8=E5=86=8C=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=94=A8=E6=88=B7=E5=90=8D=E5=92=8C=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E9=AA=8C=E8=AF=81=E6=94=B9=E4=B8=BA=E4=BA=86=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A1=86=E5=A4=B1=E5=8E=BB=E7=84=A6=E7=82=B9=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E6=89=8D=E9=AA=8C=E8=AF=81=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=8F=91=E9=80=81=E5=A4=A7=E9=87=8F=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E3=80=82=20=E5=A2=9E=E5=8A=A0=E6=B3=A8=E5=86=8C=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E5=90=91=E5=90=8E=E7=AB=AF=E5=8F=91=E9=80=81?= =?UTF-8?q?=E9=82=AE=E7=AE=B1=E5=AD=97=E6=AE=B5=E3=80=82=20=E6=95=B4?= =?UTF-8?q?=E7=90=86=20js=20=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/js/app/oj/account/change_password.js | 24 +++++------ static/src/js/app/oj/account/login.js | 12 +++--- static/src/js/app/oj/account/register.js | 42 +++++++++---------- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/static/src/js/app/oj/account/change_password.js b/static/src/js/app/oj/account/change_password.js index e3e907f..c76dd9d 100644 --- a/static/src/js/app/oj/account/change_password.js +++ b/static/src/js/app/oj/account/change_password.js @@ -1,4 +1,4 @@ -require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrfHeader){ +require(["jquery", "bs_alert", "csrf", "validation"], function ($, bs_alert, csrfHeader) { $("#change_password-form").formValidation({ framework: "bootstrap", fields: { @@ -13,22 +13,22 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf validators: { notEmpty: { message: "请填写旧密码" - } + } } }, new_password: { validators: { notEmpty: { message: "请填写新密码" - }, + }, stringLength: { min: 6, max: 30, message: '密码长度必须在6到30位之间' } }, - onSuccess: function(e, data) { - data.fv.revalidateField('confirm_password'); + onSuccess: function (e, data) { + data.fv.revalidateField('confirm_password'); } }, confirm_password: { @@ -40,27 +40,27 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf original: $("#new_password"), message: "两次输入的密码必须一致" } - }, + } } } } - ).on('success.form.fv', function(e) { + ).on('success.form.fv', function (e) { e.preventDefault(); var username = $("#username").val(); - var new_password = $("#new_password ").val(); + var new_password = $("#new_password ").val(); var password = $("#password").val(); $.ajax({ beforeSend: csrfHeader, url: "/api/change_password/", - data: {username: username, new_password: new_password , old_password : password}, + data: {username: username, new_password: new_password, old_password: password}, dataType: "json", method: "post", success: function (data) { - if(!data.code){ - window.location.href="/login/"; + if (!data.code) { + window.location.href = "/login/"; } - else{ + else { bs_alert(data.data); } } diff --git a/static/src/js/app/oj/account/login.js b/static/src/js/app/oj/account/login.js index da4416d..2ecebf7 100644 --- a/static/src/js/app/oj/account/login.js +++ b/static/src/js/app/oj/account/login.js @@ -1,6 +1,6 @@ -require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrfHeader){ +require(["jquery", "bs_alert", "csrf", "validation"], function ($, bs_alert, csrfHeader) { $("#login-form") - .formValidation({ + .formValidation({ framework: "bootstrap", fields: { username: { @@ -19,7 +19,7 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf } } } - ).on('success.form.fv', function(e) { + ).on('success.form.fv', function (e) { e.preventDefault(); var username = $("#username").val(); var password = $("#password").val(); @@ -30,10 +30,10 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf dataType: "json", method: "post", success: function (data) { - if(!data.code){ - window.location.href="/"; + if (!data.code) { + window.location.href = "/"; } - else{ + else { bs_alert(data.data); } } diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js index a7a3ea1..52c3d36 100644 --- a/static/src/js/app/oj/account/register.js +++ b/static/src/js/app/oj/account/register.js @@ -1,14 +1,10 @@ -require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrfHeader){ +require(["jquery", "bs_alert", "csrf", "validation"], function ($, bs_alert, csrfHeader) { $("#register-form") - .formValidation({ + .formValidation({ framework: "bootstrap", - icon: { - valid: 'glyphicon glyphicon-ok', - invalid: 'glyphicon glyphicon-remove', - validating: 'glyphicon glyphicon-refresh' - }, fields: { username: { + trigger: 'blur', validators: { notEmpty: { message: "请填写用户名" @@ -29,23 +25,23 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf validators: { notEmpty: { message: "请填写密码" - }, - stringLength: { - min: 6, - max: 30, - message: '密码长度必须在6到30位之间' - } + }, + stringLength: { + min: 6, + max: 30, + message: '密码长度必须在6到30位之间' + } }, - onSuccess: function(e, data) { - data.fv.revalidateField('confirm_password'); + onSuccess: function (e, data) { + data.fv.revalidateField('confirm_password'); } }, real_name: { validators: { notEmpty: { message: "请填写真实姓名" - } - }, + } + } }, confirm_password: { validators: { @@ -59,6 +55,7 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf } }, email: { + trigger: 'blur', validators: { notEmpty: { message: "请填写电子邮箱邮箱地址" @@ -75,22 +72,23 @@ require(["jquery", "bs_alert", "csrf", "validation"], function($, bs_alert, csrf } } } - ).on('success.form.fv', function(e) { + ).on('success.form.fv', function (e) { e.preventDefault(); var username = $("#username").val(); var real_name = $("#real_name").val(); var password = $("#password").val(); + var email = $("#email").val(); $.ajax({ beforeSend: csrfHeader, url: "/api/register/", - data: {username: username, real_name: real_name, password: password}, + data: {username: username, real_name: real_name, password: password, email: email}, dataType: "json", method: "post", success: function (data) { - if(!data.code){ - window.location.href="/login/"; + if (!data.code) { + window.location.href = "/login/"; } - else{ + else { bs_alert(data.data); } } From 2bf0389e7be0285288709fc53aa0a22519223642 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Thu, 6 Aug 2015 11:08:02 +0800 Subject: [PATCH 24/99] =?UTF-8?q?announcement=20model.py=20=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=20description=20=E6=94=B9=E5=90=8D=E4=B8=BA?= =?UTF-8?q?=20content,=E5=B9=B6=E4=BF=AE=E6=94=B9=E5=85=B6=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84serializers=E5=92=8Cviews?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0002_auto_20150806_1104.py | 19 +++++++++++++++++++ announcement/models.py | 4 ++-- announcement/serializers.py | 2 +- announcement/views.py | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 announcement/migrations/0002_auto_20150806_1104.py diff --git a/announcement/migrations/0002_auto_20150806_1104.py b/announcement/migrations/0002_auto_20150806_1104.py new file mode 100644 index 0000000..2768cc6 --- /dev/null +++ b/announcement/migrations/0002_auto_20150806_1104.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('announcement', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='announcement', + old_name='description', + new_name='content', + ), + ] diff --git a/announcement/models.py b/announcement/models.py index a47eba6..a3574b8 100644 --- a/announcement/models.py +++ b/announcement/models.py @@ -7,8 +7,8 @@ from account.models import User class Announcement(models.Model): # 标题 title = models.CharField(max_length=50) - # 公告的描述 HTML 格式 - description = models.TextField() + # 公告的内容 HTML 格式 + content = models.TextField() # 创建时间 create_time = models.DateTimeField(auto_now_add=True) # 这个公告是谁创建的 diff --git a/announcement/serializers.py b/announcement/serializers.py index a1525b9..3878e14 100644 --- a/announcement/serializers.py +++ b/announcement/serializers.py @@ -4,5 +4,5 @@ from rest_framework import serializers class AnnouncementSerializer(serializers.Serializer): title = serializers.CharField(max_length=50) - description = serializers.CharField(max_length=10000) + content = serializers.CharField(max_length=10000) diff --git a/announcement/views.py b/announcement/views.py index 220e806..e3766e8 100644 --- a/announcement/views.py +++ b/announcement/views.py @@ -21,7 +21,7 @@ class AnnouncementAPIView(APIView): if serializer.is_valid(): data = serializer.data Announcement.objects.create(title=data["title"], - description=data["description"], + content=data["content"], created_by=request.user) return success_response(u"公告发布成功!") else: From 62f07e713f8a4137b24a6791cf1a18dbe1c06f82 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 12:25:16 +0800 Subject: [PATCH 25/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20@admin=5Frequired=20?= =?UTF-8?q?=E4=BF=AE=E9=A5=B0=E7=AC=A6=E4=BB=A3=E7=A0=81=E5=92=8C=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/decorators.py | 12 +++++- account/models.py | 3 +- account/test_urls.py | 16 +++++--- account/tests.py | 92 ++++++++++++++++++++++++++++++++++++++----- 4 files changed, 106 insertions(+), 17 deletions(-) diff --git a/account/decorators.py b/account/decorators.py index 6b10896..01cdd68 100644 --- a/account/decorators.py +++ b/account/decorators.py @@ -20,5 +20,13 @@ def login_required(func): return check -def admin_required(): - pass +def admin_required(func): + def check(*args, **kwargs): + request = args[-1] + if request.user.is_authenticated() and request.user.admin_type: + return func(*args, **kwargs) + if request.is_ajax(): + return error_response(u"需要管理员权限") + else: + return render(request, "utils/error.html", {"error": "需要管理员权限"}) + return check diff --git a/account/models.py b/account/models.py index 1f02eef..7c5afb9 100644 --- a/account/models.py +++ b/account/models.py @@ -21,7 +21,8 @@ class User(AbstractBaseUser): real_name = models.CharField(max_length=30, blank=True, null=True) # 用户邮箱 email = models.EmailField(max_length=254, blank=True, null=True) - admin_group = models.ForeignKey(AdminGroup, null=True, on_delete=models.SET_NULL) + # 0代表不是管理员 1是普通管理员 2是超级管理员 + admin_type = models.IntegerField(default=0) USERNAME_FIELD = 'username' REQUIRED_FIELDS = [] diff --git a/account/test_urls.py b/account/test_urls.py index 4066721..9757d90 100644 --- a/account/test_urls.py +++ b/account/test_urls.py @@ -1,12 +1,18 @@ # coding=utf-8 from django.conf.urls import include, url -from .tests import LoginRequiredCBVTestWithArgs, LoginRequiredCBVTestWithoutArgs +from .tests import (LoginRequiredCBVTestWithArgs, LoginRequiredCBVTestWithoutArgs, + AdminRequiredCBVTestWithArgs, AdminRequiredCBVTestWithoutArgs) urlpatterns = [ - url(r'^test/fbv/1/$', "account.tests.login_required_FBV_test_without_args"), - url(r'^test/fbv/(?P\d+)/$', "account.tests.login_required_FBC_test_with_args"), - url(r'^test/cbv/1/$', LoginRequiredCBVTestWithoutArgs.as_view()), - url(r'^test/cbv/(?P\d+)/$', LoginRequiredCBVTestWithArgs.as_view()), + url(r'^login_required_test/fbv/1/$', "account.tests.login_required_FBV_test_without_args"), + url(r'^login_required_test/fbv/(?P\d+)/$', "account.tests.login_required_FBC_test_with_args"), + url(r'^login_required_test/cbv/1/$', LoginRequiredCBVTestWithoutArgs.as_view()), + url(r'^login_required_test/cbv/(?P\d+)/$', LoginRequiredCBVTestWithArgs.as_view()), + + url(r'^admin_required_test/fbv/1/$', "account.tests.admin_required_FBV_test_without_args"), + url(r'^admin_required_test/fbv/(?P\d+)/$', "account.tests.admin_required_FBC_test_with_args"), + url(r'^admin_required_test/cbv/1/$', AdminRequiredCBVTestWithoutArgs.as_view()), + url(r'^admin_required_test/cbv/(?P\d+)/$', AdminRequiredCBVTestWithArgs.as_view()), ] diff --git a/account/tests.py b/account/tests.py index 89410da..3529bb6 100644 --- a/account/tests.py +++ b/account/tests.py @@ -10,7 +10,7 @@ from rest_framework.views import APIView from rest_framework.response import Response from .models import User -from .decorators import login_required +from .decorators import login_required, admin_required class UserLoginTest(TestCase): @@ -159,6 +159,7 @@ class LoginRequiredCBVTestWithoutArgs(APIView): def get(self, request): return HttpResponse("class based view login required test1") + class LoginRequiredCBVTestWithArgs(APIView): @login_required def get(self, request, problem_id): @@ -176,40 +177,113 @@ class LoginRequiredDecoratorTest(TestCase): def test_fbv_without_args(self): # 没登陆 - response = self.client.get("/test/fbv/1/") + response = self.client.get("/login_required_test/fbv/1/") self.assertTemplateUsed(response, "utils/error.html") # 登陆后 self.client.login(username="test", password="test") - response = self.client.get("/test/fbv/1/") + response = self.client.get("/login_required_test/fbv/1/") self.assertEqual(response.content, "function based view test1") def test_fbv_with_args(self): # 没登陆 - response = self.client.get("/test/fbv/1024/") + response = self.client.get("/login_required_test/fbv/1024/") self.assertTemplateUsed(response, "utils/error.html") # 登陆后 self.client.login(username="test", password="test") - response = self.client.get("/test/fbv/1024/") + response = self.client.get("/login_required_test/fbv/1024/") self.assertEqual(response.content, "1024") def test_cbv_without_args(self): # 没登陆 - response = self.client.get("/test/cbv/1/") + response = self.client.get("/login_required_test/cbv/1/") self.assertTemplateUsed(response, "utils/error.html") # 登陆后 self.client.login(username="test", password="test") - response = self.client.get("/test/cbv/1/") + response = self.client.get("/login_required_test/cbv/1/") self.assertEqual(response.content, "class based view login required test1") def test_cbv_with_args(self): # 没登陆 - response = self.client.get("/test/cbv/1024/", HTTP_X_REQUESTED_WITH='XMLHttpRequest') + response = self.client.get("/login_required_test/cbv/1024/", HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(json.loads(response.content), {"code": 1, "data": u"请先登录"}) # 登陆后 self.client.login(username="test", password="test") - response = self.client.get("/test/cbv/1024/") + response = self.client.get("/login_required_test/cbv/1024/") + self.assertEqual(response.content, "1024") + + +@admin_required +def admin_required_FBV_test_without_args(request): + return HttpResponse("function based view test1") + + +@admin_required +def admin_required_FBC_test_with_args(request, problem_id): + return HttpResponse(problem_id) + + +class AdminRequiredCBVTestWithoutArgs(APIView): + @admin_required + def get(self, request): + return HttpResponse("class based view login required test1") + + +class AdminRequiredCBVTestWithArgs(APIView): + @admin_required + def get(self, request, problem_id): + return HttpResponse(problem_id) + + +class AdminRequiredDecoratorTest(TestCase): + urls = 'account.test_urls' + + def setUp(self): + self.client = Client() + user = User.objects.create(username="test") + user.admin_type = 1 + user.set_password("test") + user.save() + + def test_fbv_without_args(self): + # 没登陆 + response = self.client.get("/admin_required_test/fbv/1/") + self.assertTemplateUsed(response, "utils/error.html") + + # 登陆后 + self.client.login(username="test", password="test") + response = self.client.get("/admin_required_test/fbv/1/") + self.assertEqual(response.content, "function based view test1") + + def test_fbv_with_args(self): + # 没登陆 + response = self.client.get("/admin_required_test/fbv/1024/") + self.assertTemplateUsed(response, "utils/error.html") + + # 登陆后 + self.client.login(username="test", password="test") + response = self.client.get("/admin_required_test/fbv/1024/") + self.assertEqual(response.content, "1024") + + def test_cbv_without_args(self): + # 没登陆 + response = self.client.get("/admin_required_test/cbv/1/") + self.assertTemplateUsed(response, "utils/error.html") + + # 登陆后 + self.client.login(username="test", password="test") + response = self.client.get("/admin_required_test/cbv/1/") + self.assertEqual(response.content, "class based view login required test1") + + def test_cbv_with_args(self): + # 没登陆 + response = self.client.get("/admin_required_test/cbv/1024/", HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(json.loads(response.content), {"code": 1, "data": u"需要管理员权限"}) + + # 登陆后 + self.client.login(username="test", password="test") + response = self.client.get("/admin_required_test/cbv/1024/") self.assertEqual(response.content, "1024") From 53afd2a0324281115e46607ff6f1572e1d922a03 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 13:05:00 +0800 Subject: [PATCH 26/99] =?UTF-8?q?bug-fix:=20=E5=A2=9E=E5=8A=A0=20account/m?= =?UTF-8?q?odels=20=E7=9A=84=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/migrations/0004_auto_20150806_1211.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 account/migrations/0004_auto_20150806_1211.py diff --git a/account/migrations/0004_auto_20150806_1211.py b/account/migrations/0004_auto_20150806_1211.py new file mode 100644 index 0000000..d3d2225 --- /dev/null +++ b/account/migrations/0004_auto_20150806_1211.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0003_user_email'), + ] + + operations = [ + migrations.RemoveField( + model_name='user', + name='admin_group', + ), + migrations.AddField( + model_name='user', + name='admin_type', + field=models.IntegerField(default=0), + ), + ] From 96c8d28c6460c6e208b47e8fd0b70f7f3beace25 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Thu, 6 Aug 2015 13:17:15 +0800 Subject: [PATCH 27/99] =?UTF-8?q?announcement=20model.py=20=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=88=E6=9C=80=E5=90=8E=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E9=97=B4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/migrations/0004_auto_20150806_1251.py | 23 +++++++++++++++++++ announcement/migrations/0001_initial.py | 3 ++- .../migrations/0002_auto_20150806_1104.py | 19 --------------- announcement/models.py | 2 ++ 4 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 account/migrations/0004_auto_20150806_1251.py delete mode 100644 announcement/migrations/0002_auto_20150806_1104.py diff --git a/account/migrations/0004_auto_20150806_1251.py b/account/migrations/0004_auto_20150806_1251.py new file mode 100644 index 0000000..d3d2225 --- /dev/null +++ b/account/migrations/0004_auto_20150806_1251.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0003_user_email'), + ] + + operations = [ + migrations.RemoveField( + model_name='user', + name='admin_group', + ), + migrations.AddField( + model_name='user', + name='admin_type', + field=models.IntegerField(default=0), + ), + ] diff --git a/announcement/migrations/0001_initial.py b/announcement/migrations/0001_initial.py index 24a1d13..7e8d583 100644 --- a/announcement/migrations/0001_initial.py +++ b/announcement/migrations/0001_initial.py @@ -17,8 +17,9 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('title', models.CharField(max_length=50)), - ('description', models.TextField()), + ('content', models.TextField()), ('create_time', models.DateTimeField(auto_now_add=True)), + ('last_update_time', models.DateTimeField(auto_now=True)), ('visible', models.BooleanField(default=True)), ('created_by', models.ForeignKey(to=settings.AUTH_USER_MODEL)), ], diff --git a/announcement/migrations/0002_auto_20150806_1104.py b/announcement/migrations/0002_auto_20150806_1104.py deleted file mode 100644 index 2768cc6..0000000 --- a/announcement/migrations/0002_auto_20150806_1104.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('announcement', '0001_initial'), - ] - - operations = [ - migrations.RenameField( - model_name='announcement', - old_name='description', - new_name='content', - ), - ] diff --git a/announcement/models.py b/announcement/models.py index a3574b8..491c219 100644 --- a/announcement/models.py +++ b/announcement/models.py @@ -13,6 +13,8 @@ class Announcement(models.Model): create_time = models.DateTimeField(auto_now_add=True) # 这个公告是谁创建的 created_by = models.ForeignKey(User) + # 最后更新时间 + last_update_time = models.DateTimeField(auto_now=True) # 是否可见 false的话相当于删除 visible = models.BooleanField(default=True) From 65dfd1149b6984c10cd273f314a9aa6cbf7181a6 Mon Sep 17 00:00:00 2001 From: sxw Date: Thu, 6 Aug 2015 15:12:28 +0800 Subject: [PATCH 28/99] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=85=B3?= =?UTF-8?q?=E4=BA=8E=E7=94=B5=E5=AD=90=E9=82=AE=E7=AE=B1=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E5=89=8D=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=A0=87=E5=87=86=E5=B7=AE=E5=BC=82=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E7=AB=AF=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=85=88=E5=88=A4=E6=96=ADcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/lib/formValidation/validator/remote.js | 2 ++ 1 file changed, 2 insertions(+) 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) { From 844e9702764c36d60bd0dac9ba0f1f944f96c51a Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Thu, 6 Aug 2015 16:28:59 +0800 Subject: [PATCH 29/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E5=8F=91=E5=B8=83=E6=88=90=E5=8A=9F=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=EF=BC=8C=E4=BB=A5=E5=8F=8A=E5=85=AC=E5=91=8A=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E7=9A=84APIview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- announcement/serializers.py | 18 +++++++++++++++++- announcement/tests.py | 15 +++++++++++++-- announcement/views.py | 24 +++++++++++++++++------- oj/urls.py | 6 ++++-- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/announcement/serializers.py b/announcement/serializers.py index 3878e14..a195b2e 100644 --- a/announcement/serializers.py +++ b/announcement/serializers.py @@ -1,8 +1,24 @@ # coding=utf-8 from rest_framework import serializers +from account.models import User +from .models import Announcement -class AnnouncementSerializer(serializers.Serializer): + +class CreateAnnouncementSerializer(serializers.Serializer): title = serializers.CharField(max_length=50) content = serializers.CharField(max_length=10000) + +class AnnouncementSerializer(serializers.ModelSerializer): + + class UserSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = ["username"] + + created_by = UserSerializer() + + class Meta: + model = Announcement + diff --git a/announcement/tests.py b/announcement/tests.py index f73805e..f337a9c 100644 --- a/announcement/tests.py +++ b/announcement/tests.py @@ -3,14 +3,25 @@ from django.core.urlresolvers import reverse from rest_framework.test import APITestCase, APIClient +from account.models import User + class AnnouncementAPITest(APITestCase): def setUp(self): self.client = APIClient() - self.url = reverse("announcement_api") + self.url = reverse("announcement_admin_api") + user = User.objects.create(username="test") + user.set_password("test") + user.save() def test_invalid_format(self): - # todo 判断用户是否登录 + self.client.login(username="test", password="test") data = {"title": "test1"} response = self.client.post(self.url, data=data) self.assertEqual(response.data["code"], 1) + + def test_success_announcement(self): + self.client.login(username="test", password="test") + data = {"title": "title0", "content": "content0"} + response = self.client.post(self.url, data=data) + self.assertEqual(response.data, {"code": 0, "data": u"公告发布成功!"}) \ No newline at end of file diff --git a/announcement/views.py b/announcement/views.py index e3766e8..b01af7f 100644 --- a/announcement/views.py +++ b/announcement/views.py @@ -4,20 +4,19 @@ from rest_framework.views import APIView from utils.shortcuts import serializer_invalid_response, error_response, success_response from account.models import User - +from utils.shortcuts import paginate from .models import Announcement -from .serializers import AnnouncementSerializer +from .serializers import CreateAnnouncementSerializer, AnnouncementSerializer -class AnnouncementAPIView(APIView): - # todo 判断用户是否需要登录 +class AnnouncementAdminAPIView(APIView): def post(self, request): """ 公告发布json api接口 --- - request_serializer: AnnouncementSerializer + request_serializer: CreateAnnouncementSerializer """ - serializer = AnnouncementSerializer(data=request.DATA) + serializer = CreateAnnouncementSerializer(data=request.DATA) if serializer.is_valid(): data = serializer.data Announcement.objects.create(title=data["title"], @@ -25,4 +24,15 @@ class AnnouncementAPIView(APIView): created_by=request.user) return success_response(u"公告发布成功!") else: - return serializer_invalid_response(serializer) \ No newline at end of file + return serializer_invalid_response(serializer) + + +class AnnouncementAPIView(APIView): + def get(self, request): + """ + 公告分页json api接口 + --- + request_serializer: AnnouncementSerializer + """ + announcement = Announcement.objects.all().order_by("last_update_time") + return paginate(request, announcement, AnnouncementSerializer) diff --git a/oj/urls.py b/oj/urls.py index 82ecafb..2586cb6 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -5,7 +5,7 @@ from django.views.generic import TemplateView from account.views import UserLoginAPIView, UsernameCheckAPIView, UserRegisterAPIView, UserChangePasswordAPIView, \ EmailCheckAPIView -from announcement.views import AnnouncementAPIView +from announcement.views import AnnouncementAPIView, AnnouncementAdminAPIView from admin.views import AdminTemplateView urlpatterns = [ @@ -20,9 +20,11 @@ urlpatterns = [ url(r'^api/change_password/$', UserChangePasswordAPIView.as_view(), name="user_change_password_api"), url(r'^api/username_check/$', UsernameCheckAPIView.as_view(), name="username_check_api"), url(r'^api/email_check/$', EmailCheckAPIView.as_view(), name="email_check_api"), - url(r'^api/admin/announcement/$', AnnouncementAPIView.as_view(), name="announcement_api"), + url(r'^api/admin/announcement/$', AnnouncementAdminAPIView.as_view(), name="announcement_admin_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), + url(r'^announcements/$', AnnouncementAPIView.as_view()), + url(r'^admin/contest/$', TemplateView.as_view(template_name="admin/contest/add_contest.html"), name="add_contest_page"), url(r'^problems/$', TemplateView.as_view(template_name="oj/problem/problem_list.html"), name="problem_list_page"), url(r'^admin/template/(?P\w+)/(?P\w+).html', AdminTemplateView.as_view(), name="admin_template") From 8e8909973ee8fbbca65829dbd50e9cbd504338f9 Mon Sep 17 00:00:00 2001 From: sxw Date: Thu, 6 Aug 2015 16:33:37 +0800 Subject: [PATCH 30/99] =?UTF-8?q?=E5=8F=96=E6=B6=88username=EF=BC=8Cemail?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=A4=B1=E5=8E=BB=E7=84=A6=E7=82=B9=E5=86=8D?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=AA=8C=E8=AF=81=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/oj/account/register.js | 2 -- 1 file changed, 2 deletions(-) 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: "请填写电子邮箱邮箱地址" From e0dec79066d088b86e7fefb48c9a66ec213d55a6 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 16:45:51 +0800 Subject: [PATCH 31/99] =?UTF-8?q?fix-bug=20=E4=BF=AE=E5=A4=8D=20account=20?= =?UTF-8?q?migrate=20=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/migrations/0004_auto_20150806_1251.py | 23 ------------------- ...806_1211.py => 0004_auto_20150806_1645.py} | 0 2 files changed, 23 deletions(-) delete mode 100644 account/migrations/0004_auto_20150806_1251.py rename account/migrations/{0004_auto_20150806_1211.py => 0004_auto_20150806_1645.py} (100%) diff --git a/account/migrations/0004_auto_20150806_1251.py b/account/migrations/0004_auto_20150806_1251.py deleted file mode 100644 index d3d2225..0000000 --- a/account/migrations/0004_auto_20150806_1251.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('account', '0003_user_email'), - ] - - operations = [ - migrations.RemoveField( - model_name='user', - name='admin_group', - ), - migrations.AddField( - model_name='user', - name='admin_type', - field=models.IntegerField(default=0), - ), - ] diff --git a/account/migrations/0004_auto_20150806_1211.py b/account/migrations/0004_auto_20150806_1645.py similarity index 100% rename from account/migrations/0004_auto_20150806_1211.py rename to account/migrations/0004_auto_20150806_1645.py From 529cea5476ab871045f8d3d0a22156d5a62df4c9 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 16:49:48 +0800 Subject: [PATCH 32/99] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20announcement=20url?= =?UTF-8?q?=20=E5=89=8D=E7=BC=80=E9=94=99=E8=AF=AF=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20api=20doc=20=E6=A0=BC=E5=BC=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- announcement/views.py | 2 +- oj/urls.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/announcement/views.py b/announcement/views.py index b01af7f..9649875 100644 --- a/announcement/views.py +++ b/announcement/views.py @@ -32,7 +32,7 @@ class AnnouncementAPIView(APIView): """ 公告分页json api接口 --- - request_serializer: AnnouncementSerializer + response_serializer: AnnouncementSerializer """ announcement = Announcement.objects.all().order_by("last_update_time") return paginate(request, announcement, AnnouncementSerializer) diff --git a/oj/urls.py b/oj/urls.py index 2586cb6..97ecb02 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -23,7 +23,7 @@ urlpatterns = [ url(r'^api/admin/announcement/$', AnnouncementAdminAPIView.as_view(), name="announcement_admin_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), - url(r'^announcements/$', AnnouncementAPIView.as_view()), + url(r'^api/announcements/$', AnnouncementAPIView.as_view(), name="announcement_list_api"), url(r'^admin/contest/$', TemplateView.as_view(template_name="admin/contest/add_contest.html"), name="add_contest_page"), url(r'^problems/$', TemplateView.as_view(template_name="oj/problem/problem_list.html"), name="problem_list_page"), From 1675eed67d73a0bf04daa9c0eacf806128ea6828 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Thu, 6 Aug 2015 19:07:46 +0800 Subject: [PATCH 33/99] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Announcement=E7=9A=84AP?= =?UTF-8?q?I=E6=B5=8B=E8=AF=95=EF=BC=8C=E5=8D=B3url=E4=B8=AD=E7=9A=84annou?= =?UTF-8?q?ncement=5Flist=5Fapi=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E7=BC=96=E8=BE=91=E5=8F=8A=E7=9B=B8=E5=BA=94=E7=9A=84?= =?UTF-8?q?API=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/views.py | 1 + announcement/serializers.py | 6 +++++ announcement/tests.py | 44 +++++++++++++++++++++++++++++++++++-- announcement/views.py | 25 ++++++++++++++++++++- 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/account/views.py b/account/views.py index ea13663..7214c8a 100644 --- a/account/views.py +++ b/account/views.py @@ -97,6 +97,7 @@ class UsernameCheckAPIView(APIView): else: return serializer_invalid_response(serializer) + class EmailCheckAPIView(APIView): def post(self, request): """ diff --git a/announcement/serializers.py b/announcement/serializers.py index a195b2e..d6380b0 100644 --- a/announcement/serializers.py +++ b/announcement/serializers.py @@ -22,3 +22,9 @@ class AnnouncementSerializer(serializers.ModelSerializer): class Meta: model = Announcement + +class EditAnnouncementSerializer(serializers.Serializer): + id = serializers.IntegerField() + title = serializers.CharField(max_length=50) + content = serializers.CharField(max_length=10000) + visible = serializers.BooleanField() diff --git a/announcement/tests.py b/announcement/tests.py index f337a9c..a7fd120 100644 --- a/announcement/tests.py +++ b/announcement/tests.py @@ -4,9 +4,10 @@ from django.core.urlresolvers import reverse from rest_framework.test import APITestCase, APIClient from account.models import User +from announcement.models import Announcement -class AnnouncementAPITest(APITestCase): +class AnnouncementAdminAPITest(APITestCase): def setUp(self): self.client = APIClient() self.url = reverse("announcement_admin_api") @@ -14,6 +15,7 @@ class AnnouncementAPITest(APITestCase): user.set_password("test") user.save() + # 以下是发布公告的测试 def test_invalid_format(self): self.client.login(username="test", password="test") data = {"title": "test1"} @@ -24,4 +26,42 @@ class AnnouncementAPITest(APITestCase): self.client.login(username="test", password="test") data = {"title": "title0", "content": "content0"} response = self.client.post(self.url, data=data) - self.assertEqual(response.data, {"code": 0, "data": u"公告发布成功!"}) \ No newline at end of file + self.assertEqual(response.data, {"code": 0, "data": u"公告发布成功!"}) + + def test_post_invalid_data(self): + self.client.login(username="test", password="test") + data = {"title": "test"} + response = self.client.post(self.url, data=data) + self.assertEqual(response.data["code"], 1) + + # 以下是编辑公告的测试 + def test_put_invalid_data(self): + self.client.login(username="test", password="test") + data = {"title": "test0", "content": "test0", "visible": "True"} + response = self.client.put(self.url, data=data) + self.assertEqual(response.data["code"], 1) + + def test_announcement_does_not_exist(self): + announcement = Announcement.objects.create(title="aa", + content="AA", + created_by=User.objects.get(username="test")) + data = {"id": announcement.id + 1, "title": "11", "content": "22", "visible": True} + response = self.client.put(self.url, data=data) + self.assertEqual(response.data, {"code": 1, "data": u"该公告不存在!"}) + + def test_success_edit_announcement(self): + announcement = Announcement.objects.create(title="bb", + content="BB", + created_by=User.objects.get(username="test")) + data = {"id": announcement.id, "title": "11", "content": "22", "visible": True} + response = self.client.put(self.url, data=data) + self.assertEqual(response.data["code"], 0) + + +class AnnouncementAPITest(APITestCase): + def setUp(self): + self.client = APIClient() + self.url = reverse("announcement_list_api") + + def test_success_get_data(self): + self.assertEqual(self.client.get(self.url).data["code"], 0) diff --git a/announcement/views.py b/announcement/views.py index 9649875..bc14889 100644 --- a/announcement/views.py +++ b/announcement/views.py @@ -6,7 +6,8 @@ from utils.shortcuts import serializer_invalid_response, error_response, success from account.models import User from utils.shortcuts import paginate from .models import Announcement -from .serializers import CreateAnnouncementSerializer, AnnouncementSerializer +from .serializers import (CreateAnnouncementSerializer, AnnouncementSerializer, + EditAnnouncementSerializer) class AnnouncementAdminAPIView(APIView): @@ -26,6 +27,28 @@ class AnnouncementAdminAPIView(APIView): else: return serializer_invalid_response(serializer) + def put(self, request): + """ + 公告编辑json api接口 + --- + request_serializer: EditAnnouncementSerializer + response_serializer: AnnouncementSerializer + """ + serializer = EditAnnouncementSerializer(data=request.DATA) + if serializer.is_valid(): + data = serializer.data + try: + announcement = Announcement.objects.get(id=data["id"]) + except Announcement.DoesNotExist: + return error_response(u"该公告不存在!") + announcement.title = data["title"] + announcement.content = data["content"] + announcement.visible = data["visible"] + announcement.save() + return success_response(AnnouncementSerializer(announcement).data) + else: + return serializer_invalid_response(serializer) + class AnnouncementAPIView(APIView): def get(self, request): From ab63ac652fc2ee838ce58e8caa1a6dd8ec3b66f7 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 23:47:28 +0800 Subject: [PATCH 34/99] =?UTF-8?q?=E5=88=86=E7=A6=BB=E5=85=AC=E5=85=B1=20js?= =?UTF-8?q?=EF=BC=9B=E4=BF=AE=E6=94=B9=20footer=20=E6=95=88=E6=9E=9C?= =?UTF-8?q?=EF=BC=8C=E5=9B=BA=E5=AE=9A=E5=9C=A8=E5=BA=95=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/css/admin.css | 24 +++++++----------------- static/src/css/global.css | 15 +++++++++++++++ static/src/css/oj.css | 19 ------------------- 3 files changed, 22 insertions(+), 36 deletions(-) create mode 100644 static/src/css/global.css 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..edc04a7 --- /dev/null +++ b/static/src/css/global.css @@ -0,0 +1,15 @@ +img { + max-width: 100%; + height: auto; +} + +.footer { + left: 0; + right: 0; + position: absolute; + bottom: 30px; +} + +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..5e1bfc5 100644 --- a/static/src/css/oj.css +++ b/static/src/css/oj.css @@ -1,25 +1,7 @@ @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 +29,6 @@ label { font-size: 15px; } -/* index css */ .jumbotron { text-align: center; background-color: transparent; From d6a36fe20ce722b89e06d8e81337626b557c4a89 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 23:47:54 +0800 Subject: [PATCH 35/99] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=95=88=E6=9E=9C=E5=92=8C=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=20js=20=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/admin/admin.js | 6 +++++- template/admin/admin.html | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/static/src/js/app/admin/admin.js b/static/src/js/app/admin/admin.js index d3e30ac..b44f575 100644 --- a/static/src/js/app/admin/admin.js +++ b/static/src/js/app/admin/admin.js @@ -20,12 +20,16 @@ define("admin", ["jquery", "avalon"], function($, avalon){ if(hash){ li_inactive(".list-group-item"); li_active("#li-" + hash); + $("#loading-gif").show(); vm.template_url = "template/index/" + hash + ".html"; } }; var vm = avalon.define({ $id: "admin", - template_url: "template/index/index.html" + template_url: "template/index/index.html", + hide_loading: function(){ + $("#loading-gif").hide(); + } }); }); \ No newline at end of file diff --git a/template/admin/admin.html b/template/admin/admin.html index c712084..6ec5a4e 100644 --- a/template/admin/admin.html +++ b/template/admin/admin.html @@ -81,9 +81,9 @@
- + -
+
From 2a29dfffb404ae146be7d34988aed1530d0d92fe Mon Sep 17 00:00:00 2001 From: sxw Date: Fri, 7 Aug 2015 09:24:52 +0800 Subject: [PATCH 36/99] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=9A=84js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/app/admin/announcement/announcement.js | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 static/src/js/app/admin/announcement/announcement.js 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..115873c --- /dev/null +++ b/static/src/js/app/admin/announcement/announcement.js @@ -0,0 +1,153 @@ +require(["jquery", "avalon", "csrf", "bs_alert", "editor", "validation"], function ($, avalon, csrfHeader, bs_alert, editor) { + annoumcementEditor = editor("#editor"); + editAnnoumcementEditor = null; + if (!avalon.vmodels.announcement) + avalon.vmodels.announcement = null; + vm = avalon.define({ + $id: "announcement", + announcement: [], + previous_page: 0, + next_page: 0, + page: 1, + isEditing: false, + getState: function (el) { + if (el.visible) + return "可见"; + else + return "隐藏"; + }, + getNext: function (el) { + getPageData(++(vm.page), function (data) { + }); + }, + getPrevious: function (el) { + getPageData(--(vm.page), function (data) { + }); + }, + 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 (!editAnnoumcementEditor) + editAnnoumcementEditor = editor("#editAnnoumcementEditor"); + editAnnoumcementEditor.setValue(el.content); + vm.isEditing = true; + editAnnoumcementEditor.focus(); + } + }); + + getPageData(1, function (data) { + avalon.scan(); + }); + + function getPageData(page, callback) { + $.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; + callback(data); + } + else { + bs_alert(data.data); + } + } + }); + } + + + $("#announcement-edit-form") + .formValidation({ + framework: "bootstrap", + fields: { + title: { + validators: { + notEmpty: { + message: "请填写公告标题" + } + } + } + } + } + ).on('success.form.fv', function (e) { + e.preventDefault(); + var title = $("#newTitle").val(); + var content = editor1.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(""); + editor1.setValue(""); + getPageData(1, function (data) {}); + } 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 = editor1.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(""); + editor1.setValue(""); + getPageData(1, function (data) {}); + } else { + bs_alert(data.data); + } + } + + }) + }); + +}); \ No newline at end of file From a66b755aa3327acd024db892e2e616be707646f1 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Fri, 7 Aug 2015 17:11:20 +0800 Subject: [PATCH 37/99] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20footer=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=BD=8D=E7=BD=AE=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/css/global.css | 16 ++++++++++++++-- static/src/css/oj.css | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/static/src/css/global.css b/static/src/css/global.css index edc04a7..c55a0bb 100644 --- a/static/src/css/global.css +++ b/static/src/css/global.css @@ -1,3 +1,16 @@ +html{ + height: 100%; +} + +body{ + height:100%; /*使内容高度和body一样*/ + margin-bottom:-80px;/*向上缩减80像素,不至于footer超出屏幕可视范围*/ +} + +.main{ + padding-bottom: 120px; +} + img { max-width: 100%; height: auto; @@ -6,8 +19,7 @@ img { .footer { left: 0; right: 0; - position: absolute; - bottom: 30px; + height: 80px } label { diff --git a/static/src/css/oj.css b/static/src/css/oj.css index 5e1bfc5..cc6ac62 100644 --- a/static/src/css/oj.css +++ b/static/src/css/oj.css @@ -1,3 +1,4 @@ +@import url("global.css"); @import url("bootstrap/bootstrap.min.css"); @import url("bootstrap/todc-bootstrap.min.css"); @import url("codeMirror/codemirror.css"); From 2475407597b9f9078a319f286c9c64beacb55914 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Fri, 7 Aug 2015 17:12:08 +0800 Subject: [PATCH 38/99] =?UTF-8?q?=E5=89=8D=E5=8F=B0=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=20class=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20footer=20=E6=98=BE=E7=A4=BA=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/oj/account/change_password.html | 2 +- template/oj/account/login.html | 2 +- template/oj/account/register.html | 2 +- template/oj/contest/problems.html | 2 +- template/oj/problem/problem.html | 2 +- template/oj/problem/problem_list.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) 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 %} -
+
- +
+ 请将所有测试用例打包在一个文件中上传,所有文件要在压缩包的根目录,且输入输出文件名要以从1开始连续数字标识要对应例如:
+ 1.in 1.out 2.in 2.out +
+ + + + + + + + + + + +
编号输入文件名输出文件名
{{$index}}{{el.input}}{{el.output}}
@@ -184,4 +214,5 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/template/admin/problem/add_problem.html b/template/admin/problem/add_problem.html index 0c6dad0..6ebb49a 100644 --- a/template/admin/problem/add_problem.html +++ b/template/admin/problem/add_problem.html @@ -12,7 +12,7 @@
- +
From 70a77cccc87617713c5081a563c87e59cc21f16c Mon Sep 17 00:00:00 2001 From: esp Date: Mon, 10 Aug 2015 17:00:39 +0800 Subject: [PATCH 95/99] =?UTF-8?q?[=E5=89=8D=E7=AB=AF]=E4=BF=AE=E6=AD=A3csr?= =?UTF-8?q?f.js=20=20=20=20uploader.js=20=20=E7=9A=84=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20[CI=20SKIP]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/utils/csrf.js | 2 +- static/src/js/utils/uploader.js | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/static/src/js/utils/csrf.js b/static/src/js/utils/csrf.js index 6a004b4..0e21e0f 100644 --- a/static/src/js/utils/csrf.js +++ b/static/src/js/utils/csrf.js @@ -11,7 +11,7 @@ define("csrf",function(){ } function csrfHeader(){ // jquery的请求 - if(arguments.length == 1) { + if(arguments.length == 2) { arguments[0].setRequestHeader("X-CSRFToken", get_cookie("csrftoken")); } // 百度webuploader 的请求 diff --git a/static/src/js/utils/uploader.js b/static/src/js/utils/uploader.js index ec418c5..83c2b1f 100644 --- a/static/src/js/utils/uploader.js +++ b/static/src/js/utils/uploader.js @@ -1,20 +1,23 @@ -define("uploader", ["webuploader"], function(webuploader){ - function uploader(selector, server) { - return webuploader.create({ - +define("uploader", ["webuploader", "csrf"], function(webuploader,csrf){ + function uploader(selector, server, onSuccess) { + var Webuploader= webuploader.create({ + auto: true, // swf文件路径 - swf: "/js/Uploader.swf", - + swf: "/static/img/Uploader.swf", // 文件接收服务端。 server: server, - // 选择文件的按钮。可选。 // 内部根据当前运行是创建,可能是input元素,也可能是flash. pick: selector, - // 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传! - resize: false + resize: false, + uploadBeforeSend : csrf }); + Webuploader.on("uploadBeforeSend",csrf); + Webuploader.on("uploadSuccess", onSuccess); + + return Webuploader; } + return uploader; }); \ No newline at end of file From a6268dcb53b62cd7af1e787356855e2f7ff20a82 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Mon, 10 Aug 2015 17:59:39 +0800 Subject: [PATCH 96/99] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=A2=98=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=9B=B8=E5=85=B3=E7=9A=84=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 3 +- .../0002_remove_problemtag_description.py | 18 ++++++++++++ problem/models.py | 2 +- problem/serizalizers.py | 11 +++++++- problem/views.py | 28 ++++++++++++++++++- 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 problem/migrations/0002_remove_problemtag_description.py diff --git a/oj/urls.py b/oj/urls.py index 1431dc6..fbe7856 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -11,7 +11,7 @@ from group.views import GroupAdminAPIView from admin.views import AdminTemplateView from problem.views import ProblemAdminAPIView -from problem.views import TestCaseUploadAPIView +from problem.views import TestCaseUploadAPIView, ProblemTagAdminAPIView urlpatterns = [ @@ -41,4 +41,5 @@ urlpatterns = [ url(r'^api/admin/group/$', GroupAdminAPIView.as_view(), name="group_admin_api"), url(r'^api/admin/problem/$', ProblemAdminAPIView.as_view(), name="problem_admin_api"), url(r'^api/admin/test_case_upload/$', TestCaseUploadAPIView.as_view(), name="test_case_upload_api"), + url(r'^api/admin/tag/$', ProblemTagAdminAPIView.as_view(), name="problem_tag_admin_api"), ] diff --git a/problem/migrations/0002_remove_problemtag_description.py b/problem/migrations/0002_remove_problemtag_description.py new file mode 100644 index 0000000..2953e68 --- /dev/null +++ b/problem/migrations/0002_remove_problemtag_description.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('problem', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='problemtag', + name='description', + ), + ] diff --git a/problem/models.py b/problem/models.py index 0132072..3e236af 100644 --- a/problem/models.py +++ b/problem/models.py @@ -6,7 +6,7 @@ from account.models import User class ProblemTag(models.Model): name = models.CharField(max_length=30) - description = models.CharField(max_length=50) + # description = models.CharField(max_length=50) class Meta: db_table = "problem_tag" diff --git a/problem/serizalizers.py b/problem/serizalizers.py index 441c9c5..66f3d75 100644 --- a/problem/serizalizers.py +++ b/problem/serizalizers.py @@ -4,7 +4,7 @@ import json from rest_framework import serializers from account.models import User -from .models import Problem +from .models import Problem, ProblemTag class ProblemSampleSerializer(serializers.ListField): @@ -60,3 +60,12 @@ class EditProblemSerializer(serializers.Serializer): hint = serializers.CharField(max_length=10000) visible = serializers.BooleanField() + + +class ProblemTagSerializer(serializers.ModelSerializer): + class Meta: + model = ProblemTag + + +class CreateProblemTagSerializer(serializers.Serializer): + name = serializers.CharField(max_length=10) \ No newline at end of file diff --git a/problem/views.py b/problem/views.py index 0a5490f..eda2c72 100644 --- a/problem/views.py +++ b/problem/views.py @@ -11,10 +11,36 @@ from django.db.models import Q from rest_framework.views import APIView from utils.shortcuts import serializer_invalid_response, error_response, success_response, paginate, rand_str -from .serizalizers import CreateProblemSerializer, EditProblemSerializer, ProblemSerializer +from .serizalizers import (CreateProblemSerializer, EditProblemSerializer, ProblemSerializer, + ProblemTagSerializer, CreateProblemTagSerializer) from .models import Problem, ProblemTag +class ProblemTagAdminAPIView(APIView): + def post(self, request): + """ + 创建标签的接口 + --- + request_serializer: CreateProblemTagSerializer + """ + serializer = CreateProblemTagSerializer(data=request.data) + if serializer.is_valid(): + try: + tag = ProblemTag.objects.get(name=serializer.data["name"]) + except ProblemTag.DoesNotExist: + tag = ProblemTag.objects.create(name=serializer.data["name"]) + return success_response(ProblemTagSerializer(tag).data) + else: + return error_response(serializer) + + def get(self, request): + keyword = request.GET.get("keyword", None) + if not keyword: + return error_response(u"参数错误") + tags = ProblemTag.objects.filter(name__contains=keyword) + return success_response(ProblemTagSerializer(tags, many=True).data) + + def problem_page(request, problem_id): From 5254f428b4aac9f07660b78c8189f4c99121d23a Mon Sep 17 00:00:00 2001 From: esp Date: Mon, 10 Aug 2015 18:05:22 +0800 Subject: [PATCH 97/99] =?UTF-8?q?[=E5=89=8D=E7=AB=AF-=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=97=AE=E9=A2=98]=E6=B7=BB=E5=8A=A0=E6=9D=A5=E6=BA=90?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=20=20=20[CI=20SKIP]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/admin/problem/add_problem.js | 1 + template/admin/problem/add_problem.html | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/static/src/js/app/admin/problem/add_problem.js b/static/src/js/app/admin/problem/add_problem.js index c0ac63f..09862d3 100644 --- a/static/src/js/app/admin/problem/add_problem.js +++ b/static/src/js/app/admin/problem/add_problem.js @@ -98,6 +98,7 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val test_case_id: "", testCaseList: [], uploadSuccess: false, + source: "", checkTag: function () { alert("11"); if (event.keyCode == 13) diff --git a/template/admin/problem/add_problem.html b/template/admin/problem/add_problem.html index 6ebb49a..1c78a9e 100644 --- a/template/admin/problem/add_problem.html +++ b/template/admin/problem/add_problem.html @@ -1,10 +1,14 @@
-
+
+
+ + +
From b1b996271fae2d991e2d3ea320342850a5148fe7 Mon Sep 17 00:00:00 2001 From: esp Date: Mon, 10 Aug 2015 20:56:34 +0800 Subject: [PATCH 98/99] =?UTF-8?q?[=E5=89=8D=E7=AB=AF]=E6=96=B0=E5=A2=9Ejqu?= =?UTF-8?q?eryUI=E5=BA=93js+css=EF=BC=8C=E4=BD=86=E6=98=AFcss=E5=B9=B6?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E7=94=A8=E5=88=B0=EF=BC=8C=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E7=94=A8=E4=BA=86=E6=95=88=E6=9E=9C=E5=B7=AE=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0img=E8=B5=84=E6=BA=90=E4=B9=9F=E6=B2=A1=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=89=80=E4=BB=A5=E5=B9=B2=E8=84=86=E5=88=A0=E5=8E=BB?= =?UTF-8?q?[CI=20SKIP]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/css/jqueryUI/jquery-ui.css | 544 ++++ static/src/css/jqueryUI/jquery-ui.min.css | 7 + .../src/css/jqueryUI/jquery-ui.structure.css | 152 + static/src/css/jqueryUI/jquery-ui.theme.css | 410 +++ static/src/js/config.js | 2 +- static/src/js/lib/jqueryUI/jquery-ui.js | 2610 +++++++++++++++++ 6 files changed, 3724 insertions(+), 1 deletion(-) create mode 100644 static/src/css/jqueryUI/jquery-ui.css create mode 100644 static/src/css/jqueryUI/jquery-ui.min.css create mode 100644 static/src/css/jqueryUI/jquery-ui.structure.css create mode 100644 static/src/css/jqueryUI/jquery-ui.theme.css create mode 100644 static/src/js/lib/jqueryUI/jquery-ui.js diff --git a/static/src/css/jqueryUI/jquery-ui.css b/static/src/css/jqueryUI/jquery-ui.css new file mode 100644 index 0000000..cb2ac4b --- /dev/null +++ b/static/src/css/jqueryUI/jquery-ui.css @@ -0,0 +1,544 @@ +/*! jQuery UI - v1.11.4 - 2015-08-10 +* http://jqueryui.com +* Includes: core.css, autocomplete.css, menu.css, theme.css +* To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Trebuchet%20MS%2CTahoma%2CVerdana%2CArial%2Csans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=f6a828&bgTextureHeader=gloss_wave&bgImgOpacityHeader=35&borderColorHeader=e78f08&fcHeader=ffffff&iconColorHeader=ffffff&bgColorContent=eeeeee&bgTextureContent=highlight_soft&bgImgOpacityContent=100&borderColorContent=dddddd&fcContent=333333&iconColorContent=222222&bgColorDefault=f6f6f6&bgTextureDefault=glass&bgImgOpacityDefault=100&borderColorDefault=cccccc&fcDefault=1c94c4&iconColorDefault=ef8c08&bgColorHover=fdf5ce&bgTextureHover=glass&bgImgOpacityHover=100&borderColorHover=fbcb09&fcHover=c77405&iconColorHover=ef8c08&bgColorActive=ffffff&bgTextureActive=glass&bgImgOpacityActive=65&borderColorActive=fbd850&fcActive=eb8f00&iconColorActive=ef8c08&bgColorHighlight=ffe45c&bgTextureHighlight=highlight_soft&bgImgOpacityHighlight=75&borderColorHighlight=fed22f&fcHighlight=363636&iconColorHighlight=228ef1&bgColorError=b81900&bgTextureError=diagonals_thick&bgImgOpacityError=18&borderColorError=cd0a0a&fcError=ffffff&iconColorError=ffd27a&bgColorOverlay=666666&bgTextureOverlay=diagonals_thick&bgImgOpacityOverlay=20&opacityOverlay=50&bgColorShadow=000000&bgTextureShadow=flat&bgImgOpacityShadow=10&opacityShadow=20&thicknessShadow=5px&offsetTopShadow=-5px&offsetLeftShadow=-5px&cornerRadiusShadow=5px +* Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */ + +/* Layout helpers +----------------------------------*/ +.ui-helper-hidden { + display: none; +} +.ui-helper-hidden-accessible { + border: 0; + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} +.ui-helper-reset { + margin: 0; + padding: 0; + border: 0; + outline: 0; + line-height: 1.3; + text-decoration: none; + font-size: 100%; + list-style: none; +} +.ui-helper-clearfix:before, +.ui-helper-clearfix:after { + content: ""; + display: table; + border-collapse: collapse; +} +.ui-helper-clearfix:after { + clear: both; +} +.ui-helper-clearfix { + min-height: 0; /* support: IE7 */ +} +.ui-helper-zfix { + width: 100%; + height: 100%; + top: 0; + left: 0; + position: absolute; + opacity: 0; + filter:Alpha(Opacity=0); /* support: IE8 */ +} + +.ui-front { + z-index: 100; +} + + +/* Interaction Cues +----------------------------------*/ +.ui-state-disabled { + cursor: default !important; +} + + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { + display: block; + text-indent: -99999px; + overflow: hidden; + background-repeat: no-repeat; +} + + +/* Misc visuals +----------------------------------*/ + +/* Overlays */ +.ui-widget-overlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; +} +.ui-autocomplete { + position: absolute; + top: 0; + left: 0; + cursor: default; +} +.ui-menu { + list-style: none; + padding: 0; + margin: 0; + display: block; + outline: none; +} +.ui-menu .ui-menu { + position: absolute; +} +.ui-menu .ui-menu-item { + position: relative; + margin: 0; + padding: 3px 1em 3px .4em; + cursor: pointer; + min-height: 0; /* support: IE7 */ + /* support: IE10, see #8844 */ + list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); +} +.ui-menu .ui-menu-divider { + margin: 5px 0; + height: 0; + font-size: 0; + line-height: 0; + border-width: 1px 0 0 0; +} +.ui-menu .ui-state-focus, +.ui-menu .ui-state-active { + margin: -1px; +} + +/* icon support */ +.ui-menu-icons { + position: relative; +} +.ui-menu-icons .ui-menu-item { + padding-left: 2em; +} + +/* left-aligned */ +.ui-menu .ui-icon { + position: absolute; + top: 0; + bottom: 0; + left: .2em; + margin: auto 0; +} + +/* right-aligned */ +.ui-menu .ui-menu-icon { + left: auto; + right: 0; +} + +/* Component containers +----------------------------------*/ +.ui-widget { + font-family: Trebuchet MS,Tahoma,Verdana,Arial,sans-serif; + font-size: 1.1em; +} +.ui-widget .ui-widget { + font-size: 1em; +} +.ui-widget input, +.ui-widget select, +.ui-widget textarea, +.ui-widget button { + font-family: Trebuchet MS,Tahoma,Verdana,Arial,sans-serif; + font-size: 1em; +} +.ui-widget-content { + border: 1px solid #dddddd; + background: #eeeeee url("images/ui-bg_highlight-soft_100_eeeeee_1x100.png") 50% top repeat-x; + color: #333333; +} +.ui-widget-content a { + color: #333333; +} +.ui-widget-header { + border: 1px solid #e78f08; + background: #f6a828 url("images/ui-bg_gloss-wave_35_f6a828_500x100.png") 50% 50% repeat-x; + color: #ffffff; + font-weight: bold; +} +.ui-widget-header a { + color: #ffffff; +} + +/* Interaction states +----------------------------------*/ +.ui-state-default, +.ui-widget-content .ui-state-default, +.ui-widget-header .ui-state-default { + border: 1px solid #cccccc; + background: #f6f6f6 url("images/ui-bg_glass_100_f6f6f6_1x400.png") 50% 50% repeat-x; + font-weight: bold; + color: #1c94c4; +} +.ui-state-default a, +.ui-state-default a:link, +.ui-state-default a:visited { + color: #1c94c4; + text-decoration: none; +} +.ui-state-hover, +.ui-widget-content .ui-state-hover, +.ui-widget-header .ui-state-hover, +.ui-state-focus, +.ui-widget-content .ui-state-focus, +.ui-widget-header .ui-state-focus { + border: 1px solid #fbcb09; + background: #fdf5ce url("images/ui-bg_glass_100_fdf5ce_1x400.png") 50% 50% repeat-x; + font-weight: bold; + color: #c77405; +} +.ui-state-hover a, +.ui-state-hover a:hover, +.ui-state-hover a:link, +.ui-state-hover a:visited, +.ui-state-focus a, +.ui-state-focus a:hover, +.ui-state-focus a:link, +.ui-state-focus a:visited { + color: #c77405; + text-decoration: none; +} +.ui-state-active, +.ui-widget-content .ui-state-active, +.ui-widget-header .ui-state-active { + border: 1px solid #fbd850; + background: #ffffff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x; + font-weight: bold; + color: #eb8f00; +} +.ui-state-active a, +.ui-state-active a:link, +.ui-state-active a:visited { + color: #eb8f00; + text-decoration: none; +} + +/* Interaction Cues +----------------------------------*/ +.ui-state-highlight, +.ui-widget-content .ui-state-highlight, +.ui-widget-header .ui-state-highlight { + border: 1px solid #fed22f; + background: #ffe45c url("images/ui-bg_highlight-soft_75_ffe45c_1x100.png") 50% top repeat-x; + color: #363636; +} +.ui-state-highlight a, +.ui-widget-content .ui-state-highlight a, +.ui-widget-header .ui-state-highlight a { + color: #363636; +} +.ui-state-error, +.ui-widget-content .ui-state-error, +.ui-widget-header .ui-state-error { + border: 1px solid #cd0a0a; + background: #b81900 url("images/ui-bg_diagonals-thick_18_b81900_40x40.png") 50% 50% repeat; + color: #ffffff; +} +.ui-state-error a, +.ui-widget-content .ui-state-error a, +.ui-widget-header .ui-state-error a { + color: #ffffff; +} +.ui-state-error-text, +.ui-widget-content .ui-state-error-text, +.ui-widget-header .ui-state-error-text { + color: #ffffff; +} +.ui-priority-primary, +.ui-widget-content .ui-priority-primary, +.ui-widget-header .ui-priority-primary { + font-weight: bold; +} +.ui-priority-secondary, +.ui-widget-content .ui-priority-secondary, +.ui-widget-header .ui-priority-secondary { + opacity: .7; + filter:Alpha(Opacity=70); /* support: IE8 */ + font-weight: normal; +} +.ui-state-disabled, +.ui-widget-content .ui-state-disabled, +.ui-widget-header .ui-state-disabled { + opacity: .35; + filter:Alpha(Opacity=35); /* support: IE8 */ + background-image: none; +} +.ui-state-disabled .ui-icon { + filter:Alpha(Opacity=35); /* support: IE8 - See #6059 */ +} + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { + width: 16px; + height: 16px; +} +.ui-icon, +.ui-widget-content .ui-icon { + background-image: url("images/ui-icons_222222_256x240.png"); +} +.ui-widget-header .ui-icon { + background-image: url("images/ui-icons_ffffff_256x240.png"); +} +.ui-state-default .ui-icon { + background-image: url("images/ui-icons_ef8c08_256x240.png"); +} +.ui-state-hover .ui-icon, +.ui-state-focus .ui-icon { + background-image: url("images/ui-icons_ef8c08_256x240.png"); +} +.ui-state-active .ui-icon { + background-image: url("images/ui-icons_ef8c08_256x240.png"); +} +.ui-state-highlight .ui-icon { + background-image: url("images/ui-icons_228ef1_256x240.png"); +} +.ui-state-error .ui-icon, +.ui-state-error-text .ui-icon { + background-image: url("images/ui-icons_ffd27a_256x240.png"); +} + +/* positioning */ +.ui-icon-blank { background-position: 16px 16px; } +.ui-icon-carat-1-n { background-position: 0 0; } +.ui-icon-carat-1-ne { background-position: -16px 0; } +.ui-icon-carat-1-e { background-position: -32px 0; } +.ui-icon-carat-1-se { background-position: -48px 0; } +.ui-icon-carat-1-s { background-position: -64px 0; } +.ui-icon-carat-1-sw { background-position: -80px 0; } +.ui-icon-carat-1-w { background-position: -96px 0; } +.ui-icon-carat-1-nw { background-position: -112px 0; } +.ui-icon-carat-2-n-s { background-position: -128px 0; } +.ui-icon-carat-2-e-w { background-position: -144px 0; } +.ui-icon-triangle-1-n { background-position: 0 -16px; } +.ui-icon-triangle-1-ne { background-position: -16px -16px; } +.ui-icon-triangle-1-e { background-position: -32px -16px; } +.ui-icon-triangle-1-se { background-position: -48px -16px; } +.ui-icon-triangle-1-s { background-position: -64px -16px; } +.ui-icon-triangle-1-sw { background-position: -80px -16px; } +.ui-icon-triangle-1-w { background-position: -96px -16px; } +.ui-icon-triangle-1-nw { background-position: -112px -16px; } +.ui-icon-triangle-2-n-s { background-position: -128px -16px; } +.ui-icon-triangle-2-e-w { background-position: -144px -16px; } +.ui-icon-arrow-1-n { background-position: 0 -32px; } +.ui-icon-arrow-1-ne { background-position: -16px -32px; } +.ui-icon-arrow-1-e { background-position: -32px -32px; } +.ui-icon-arrow-1-se { background-position: -48px -32px; } +.ui-icon-arrow-1-s { background-position: -64px -32px; } +.ui-icon-arrow-1-sw { background-position: -80px -32px; } +.ui-icon-arrow-1-w { background-position: -96px -32px; } +.ui-icon-arrow-1-nw { background-position: -112px -32px; } +.ui-icon-arrow-2-n-s { background-position: -128px -32px; } +.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; } +.ui-icon-arrow-2-e-w { background-position: -160px -32px; } +.ui-icon-arrow-2-se-nw { background-position: -176px -32px; } +.ui-icon-arrowstop-1-n { background-position: -192px -32px; } +.ui-icon-arrowstop-1-e { background-position: -208px -32px; } +.ui-icon-arrowstop-1-s { background-position: -224px -32px; } +.ui-icon-arrowstop-1-w { background-position: -240px -32px; } +.ui-icon-arrowthick-1-n { background-position: 0 -48px; } +.ui-icon-arrowthick-1-ne { background-position: -16px -48px; } +.ui-icon-arrowthick-1-e { background-position: -32px -48px; } +.ui-icon-arrowthick-1-se { background-position: -48px -48px; } +.ui-icon-arrowthick-1-s { background-position: -64px -48px; } +.ui-icon-arrowthick-1-sw { background-position: -80px -48px; } +.ui-icon-arrowthick-1-w { background-position: -96px -48px; } +.ui-icon-arrowthick-1-nw { background-position: -112px -48px; } +.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; } +.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; } +.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; } +.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; } +.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; } +.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; } +.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; } +.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; } +.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; } +.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; } +.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; } +.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; } +.ui-icon-arrowreturn-1-w { background-position: -64px -64px; } +.ui-icon-arrowreturn-1-n { background-position: -80px -64px; } +.ui-icon-arrowreturn-1-e { background-position: -96px -64px; } +.ui-icon-arrowreturn-1-s { background-position: -112px -64px; } +.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; } +.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; } +.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; } +.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; } +.ui-icon-arrow-4 { background-position: 0 -80px; } +.ui-icon-arrow-4-diag { background-position: -16px -80px; } +.ui-icon-extlink { background-position: -32px -80px; } +.ui-icon-newwin { background-position: -48px -80px; } +.ui-icon-refresh { background-position: -64px -80px; } +.ui-icon-shuffle { background-position: -80px -80px; } +.ui-icon-transfer-e-w { background-position: -96px -80px; } +.ui-icon-transferthick-e-w { background-position: -112px -80px; } +.ui-icon-folder-collapsed { background-position: 0 -96px; } +.ui-icon-folder-open { background-position: -16px -96px; } +.ui-icon-document { background-position: -32px -96px; } +.ui-icon-document-b { background-position: -48px -96px; } +.ui-icon-note { background-position: -64px -96px; } +.ui-icon-mail-closed { background-position: -80px -96px; } +.ui-icon-mail-open { background-position: -96px -96px; } +.ui-icon-suitcase { background-position: -112px -96px; } +.ui-icon-comment { background-position: -128px -96px; } +.ui-icon-person { background-position: -144px -96px; } +.ui-icon-print { background-position: -160px -96px; } +.ui-icon-trash { background-position: -176px -96px; } +.ui-icon-locked { background-position: -192px -96px; } +.ui-icon-unlocked { background-position: -208px -96px; } +.ui-icon-bookmark { background-position: -224px -96px; } +.ui-icon-tag { background-position: -240px -96px; } +.ui-icon-home { background-position: 0 -112px; } +.ui-icon-flag { background-position: -16px -112px; } +.ui-icon-calendar { background-position: -32px -112px; } +.ui-icon-cart { background-position: -48px -112px; } +.ui-icon-pencil { background-position: -64px -112px; } +.ui-icon-clock { background-position: -80px -112px; } +.ui-icon-disk { background-position: -96px -112px; } +.ui-icon-calculator { background-position: -112px -112px; } +.ui-icon-zoomin { background-position: -128px -112px; } +.ui-icon-zoomout { background-position: -144px -112px; } +.ui-icon-search { background-position: -160px -112px; } +.ui-icon-wrench { background-position: -176px -112px; } +.ui-icon-gear { background-position: -192px -112px; } +.ui-icon-heart { background-position: -208px -112px; } +.ui-icon-star { background-position: -224px -112px; } +.ui-icon-link { background-position: -240px -112px; } +.ui-icon-cancel { background-position: 0 -128px; } +.ui-icon-plus { background-position: -16px -128px; } +.ui-icon-plusthick { background-position: -32px -128px; } +.ui-icon-minus { background-position: -48px -128px; } +.ui-icon-minusthick { background-position: -64px -128px; } +.ui-icon-close { background-position: -80px -128px; } +.ui-icon-closethick { background-position: -96px -128px; } +.ui-icon-key { background-position: -112px -128px; } +.ui-icon-lightbulb { background-position: -128px -128px; } +.ui-icon-scissors { background-position: -144px -128px; } +.ui-icon-clipboard { background-position: -160px -128px; } +.ui-icon-copy { background-position: -176px -128px; } +.ui-icon-contact { background-position: -192px -128px; } +.ui-icon-image { background-position: -208px -128px; } +.ui-icon-video { background-position: -224px -128px; } +.ui-icon-script { background-position: -240px -128px; } +.ui-icon-alert { background-position: 0 -144px; } +.ui-icon-info { background-position: -16px -144px; } +.ui-icon-notice { background-position: -32px -144px; } +.ui-icon-help { background-position: -48px -144px; } +.ui-icon-check { background-position: -64px -144px; } +.ui-icon-bullet { background-position: -80px -144px; } +.ui-icon-radio-on { background-position: -96px -144px; } +.ui-icon-radio-off { background-position: -112px -144px; } +.ui-icon-pin-w { background-position: -128px -144px; } +.ui-icon-pin-s { background-position: -144px -144px; } +.ui-icon-play { background-position: 0 -160px; } +.ui-icon-pause { background-position: -16px -160px; } +.ui-icon-seek-next { background-position: -32px -160px; } +.ui-icon-seek-prev { background-position: -48px -160px; } +.ui-icon-seek-end { background-position: -64px -160px; } +.ui-icon-seek-start { background-position: -80px -160px; } +/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */ +.ui-icon-seek-first { background-position: -80px -160px; } +.ui-icon-stop { background-position: -96px -160px; } +.ui-icon-eject { background-position: -112px -160px; } +.ui-icon-volume-off { background-position: -128px -160px; } +.ui-icon-volume-on { background-position: -144px -160px; } +.ui-icon-power { background-position: 0 -176px; } +.ui-icon-signal-diag { background-position: -16px -176px; } +.ui-icon-signal { background-position: -32px -176px; } +.ui-icon-battery-0 { background-position: -48px -176px; } +.ui-icon-battery-1 { background-position: -64px -176px; } +.ui-icon-battery-2 { background-position: -80px -176px; } +.ui-icon-battery-3 { background-position: -96px -176px; } +.ui-icon-circle-plus { background-position: 0 -192px; } +.ui-icon-circle-minus { background-position: -16px -192px; } +.ui-icon-circle-close { background-position: -32px -192px; } +.ui-icon-circle-triangle-e { background-position: -48px -192px; } +.ui-icon-circle-triangle-s { background-position: -64px -192px; } +.ui-icon-circle-triangle-w { background-position: -80px -192px; } +.ui-icon-circle-triangle-n { background-position: -96px -192px; } +.ui-icon-circle-arrow-e { background-position: -112px -192px; } +.ui-icon-circle-arrow-s { background-position: -128px -192px; } +.ui-icon-circle-arrow-w { background-position: -144px -192px; } +.ui-icon-circle-arrow-n { background-position: -160px -192px; } +.ui-icon-circle-zoomin { background-position: -176px -192px; } +.ui-icon-circle-zoomout { background-position: -192px -192px; } +.ui-icon-circle-check { background-position: -208px -192px; } +.ui-icon-circlesmall-plus { background-position: 0 -208px; } +.ui-icon-circlesmall-minus { background-position: -16px -208px; } +.ui-icon-circlesmall-close { background-position: -32px -208px; } +.ui-icon-squaresmall-plus { background-position: -48px -208px; } +.ui-icon-squaresmall-minus { background-position: -64px -208px; } +.ui-icon-squaresmall-close { background-position: -80px -208px; } +.ui-icon-grip-dotted-vertical { background-position: 0 -224px; } +.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; } +.ui-icon-grip-solid-vertical { background-position: -32px -224px; } +.ui-icon-grip-solid-horizontal { background-position: -48px -224px; } +.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; } +.ui-icon-grip-diagonal-se { background-position: -80px -224px; } + + +/* Misc visuals +----------------------------------*/ + +/* Corner radius */ +.ui-corner-all, +.ui-corner-top, +.ui-corner-left, +.ui-corner-tl { + border-top-left-radius: 4px; +} +.ui-corner-all, +.ui-corner-top, +.ui-corner-right, +.ui-corner-tr { + border-top-right-radius: 4px; +} +.ui-corner-all, +.ui-corner-bottom, +.ui-corner-left, +.ui-corner-bl { + border-bottom-left-radius: 4px; +} +.ui-corner-all, +.ui-corner-bottom, +.ui-corner-right, +.ui-corner-br { + border-bottom-right-radius: 4px; +} + +/* Overlays */ +.ui-widget-overlay { + background: #666666 url("images/ui-bg_diagonals-thick_20_666666_40x40.png") 50% 50% repeat; + opacity: .5; + filter: Alpha(Opacity=50); /* support: IE8 */ +} +.ui-widget-shadow { + margin: -5px 0 0 -5px; + padding: 5px; + background: #000000 url("images/ui-bg_flat_10_000000_40x100.png") 50% 50% repeat-x; + opacity: .2; + filter: Alpha(Opacity=20); /* support: IE8 */ + border-radius: 5px; +} diff --git a/static/src/css/jqueryUI/jquery-ui.min.css b/static/src/css/jqueryUI/jquery-ui.min.css new file mode 100644 index 0000000..d3534c7 --- /dev/null +++ b/static/src/css/jqueryUI/jquery-ui.min.css @@ -0,0 +1,7 @@ +/*! jQuery UI - v1.11.4 - 2015-08-10 +* http://jqueryui.com +* Includes: core.css, autocomplete.css, menu.css, theme.css +* To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Trebuchet%20MS%2CTahoma%2CVerdana%2CArial%2Csans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=f6a828&bgTextureHeader=gloss_wave&bgImgOpacityHeader=35&borderColorHeader=e78f08&fcHeader=ffffff&iconColorHeader=ffffff&bgColorContent=eeeeee&bgTextureContent=highlight_soft&bgImgOpacityContent=100&borderColorContent=dddddd&fcContent=333333&iconColorContent=222222&bgColorDefault=f6f6f6&bgTextureDefault=glass&bgImgOpacityDefault=100&borderColorDefault=cccccc&fcDefault=1c94c4&iconColorDefault=ef8c08&bgColorHover=fdf5ce&bgTextureHover=glass&bgImgOpacityHover=100&borderColorHover=fbcb09&fcHover=c77405&iconColorHover=ef8c08&bgColorActive=ffffff&bgTextureActive=glass&bgImgOpacityActive=65&borderColorActive=fbd850&fcActive=eb8f00&iconColorActive=ef8c08&bgColorHighlight=ffe45c&bgTextureHighlight=highlight_soft&bgImgOpacityHighlight=75&borderColorHighlight=fed22f&fcHighlight=363636&iconColorHighlight=228ef1&bgColorError=b81900&bgTextureError=diagonals_thick&bgImgOpacityError=18&borderColorError=cd0a0a&fcError=ffffff&iconColorError=ffd27a&bgColorOverlay=666666&bgTextureOverlay=diagonals_thick&bgImgOpacityOverlay=20&opacityOverlay=50&bgColorShadow=000000&bgTextureShadow=flat&bgImgOpacityShadow=10&opacityShadow=20&thicknessShadow=5px&offsetTopShadow=-5px&offsetLeftShadow=-5px&cornerRadiusShadow=5px +* Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */ + +.ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-clearfix{min-height:0}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important}.ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-autocomplete{position:absolute;top:0;left:0;cursor:default}.ui-menu{list-style:none;padding:0;margin:0;display:block;outline:none}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{position:relative;margin:0;padding:3px 1em 3px .4em;cursor:pointer;min-height:0;list-style-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")}.ui-menu .ui-menu-divider{margin:5px 0;height:0;font-size:0;line-height:0;border-width:1px 0 0 0}.ui-menu .ui-state-focus,.ui-menu .ui-state-active{margin:-1px}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item{padding-left:2em}.ui-menu .ui-icon{position:absolute;top:0;bottom:0;left:.2em;margin:auto 0}.ui-menu .ui-menu-icon{left:auto;right:0}.ui-widget{font-family:Trebuchet MS,Tahoma,Verdana,Arial,sans-serif;font-size:1.1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Trebuchet MS,Tahoma,Verdana,Arial,sans-serif;font-size:1em}.ui-widget-content{border:1px solid #ddd;background:#eee url("images/ui-bg_highlight-soft_100_eeeeee_1x100.png") 50% top repeat-x;color:#333}.ui-widget-content a{color:#333}.ui-widget-header{border:1px solid #e78f08;background:#f6a828 url("images/ui-bg_gloss-wave_35_f6a828_500x100.png") 50% 50% repeat-x;color:#fff;font-weight:bold}.ui-widget-header a{color:#fff}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{border:1px solid #ccc;background:#f6f6f6 url("images/ui-bg_glass_100_f6f6f6_1x400.png") 50% 50% repeat-x;font-weight:bold;color:#1c94c4}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited{color:#1c94c4;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus{border:1px solid #fbcb09;background:#fdf5ce url("images/ui-bg_glass_100_fdf5ce_1x400.png") 50% 50% repeat-x;font-weight:bold;color:#c77405}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited,.ui-state-focus a,.ui-state-focus a:hover,.ui-state-focus a:link,.ui-state-focus a:visited{color:#c77405;text-decoration:none}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active{border:1px solid #fbd850;background:#fff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x;font-weight:bold;color:#eb8f00}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#eb8f00;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #fed22f;background:#ffe45c url("images/ui-bg_highlight-soft_75_ffe45c_1x100.png") 50% top repeat-x;color:#363636}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#363636}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #cd0a0a;background:#b81900 url("images/ui-bg_diagonals-thick_18_b81900_40x40.png") 50% 50% repeat;color:#fff}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#fff}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#fff}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url("images/ui-icons_222222_256x240.png")}.ui-widget-header .ui-icon{background-image:url("images/ui-icons_ffffff_256x240.png")}.ui-state-default .ui-icon{background-image:url("images/ui-icons_ef8c08_256x240.png")}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon{background-image:url("images/ui-icons_ef8c08_256x240.png")}.ui-state-active .ui-icon{background-image:url("images/ui-icons_ef8c08_256x240.png")}.ui-state-highlight .ui-icon{background-image:url("images/ui-icons_228ef1_256x240.png")}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url("images/ui-icons_ffd27a_256x240.png")}.ui-icon-blank{background-position:16px 16px}.ui-icon-carat-1-n{background-position:0 0}.ui-icon-carat-1-ne{background-position:-16px 0}.ui-icon-carat-1-e{background-position:-32px 0}.ui-icon-carat-1-se{background-position:-48px 0}.ui-icon-carat-1-s{background-position:-64px 0}.ui-icon-carat-1-sw{background-position:-80px 0}.ui-icon-carat-1-w{background-position:-96px 0}.ui-icon-carat-1-nw{background-position:-112px 0}.ui-icon-carat-2-n-s{background-position:-128px 0}.ui-icon-carat-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-64px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-64px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:0 -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:4px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:4px}.ui-widget-overlay{background:#666 url("images/ui-bg_diagonals-thick_20_666666_40x40.png") 50% 50% repeat;opacity:.5;filter:Alpha(Opacity=50)}.ui-widget-shadow{margin:-5px 0 0 -5px;padding:5px;background:#000 url("images/ui-bg_flat_10_000000_40x100.png") 50% 50% repeat-x;opacity:.2;filter:Alpha(Opacity=20);border-radius:5px} \ No newline at end of file diff --git a/static/src/css/jqueryUI/jquery-ui.structure.css b/static/src/css/jqueryUI/jquery-ui.structure.css new file mode 100644 index 0000000..1a53ab4 --- /dev/null +++ b/static/src/css/jqueryUI/jquery-ui.structure.css @@ -0,0 +1,152 @@ +/*! + * jQuery UI CSS Framework 1.11.4 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + * + * http://api.jqueryui.com/category/theming/ + */ + +/* Layout helpers +----------------------------------*/ +.ui-helper-hidden { + display: none; +} +.ui-helper-hidden-accessible { + border: 0; + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} +.ui-helper-reset { + margin: 0; + padding: 0; + border: 0; + outline: 0; + line-height: 1.3; + text-decoration: none; + font-size: 100%; + list-style: none; +} +.ui-helper-clearfix:before, +.ui-helper-clearfix:after { + content: ""; + display: table; + border-collapse: collapse; +} +.ui-helper-clearfix:after { + clear: both; +} +.ui-helper-clearfix { + min-height: 0; /* support: IE7 */ +} +.ui-helper-zfix { + width: 100%; + height: 100%; + top: 0; + left: 0; + position: absolute; + opacity: 0; + filter:Alpha(Opacity=0); /* support: IE8 */ +} + +.ui-front { + z-index: 100; +} + + +/* Interaction Cues +----------------------------------*/ +.ui-state-disabled { + cursor: default !important; +} + + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { + display: block; + text-indent: -99999px; + overflow: hidden; + background-repeat: no-repeat; +} + + +/* Misc visuals +----------------------------------*/ + +/* Overlays */ +.ui-widget-overlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; +} +.ui-autocomplete { + position: absolute; + top: 0; + left: 0; + cursor: default; +} +.ui-menu { + list-style: none; + padding: 0; + margin: 0; + display: block; + outline: none; +} +.ui-menu .ui-menu { + position: absolute; +} +.ui-menu .ui-menu-item { + position: relative; + margin: 0; + padding: 3px 1em 3px .4em; + cursor: pointer; + min-height: 0; /* support: IE7 */ + /* support: IE10, see #8844 */ + list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); +} +.ui-menu .ui-menu-divider { + margin: 5px 0; + height: 0; + font-size: 0; + line-height: 0; + border-width: 1px 0 0 0; +} +.ui-menu .ui-state-focus, +.ui-menu .ui-state-active { + margin: -1px; +} + +/* icon support */ +.ui-menu-icons { + position: relative; +} +.ui-menu-icons .ui-menu-item { + padding-left: 2em; +} + +/* left-aligned */ +.ui-menu .ui-icon { + position: absolute; + top: 0; + bottom: 0; + left: .2em; + margin: auto 0; +} + +/* right-aligned */ +.ui-menu .ui-menu-icon { + left: auto; + right: 0; +} diff --git a/static/src/css/jqueryUI/jquery-ui.theme.css b/static/src/css/jqueryUI/jquery-ui.theme.css new file mode 100644 index 0000000..5db92db --- /dev/null +++ b/static/src/css/jqueryUI/jquery-ui.theme.css @@ -0,0 +1,410 @@ +/*! + * jQuery UI CSS Framework 1.11.4 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + * + * http://api.jqueryui.com/category/theming/ + * + * To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Trebuchet%20MS%2CTahoma%2CVerdana%2CArial%2Csans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=f6a828&bgTextureHeader=gloss_wave&bgImgOpacityHeader=35&borderColorHeader=e78f08&fcHeader=ffffff&iconColorHeader=ffffff&bgColorContent=eeeeee&bgTextureContent=highlight_soft&bgImgOpacityContent=100&borderColorContent=dddddd&fcContent=333333&iconColorContent=222222&bgColorDefault=f6f6f6&bgTextureDefault=glass&bgImgOpacityDefault=100&borderColorDefault=cccccc&fcDefault=1c94c4&iconColorDefault=ef8c08&bgColorHover=fdf5ce&bgTextureHover=glass&bgImgOpacityHover=100&borderColorHover=fbcb09&fcHover=c77405&iconColorHover=ef8c08&bgColorActive=ffffff&bgTextureActive=glass&bgImgOpacityActive=65&borderColorActive=fbd850&fcActive=eb8f00&iconColorActive=ef8c08&bgColorHighlight=ffe45c&bgTextureHighlight=highlight_soft&bgImgOpacityHighlight=75&borderColorHighlight=fed22f&fcHighlight=363636&iconColorHighlight=228ef1&bgColorError=b81900&bgTextureError=diagonals_thick&bgImgOpacityError=18&borderColorError=cd0a0a&fcError=ffffff&iconColorError=ffd27a&bgColorOverlay=666666&bgTextureOverlay=diagonals_thick&bgImgOpacityOverlay=20&opacityOverlay=50&bgColorShadow=000000&bgTextureShadow=flat&bgImgOpacityShadow=10&opacityShadow=20&thicknessShadow=5px&offsetTopShadow=-5px&offsetLeftShadow=-5px&cornerRadiusShadow=5px + */ + + +/* Component containers +----------------------------------*/ +.ui-widget { + font-family: Trebuchet MS,Tahoma,Verdana,Arial,sans-serif; + font-size: 1.1em; +} +.ui-widget .ui-widget { + font-size: 1em; +} +.ui-widget input, +.ui-widget select, +.ui-widget textarea, +.ui-widget button { + font-family: Trebuchet MS,Tahoma,Verdana,Arial,sans-serif; + font-size: 1em; +} +.ui-widget-content { + border: 1px solid #dddddd; + background: #eeeeee url("images/ui-bg_highlight-soft_100_eeeeee_1x100.png") 50% top repeat-x; + color: #333333; +} +.ui-widget-content a { + color: #333333; +} +.ui-widget-header { + border: 1px solid #e78f08; + background: #f6a828 url("images/ui-bg_gloss-wave_35_f6a828_500x100.png") 50% 50% repeat-x; + color: #ffffff; + font-weight: bold; +} +.ui-widget-header a { + color: #ffffff; +} + +/* Interaction states +----------------------------------*/ +.ui-state-default, +.ui-widget-content .ui-state-default, +.ui-widget-header .ui-state-default { + border: 1px solid #cccccc; + background: #f6f6f6 url("images/ui-bg_glass_100_f6f6f6_1x400.png") 50% 50% repeat-x; + font-weight: bold; + color: #1c94c4; +} +.ui-state-default a, +.ui-state-default a:link, +.ui-state-default a:visited { + color: #1c94c4; + text-decoration: none; +} +.ui-state-hover, +.ui-widget-content .ui-state-hover, +.ui-widget-header .ui-state-hover, +.ui-state-focus, +.ui-widget-content .ui-state-focus, +.ui-widget-header .ui-state-focus { + border: 1px solid #fbcb09; + background: #fdf5ce url("images/ui-bg_glass_100_fdf5ce_1x400.png") 50% 50% repeat-x; + font-weight: bold; + color: #c77405; +} +.ui-state-hover a, +.ui-state-hover a:hover, +.ui-state-hover a:link, +.ui-state-hover a:visited, +.ui-state-focus a, +.ui-state-focus a:hover, +.ui-state-focus a:link, +.ui-state-focus a:visited { + color: #c77405; + text-decoration: none; +} +.ui-state-active, +.ui-widget-content .ui-state-active, +.ui-widget-header .ui-state-active { + border: 1px solid #fbd850; + background: #ffffff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x; + font-weight: bold; + color: #eb8f00; +} +.ui-state-active a, +.ui-state-active a:link, +.ui-state-active a:visited { + color: #eb8f00; + text-decoration: none; +} + +/* Interaction Cues +----------------------------------*/ +.ui-state-highlight, +.ui-widget-content .ui-state-highlight, +.ui-widget-header .ui-state-highlight { + border: 1px solid #fed22f; + background: #ffe45c url("images/ui-bg_highlight-soft_75_ffe45c_1x100.png") 50% top repeat-x; + color: #363636; +} +.ui-state-highlight a, +.ui-widget-content .ui-state-highlight a, +.ui-widget-header .ui-state-highlight a { + color: #363636; +} +.ui-state-error, +.ui-widget-content .ui-state-error, +.ui-widget-header .ui-state-error { + border: 1px solid #cd0a0a; + background: #b81900 url("images/ui-bg_diagonals-thick_18_b81900_40x40.png") 50% 50% repeat; + color: #ffffff; +} +.ui-state-error a, +.ui-widget-content .ui-state-error a, +.ui-widget-header .ui-state-error a { + color: #ffffff; +} +.ui-state-error-text, +.ui-widget-content .ui-state-error-text, +.ui-widget-header .ui-state-error-text { + color: #ffffff; +} +.ui-priority-primary, +.ui-widget-content .ui-priority-primary, +.ui-widget-header .ui-priority-primary { + font-weight: bold; +} +.ui-priority-secondary, +.ui-widget-content .ui-priority-secondary, +.ui-widget-header .ui-priority-secondary { + opacity: .7; + filter:Alpha(Opacity=70); /* support: IE8 */ + font-weight: normal; +} +.ui-state-disabled, +.ui-widget-content .ui-state-disabled, +.ui-widget-header .ui-state-disabled { + opacity: .35; + filter:Alpha(Opacity=35); /* support: IE8 */ + background-image: none; +} +.ui-state-disabled .ui-icon { + filter:Alpha(Opacity=35); /* support: IE8 - See #6059 */ +} + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { + width: 16px; + height: 16px; +} +.ui-icon, +.ui-widget-content .ui-icon { + background-image: url("images/ui-icons_222222_256x240.png"); +} +.ui-widget-header .ui-icon { + background-image: url("images/ui-icons_ffffff_256x240.png"); +} +.ui-state-default .ui-icon { + background-image: url("images/ui-icons_ef8c08_256x240.png"); +} +.ui-state-hover .ui-icon, +.ui-state-focus .ui-icon { + background-image: url("images/ui-icons_ef8c08_256x240.png"); +} +.ui-state-active .ui-icon { + background-image: url("images/ui-icons_ef8c08_256x240.png"); +} +.ui-state-highlight .ui-icon { + background-image: url("images/ui-icons_228ef1_256x240.png"); +} +.ui-state-error .ui-icon, +.ui-state-error-text .ui-icon { + background-image: url("images/ui-icons_ffd27a_256x240.png"); +} + +/* positioning */ +.ui-icon-blank { background-position: 16px 16px; } +.ui-icon-carat-1-n { background-position: 0 0; } +.ui-icon-carat-1-ne { background-position: -16px 0; } +.ui-icon-carat-1-e { background-position: -32px 0; } +.ui-icon-carat-1-se { background-position: -48px 0; } +.ui-icon-carat-1-s { background-position: -64px 0; } +.ui-icon-carat-1-sw { background-position: -80px 0; } +.ui-icon-carat-1-w { background-position: -96px 0; } +.ui-icon-carat-1-nw { background-position: -112px 0; } +.ui-icon-carat-2-n-s { background-position: -128px 0; } +.ui-icon-carat-2-e-w { background-position: -144px 0; } +.ui-icon-triangle-1-n { background-position: 0 -16px; } +.ui-icon-triangle-1-ne { background-position: -16px -16px; } +.ui-icon-triangle-1-e { background-position: -32px -16px; } +.ui-icon-triangle-1-se { background-position: -48px -16px; } +.ui-icon-triangle-1-s { background-position: -64px -16px; } +.ui-icon-triangle-1-sw { background-position: -80px -16px; } +.ui-icon-triangle-1-w { background-position: -96px -16px; } +.ui-icon-triangle-1-nw { background-position: -112px -16px; } +.ui-icon-triangle-2-n-s { background-position: -128px -16px; } +.ui-icon-triangle-2-e-w { background-position: -144px -16px; } +.ui-icon-arrow-1-n { background-position: 0 -32px; } +.ui-icon-arrow-1-ne { background-position: -16px -32px; } +.ui-icon-arrow-1-e { background-position: -32px -32px; } +.ui-icon-arrow-1-se { background-position: -48px -32px; } +.ui-icon-arrow-1-s { background-position: -64px -32px; } +.ui-icon-arrow-1-sw { background-position: -80px -32px; } +.ui-icon-arrow-1-w { background-position: -96px -32px; } +.ui-icon-arrow-1-nw { background-position: -112px -32px; } +.ui-icon-arrow-2-n-s { background-position: -128px -32px; } +.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; } +.ui-icon-arrow-2-e-w { background-position: -160px -32px; } +.ui-icon-arrow-2-se-nw { background-position: -176px -32px; } +.ui-icon-arrowstop-1-n { background-position: -192px -32px; } +.ui-icon-arrowstop-1-e { background-position: -208px -32px; } +.ui-icon-arrowstop-1-s { background-position: -224px -32px; } +.ui-icon-arrowstop-1-w { background-position: -240px -32px; } +.ui-icon-arrowthick-1-n { background-position: 0 -48px; } +.ui-icon-arrowthick-1-ne { background-position: -16px -48px; } +.ui-icon-arrowthick-1-e { background-position: -32px -48px; } +.ui-icon-arrowthick-1-se { background-position: -48px -48px; } +.ui-icon-arrowthick-1-s { background-position: -64px -48px; } +.ui-icon-arrowthick-1-sw { background-position: -80px -48px; } +.ui-icon-arrowthick-1-w { background-position: -96px -48px; } +.ui-icon-arrowthick-1-nw { background-position: -112px -48px; } +.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; } +.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; } +.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; } +.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; } +.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; } +.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; } +.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; } +.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; } +.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; } +.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; } +.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; } +.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; } +.ui-icon-arrowreturn-1-w { background-position: -64px -64px; } +.ui-icon-arrowreturn-1-n { background-position: -80px -64px; } +.ui-icon-arrowreturn-1-e { background-position: -96px -64px; } +.ui-icon-arrowreturn-1-s { background-position: -112px -64px; } +.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; } +.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; } +.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; } +.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; } +.ui-icon-arrow-4 { background-position: 0 -80px; } +.ui-icon-arrow-4-diag { background-position: -16px -80px; } +.ui-icon-extlink { background-position: -32px -80px; } +.ui-icon-newwin { background-position: -48px -80px; } +.ui-icon-refresh { background-position: -64px -80px; } +.ui-icon-shuffle { background-position: -80px -80px; } +.ui-icon-transfer-e-w { background-position: -96px -80px; } +.ui-icon-transferthick-e-w { background-position: -112px -80px; } +.ui-icon-folder-collapsed { background-position: 0 -96px; } +.ui-icon-folder-open { background-position: -16px -96px; } +.ui-icon-document { background-position: -32px -96px; } +.ui-icon-document-b { background-position: -48px -96px; } +.ui-icon-note { background-position: -64px -96px; } +.ui-icon-mail-closed { background-position: -80px -96px; } +.ui-icon-mail-open { background-position: -96px -96px; } +.ui-icon-suitcase { background-position: -112px -96px; } +.ui-icon-comment { background-position: -128px -96px; } +.ui-icon-person { background-position: -144px -96px; } +.ui-icon-print { background-position: -160px -96px; } +.ui-icon-trash { background-position: -176px -96px; } +.ui-icon-locked { background-position: -192px -96px; } +.ui-icon-unlocked { background-position: -208px -96px; } +.ui-icon-bookmark { background-position: -224px -96px; } +.ui-icon-tag { background-position: -240px -96px; } +.ui-icon-home { background-position: 0 -112px; } +.ui-icon-flag { background-position: -16px -112px; } +.ui-icon-calendar { background-position: -32px -112px; } +.ui-icon-cart { background-position: -48px -112px; } +.ui-icon-pencil { background-position: -64px -112px; } +.ui-icon-clock { background-position: -80px -112px; } +.ui-icon-disk { background-position: -96px -112px; } +.ui-icon-calculator { background-position: -112px -112px; } +.ui-icon-zoomin { background-position: -128px -112px; } +.ui-icon-zoomout { background-position: -144px -112px; } +.ui-icon-search { background-position: -160px -112px; } +.ui-icon-wrench { background-position: -176px -112px; } +.ui-icon-gear { background-position: -192px -112px; } +.ui-icon-heart { background-position: -208px -112px; } +.ui-icon-star { background-position: -224px -112px; } +.ui-icon-link { background-position: -240px -112px; } +.ui-icon-cancel { background-position: 0 -128px; } +.ui-icon-plus { background-position: -16px -128px; } +.ui-icon-plusthick { background-position: -32px -128px; } +.ui-icon-minus { background-position: -48px -128px; } +.ui-icon-minusthick { background-position: -64px -128px; } +.ui-icon-close { background-position: -80px -128px; } +.ui-icon-closethick { background-position: -96px -128px; } +.ui-icon-key { background-position: -112px -128px; } +.ui-icon-lightbulb { background-position: -128px -128px; } +.ui-icon-scissors { background-position: -144px -128px; } +.ui-icon-clipboard { background-position: -160px -128px; } +.ui-icon-copy { background-position: -176px -128px; } +.ui-icon-contact { background-position: -192px -128px; } +.ui-icon-image { background-position: -208px -128px; } +.ui-icon-video { background-position: -224px -128px; } +.ui-icon-script { background-position: -240px -128px; } +.ui-icon-alert { background-position: 0 -144px; } +.ui-icon-info { background-position: -16px -144px; } +.ui-icon-notice { background-position: -32px -144px; } +.ui-icon-help { background-position: -48px -144px; } +.ui-icon-check { background-position: -64px -144px; } +.ui-icon-bullet { background-position: -80px -144px; } +.ui-icon-radio-on { background-position: -96px -144px; } +.ui-icon-radio-off { background-position: -112px -144px; } +.ui-icon-pin-w { background-position: -128px -144px; } +.ui-icon-pin-s { background-position: -144px -144px; } +.ui-icon-play { background-position: 0 -160px; } +.ui-icon-pause { background-position: -16px -160px; } +.ui-icon-seek-next { background-position: -32px -160px; } +.ui-icon-seek-prev { background-position: -48px -160px; } +.ui-icon-seek-end { background-position: -64px -160px; } +.ui-icon-seek-start { background-position: -80px -160px; } +/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */ +.ui-icon-seek-first { background-position: -80px -160px; } +.ui-icon-stop { background-position: -96px -160px; } +.ui-icon-eject { background-position: -112px -160px; } +.ui-icon-volume-off { background-position: -128px -160px; } +.ui-icon-volume-on { background-position: -144px -160px; } +.ui-icon-power { background-position: 0 -176px; } +.ui-icon-signal-diag { background-position: -16px -176px; } +.ui-icon-signal { background-position: -32px -176px; } +.ui-icon-battery-0 { background-position: -48px -176px; } +.ui-icon-battery-1 { background-position: -64px -176px; } +.ui-icon-battery-2 { background-position: -80px -176px; } +.ui-icon-battery-3 { background-position: -96px -176px; } +.ui-icon-circle-plus { background-position: 0 -192px; } +.ui-icon-circle-minus { background-position: -16px -192px; } +.ui-icon-circle-close { background-position: -32px -192px; } +.ui-icon-circle-triangle-e { background-position: -48px -192px; } +.ui-icon-circle-triangle-s { background-position: -64px -192px; } +.ui-icon-circle-triangle-w { background-position: -80px -192px; } +.ui-icon-circle-triangle-n { background-position: -96px -192px; } +.ui-icon-circle-arrow-e { background-position: -112px -192px; } +.ui-icon-circle-arrow-s { background-position: -128px -192px; } +.ui-icon-circle-arrow-w { background-position: -144px -192px; } +.ui-icon-circle-arrow-n { background-position: -160px -192px; } +.ui-icon-circle-zoomin { background-position: -176px -192px; } +.ui-icon-circle-zoomout { background-position: -192px -192px; } +.ui-icon-circle-check { background-position: -208px -192px; } +.ui-icon-circlesmall-plus { background-position: 0 -208px; } +.ui-icon-circlesmall-minus { background-position: -16px -208px; } +.ui-icon-circlesmall-close { background-position: -32px -208px; } +.ui-icon-squaresmall-plus { background-position: -48px -208px; } +.ui-icon-squaresmall-minus { background-position: -64px -208px; } +.ui-icon-squaresmall-close { background-position: -80px -208px; } +.ui-icon-grip-dotted-vertical { background-position: 0 -224px; } +.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; } +.ui-icon-grip-solid-vertical { background-position: -32px -224px; } +.ui-icon-grip-solid-horizontal { background-position: -48px -224px; } +.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; } +.ui-icon-grip-diagonal-se { background-position: -80px -224px; } + + +/* Misc visuals +----------------------------------*/ + +/* Corner radius */ +.ui-corner-all, +.ui-corner-top, +.ui-corner-left, +.ui-corner-tl { + border-top-left-radius: 4px; +} +.ui-corner-all, +.ui-corner-top, +.ui-corner-right, +.ui-corner-tr { + border-top-right-radius: 4px; +} +.ui-corner-all, +.ui-corner-bottom, +.ui-corner-left, +.ui-corner-bl { + border-bottom-left-radius: 4px; +} +.ui-corner-all, +.ui-corner-bottom, +.ui-corner-right, +.ui-corner-br { + border-bottom-right-radius: 4px; +} + +/* Overlays */ +.ui-widget-overlay { + background: #666666 url("images/ui-bg_diagonals-thick_20_666666_40x40.png") 50% 50% repeat; + opacity: .5; + filter: Alpha(Opacity=50); /* support: IE8 */ +} +.ui-widget-shadow { + margin: -5px 0 0 -5px; + padding: 5px; + background: #000000 url("images/ui-bg_flat_10_000000_40x100.png") 50% 50% repeat-x; + opacity: .2; + filter: Alpha(Opacity=20); /* support: IE8 */ + border-radius: 5px; +} diff --git a/static/src/js/config.js b/static/src/js/config.js index f852cc8..997877a 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -18,7 +18,7 @@ var require = { admin: "app/admin/admin", chart: "lib/chart/Chart", tagEditor: "lib/tagEditor/jquery.tag-editor.min", - + jqueryUI: "lib/jqueryUI/jquery-ui", //formValidation 不要在代码中单独使用,而是使用和修改utils/validation base: "lib/formValidation/base", helper: "lib/formValidation/helper", diff --git a/static/src/js/lib/jqueryUI/jquery-ui.js b/static/src/js/lib/jqueryUI/jquery-ui.js new file mode 100644 index 0000000..32278fb --- /dev/null +++ b/static/src/js/lib/jqueryUI/jquery-ui.js @@ -0,0 +1,2610 @@ +/*! jQuery UI - v1.11.4 - 2015-08-10 +* http://jqueryui.com +* Includes: core.js, widget.js, position.js, autocomplete.js, menu.js +* Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */ + +(function( factory ) { + if ( typeof define === "function" && define.amd ) { + + // AMD. Register as an anonymous module. + define([ "jquery" ], factory ); + } else { + + // Browser globals + factory( jQuery ); + } +}(function( $ ) { +/*! + * jQuery UI Core 1.11.4 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + * + * http://api.jqueryui.com/category/ui-core/ + */ + + +// $.ui might exist from components with no dependencies, e.g., $.ui.position +$.ui = $.ui || {}; + +$.extend( $.ui, { + version: "1.11.4", + + keyCode: { + BACKSPACE: 8, + COMMA: 188, + DELETE: 46, + DOWN: 40, + END: 35, + ENTER: 13, + ESCAPE: 27, + HOME: 36, + LEFT: 37, + PAGE_DOWN: 34, + PAGE_UP: 33, + PERIOD: 190, + RIGHT: 39, + SPACE: 32, + TAB: 9, + UP: 38 + } +}); + +// plugins +$.fn.extend({ + scrollParent: function( includeHidden ) { + var position = this.css( "position" ), + excludeStaticParent = position === "absolute", + overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/, + scrollParent = this.parents().filter( function() { + var parent = $( this ); + if ( excludeStaticParent && parent.css( "position" ) === "static" ) { + return false; + } + return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) ); + }).eq( 0 ); + + return position === "fixed" || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent; + }, + + uniqueId: (function() { + var uuid = 0; + + return function() { + return this.each(function() { + if ( !this.id ) { + this.id = "ui-id-" + ( ++uuid ); + } + }); + }; + })(), + + removeUniqueId: function() { + return this.each(function() { + if ( /^ui-id-\d+$/.test( this.id ) ) { + $( this ).removeAttr( "id" ); + } + }); + } +}); + +// selectors +function focusable( element, isTabIndexNotNaN ) { + var map, mapName, img, + nodeName = element.nodeName.toLowerCase(); + if ( "area" === nodeName ) { + map = element.parentNode; + mapName = map.name; + if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) { + return false; + } + img = $( "img[usemap='#" + mapName + "']" )[ 0 ]; + return !!img && visible( img ); + } + return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ? + !element.disabled : + "a" === nodeName ? + element.href || isTabIndexNotNaN : + isTabIndexNotNaN) && + // the element and all of its ancestors must be visible + visible( element ); +} + +function visible( element ) { + return $.expr.filters.visible( element ) && + !$( element ).parents().addBack().filter(function() { + return $.css( this, "visibility" ) === "hidden"; + }).length; +} + +$.extend( $.expr[ ":" ], { + data: $.expr.createPseudo ? + $.expr.createPseudo(function( dataName ) { + return function( elem ) { + return !!$.data( elem, dataName ); + }; + }) : + // support: jQuery <1.8 + function( elem, i, match ) { + return !!$.data( elem, match[ 3 ] ); + }, + + focusable: function( element ) { + return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) ); + }, + + tabbable: function( element ) { + var tabIndex = $.attr( element, "tabindex" ), + isTabIndexNaN = isNaN( tabIndex ); + return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN ); + } +}); + +// support: jQuery <1.8 +if ( !$( "" ).outerWidth( 1 ).jquery ) { + $.each( [ "Width", "Height" ], function( i, name ) { + var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ], + type = name.toLowerCase(), + orig = { + innerWidth: $.fn.innerWidth, + innerHeight: $.fn.innerHeight, + outerWidth: $.fn.outerWidth, + outerHeight: $.fn.outerHeight + }; + + function reduce( elem, size, border, margin ) { + $.each( side, function() { + size -= parseFloat( $.css( elem, "padding" + this ) ) || 0; + if ( border ) { + size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0; + } + if ( margin ) { + size -= parseFloat( $.css( elem, "margin" + this ) ) || 0; + } + }); + return size; + } + + $.fn[ "inner" + name ] = function( size ) { + if ( size === undefined ) { + return orig[ "inner" + name ].call( this ); + } + + return this.each(function() { + $( this ).css( type, reduce( this, size ) + "px" ); + }); + }; + + $.fn[ "outer" + name] = function( size, margin ) { + if ( typeof size !== "number" ) { + return orig[ "outer" + name ].call( this, size ); + } + + return this.each(function() { + $( this).css( type, reduce( this, size, true, margin ) + "px" ); + }); + }; + }); +} + +// support: jQuery <1.8 +if ( !$.fn.addBack ) { + $.fn.addBack = function( selector ) { + return this.add( selector == null ? + this.prevObject : this.prevObject.filter( selector ) + ); + }; +} + +// support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413) +if ( $( "" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) { + $.fn.removeData = (function( removeData ) { + return function( key ) { + if ( arguments.length ) { + return removeData.call( this, $.camelCase( key ) ); + } else { + return removeData.call( this ); + } + }; + })( $.fn.removeData ); +} + +// deprecated +$.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() ); + +$.fn.extend({ + focus: (function( orig ) { + return function( delay, fn ) { + return typeof delay === "number" ? + this.each(function() { + var elem = this; + setTimeout(function() { + $( elem ).focus(); + if ( fn ) { + fn.call( elem ); + } + }, delay ); + }) : + orig.apply( this, arguments ); + }; + })( $.fn.focus ), + + disableSelection: (function() { + var eventType = "onselectstart" in document.createElement( "div" ) ? + "selectstart" : + "mousedown"; + + return function() { + return this.bind( eventType + ".ui-disableSelection", function( event ) { + event.preventDefault(); + }); + }; + })(), + + enableSelection: function() { + return this.unbind( ".ui-disableSelection" ); + }, + + zIndex: function( zIndex ) { + if ( zIndex !== undefined ) { + return this.css( "zIndex", zIndex ); + } + + if ( this.length ) { + var elem = $( this[ 0 ] ), position, value; + while ( elem.length && elem[ 0 ] !== document ) { + // Ignore z-index if position is set to a value where z-index is ignored by the browser + // This makes behavior of this function consistent across browsers + // WebKit always returns auto if the element is positioned + position = elem.css( "position" ); + if ( position === "absolute" || position === "relative" || position === "fixed" ) { + // IE returns 0 when zIndex is not specified + // other browsers return a string + // we ignore the case of nested elements with an explicit value of 0 + //
+ value = parseInt( elem.css( "zIndex" ), 10 ); + if ( !isNaN( value ) && value !== 0 ) { + return value; + } + } + elem = elem.parent(); + } + } + + return 0; + } +}); + +// $.ui.plugin is deprecated. Use $.widget() extensions instead. +$.ui.plugin = { + add: function( module, option, set ) { + var i, + proto = $.ui[ module ].prototype; + for ( i in set ) { + proto.plugins[ i ] = proto.plugins[ i ] || []; + proto.plugins[ i ].push( [ option, set[ i ] ] ); + } + }, + call: function( instance, name, args, allowDisconnected ) { + var i, + set = instance.plugins[ name ]; + + if ( !set ) { + return; + } + + if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) ) { + return; + } + + for ( i = 0; i < set.length; i++ ) { + if ( instance.options[ set[ i ][ 0 ] ] ) { + set[ i ][ 1 ].apply( instance.element, args ); + } + } + } +}; + + +/*! + * jQuery UI Widget 1.11.4 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + * + * http://api.jqueryui.com/jQuery.widget/ + */ + + +var widget_uuid = 0, + widget_slice = Array.prototype.slice; + +$.cleanData = (function( orig ) { + return function( elems ) { + var events, elem, i; + for ( i = 0; (elem = elems[i]) != null; i++ ) { + try { + + // Only trigger remove when necessary to save time + events = $._data( elem, "events" ); + if ( events && events.remove ) { + $( elem ).triggerHandler( "remove" ); + } + + // http://bugs.jquery.com/ticket/8235 + } catch ( e ) {} + } + orig( elems ); + }; +})( $.cleanData ); + +$.widget = function( name, base, prototype ) { + var fullName, existingConstructor, constructor, basePrototype, + // proxiedPrototype allows the provided prototype to remain unmodified + // so that it can be used as a mixin for multiple widgets (#8876) + proxiedPrototype = {}, + namespace = name.split( "." )[ 0 ]; + + name = name.split( "." )[ 1 ]; + fullName = namespace + "-" + name; + + if ( !prototype ) { + prototype = base; + base = $.Widget; + } + + // create selector for plugin + $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) { + return !!$.data( elem, fullName ); + }; + + $[ namespace ] = $[ namespace ] || {}; + existingConstructor = $[ namespace ][ name ]; + constructor = $[ namespace ][ name ] = function( options, element ) { + // allow instantiation without "new" keyword + if ( !this._createWidget ) { + return new constructor( options, element ); + } + + // allow instantiation without initializing for simple inheritance + // must use "new" keyword (the code above always passes args) + if ( arguments.length ) { + this._createWidget( options, element ); + } + }; + // extend with the existing constructor to carry over any static properties + $.extend( constructor, existingConstructor, { + version: prototype.version, + // copy the object used to create the prototype in case we need to + // redefine the widget later + _proto: $.extend( {}, prototype ), + // track widgets that inherit from this widget in case this widget is + // redefined after a widget inherits from it + _childConstructors: [] + }); + + basePrototype = new base(); + // we need to make the options hash a property directly on the new instance + // otherwise we'll modify the options hash on the prototype that we're + // inheriting from + basePrototype.options = $.widget.extend( {}, basePrototype.options ); + $.each( prototype, function( prop, value ) { + if ( !$.isFunction( value ) ) { + proxiedPrototype[ prop ] = value; + return; + } + proxiedPrototype[ prop ] = (function() { + var _super = function() { + return base.prototype[ prop ].apply( this, arguments ); + }, + _superApply = function( args ) { + return base.prototype[ prop ].apply( this, args ); + }; + return function() { + var __super = this._super, + __superApply = this._superApply, + returnValue; + + this._super = _super; + this._superApply = _superApply; + + returnValue = value.apply( this, arguments ); + + this._super = __super; + this._superApply = __superApply; + + return returnValue; + }; + })(); + }); + constructor.prototype = $.widget.extend( basePrototype, { + // TODO: remove support for widgetEventPrefix + // always use the name + a colon as the prefix, e.g., draggable:start + // don't prefix for widgets that aren't DOM-based + widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name + }, proxiedPrototype, { + constructor: constructor, + namespace: namespace, + widgetName: name, + widgetFullName: fullName + }); + + // If this widget is being redefined then we need to find all widgets that + // are inheriting from it and redefine all of them so that they inherit from + // the new version of this widget. We're essentially trying to replace one + // level in the prototype chain. + if ( existingConstructor ) { + $.each( existingConstructor._childConstructors, function( i, child ) { + var childPrototype = child.prototype; + + // redefine the child widget using the same prototype that was + // originally used, but inherit from the new version of the base + $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto ); + }); + // remove the list of existing child constructors from the old constructor + // so the old child constructors can be garbage collected + delete existingConstructor._childConstructors; + } else { + base._childConstructors.push( constructor ); + } + + $.widget.bridge( name, constructor ); + + return constructor; +}; + +$.widget.extend = function( target ) { + var input = widget_slice.call( arguments, 1 ), + inputIndex = 0, + inputLength = input.length, + key, + value; + for ( ; inputIndex < inputLength; inputIndex++ ) { + for ( key in input[ inputIndex ] ) { + value = input[ inputIndex ][ key ]; + if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { + // Clone objects + if ( $.isPlainObject( value ) ) { + target[ key ] = $.isPlainObject( target[ key ] ) ? + $.widget.extend( {}, target[ key ], value ) : + // Don't extend strings, arrays, etc. with objects + $.widget.extend( {}, value ); + // Copy everything else by reference + } else { + target[ key ] = value; + } + } + } + } + return target; +}; + +$.widget.bridge = function( name, object ) { + var fullName = object.prototype.widgetFullName || name; + $.fn[ name ] = function( options ) { + var isMethodCall = typeof options === "string", + args = widget_slice.call( arguments, 1 ), + returnValue = this; + + if ( isMethodCall ) { + this.each(function() { + var methodValue, + instance = $.data( this, fullName ); + if ( options === "instance" ) { + returnValue = instance; + return false; + } + if ( !instance ) { + return $.error( "cannot call methods on " + name + " prior to initialization; " + + "attempted to call method '" + options + "'" ); + } + if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) { + return $.error( "no such method '" + options + "' for " + name + " widget instance" ); + } + methodValue = instance[ options ].apply( instance, args ); + if ( methodValue !== instance && methodValue !== undefined ) { + returnValue = methodValue && methodValue.jquery ? + returnValue.pushStack( methodValue.get() ) : + methodValue; + return false; + } + }); + } else { + + // Allow multiple hashes to be passed on init + if ( args.length ) { + options = $.widget.extend.apply( null, [ options ].concat(args) ); + } + + this.each(function() { + var instance = $.data( this, fullName ); + if ( instance ) { + instance.option( options || {} ); + if ( instance._init ) { + instance._init(); + } + } else { + $.data( this, fullName, new object( options, this ) ); + } + }); + } + + return returnValue; + }; +}; + +$.Widget = function( /* options, element */ ) {}; +$.Widget._childConstructors = []; + +$.Widget.prototype = { + widgetName: "widget", + widgetEventPrefix: "", + defaultElement: "
", + options: { + disabled: false, + + // callbacks + create: null + }, + _createWidget: function( options, element ) { + element = $( element || this.defaultElement || this )[ 0 ]; + this.element = $( element ); + this.uuid = widget_uuid++; + this.eventNamespace = "." + this.widgetName + this.uuid; + + this.bindings = $(); + this.hoverable = $(); + this.focusable = $(); + + if ( element !== this ) { + $.data( element, this.widgetFullName, this ); + this._on( true, this.element, { + remove: function( event ) { + if ( event.target === element ) { + this.destroy(); + } + } + }); + this.document = $( element.style ? + // element within the document + element.ownerDocument : + // element is window or document + element.document || element ); + this.window = $( this.document[0].defaultView || this.document[0].parentWindow ); + } + + this.options = $.widget.extend( {}, + this.options, + this._getCreateOptions(), + options ); + + this._create(); + this._trigger( "create", null, this._getCreateEventData() ); + this._init(); + }, + _getCreateOptions: $.noop, + _getCreateEventData: $.noop, + _create: $.noop, + _init: $.noop, + + destroy: function() { + this._destroy(); + // we can probably remove the unbind calls in 2.0 + // all event bindings should go through this._on() + this.element + .unbind( this.eventNamespace ) + .removeData( this.widgetFullName ) + // support: jquery <1.6.3 + // http://bugs.jquery.com/ticket/9413 + .removeData( $.camelCase( this.widgetFullName ) ); + this.widget() + .unbind( this.eventNamespace ) + .removeAttr( "aria-disabled" ) + .removeClass( + this.widgetFullName + "-disabled " + + "ui-state-disabled" ); + + // clean up events and states + this.bindings.unbind( this.eventNamespace ); + this.hoverable.removeClass( "ui-state-hover" ); + this.focusable.removeClass( "ui-state-focus" ); + }, + _destroy: $.noop, + + widget: function() { + return this.element; + }, + + option: function( key, value ) { + var options = key, + parts, + curOption, + i; + + if ( arguments.length === 0 ) { + // don't return a reference to the internal hash + return $.widget.extend( {}, this.options ); + } + + if ( typeof key === "string" ) { + // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } } + options = {}; + parts = key.split( "." ); + key = parts.shift(); + if ( parts.length ) { + curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] ); + for ( i = 0; i < parts.length - 1; i++ ) { + curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {}; + curOption = curOption[ parts[ i ] ]; + } + key = parts.pop(); + if ( arguments.length === 1 ) { + return curOption[ key ] === undefined ? null : curOption[ key ]; + } + curOption[ key ] = value; + } else { + if ( arguments.length === 1 ) { + return this.options[ key ] === undefined ? null : this.options[ key ]; + } + options[ key ] = value; + } + } + + this._setOptions( options ); + + return this; + }, + _setOptions: function( options ) { + var key; + + for ( key in options ) { + this._setOption( key, options[ key ] ); + } + + return this; + }, + _setOption: function( key, value ) { + this.options[ key ] = value; + + if ( key === "disabled" ) { + this.widget() + .toggleClass( this.widgetFullName + "-disabled", !!value ); + + // If the widget is becoming disabled, then nothing is interactive + if ( value ) { + this.hoverable.removeClass( "ui-state-hover" ); + this.focusable.removeClass( "ui-state-focus" ); + } + } + + return this; + }, + + enable: function() { + return this._setOptions({ disabled: false }); + }, + disable: function() { + return this._setOptions({ disabled: true }); + }, + + _on: function( suppressDisabledCheck, element, handlers ) { + var delegateElement, + instance = this; + + // no suppressDisabledCheck flag, shuffle arguments + if ( typeof suppressDisabledCheck !== "boolean" ) { + handlers = element; + element = suppressDisabledCheck; + suppressDisabledCheck = false; + } + + // no element argument, shuffle and use this.element + if ( !handlers ) { + handlers = element; + element = this.element; + delegateElement = this.widget(); + } else { + element = delegateElement = $( element ); + this.bindings = this.bindings.add( element ); + } + + $.each( handlers, function( event, handler ) { + function handlerProxy() { + // allow widgets to customize the disabled handling + // - disabled as an array instead of boolean + // - disabled class as method for disabling individual parts + if ( !suppressDisabledCheck && + ( instance.options.disabled === true || + $( this ).hasClass( "ui-state-disabled" ) ) ) { + return; + } + return ( typeof handler === "string" ? instance[ handler ] : handler ) + .apply( instance, arguments ); + } + + // copy the guid so direct unbinding works + if ( typeof handler !== "string" ) { + handlerProxy.guid = handler.guid = + handler.guid || handlerProxy.guid || $.guid++; + } + + var match = event.match( /^([\w:-]*)\s*(.*)$/ ), + eventName = match[1] + instance.eventNamespace, + selector = match[2]; + if ( selector ) { + delegateElement.delegate( selector, eventName, handlerProxy ); + } else { + element.bind( eventName, handlerProxy ); + } + }); + }, + + _off: function( element, eventName ) { + eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + + this.eventNamespace; + element.unbind( eventName ).undelegate( eventName ); + + // Clear the stack to avoid memory leaks (#10056) + this.bindings = $( this.bindings.not( element ).get() ); + this.focusable = $( this.focusable.not( element ).get() ); + this.hoverable = $( this.hoverable.not( element ).get() ); + }, + + _delay: function( handler, delay ) { + function handlerProxy() { + return ( typeof handler === "string" ? instance[ handler ] : handler ) + .apply( instance, arguments ); + } + var instance = this; + return setTimeout( handlerProxy, delay || 0 ); + }, + + _hoverable: function( element ) { + this.hoverable = this.hoverable.add( element ); + this._on( element, { + mouseenter: function( event ) { + $( event.currentTarget ).addClass( "ui-state-hover" ); + }, + mouseleave: function( event ) { + $( event.currentTarget ).removeClass( "ui-state-hover" ); + } + }); + }, + + _focusable: function( element ) { + this.focusable = this.focusable.add( element ); + this._on( element, { + focusin: function( event ) { + $( event.currentTarget ).addClass( "ui-state-focus" ); + }, + focusout: function( event ) { + $( event.currentTarget ).removeClass( "ui-state-focus" ); + } + }); + }, + + _trigger: function( type, event, data ) { + var prop, orig, + callback = this.options[ type ]; + + data = data || {}; + event = $.Event( event ); + event.type = ( type === this.widgetEventPrefix ? + type : + this.widgetEventPrefix + type ).toLowerCase(); + // the original event may come from any element + // so we need to reset the target on the new event + event.target = this.element[ 0 ]; + + // copy original event properties over to the new event + orig = event.originalEvent; + if ( orig ) { + for ( prop in orig ) { + if ( !( prop in event ) ) { + event[ prop ] = orig[ prop ]; + } + } + } + + this.element.trigger( event, data ); + return !( $.isFunction( callback ) && + callback.apply( this.element[0], [ event ].concat( data ) ) === false || + event.isDefaultPrevented() ); + } +}; + +$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) { + $.Widget.prototype[ "_" + method ] = function( element, options, callback ) { + if ( typeof options === "string" ) { + options = { effect: options }; + } + var hasOptions, + effectName = !options ? + method : + options === true || typeof options === "number" ? + defaultEffect : + options.effect || defaultEffect; + options = options || {}; + if ( typeof options === "number" ) { + options = { duration: options }; + } + hasOptions = !$.isEmptyObject( options ); + options.complete = callback; + if ( options.delay ) { + element.delay( options.delay ); + } + if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) { + element[ method ]( options ); + } else if ( effectName !== method && element[ effectName ] ) { + element[ effectName ]( options.duration, options.easing, callback ); + } else { + element.queue(function( next ) { + $( this )[ method ](); + if ( callback ) { + callback.call( element[ 0 ] ); + } + next(); + }); + } + }; +}); + +var widget = $.widget; + + +/*! + * jQuery UI Position 1.11.4 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + * + * http://api.jqueryui.com/position/ + */ + +(function() { + +$.ui = $.ui || {}; + +var cachedScrollbarWidth, supportsOffsetFractions, + max = Math.max, + abs = Math.abs, + round = Math.round, + rhorizontal = /left|center|right/, + rvertical = /top|center|bottom/, + roffset = /[\+\-]\d+(\.[\d]+)?%?/, + rposition = /^\w+/, + rpercent = /%$/, + _position = $.fn.position; + +function getOffsets( offsets, width, height ) { + return [ + parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ), + parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 ) + ]; +} + +function parseCss( element, property ) { + return parseInt( $.css( element, property ), 10 ) || 0; +} + +function getDimensions( elem ) { + var raw = elem[0]; + if ( raw.nodeType === 9 ) { + return { + width: elem.width(), + height: elem.height(), + offset: { top: 0, left: 0 } + }; + } + if ( $.isWindow( raw ) ) { + return { + width: elem.width(), + height: elem.height(), + offset: { top: elem.scrollTop(), left: elem.scrollLeft() } + }; + } + if ( raw.preventDefault ) { + return { + width: 0, + height: 0, + offset: { top: raw.pageY, left: raw.pageX } + }; + } + return { + width: elem.outerWidth(), + height: elem.outerHeight(), + offset: elem.offset() + }; +} + +$.position = { + scrollbarWidth: function() { + if ( cachedScrollbarWidth !== undefined ) { + return cachedScrollbarWidth; + } + var w1, w2, + div = $( "
" ), + innerDiv = div.children()[0]; + + $( "body" ).append( div ); + w1 = innerDiv.offsetWidth; + div.css( "overflow", "scroll" ); + + w2 = innerDiv.offsetWidth; + + if ( w1 === w2 ) { + w2 = div[0].clientWidth; + } + + div.remove(); + + return (cachedScrollbarWidth = w1 - w2); + }, + getScrollInfo: function( within ) { + var overflowX = within.isWindow || within.isDocument ? "" : + within.element.css( "overflow-x" ), + overflowY = within.isWindow || within.isDocument ? "" : + within.element.css( "overflow-y" ), + hasOverflowX = overflowX === "scroll" || + ( overflowX === "auto" && within.width < within.element[0].scrollWidth ), + hasOverflowY = overflowY === "scroll" || + ( overflowY === "auto" && within.height < within.element[0].scrollHeight ); + return { + width: hasOverflowY ? $.position.scrollbarWidth() : 0, + height: hasOverflowX ? $.position.scrollbarWidth() : 0 + }; + }, + getWithinInfo: function( element ) { + var withinElement = $( element || window ), + isWindow = $.isWindow( withinElement[0] ), + isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9; + return { + element: withinElement, + isWindow: isWindow, + isDocument: isDocument, + offset: withinElement.offset() || { left: 0, top: 0 }, + scrollLeft: withinElement.scrollLeft(), + scrollTop: withinElement.scrollTop(), + + // support: jQuery 1.6.x + // jQuery 1.6 doesn't support .outerWidth/Height() on documents or windows + width: isWindow || isDocument ? withinElement.width() : withinElement.outerWidth(), + height: isWindow || isDocument ? withinElement.height() : withinElement.outerHeight() + }; + } +}; + +$.fn.position = function( options ) { + if ( !options || !options.of ) { + return _position.apply( this, arguments ); + } + + // make a copy, we don't want to modify arguments + options = $.extend( {}, options ); + + var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions, + target = $( options.of ), + within = $.position.getWithinInfo( options.within ), + scrollInfo = $.position.getScrollInfo( within ), + collision = ( options.collision || "flip" ).split( " " ), + offsets = {}; + + dimensions = getDimensions( target ); + if ( target[0].preventDefault ) { + // force left top to allow flipping + options.at = "left top"; + } + targetWidth = dimensions.width; + targetHeight = dimensions.height; + targetOffset = dimensions.offset; + // clone to reuse original targetOffset later + basePosition = $.extend( {}, targetOffset ); + + // force my and at to have valid horizontal and vertical positions + // if a value is missing or invalid, it will be converted to center + $.each( [ "my", "at" ], function() { + var pos = ( options[ this ] || "" ).split( " " ), + horizontalOffset, + verticalOffset; + + if ( pos.length === 1) { + pos = rhorizontal.test( pos[ 0 ] ) ? + pos.concat( [ "center" ] ) : + rvertical.test( pos[ 0 ] ) ? + [ "center" ].concat( pos ) : + [ "center", "center" ]; + } + pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center"; + pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center"; + + // calculate offsets + horizontalOffset = roffset.exec( pos[ 0 ] ); + verticalOffset = roffset.exec( pos[ 1 ] ); + offsets[ this ] = [ + horizontalOffset ? horizontalOffset[ 0 ] : 0, + verticalOffset ? verticalOffset[ 0 ] : 0 + ]; + + // reduce to just the positions without the offsets + options[ this ] = [ + rposition.exec( pos[ 0 ] )[ 0 ], + rposition.exec( pos[ 1 ] )[ 0 ] + ]; + }); + + // normalize collision option + if ( collision.length === 1 ) { + collision[ 1 ] = collision[ 0 ]; + } + + if ( options.at[ 0 ] === "right" ) { + basePosition.left += targetWidth; + } else if ( options.at[ 0 ] === "center" ) { + basePosition.left += targetWidth / 2; + } + + if ( options.at[ 1 ] === "bottom" ) { + basePosition.top += targetHeight; + } else if ( options.at[ 1 ] === "center" ) { + basePosition.top += targetHeight / 2; + } + + atOffset = getOffsets( offsets.at, targetWidth, targetHeight ); + basePosition.left += atOffset[ 0 ]; + basePosition.top += atOffset[ 1 ]; + + return this.each(function() { + var collisionPosition, using, + elem = $( this ), + elemWidth = elem.outerWidth(), + elemHeight = elem.outerHeight(), + marginLeft = parseCss( this, "marginLeft" ), + marginTop = parseCss( this, "marginTop" ), + collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width, + collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height, + position = $.extend( {}, basePosition ), + myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() ); + + if ( options.my[ 0 ] === "right" ) { + position.left -= elemWidth; + } else if ( options.my[ 0 ] === "center" ) { + position.left -= elemWidth / 2; + } + + if ( options.my[ 1 ] === "bottom" ) { + position.top -= elemHeight; + } else if ( options.my[ 1 ] === "center" ) { + position.top -= elemHeight / 2; + } + + position.left += myOffset[ 0 ]; + position.top += myOffset[ 1 ]; + + // if the browser doesn't support fractions, then round for consistent results + if ( !supportsOffsetFractions ) { + position.left = round( position.left ); + position.top = round( position.top ); + } + + collisionPosition = { + marginLeft: marginLeft, + marginTop: marginTop + }; + + $.each( [ "left", "top" ], function( i, dir ) { + if ( $.ui.position[ collision[ i ] ] ) { + $.ui.position[ collision[ i ] ][ dir ]( position, { + targetWidth: targetWidth, + targetHeight: targetHeight, + elemWidth: elemWidth, + elemHeight: elemHeight, + collisionPosition: collisionPosition, + collisionWidth: collisionWidth, + collisionHeight: collisionHeight, + offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ], + my: options.my, + at: options.at, + within: within, + elem: elem + }); + } + }); + + if ( options.using ) { + // adds feedback as second argument to using callback, if present + using = function( props ) { + var left = targetOffset.left - position.left, + right = left + targetWidth - elemWidth, + top = targetOffset.top - position.top, + bottom = top + targetHeight - elemHeight, + feedback = { + target: { + element: target, + left: targetOffset.left, + top: targetOffset.top, + width: targetWidth, + height: targetHeight + }, + element: { + element: elem, + left: position.left, + top: position.top, + width: elemWidth, + height: elemHeight + }, + horizontal: right < 0 ? "left" : left > 0 ? "right" : "center", + vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle" + }; + if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) { + feedback.horizontal = "center"; + } + if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) { + feedback.vertical = "middle"; + } + if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) { + feedback.important = "horizontal"; + } else { + feedback.important = "vertical"; + } + options.using.call( this, props, feedback ); + }; + } + + elem.offset( $.extend( position, { using: using } ) ); + }); +}; + +$.ui.position = { + fit: { + left: function( position, data ) { + var within = data.within, + withinOffset = within.isWindow ? within.scrollLeft : within.offset.left, + outerWidth = within.width, + collisionPosLeft = position.left - data.collisionPosition.marginLeft, + overLeft = withinOffset - collisionPosLeft, + overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset, + newOverRight; + + // element is wider than within + if ( data.collisionWidth > outerWidth ) { + // element is initially over the left side of within + if ( overLeft > 0 && overRight <= 0 ) { + newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset; + position.left += overLeft - newOverRight; + // element is initially over right side of within + } else if ( overRight > 0 && overLeft <= 0 ) { + position.left = withinOffset; + // element is initially over both left and right sides of within + } else { + if ( overLeft > overRight ) { + position.left = withinOffset + outerWidth - data.collisionWidth; + } else { + position.left = withinOffset; + } + } + // too far left -> align with left edge + } else if ( overLeft > 0 ) { + position.left += overLeft; + // too far right -> align with right edge + } else if ( overRight > 0 ) { + position.left -= overRight; + // adjust based on position and margin + } else { + position.left = max( position.left - collisionPosLeft, position.left ); + } + }, + top: function( position, data ) { + var within = data.within, + withinOffset = within.isWindow ? within.scrollTop : within.offset.top, + outerHeight = data.within.height, + collisionPosTop = position.top - data.collisionPosition.marginTop, + overTop = withinOffset - collisionPosTop, + overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset, + newOverBottom; + + // element is taller than within + if ( data.collisionHeight > outerHeight ) { + // element is initially over the top of within + if ( overTop > 0 && overBottom <= 0 ) { + newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset; + position.top += overTop - newOverBottom; + // element is initially over bottom of within + } else if ( overBottom > 0 && overTop <= 0 ) { + position.top = withinOffset; + // element is initially over both top and bottom of within + } else { + if ( overTop > overBottom ) { + position.top = withinOffset + outerHeight - data.collisionHeight; + } else { + position.top = withinOffset; + } + } + // too far up -> align with top + } else if ( overTop > 0 ) { + position.top += overTop; + // too far down -> align with bottom edge + } else if ( overBottom > 0 ) { + position.top -= overBottom; + // adjust based on position and margin + } else { + position.top = max( position.top - collisionPosTop, position.top ); + } + } + }, + flip: { + left: function( position, data ) { + var within = data.within, + withinOffset = within.offset.left + within.scrollLeft, + outerWidth = within.width, + offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left, + collisionPosLeft = position.left - data.collisionPosition.marginLeft, + overLeft = collisionPosLeft - offsetLeft, + overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft, + myOffset = data.my[ 0 ] === "left" ? + -data.elemWidth : + data.my[ 0 ] === "right" ? + data.elemWidth : + 0, + atOffset = data.at[ 0 ] === "left" ? + data.targetWidth : + data.at[ 0 ] === "right" ? + -data.targetWidth : + 0, + offset = -2 * data.offset[ 0 ], + newOverRight, + newOverLeft; + + if ( overLeft < 0 ) { + newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset; + if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) { + position.left += myOffset + atOffset + offset; + } + } else if ( overRight > 0 ) { + newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft; + if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) { + position.left += myOffset + atOffset + offset; + } + } + }, + top: function( position, data ) { + var within = data.within, + withinOffset = within.offset.top + within.scrollTop, + outerHeight = within.height, + offsetTop = within.isWindow ? within.scrollTop : within.offset.top, + collisionPosTop = position.top - data.collisionPosition.marginTop, + overTop = collisionPosTop - offsetTop, + overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop, + top = data.my[ 1 ] === "top", + myOffset = top ? + -data.elemHeight : + data.my[ 1 ] === "bottom" ? + data.elemHeight : + 0, + atOffset = data.at[ 1 ] === "top" ? + data.targetHeight : + data.at[ 1 ] === "bottom" ? + -data.targetHeight : + 0, + offset = -2 * data.offset[ 1 ], + newOverTop, + newOverBottom; + if ( overTop < 0 ) { + newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset; + if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) { + position.top += myOffset + atOffset + offset; + } + } else if ( overBottom > 0 ) { + newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop; + if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) { + position.top += myOffset + atOffset + offset; + } + } + } + }, + flipfit: { + left: function() { + $.ui.position.flip.left.apply( this, arguments ); + $.ui.position.fit.left.apply( this, arguments ); + }, + top: function() { + $.ui.position.flip.top.apply( this, arguments ); + $.ui.position.fit.top.apply( this, arguments ); + } + } +}; + +// fraction support test +(function() { + var testElement, testElementParent, testElementStyle, offsetLeft, i, + body = document.getElementsByTagName( "body" )[ 0 ], + div = document.createElement( "div" ); + + //Create a "fake body" for testing based on method used in jQuery.support + testElement = document.createElement( body ? "div" : "body" ); + testElementStyle = { + visibility: "hidden", + width: 0, + height: 0, + border: 0, + margin: 0, + background: "none" + }; + if ( body ) { + $.extend( testElementStyle, { + position: "absolute", + left: "-1000px", + top: "-1000px" + }); + } + for ( i in testElementStyle ) { + testElement.style[ i ] = testElementStyle[ i ]; + } + testElement.appendChild( div ); + testElementParent = body || document.documentElement; + testElementParent.insertBefore( testElement, testElementParent.firstChild ); + + div.style.cssText = "position: absolute; left: 10.7432222px;"; + + offsetLeft = $( div ).offset().left; + supportsOffsetFractions = offsetLeft > 10 && offsetLeft < 11; + + testElement.innerHTML = ""; + testElementParent.removeChild( testElement ); +})(); + +})(); + +var position = $.ui.position; + + +/*! + * jQuery UI Menu 1.11.4 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + * + * http://api.jqueryui.com/menu/ + */ + + +var menu = $.widget( "ui.menu", { + version: "1.11.4", + defaultElement: "
    ", + delay: 300, + options: { + icons: { + submenu: "ui-icon-carat-1-e" + }, + items: "> *", + menus: "ul", + position: { + my: "left-1 top", + at: "right top" + }, + role: "menu", + + // callbacks + blur: null, + focus: null, + select: null + }, + + _create: function() { + this.activeMenu = this.element; + + // Flag used to prevent firing of the click handler + // as the event bubbles up through nested menus + this.mouseHandled = false; + this.element + .uniqueId() + .addClass( "ui-menu ui-widget ui-widget-content" ) + .toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length ) + .attr({ + role: this.options.role, + tabIndex: 0 + }); + + if ( this.options.disabled ) { + this.element + .addClass( "ui-state-disabled" ) + .attr( "aria-disabled", "true" ); + } + + this._on({ + // Prevent focus from sticking to links inside menu after clicking + // them (focus should always stay on UL during navigation). + "mousedown .ui-menu-item": function( event ) { + event.preventDefault(); + }, + "click .ui-menu-item": function( event ) { + var target = $( event.target ); + if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) { + this.select( event ); + + // Only set the mouseHandled flag if the event will bubble, see #9469. + if ( !event.isPropagationStopped() ) { + this.mouseHandled = true; + } + + // Open submenu on click + if ( target.has( ".ui-menu" ).length ) { + this.expand( event ); + } else if ( !this.element.is( ":focus" ) && $( this.document[ 0 ].activeElement ).closest( ".ui-menu" ).length ) { + + // Redirect focus to the menu + this.element.trigger( "focus", [ true ] ); + + // If the active item is on the top level, let it stay active. + // Otherwise, blur the active item since it is no longer visible. + if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) { + clearTimeout( this.timer ); + } + } + } + }, + "mouseenter .ui-menu-item": function( event ) { + // Ignore mouse events while typeahead is active, see #10458. + // Prevents focusing the wrong item when typeahead causes a scroll while the mouse + // is over an item in the menu + if ( this.previousFilter ) { + return; + } + var target = $( event.currentTarget ); + // Remove ui-state-active class from siblings of the newly focused menu item + // to avoid a jump caused by adjacent elements both having a class with a border + target.siblings( ".ui-state-active" ).removeClass( "ui-state-active" ); + this.focus( event, target ); + }, + mouseleave: "collapseAll", + "mouseleave .ui-menu": "collapseAll", + focus: function( event, keepActiveItem ) { + // If there's already an active item, keep it active + // If not, activate the first item + var item = this.active || this.element.find( this.options.items ).eq( 0 ); + + if ( !keepActiveItem ) { + this.focus( event, item ); + } + }, + blur: function( event ) { + this._delay(function() { + if ( !$.contains( this.element[0], this.document[0].activeElement ) ) { + this.collapseAll( event ); + } + }); + }, + keydown: "_keydown" + }); + + this.refresh(); + + // Clicks outside of a menu collapse any open menus + this._on( this.document, { + click: function( event ) { + if ( this._closeOnDocumentClick( event ) ) { + this.collapseAll( event ); + } + + // Reset the mouseHandled flag + this.mouseHandled = false; + } + }); + }, + + _destroy: function() { + // Destroy (sub)menus + this.element + .removeAttr( "aria-activedescendant" ) + .find( ".ui-menu" ).addBack() + .removeClass( "ui-menu ui-widget ui-widget-content ui-menu-icons ui-front" ) + .removeAttr( "role" ) + .removeAttr( "tabIndex" ) + .removeAttr( "aria-labelledby" ) + .removeAttr( "aria-expanded" ) + .removeAttr( "aria-hidden" ) + .removeAttr( "aria-disabled" ) + .removeUniqueId() + .show(); + + // Destroy menu items + this.element.find( ".ui-menu-item" ) + .removeClass( "ui-menu-item" ) + .removeAttr( "role" ) + .removeAttr( "aria-disabled" ) + .removeUniqueId() + .removeClass( "ui-state-hover" ) + .removeAttr( "tabIndex" ) + .removeAttr( "role" ) + .removeAttr( "aria-haspopup" ) + .children().each( function() { + var elem = $( this ); + if ( elem.data( "ui-menu-submenu-carat" ) ) { + elem.remove(); + } + }); + + // Destroy menu dividers + this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" ); + }, + + _keydown: function( event ) { + var match, prev, character, skip, + preventDefault = true; + + switch ( event.keyCode ) { + case $.ui.keyCode.PAGE_UP: + this.previousPage( event ); + break; + case $.ui.keyCode.PAGE_DOWN: + this.nextPage( event ); + break; + case $.ui.keyCode.HOME: + this._move( "first", "first", event ); + break; + case $.ui.keyCode.END: + this._move( "last", "last", event ); + break; + case $.ui.keyCode.UP: + this.previous( event ); + break; + case $.ui.keyCode.DOWN: + this.next( event ); + break; + case $.ui.keyCode.LEFT: + this.collapse( event ); + break; + case $.ui.keyCode.RIGHT: + if ( this.active && !this.active.is( ".ui-state-disabled" ) ) { + this.expand( event ); + } + break; + case $.ui.keyCode.ENTER: + case $.ui.keyCode.SPACE: + this._activate( event ); + break; + case $.ui.keyCode.ESCAPE: + this.collapse( event ); + break; + default: + preventDefault = false; + prev = this.previousFilter || ""; + character = String.fromCharCode( event.keyCode ); + skip = false; + + clearTimeout( this.filterTimer ); + + if ( character === prev ) { + skip = true; + } else { + character = prev + character; + } + + match = this._filterMenuItems( character ); + match = skip && match.index( this.active.next() ) !== -1 ? + this.active.nextAll( ".ui-menu-item" ) : + match; + + // If no matches on the current filter, reset to the last character pressed + // to move down the menu to the first item that starts with that character + if ( !match.length ) { + character = String.fromCharCode( event.keyCode ); + match = this._filterMenuItems( character ); + } + + if ( match.length ) { + this.focus( event, match ); + this.previousFilter = character; + this.filterTimer = this._delay(function() { + delete this.previousFilter; + }, 1000 ); + } else { + delete this.previousFilter; + } + } + + if ( preventDefault ) { + event.preventDefault(); + } + }, + + _activate: function( event ) { + if ( !this.active.is( ".ui-state-disabled" ) ) { + if ( this.active.is( "[aria-haspopup='true']" ) ) { + this.expand( event ); + } else { + this.select( event ); + } + } + }, + + refresh: function() { + var menus, items, + that = this, + icon = this.options.icons.submenu, + submenus = this.element.find( this.options.menus ); + + this.element.toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length ); + + // Initialize nested menus + submenus.filter( ":not(.ui-menu)" ) + .addClass( "ui-menu ui-widget ui-widget-content ui-front" ) + .hide() + .attr({ + role: this.options.role, + "aria-hidden": "true", + "aria-expanded": "false" + }) + .each(function() { + var menu = $( this ), + item = menu.parent(), + submenuCarat = $( "" ) + .addClass( "ui-menu-icon ui-icon " + icon ) + .data( "ui-menu-submenu-carat", true ); + + item + .attr( "aria-haspopup", "true" ) + .prepend( submenuCarat ); + menu.attr( "aria-labelledby", item.attr( "id" ) ); + }); + + menus = submenus.add( this.element ); + items = menus.find( this.options.items ); + + // Initialize menu-items containing spaces and/or dashes only as dividers + items.not( ".ui-menu-item" ).each(function() { + var item = $( this ); + if ( that._isDivider( item ) ) { + item.addClass( "ui-widget-content ui-menu-divider" ); + } + }); + + // Don't refresh list items that are already adapted + items.not( ".ui-menu-item, .ui-menu-divider" ) + .addClass( "ui-menu-item" ) + .uniqueId() + .attr({ + tabIndex: -1, + role: this._itemRole() + }); + + // Add aria-disabled attribute to any disabled menu item + items.filter( ".ui-state-disabled" ).attr( "aria-disabled", "true" ); + + // If the active item has been removed, blur the menu + if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) { + this.blur(); + } + }, + + _itemRole: function() { + return { + menu: "menuitem", + listbox: "option" + }[ this.options.role ]; + }, + + _setOption: function( key, value ) { + if ( key === "icons" ) { + this.element.find( ".ui-menu-icon" ) + .removeClass( this.options.icons.submenu ) + .addClass( value.submenu ); + } + if ( key === "disabled" ) { + this.element + .toggleClass( "ui-state-disabled", !!value ) + .attr( "aria-disabled", value ); + } + this._super( key, value ); + }, + + focus: function( event, item ) { + var nested, focused; + this.blur( event, event && event.type === "focus" ); + + this._scrollIntoView( item ); + + this.active = item.first(); + focused = this.active.addClass( "ui-state-focus" ).removeClass( "ui-state-active" ); + // Only update aria-activedescendant if there's a role + // otherwise we assume focus is managed elsewhere + if ( this.options.role ) { + this.element.attr( "aria-activedescendant", focused.attr( "id" ) ); + } + + // Highlight active parent menu item, if any + this.active + .parent() + .closest( ".ui-menu-item" ) + .addClass( "ui-state-active" ); + + if ( event && event.type === "keydown" ) { + this._close(); + } else { + this.timer = this._delay(function() { + this._close(); + }, this.delay ); + } + + nested = item.children( ".ui-menu" ); + if ( nested.length && event && ( /^mouse/.test( event.type ) ) ) { + this._startOpening(nested); + } + this.activeMenu = item.parent(); + + this._trigger( "focus", event, { item: item } ); + }, + + _scrollIntoView: function( item ) { + var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight; + if ( this._hasScroll() ) { + borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0; + paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0; + offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop; + scroll = this.activeMenu.scrollTop(); + elementHeight = this.activeMenu.height(); + itemHeight = item.outerHeight(); + + if ( offset < 0 ) { + this.activeMenu.scrollTop( scroll + offset ); + } else if ( offset + itemHeight > elementHeight ) { + this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight ); + } + } + }, + + blur: function( event, fromFocus ) { + if ( !fromFocus ) { + clearTimeout( this.timer ); + } + + if ( !this.active ) { + return; + } + + this.active.removeClass( "ui-state-focus" ); + this.active = null; + + this._trigger( "blur", event, { item: this.active } ); + }, + + _startOpening: function( submenu ) { + clearTimeout( this.timer ); + + // Don't open if already open fixes a Firefox bug that caused a .5 pixel + // shift in the submenu position when mousing over the carat icon + if ( submenu.attr( "aria-hidden" ) !== "true" ) { + return; + } + + this.timer = this._delay(function() { + this._close(); + this._open( submenu ); + }, this.delay ); + }, + + _open: function( submenu ) { + var position = $.extend({ + of: this.active + }, this.options.position ); + + clearTimeout( this.timer ); + this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) ) + .hide() + .attr( "aria-hidden", "true" ); + + submenu + .show() + .removeAttr( "aria-hidden" ) + .attr( "aria-expanded", "true" ) + .position( position ); + }, + + collapseAll: function( event, all ) { + clearTimeout( this.timer ); + this.timer = this._delay(function() { + // If we were passed an event, look for the submenu that contains the event + var currentMenu = all ? this.element : + $( event && event.target ).closest( this.element.find( ".ui-menu" ) ); + + // If we found no valid submenu ancestor, use the main menu to close all sub menus anyway + if ( !currentMenu.length ) { + currentMenu = this.element; + } + + this._close( currentMenu ); + + this.blur( event ); + this.activeMenu = currentMenu; + }, this.delay ); + }, + + // With no arguments, closes the currently active menu - if nothing is active + // it closes all menus. If passed an argument, it will search for menus BELOW + _close: function( startMenu ) { + if ( !startMenu ) { + startMenu = this.active ? this.active.parent() : this.element; + } + + startMenu + .find( ".ui-menu" ) + .hide() + .attr( "aria-hidden", "true" ) + .attr( "aria-expanded", "false" ) + .end() + .find( ".ui-state-active" ).not( ".ui-state-focus" ) + .removeClass( "ui-state-active" ); + }, + + _closeOnDocumentClick: function( event ) { + return !$( event.target ).closest( ".ui-menu" ).length; + }, + + _isDivider: function( item ) { + + // Match hyphen, em dash, en dash + return !/[^\-\u2014\u2013\s]/.test( item.text() ); + }, + + collapse: function( event ) { + var newItem = this.active && + this.active.parent().closest( ".ui-menu-item", this.element ); + if ( newItem && newItem.length ) { + this._close(); + this.focus( event, newItem ); + } + }, + + expand: function( event ) { + var newItem = this.active && + this.active + .children( ".ui-menu " ) + .find( this.options.items ) + .first(); + + if ( newItem && newItem.length ) { + this._open( newItem.parent() ); + + // Delay so Firefox will not hide activedescendant change in expanding submenu from AT + this._delay(function() { + this.focus( event, newItem ); + }); + } + }, + + next: function( event ) { + this._move( "next", "first", event ); + }, + + previous: function( event ) { + this._move( "prev", "last", event ); + }, + + isFirstItem: function() { + return this.active && !this.active.prevAll( ".ui-menu-item" ).length; + }, + + isLastItem: function() { + return this.active && !this.active.nextAll( ".ui-menu-item" ).length; + }, + + _move: function( direction, filter, event ) { + var next; + if ( this.active ) { + if ( direction === "first" || direction === "last" ) { + next = this.active + [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" ) + .eq( -1 ); + } else { + next = this.active + [ direction + "All" ]( ".ui-menu-item" ) + .eq( 0 ); + } + } + if ( !next || !next.length || !this.active ) { + next = this.activeMenu.find( this.options.items )[ filter ](); + } + + this.focus( event, next ); + }, + + nextPage: function( event ) { + var item, base, height; + + if ( !this.active ) { + this.next( event ); + return; + } + if ( this.isLastItem() ) { + return; + } + if ( this._hasScroll() ) { + base = this.active.offset().top; + height = this.element.height(); + this.active.nextAll( ".ui-menu-item" ).each(function() { + item = $( this ); + return item.offset().top - base - height < 0; + }); + + this.focus( event, item ); + } else { + this.focus( event, this.activeMenu.find( this.options.items ) + [ !this.active ? "first" : "last" ]() ); + } + }, + + previousPage: function( event ) { + var item, base, height; + if ( !this.active ) { + this.next( event ); + return; + } + if ( this.isFirstItem() ) { + return; + } + if ( this._hasScroll() ) { + base = this.active.offset().top; + height = this.element.height(); + this.active.prevAll( ".ui-menu-item" ).each(function() { + item = $( this ); + return item.offset().top - base + height > 0; + }); + + this.focus( event, item ); + } else { + this.focus( event, this.activeMenu.find( this.options.items ).first() ); + } + }, + + _hasScroll: function() { + return this.element.outerHeight() < this.element.prop( "scrollHeight" ); + }, + + select: function( event ) { + // TODO: It should never be possible to not have an active item at this + // point, but the tests don't trigger mouseenter before click. + this.active = this.active || $( event.target ).closest( ".ui-menu-item" ); + var ui = { item: this.active }; + if ( !this.active.has( ".ui-menu" ).length ) { + this.collapseAll( event, true ); + } + this._trigger( "select", event, ui ); + }, + + _filterMenuItems: function(character) { + var escapedCharacter = character.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" ), + regex = new RegExp( "^" + escapedCharacter, "i" ); + + return this.activeMenu + .find( this.options.items ) + + // Only match on items, not dividers or other content (#10571) + .filter( ".ui-menu-item" ) + .filter(function() { + return regex.test( $.trim( $( this ).text() ) ); + }); + } +}); + + +/*! + * jQuery UI Autocomplete 1.11.4 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + * + * http://api.jqueryui.com/autocomplete/ + */ + + +$.widget( "ui.autocomplete", { + version: "1.11.4", + defaultElement: "", + options: { + appendTo: null, + autoFocus: false, + delay: 300, + minLength: 1, + position: { + my: "left top", + at: "left bottom", + collision: "none" + }, + source: null, + + // callbacks + change: null, + close: null, + focus: null, + open: null, + response: null, + search: null, + select: null + }, + + requestIndex: 0, + pending: 0, + + _create: function() { + // Some browsers only repeat keydown events, not keypress events, + // so we use the suppressKeyPress flag to determine if we've already + // handled the keydown event. #7269 + // Unfortunately the code for & in keypress is the same as the up arrow, + // so we use the suppressKeyPressRepeat flag to avoid handling keypress + // events when we know the keydown event was used to modify the + // search term. #7799 + var suppressKeyPress, suppressKeyPressRepeat, suppressInput, + nodeName = this.element[ 0 ].nodeName.toLowerCase(), + isTextarea = nodeName === "textarea", + isInput = nodeName === "input"; + + this.isMultiLine = + // Textareas are always multi-line + isTextarea ? true : + // Inputs are always single-line, even if inside a contentEditable element + // IE also treats inputs as contentEditable + isInput ? false : + // All other element types are determined by whether or not they're contentEditable + this.element.prop( "isContentEditable" ); + + this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ]; + this.isNewMenu = true; + + this.element + .addClass( "ui-autocomplete-input" ) + .attr( "autocomplete", "off" ); + + this._on( this.element, { + keydown: function( event ) { + if ( this.element.prop( "readOnly" ) ) { + suppressKeyPress = true; + suppressInput = true; + suppressKeyPressRepeat = true; + return; + } + + suppressKeyPress = false; + suppressInput = false; + suppressKeyPressRepeat = false; + var keyCode = $.ui.keyCode; + switch ( event.keyCode ) { + case keyCode.PAGE_UP: + suppressKeyPress = true; + this._move( "previousPage", event ); + break; + case keyCode.PAGE_DOWN: + suppressKeyPress = true; + this._move( "nextPage", event ); + break; + case keyCode.UP: + suppressKeyPress = true; + this._keyEvent( "previous", event ); + break; + case keyCode.DOWN: + suppressKeyPress = true; + this._keyEvent( "next", event ); + break; + case keyCode.ENTER: + // when menu is open and has focus + if ( this.menu.active ) { + // #6055 - Opera still allows the keypress to occur + // which causes forms to submit + suppressKeyPress = true; + event.preventDefault(); + this.menu.select( event ); + } + break; + case keyCode.TAB: + if ( this.menu.active ) { + this.menu.select( event ); + } + break; + case keyCode.ESCAPE: + if ( this.menu.element.is( ":visible" ) ) { + if ( !this.isMultiLine ) { + this._value( this.term ); + } + this.close( event ); + // Different browsers have different default behavior for escape + // Single press can mean undo or clear + // Double press in IE means clear the whole form + event.preventDefault(); + } + break; + default: + suppressKeyPressRepeat = true; + // search timeout should be triggered before the input value is changed + this._searchTimeout( event ); + break; + } + }, + keypress: function( event ) { + if ( suppressKeyPress ) { + suppressKeyPress = false; + if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) { + event.preventDefault(); + } + return; + } + if ( suppressKeyPressRepeat ) { + return; + } + + // replicate some key handlers to allow them to repeat in Firefox and Opera + var keyCode = $.ui.keyCode; + switch ( event.keyCode ) { + case keyCode.PAGE_UP: + this._move( "previousPage", event ); + break; + case keyCode.PAGE_DOWN: + this._move( "nextPage", event ); + break; + case keyCode.UP: + this._keyEvent( "previous", event ); + break; + case keyCode.DOWN: + this._keyEvent( "next", event ); + break; + } + }, + input: function( event ) { + if ( suppressInput ) { + suppressInput = false; + event.preventDefault(); + return; + } + this._searchTimeout( event ); + }, + focus: function() { + this.selectedItem = null; + this.previous = this._value(); + }, + blur: function( event ) { + if ( this.cancelBlur ) { + delete this.cancelBlur; + return; + } + + clearTimeout( this.searching ); + this.close( event ); + this._change( event ); + } + }); + + this._initSource(); + this.menu = $( "
      " ) + .addClass( "ui-autocomplete ui-front" ) + .appendTo( this._appendTo() ) + .menu({ + // disable ARIA support, the live region takes care of that + role: null + }) + .hide() + .menu( "instance" ); + + this._on( this.menu.element, { + mousedown: function( event ) { + // prevent moving focus out of the text field + event.preventDefault(); + + // IE doesn't prevent moving focus even with event.preventDefault() + // so we set a flag to know when we should ignore the blur event + this.cancelBlur = true; + this._delay(function() { + delete this.cancelBlur; + }); + + // clicking on the scrollbar causes focus to shift to the body + // but we can't detect a mouseup or a click immediately afterward + // so we have to track the next mousedown and close the menu if + // the user clicks somewhere outside of the autocomplete + var menuElement = this.menu.element[ 0 ]; + if ( !$( event.target ).closest( ".ui-menu-item" ).length ) { + this._delay(function() { + var that = this; + this.document.one( "mousedown", function( event ) { + if ( event.target !== that.element[ 0 ] && + event.target !== menuElement && + !$.contains( menuElement, event.target ) ) { + that.close(); + } + }); + }); + } + }, + menufocus: function( event, ui ) { + var label, item; + // support: Firefox + // Prevent accidental activation of menu items in Firefox (#7024 #9118) + if ( this.isNewMenu ) { + this.isNewMenu = false; + if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) { + this.menu.blur(); + + this.document.one( "mousemove", function() { + $( event.target ).trigger( event.originalEvent ); + }); + + return; + } + } + + item = ui.item.data( "ui-autocomplete-item" ); + if ( false !== this._trigger( "focus", event, { item: item } ) ) { + // use value to match what will end up in the input, if it was a key event + if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) { + this._value( item.value ); + } + } + + // Announce the value in the liveRegion + label = ui.item.attr( "aria-label" ) || item.value; + if ( label && $.trim( label ).length ) { + this.liveRegion.children().hide(); + $( "
      " ).text( label ).appendTo( this.liveRegion ); + } + }, + menuselect: function( event, ui ) { + var item = ui.item.data( "ui-autocomplete-item" ), + previous = this.previous; + + // only trigger when focus was lost (click on menu) + if ( this.element[ 0 ] !== this.document[ 0 ].activeElement ) { + this.element.focus(); + this.previous = previous; + // #6109 - IE triggers two focus events and the second + // is asynchronous, so we need to reset the previous + // term synchronously and asynchronously :-( + this._delay(function() { + this.previous = previous; + this.selectedItem = item; + }); + } + + if ( false !== this._trigger( "select", event, { item: item } ) ) { + this._value( item.value ); + } + // reset the term after the select event + // this allows custom select handling to work properly + this.term = this._value(); + + this.close( event ); + this.selectedItem = item; + } + }); + + this.liveRegion = $( "", { + role: "status", + "aria-live": "assertive", + "aria-relevant": "additions" + }) + .addClass( "ui-helper-hidden-accessible" ) + .appendTo( this.document[ 0 ].body ); + + // turning off autocomplete prevents the browser from remembering the + // value when navigating through history, so we re-enable autocomplete + // if the page is unloaded before the widget is destroyed. #7790 + this._on( this.window, { + beforeunload: function() { + this.element.removeAttr( "autocomplete" ); + } + }); + }, + + _destroy: function() { + clearTimeout( this.searching ); + this.element + .removeClass( "ui-autocomplete-input" ) + .removeAttr( "autocomplete" ); + this.menu.element.remove(); + this.liveRegion.remove(); + }, + + _setOption: function( key, value ) { + this._super( key, value ); + if ( key === "source" ) { + this._initSource(); + } + if ( key === "appendTo" ) { + this.menu.element.appendTo( this._appendTo() ); + } + if ( key === "disabled" && value && this.xhr ) { + this.xhr.abort(); + } + }, + + _appendTo: function() { + var element = this.options.appendTo; + + if ( element ) { + element = element.jquery || element.nodeType ? + $( element ) : + this.document.find( element ).eq( 0 ); + } + + if ( !element || !element[ 0 ] ) { + element = this.element.closest( ".ui-front" ); + } + + if ( !element.length ) { + element = this.document[ 0 ].body; + } + + return element; + }, + + _initSource: function() { + var array, url, + that = this; + if ( $.isArray( this.options.source ) ) { + array = this.options.source; + this.source = function( request, response ) { + response( $.ui.autocomplete.filter( array, request.term ) ); + }; + } else if ( typeof this.options.source === "string" ) { + url = this.options.source; + this.source = function( request, response ) { + if ( that.xhr ) { + that.xhr.abort(); + } + that.xhr = $.ajax({ + url: url, + data: request, + dataType: "json", + success: function( data ) { + response( data ); + }, + error: function() { + response([]); + } + }); + }; + } else { + this.source = this.options.source; + } + }, + + _searchTimeout: function( event ) { + clearTimeout( this.searching ); + this.searching = this._delay(function() { + + // Search if the value has changed, or if the user retypes the same value (see #7434) + var equalValues = this.term === this._value(), + menuVisible = this.menu.element.is( ":visible" ), + modifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey; + + if ( !equalValues || ( equalValues && !menuVisible && !modifierKey ) ) { + this.selectedItem = null; + this.search( null, event ); + } + }, this.options.delay ); + }, + + search: function( value, event ) { + value = value != null ? value : this._value(); + + // always save the actual value, not the one passed as an argument + this.term = this._value(); + + if ( value.length < this.options.minLength ) { + return this.close( event ); + } + + if ( this._trigger( "search", event ) === false ) { + return; + } + + return this._search( value ); + }, + + _search: function( value ) { + this.pending++; + this.element.addClass( "ui-autocomplete-loading" ); + this.cancelSearch = false; + + this.source( { term: value }, this._response() ); + }, + + _response: function() { + var index = ++this.requestIndex; + + return $.proxy(function( content ) { + if ( index === this.requestIndex ) { + this.__response( content ); + } + + this.pending--; + if ( !this.pending ) { + this.element.removeClass( "ui-autocomplete-loading" ); + } + }, this ); + }, + + __response: function( content ) { + if ( content ) { + content = this._normalize( content ); + } + this._trigger( "response", null, { content: content } ); + if ( !this.options.disabled && content && content.length && !this.cancelSearch ) { + this._suggest( content ); + this._trigger( "open" ); + } else { + // use ._close() instead of .close() so we don't cancel future searches + this._close(); + } + }, + + close: function( event ) { + this.cancelSearch = true; + this._close( event ); + }, + + _close: function( event ) { + if ( this.menu.element.is( ":visible" ) ) { + this.menu.element.hide(); + this.menu.blur(); + this.isNewMenu = true; + this._trigger( "close", event ); + } + }, + + _change: function( event ) { + if ( this.previous !== this._value() ) { + this._trigger( "change", event, { item: this.selectedItem } ); + } + }, + + _normalize: function( items ) { + // assume all items have the right format when the first item is complete + if ( items.length && items[ 0 ].label && items[ 0 ].value ) { + return items; + } + return $.map( items, function( item ) { + if ( typeof item === "string" ) { + return { + label: item, + value: item + }; + } + return $.extend( {}, item, { + label: item.label || item.value, + value: item.value || item.label + }); + }); + }, + + _suggest: function( items ) { + var ul = this.menu.element.empty(); + this._renderMenu( ul, items ); + this.isNewMenu = true; + this.menu.refresh(); + + // size and position menu + ul.show(); + this._resizeMenu(); + ul.position( $.extend({ + of: this.element + }, this.options.position ) ); + + if ( this.options.autoFocus ) { + this.menu.next(); + } + }, + + _resizeMenu: function() { + var ul = this.menu.element; + ul.outerWidth( Math.max( + // Firefox wraps long text (possibly a rounding bug) + // so we add 1px to avoid the wrapping (#7513) + ul.width( "" ).outerWidth() + 1, + this.element.outerWidth() + ) ); + }, + + _renderMenu: function( ul, items ) { + var that = this; + $.each( items, function( index, item ) { + that._renderItemData( ul, item ); + }); + }, + + _renderItemData: function( ul, item ) { + return this._renderItem( ul, item ).data( "ui-autocomplete-item", item ); + }, + + _renderItem: function( ul, item ) { + return $( "
    • " ).text( item.label ).appendTo( ul ); + }, + + _move: function( direction, event ) { + if ( !this.menu.element.is( ":visible" ) ) { + this.search( null, event ); + return; + } + if ( this.menu.isFirstItem() && /^previous/.test( direction ) || + this.menu.isLastItem() && /^next/.test( direction ) ) { + + if ( !this.isMultiLine ) { + this._value( this.term ); + } + + this.menu.blur(); + return; + } + this.menu[ direction ]( event ); + }, + + widget: function() { + return this.menu.element; + }, + + _value: function() { + return this.valueMethod.apply( this.element, arguments ); + }, + + _keyEvent: function( keyEvent, event ) { + if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) { + this._move( keyEvent, event ); + + // prevents moving cursor to beginning/end of the text field in some browsers + event.preventDefault(); + } + } +}); + +$.extend( $.ui.autocomplete, { + escapeRegex: function( value ) { + return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" ); + }, + filter: function( array, term ) { + var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" ); + return $.grep( array, function( value ) { + return matcher.test( value.label || value.value || value ); + }); + } +}); + +// live region extension, adding a `messages` option +// NOTE: This is an experimental API. We are still investigating +// a full solution for string manipulation and internationalization. +$.widget( "ui.autocomplete", $.ui.autocomplete, { + options: { + messages: { + noResults: "No search results.", + results: function( amount ) { + return amount + ( amount > 1 ? " results are" : " result is" ) + + " available, use up and down arrow keys to navigate."; + } + } + }, + + __response: function( content ) { + var message; + this._superApply( arguments ); + if ( this.options.disabled || this.cancelSearch ) { + return; + } + if ( content && content.length ) { + message = this.options.messages.results( content.length ); + } else { + message = this.options.messages.noResults; + } + this.liveRegion.children().hide(); + $( "
      " ).text( message ).appendTo( this.liveRegion ); + } +}); + +var autocomplete = $.ui.autocomplete; + + + +})); \ No newline at end of file From 9f7206d114d3dab4ce97831862c028f8d52a46f7 Mon Sep 17 00:00:00 2001 From: esp Date: Mon, 10 Aug 2015 21:05:55 +0800 Subject: [PATCH 99/99] =?UTF-8?q?[=E5=89=8D=E7=AB=AF]=20=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E4=BA=86=E6=B7=BB=E5=8A=A0=E9=A2=98=E7=9B=AE=E7=9A=84=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2[CI=20SKIP]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/js/app/admin/problem/add_problem.js | 146 ++++++++++++++---- template/admin/problem/add_problem.html | 6 +- 2 files changed, 116 insertions(+), 36 deletions(-) diff --git a/static/src/js/app/admin/problem/add_problem.js b/static/src/js/app/admin/problem/add_problem.js index 09862d3..8213ad5 100644 --- a/static/src/js/app/admin/problem/add_problem.js +++ b/static/src/js/app/admin/problem/add_problem.js @@ -1,5 +1,5 @@ -require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "validation"], - function ($, avalon, editor, uploader, bs_alert) { +require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEditor", "validation", "jqueryUI"], + function ($, avalon, editor, uploader, bs_alert, csrfHeader) { avalon.vmodels.add_problem = null; $("#add-problem-form") .formValidation({ @@ -17,17 +17,10 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val } } }, - description:{ - validators: { - notEmpty: { - message: "请输入描述" - } - } - }, cpu: { validators: { notEmpty: { - message: "请输入cpu时间" + message: "请输入时间限制" }, integer: { message: "请输入一个合法的数字" @@ -43,52 +36,121 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val memory: { validators: { notEmpty: { - message: "请输入内存" + message: "请输入内存限制" }, integer: { message: "请输入一个合法的数字" } } + }, + difficulty: { + validators: { + notEmpty: { + message: "请输入难度" + }, + integer: { + message: "难度用一个整数表示" + } + } + }, + source: { + validators: { + notEmpty: { + message: "请输入题目来源" + } + } } } }) .on("success.form.fv", function (e) { e.preventDefault(); + if (vm.test_case_id == '') + { + bs_alert("你还没有上传测试数据!"); + return; + } + if (vm.description == '') + { + bs_alert("题目描述不能为空!"); + return; + } + if (vm.hint == '') + { + bs_alert("提示不能为空!"); + return; + } var ajaxData = { title: vm.title, description: vm.description, - cpu: vm.cpu, - memory: vm.memory, - samples: [] + time_limit: vm.cpu, + memory_limit: vm.memory, + samples: [], + test_case_id: vm.test_case_id, + hint: vm.hint, + source: vm.source, + tags: [], + difficulty: vm.difficulty }; - - for (var i = 0; i < vm.samples.length; i++) { - ajaxData.samples.push({input: vm.samples[i].input, output: vm.samples[i].output}); + if (vm.samples.length == 0) + { + bs_alert("请至少添加一组样例!"); + return; + } + var tags = $("#tags").tagEditor("getTags")[0].tags; + if (tags.length == 0) + { + bs_alert("请至少添加一个标签,这将有利于用户发现你的题目!"); + return; + } + for (key in vm.samples.length) { + ajaxData.samples.push({input: vm.samples[key].input, output: vm.samples[key].output}); + } + for (key in tags) { + ajaxData.tags.push(tags[key].tag); } console.log(ajaxData); + $.ajax({ + beforeSend: csrfHeader, + url: "/api/admin/problem/", + dataType: "json", + data:ajaxData, + method: "post", + success: function (data) { + if (!data.code) { + bs_alert("successful!"); + console.log(data); + } + else { + bs_alert(data.data); + } + } + + }) }); var problemDiscription = editor("#problemDescription"); - var testCaseUploader = uploader("#testCaseFile", "/api/admin/test_case_upload/",function(file, respond){ + var testCaseUploader = uploader("#testCaseFile", "/api/admin/test_case_upload/", function (file, respond) { if (respond.code) bs_alert(respond.data); - else{ + else { vm.test_case_id = respond.data.test_case_id; vm.uploadSuccess = true; vm.testCaseList = []; - for (var i = 0; i < respond.data.file_list.input.length; i++) - { - vm.testCaseList.push({input: respond.data.file_list.input[i], output: respond.data.file_list.output[i]}); + for (var i = 0; i < respond.data.file_list.input.length; i++) { + vm.testCaseList.push({ + input: respond.data.file_list.input[i], + output: respond.data.file_list.output[i] + }); } } }); var hinteditor = editor("#hint"); - $("#tags").tagEditor(); + var tagList = [], completeList = []; var vm = avalon.define({ $id: "add_problem", title: "", description: "", - cpu: 0, - memory: 0, + cpu: 1000, + memory: 256, samples: [], hint: "", visible: false, @@ -99,14 +161,6 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val testCaseList: [], uploadSuccess: false, source: "", - checkTag: function () { - alert("11"); - if (event.keyCode == 13) - { - alert("You press the enter key!"); - return false; - } - }, add_sample: function () { vm.samples.push({input: "", output: "", "visible": true}); }, @@ -125,5 +179,31 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val } }); + $.ajax({ + beforeSend: csrfHeader, + url: "/api/admin/tag/", + dataType: "json", + method: "get", + success: function (data) { + if (!data.code) { + tagList = data.data; + completeList = []; + for (key in tagList) { + completeList.push(tagList[key].name); + } + $("#tags").tagEditor({ + autocomplete: { + delay: 0, // show suggestions immediately + position: {collision: 'flip'}, // automatic menu position up/down + source: completeList + } + }); + } + else { + bs_alert(data.data); + } + } + + }); avalon.scan(); }); \ No newline at end of file diff --git a/template/admin/problem/add_problem.html b/template/admin/problem/add_problem.html index 1c78a9e..d039302 100644 --- a/template/admin/problem/add_problem.html +++ b/template/admin/problem/add_problem.html @@ -20,12 +20,12 @@
      -
      +
      -
      +
      @@ -42,7 +42,7 @@

      - +