Browse Source

Fix change contest type

pull/6/head
Menci 7 years ago
parent
commit
120d65b3b9
  1. 4
      modules/contest.js
  2. 6
      views/contest_edit.ejs

4
modules/contest.js

@ -89,6 +89,9 @@ app.post('/contest/:id/edit', async (req, res) => {
let ranklist = await ContestRanklist.create();
await ranklist.save();
contest.ranklist_id = ranklist.id;
// Only new contest can be set type
contest.type = req.body.type;
}
if (!req.body.title.trim()) throw new ErrorMessage('比赛名不能为空。');
@ -97,7 +100,6 @@ app.post('/contest/:id/edit', async (req, res) => {
if (!Array.isArray(req.body.problems)) req.body.problems = [req.body.problems];
contest.problems = req.body.problems.join('|');
if (!['noi', 'ioi', 'acm'].includes(req.body.type)) throw new ErrorMessage('无效的赛制。');
contest.type = req.body.type;
contest.information = req.body.information;
contest.start_time = syzoj.utils.parseDate(req.body.start_time);
contest.end_time = syzoj.utils.parseDate(req.body.end_time);

6
views/contest_edit.ejs

@ -22,19 +22,19 @@
<label>赛制</label>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="type" id="type-noi" value="noi"<% if (contest.type === 'noi') { %> checked="checked"<% } %>>
<input <% if (contest.id) { %>disabled <% } %>type="radio" name="type" id="type-noi" value="noi"<% if (contest.type === 'noi') { %> checked="checked"<% } %>>
<label for="type-noi">NOI</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="type" id="type-ioi" value="ioi"<% if (contest.type === 'ioi') { %> checked="checked"<% } %>>
<input <% if (contest.id) { %>disabled <% } %>type="radio" name="type" id="type-ioi" value="ioi"<% if (contest.type === 'ioi') { %> checked="checked"<% } %>>
<label for="type-ioi">IOI</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="type" id="type-acm" value="acm"<% if (contest.type === 'acm') { %> checked="checked"<% } %>>
<input <% if (contest.id) { %>disabled <% } %>type="radio" name="type" id="type-acm" value="acm"<% if (contest.type === 'acm') { %> checked="checked"<% } %>>
<label for="type-acm">ACM</label>
</div>
</div>

Loading…
Cancel
Save