-
-
Notifications
You must be signed in to change notification settings - Fork 470
Expand file tree
/
Copy pathcontest_manage.page.ts
More file actions
54 lines (52 loc) · 1.73 KB
/
Copy pathcontest_manage.page.ts
File metadata and controls
54 lines (52 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import $ from 'jquery';
import { ActionDialog } from 'vj/components/dialog';
import Notification from 'vj/components/notification';
import { NamedPage } from 'vj/misc/Page';
import { i18n, request, tpl } from 'vj/utils';
const page = new NamedPage('contest_manage', () => {
$(document).on('click', '[name="set_score"]', async (ev) => {
const pid = $(ev.currentTarget).data('pid');
const op = await new ActionDialog({
$body: tpl`
<div class="row"><div class="columns">
<h1>${i18n('Set Score for Contest')}</h1>
</div></div>
<div class="row"><div class="columns">
<label>
${i18n('score')}
<div class="textbox-container">
<input class="textbox" type="number" step="1" name="score" data-autofocus value="${$(ev.currentTarget).data('score')}"></input>
</div>
</label>
</div></div>
`,
onDispatch(action) {
if (action === 'ok' && $('[name="score"]').val() === null) {
$('[name="score"]').focus();
return false;
}
if (!Number.isFinite(+$('[name="score"]').val()) || +$('[name="score"]').val() <= 0) {
Notification.error('Invalid score');
return false;
}
return true;
},
}).open();
if (op !== 'ok') return;
try {
const res = await request.post('', {
operation: 'set_score',
pid,
score: $('[name="score"]').val(),
});
if (!res.error) {
Notification.success('Score Updated');
$(ev.currentTarget).text($('[name="score"]').val() as number);
$(ev.currentTarget).data('score', $('[name="score"]').val());
}
} catch (e) {
Notification.error(e.message);
}
});
});
export default page;