[前端]修复问题管理(后台)页面的avalon重复定义的问题[CI SKIP]

This commit is contained in:
esp
2015-08-24 18:39:11 +08:00
parent 53e82136e4
commit 2ed22c3bce
3 changed files with 76 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "jqueryUI"], require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "jqueryUI"],
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) { function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
avalon.ready(function () { avalon.ready(function () {
avalon.vmodels.addProblem = null;
$("#add-problem-form").validator() $("#add-problem-form").validator()
.on('submit', function (e) { .on('submit', function (e) {
if (!e.isDefaultPrevented()){ if (!e.isDefaultPrevented()){
@@ -63,6 +63,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
bsAlert("题目添加成功!"); bsAlert("题目添加成功!");
location.hash = "problem/problem_list";
} }
else { else {
bsAlert(data.data); bsAlert(data.data);
@@ -92,41 +93,61 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
var hintEditor = editor("#hint"); var hintEditor = editor("#hint");
var problemDescription = editor("#problemDescription"); var problemDescription = editor("#problemDescription");
if (avalon.vmodels.addProblem) {
var vm = avalon.define({ var vm = avalon.vmodels.addProblem;
$id: "addProblem", vm.title = "";
title: "", vm.description = "";
description: "", vm.timeLimit = 1000;
timeLimit: 1000, vm.memoryLimit = 256;
memoryLimit: 256, vm.samples = [{input: "", output: "", "visible": true}];
samples: [{input: "", output: "", "visible": true}], vm.hint = "";
hint: "", vm.visible = true;
visible: true, vm.difficulty = 0;
difficulty: 0, vm.tags = [];
tags: [], vm.inputDescription = "";
inputDescription: "", vm.outputDescription = "";
outputDescription: "", vm.testCaseId = "";
testCaseId: "", vm.testCaseList = [];
testCaseList: [], vm.uploadSuccess = false;
uploadSuccess: false, vm.source = "";
source: "", hintEditor.setValue("");
addSample: function () { problemDescription.setValue("");
vm.samples.push({input: "", output: "", "visible": true}); }
}, else
delSample: function (sample) { var vm = avalon.define({
if (confirm("你确定要删除么?")) { $id: "addProblem",
vm.samples.remove(sample); title: "",
description: "",
timeLimit: 1000,
memoryLimit: 256,
samples: [{input: "", output: "", "visible": true}],
hint: "",
visible: true,
difficulty: 0,
tags: [],
inputDescription: "",
outputDescription: "",
testCaseId: "",
testCaseList: [],
uploadSuccess: false,
source: "",
addSample: function () {
vm.samples.push({input: "", output: "", "visible": true});
},
delSample: function (sample) {
if (confirm("你确定要删除么?")) {
vm.samples.remove(sample);
}
},
toggleSample: function (sample) {
sample.visible = !sample.visible;
},
getBtnContent: function (item) {
if (item.visible)
return "折叠";
return "展开";
} }
}, });
toggleSample: function (sample) {
sample.visible = !sample.visible;
},
getBtnContent: function (item) {
if (item.visible)
return "折叠";
return "展开";
}
});
var tagAutoCompleteList = []; var tagAutoCompleteList = [];

View File

@@ -2,7 +2,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) { function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
avalon.ready(function () { avalon.ready(function () {
avalon.vmodels.editProblem = null;
$("#edit-problem-form").validator() $("#edit-problem-form").validator()
.on('submit', function (e) { .on('submit', function (e) {
@@ -65,6 +64,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
bsAlert("题目编辑成功!"); bsAlert("题目编辑成功!");
vm.showProblemListPage();
} }
else { else {
bsAlert(data.data); bsAlert(data.data);
@@ -75,7 +75,24 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
return false; return false;
} }
}); });
if (avalon.vmodels.editProblem) {
var vm = avalon.vmodels.editProblem;
title: "",
description= "";
timeLimit= -1;
memoryLimit= -1;
samples= [];
hint= "";
visible= true;
difficulty= 0;
inputDescription= "";
outputDescription= "";
testCaseIdd= "";
uploadSuccess= false;
source= "";
testCaseList= [];
}
else
var vm = avalon.define({ var vm = avalon.define({
$id: "editProblem", $id: "editProblem",
title: "", title: "",

View File

@@ -41,10 +41,8 @@ require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfT
vm.$fire("up!showProblemSubmissionPage", problemId); vm.$fire("up!showProblemSubmissionPage", problemId);
} }
}); });
getPageData(1);
} }
getPageData(1);
function getPageData(page) { function getPageData(page) {
var url = "/api/admin/problem/?paging=true&page=" + page + "&page_size=10"; var url = "/api/admin/problem/?paging=true&page=" + page + "&page_size=10";
if (vm.keyword != "") if (vm.keyword != "")