diff --git a/static/src/js/app/admin/announcement/announcement.js b/static/src/js/app/admin/announcement/announcement.js index 13db292..c4eebf6 100644 --- a/static/src/js/app/admin/announcement/announcement.js +++ b/static/src/js/app/admin/announcement/announcement.js @@ -1,4 +1,4 @@ -require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "formValidation"], +require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator"], function ($, avalon, csrfTokenHeader, bsAlert, editor) { @@ -122,26 +122,15 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "formValidation"] } //新建公告表单验证与数据提交 - $("#announcement-form") - .formValidation({ - framework: "bootstrap", - fields: { - title: { - validators: { - notEmpty: { - message: "请填写公告标题" - } - } - } - } - } - ).on('success.form.fv', function (e) { - e.preventDefault(); + + + $('form').validator().on('submit', function (e) { + if (!e.isDefaultPrevented()) { var title = $("#title").val(); var content = createAnnouncementEditor.getValue(); if (content == "") { bsAlert("请填写公告内容"); - return; + return false; } $.ajax({ beforeSend: csrfTokenHeader, @@ -156,11 +145,13 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "formValidation"] createAnnouncementEditor.setValue(""); getPageData(1); } else { - bs_alert(data.data); + bsAlert(data.data); } } }) - }); + return false; + } + }) }); avalon.scan(); }); \ No newline at end of file diff --git a/static/src/js/app/admin/group/group.js b/static/src/js/app/admin/group/group.js index b4b3117..470f9ca 100644 --- a/static/src/js/app/admin/group/group.js +++ b/static/src/js/app/admin/group/group.js @@ -1,4 +1,4 @@ -require(["jquery", "avalon", "csrfToken", "bsAlert", "formValidation"], function ($, avalon, csrfTokenHeader, bsAlert) { +require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfTokenHeader, bsAlert) { avalon.ready(function () { @@ -71,4 +71,4 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "formValidation"], function avalon.scan(); -}); \ No newline at end of file +}); diff --git a/static/src/js/app/admin/group/groupDetail.js b/static/src/js/app/admin/group/groupDetail.js index e622a16..cddc755 100644 --- a/static/src/js/app/admin/group/groupDetail.js +++ b/static/src/js/app/admin/group/groupDetail.js @@ -1,4 +1,4 @@ -require(["jquery", "avalon", "csrfToken", "bsAlert", "formValidation"], function ($, avalon, csrfTokenHeader, bsAlert) { +require(["jquery", "avalon", "csrfToken", "bsAlert", "validator"], function ($, avalon, csrfTokenHeader, bsAlert) { // avalon:定义模式 group_list @@ -93,58 +93,33 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "formValidation"], function } }); - $("#edit_group_form") - .formValidation({ - framework: "bootstrap", - fields: { - name: { - validators: { - notEmpty: { - message: "请填写小组名" - }, - stringLength: { - max: 20, - message: '小组名长度必须在20位之内' + $('form').validator().on('submit', function (e) { + if (!e.isDefaultPrevented()) { + + var group_id = avalon.vmodels.admin.groupId; + var name = vm.name; + var description = vm.description; + var join_group_setting = vm.checkedSetting; + + $.ajax({ + beforeSend: csrfTokenHeader, + url: "/api/admin/group/", + method: "put", + data: {group_id: group_id, name: name, description: description, + join_group_setting: join_group_setting}, + dataType: "json", + success: function (data) { + if (!data.code) { + bsAlert("修改成功"); + } + else { + bsAlert(data.data); } } - }, - description: { - validators: { - notEmpty: { - message: "请填写描述" - }, - stringLength: { - max: 300, - message: '描述长度必须在300位之内' - } - } - } + }); + return false; } - } - ).on('success.form.fv', function (e) { - e.preventDefault(); - var data = { - group_id: avalon.vmodels.admin.groupId, - name: vm.name, - description: vm.description, - join_group_setting: vm.checkedSetting - }; - $.ajax({ - beforeSend: csrfTokenHeader, - url: "/api/admin/group/", - method: "put", - data: data, - dataType: "json", - success: function (data) { - if (!data.code) { - bsAlert("修改成功"); - } - else { - bsAlert(data.data); - } - } - }) - }); + }) }); -}); \ No newline at end of file +}); diff --git a/static/src/js/app/admin/problem/add_problem.js b/static/src/js/app/admin/problem/add_problem.js index 4996f85..7331a8a 100644 --- a/static/src/js/app/admin/problem/add_problem.js +++ b/static/src/js/app/admin/problem/add_problem.js @@ -1,135 +1,76 @@ -require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "formValidation", "jqueryUI"], +require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "jqueryUI"], function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) { avalon.ready(function () { avalon.vmodels.addProblem = null; - $("#add-problem-form") - .formValidation({ - framework: "bootstrap", - fields: { - title: { - validators: { - notEmpty: { - message: "请填写题目名称" - }, - stringLength: { - min: 1, - max: 30, - message: "名称不能超过30个字" - } - } - }, - timeLimit: { - validators: { - notEmpty: { - message: "请输入时间限制" - }, - integer: { - message: "请输入一个合法的数字" - }, - between: { - inclusive: true, - min: 1, - max: 5000, - message: "只能在1-5000之间" - } - } - }, - memoryLimit: { - validators: { - notEmpty: { - message: "请输入内存限制" - }, - integer: { - message: "请输入一个合法的数字" - } - } - }, - difficulty: { - validators: { - notEmpty: { - message: "请输入难度" - }, - integer: { - message: "难度用一个整数表示" - } - } - }, - input_description: { - validators: { - notEmpty: { - message: "请填写输入描述" - } - } - }, - output_description: { - validators: { - notEmpty: { - message: "请填写输出描述" - } + $("#add-problem-form").validator() + .on('submit', function (e) { + if (!e.isDefaultPrevented()){ + if (vm.testCaseId == "") { + bsAlert("你还没有上传测试数据!"); + return false; + } + if (vm.description == "") { + bsAlert("题目描述不能为空!"); + return false; + } + if (vm.timeLimit < 1000 || vm.timeLimit > 5000) { + bsAlert("保证时间限制是一个1000-5000的合法整数"); + return false; + } + if (vm.samples.length == 0) { + bsAlert("请至少添加一组样例!"); + return false; + } + for (var i = 0; i < vm.samples.length; i++) { + if (vm.samples[i].input == "" || vm.samples[i].output == "") { + bsAlert("样例输入与样例输出不能为空!"); + return false; } } - } - }) - .on("success.form.fv", function (e) { - e.preventDefault(); - if (vm.testCaseId == "") { - bsAlert("你还没有上传测试数据!"); - return; - } - if (vm.description == "") { - bsAlert("题目描述不能为空!"); - return; - } - if (vm.samples.length == 0) { - bsAlert("请至少添加一组样例!"); - return; - } - for (var i = 0; i < vm.samples.length; i++) { - if (vm.samples[i].input == "" || vm.samples[i].output == "") { - bsAlert("样例输入与样例输出不能为空!"); - return; + var tags = $("#tags").tagEditor("getTags")[0].tags; + if (tags.length == 0) { + bsAlert("请至少添加一个标签,这将有利于用户发现你的题目!"); + return false; } - } - if (tags.length == 0) { - bsAlert("请至少添加一个标签,这将有利于用户发现你的题目!"); - return; - } - var ajaxData = { - title: vm.title, - description: vm.description, - time_limit: vm.timeLimit, - memory_limit: vm.memoryLimit, - samples: [], - test_case_id: vm.testCaseId, - hint: vm.hint, - source: vm.source, - tags: $("#tags").tagEditor("getTags")[0].tags, - input_description: vm.inputDescription, - output_description: vm.outputDescription, - difficulty: vm.difficulty - }; + var ajaxData = { + id: avalon.vmodels.admin.problemId, + title: vm.title, + description: vm.description, + time_limit: vm.timeLimit, + memory_limit: vm.memoryLimit, + samples: [], + test_case_id: vm.testCaseId, + hint: vm.hint, + source: vm.source, + visible: vm.visible, + tags: tags, + input_description: vm.inputDescription, + output_description: vm.outputDescription, + difficulty: vm.difficulty + }; - for (var i = 0; i < vm.samples.$model.length; i++) { - ajaxData.samples.push({input: vm.samples.$model[i].input, output: vm.samples.$model[i].output}); - } - - $.ajax({ - beforeSend: csrfTokenHeader, - url: "/api/admin/problem/", - dataType: "json", - data: JSON.stringify(ajaxData), - method: "post", - contentType: "application/json", - success: function (data) { - if (!data.code) { - bsAlert("题目添加成功!"); - } - else { - bsAlert(data.data); - } + for (var i = 0; i < vm.samples.$model.length; i++) { + ajaxData.samples.push({input: vm.samples.$model[i].input, output: vm.samples.$model[i].output}); } - }) + $.ajax({ + beforeSend: csrfTokenHeader, + url: "/api/admin/problem/", + dataType: "json", + data: JSON.stringify(ajaxData), + method: "post", + contentType: "application/json", + success: function (data) { + if (!data.code) { + bsAlert("题目添加成功!"); + } + else { + bsAlert(data.data); + } + } + }); + return false; + } }); var testCaseUploader = uploader("#testCaseFile", "/api/admin/test_case_upload/", function (file, response) { diff --git a/static/src/js/app/admin/problem/edit_problem.js b/static/src/js/app/admin/problem/edit_problem.js index 25462d1..26ab794 100644 --- a/static/src/js/app/admin/problem/edit_problem.js +++ b/static/src/js/app/admin/problem/edit_problem.js @@ -1,139 +1,79 @@ -require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "formValidation", "jqueryUI"], +require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "jqueryUI"], function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) { avalon.ready(function () { avalon.vmodels.editProblem = null; - $("#edit-problem-form") - .formValidation({ - framework: "bootstrap", - fields: { - title: { - validators: { - notEmpty: { - message: "请填写题目名称" - }, - stringLength: { - min: 1, - max: 30, - message: "名称不能超过30个字" - } - } - }, - cpu: { - validators: { - notEmpty: { - message: "请输入时间限制" - }, - integer: { - message: "请输入一个合法的数字" - }, - between: { - inclusive: true, - min: 1, - max: 5000, - message: "只能在1-5000之间" - } - } - }, - memory: { - validators: { - notEmpty: { - message: "请输入内存限制" - }, - integer: { - message: "请输入一个合法的数字" - } - } - }, - difficulty: { - validators: { - notEmpty: { - message: "请输入难度" - }, - integer: { - message: "难度用一个整数表示" - } - } - }, - input_description: { - validators: { - notEmpty: { - message: "请填写输入描述" - } - } - }, - output_description: { - validators: { - notEmpty: { - message: "请填写输出描述" - } + $("#edit-problem-form").validator() + .on('submit', function (e) { + if (!e.isDefaultPrevented()){ + if (vm.testCaseId == "") { + bsAlert("你还没有上传测试数据!"); + return false; + } + if (vm.description == "") { + bsAlert("题目描述不能为空!"); + return false; + } + if (vm.timeLimit < 1000 || vm.timeLimit > 5000) { + bsAlert("保证时间限制是一个1000-5000的合法整数"); + return false; + } + if (vm.samples.length == 0) { + bsAlert("请至少添加一组样例!"); + return false; + } + for (var i = 0; i < vm.samples.length; i++) { + if (vm.samples[i].input == "" || vm.samples[i].output == "") { + bsAlert("样例输入与样例输出不能为空!"); + return false; } } - } - }) - .on("success.form.fv", function (e) { - e.preventDefault(); - if (vm.testCaseId == "") { - bsAlert("你还没有上传测试数据!"); - return; - } - if (vm.description == "") { - bsAlert("题目描述不能为空!"); - return; - } - if (vm.samples.length == 0) { - bsAlert("请至少添加一组样例!"); - return; - } - for (var i = 0; i < vm.samples.length; i++) { - if (vm.samples[i].input == "" || vm.samples[i].output == "") { - bsAlert("样例输入与样例输出不能为空!"); - return; + var tags = $("#tags").tagEditor("getTags")[0].tags; + if (tags.length == 0) { + bsAlert("请至少添加一个标签,这将有利于用户发现你的题目!"); + return false; } - } - if (tags.length == 0) { - bsAlert("请至少添加一个标签,这将有利于用户发现你的题目!"); - return; - } - var ajaxData = { - id: avalon.vmodels.admin.problemId, - title: vm.title, - description: vm.description, - time_limit: vm.timeLimit, - memory_limit: vm.memoryLimit, - samples: [], - test_case_id: vm.testCaseId, - hint: vm.hint, - source: vm.source, - visible: vm.visible, - tags: $("#tags").tagEditor("getTags")[0].tags, - input_description: vm.inputDescription, - output_description: vm.outputDescription, - difficulty: vm.difficulty - }; + var ajaxData = { + id: avalon.vmodels.admin.problemId, + title: vm.title, + description: vm.description, + time_limit: vm.timeLimit, + memory_limit: vm.memoryLimit, + samples: [], + test_case_id: vm.testCaseId, + hint: vm.hint, + source: vm.source, + visible: vm.visible, + tags: tags, + input_description: vm.inputDescription, + output_description: vm.outputDescription, + difficulty: vm.difficulty + }; - for (var i = 0; i < vm.samples.$model.length; i++) { - ajaxData.samples.push({input: vm.samples.$model[i].input, output: vm.samples.$model[i].output}); - } - - $.ajax({ - beforeSend: csrfTokenHeader, - url: "/api/admin/problem/", - dataType: "json", - data: JSON.stringify(ajaxData), - method: "put", - contentType: "application/json", - success: function (data) { - if (!data.code) { - bsAlert("题目编辑成功!"); - } - else { - bsAlert(data.data); - } + for (var i = 0; i < vm.samples.$model.length; i++) { + ajaxData.samples.push({input: vm.samples.$model[i].input, output: vm.samples.$model[i].output}); } - }) + $.ajax({ + beforeSend: csrfTokenHeader, + url: "/api/admin/problem/", + dataType: "json", + data: JSON.stringify(ajaxData), + method: "put", + contentType: "application/json", + success: function (data) { + if (!data.code) { + bsAlert("题目编辑成功!"); + } + else { + bsAlert(data.data); + } + } + + }); + return false; + } }); var vm = avalon.define({ @@ -257,4 +197,4 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE }); avalon.scan(); - }); \ No newline at end of file + }); diff --git a/static/src/js/app/admin/problem/problem.js b/static/src/js/app/admin/problem/problem.js index d7e0739..cb1a0f0 100644 --- a/static/src/js/app/admin/problem/problem.js +++ b/static/src/js/app/admin/problem/problem.js @@ -1,4 +1,4 @@ -require(["jquery", "avalon", "csrfToken", "bsAlert", "formValidation"], function ($, avalon, csrfTokenHeader, bsAlert) { +require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfTokenHeader, bsAlert) { avalon.ready(function () { if(avalon.vmodels.problemList){ @@ -71,4 +71,4 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "formValidation"], function }); avalon.scan(); -}); \ No newline at end of file +}); diff --git a/static/src/js/app/admin/user/userList.js b/static/src/js/app/admin/user/userList.js index 277aa88..0842dc5 100644 --- a/static/src/js/app/admin/user/userList.js +++ b/static/src/js/app/admin/user/userList.js @@ -1,4 +1,4 @@ -require(["jquery", "avalon", "csrfToken", "bsAlert", "formValidation"], function ($, avalon, csrfTokenHeader, bsAlert) { +require(["jquery", "avalon", "csrfToken", "bsAlert", "validator"], function ($, avalon, csrfTokenHeader, bsAlert) { // avalon:定义模式 userList @@ -87,77 +87,36 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "formValidation"], function }); } - $("#edit_user-form") - .formValidation({ - framework: "bootstrap", - fields: { - username: { - validators: { - notEmpty: { - message: "请填写用户名" - }, - stringLength: { - min: 3, - max: 30, - message: '用户名长度必须在3到30位之间' + $("#edit_user-form").validator() + .on('submit', function (e) { + if (!e.isDefaultPrevented()) { + var data = { + username: vm.username, + real_name: vm.realName, + email: vm.email, + id: vm.id, + admin_type: vm.adminType + }; + if ($("#password").val() !== "") + data.password = $("#password").val(); + $.ajax({ + beforeSend: csrfTokenHeader, + url: "/api/admin/user/", + data: data, + dataType: "json", + method: "put", + success: function (data) { + if (!data.code) { + bsAlert("编辑成功!"); + getPageData(1); + $("#password").val(""); + } else { + bsAlert(data.data); } } - }, - real_name: { - validators: { - notEmpty: { - message: "请填写真实姓名" - } - } - }, - email: { - validators: { - notEmpty: { - message: "请填写电子邮箱邮箱地址" - }, - emailAddress: { - message: "请填写有效的邮箱地址" - } - } - }, - password: { - validators: { - stringLength: { - min: 6, - max: 30, - message: '密码长度必须在6到30位之间' - } - } - } + }); + return false; } - } - ).on('success.form.fv', function (e) { - e.preventDefault(); - var data = { - username: vm.username, - real_name: vm.realName, - email: vm.email, - id: vm.id, - admin_type: vm.adminType - }; - if ($("#password").val() !== "") - data.password = $("#password").val(); - $.ajax({ - beforeSend: csrfTokenHeader, - url: "/api/admin/user/", - data: data, - dataType: "json", - method: "put", - success: function (data) { - if (!data.code) { - bsAlert("提交成功!"); - getPageData(1); - $("#password").val(""); - } else { - bsAlert(data.data); - } - } - }) }); }); diff --git a/template/admin/announcement/announcement.html b/template/admin/announcement/announcement.html index 021cf29..5c0d4d9 100644 --- a/template/admin/announcement/announcement.html +++ b/template/admin/announcement/announcement.html @@ -53,11 +53,17 @@