ui: problem_copy

This commit is contained in:
undefined committed 2021-10-25 15:53:21 +08:00
1 parent 42b73f36a4
commit 0aba9f8215
6 files changed
+40 -10

No files matched your search

@@ -1,7 +1,9 @@
import { NamedPage } from 'vj/misc/Page';
import tpl from 'vj/utils/tpl';
import i18n from 'vj/utils/i18n';
import { ConfirmDialog } from 'vj/components/dialog';
import request from 'vj/utils/request';
import { ActionDialog, ConfirmDialog } from 'vj/components/dialog';
import Notification from 'vj/components/notification';
const page = new NamedPage([
'problem_create', 'problem_edit', 'problem_solution', 'problem_submit',
@@ -20,6 +22,33 @@ const page = new NamedPage([
$(ev.currentTarget).closest('form').trigger('submit');
});
});
$(document).on('click', '[name="problem-sidebar__copy"]', () => {
new ActionDialog({
$body: tpl`
<div class="typo">
<label>
${i18n('Target')}
<div class="textbox-container">
<input name="target" type="text" class="textbox" data-autofocus>
</div>
</label>
</div>
`,
}).open().then(async (action) => {
if (action !== 'ok') return;
const target = $('[name="target"]').val();
if (!target) return;
try {
const res = await request.post('', {
operation: 'copy',
target,
});
window.location.href = res.url;
} catch (error) {
Notification.error(error.message);
}
});
});
});
export default page;