mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: add selectUser api
This commit is contained in:
1 parent
c4440be61d
commit
0facd0b433
4 files changed
+57
-81
No files matched your search
@@ -1,9 +1,7 @@
|
||||
import $ from 'jquery';
|
||||
import Slideout from 'slideout';
|
||||
import UserSelectAutoComplete from 'vj/components/autocomplete/UserSelectAutoComplete';
|
||||
import { ActionDialog } from 'vj/components/dialog';
|
||||
import createHint from 'vj/components/hint';
|
||||
import Notification from 'vj/components/notification';
|
||||
import selectUser from 'vj/components/selectUser';
|
||||
import { AutoloadPage } from 'vj/misc/Page';
|
||||
import i18n from 'vj/utils/i18n';
|
||||
import request from 'vj/utils/request';
|
||||
@@ -17,46 +15,16 @@ function handleNavLogoutClick(ev) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
function handlerSwitchAccount(ev) {
|
||||
let userSelector;
|
||||
const promise = new ActionDialog({
|
||||
$body: tpl`
|
||||
<div>
|
||||
<div class="row"><div class="columns">
|
||||
<h1 name="select_user_text">${i18n('Select User')}</h1>
|
||||
</div></div>
|
||||
<div class="row">
|
||||
<div class="columns">
|
||||
<label>
|
||||
${i18n('Username / UID')}
|
||||
<input name="switch_account_target" type="text" class="textbox" autocomplete="off" data-autofocus>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
onDispatch(action) {
|
||||
if (action === 'ok' && userSelector.value() === null) {
|
||||
userSelector.focus();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}).open();
|
||||
userSelector = UserSelectAutoComplete.getOrConstruct($('[name="switch_account_target"]'));
|
||||
createHint('Hint::icon::switch_account', $('[name="select_user_text"]'));
|
||||
promise.then(async (action) => {
|
||||
if (action !== 'ok') return;
|
||||
const target = userSelector.value();
|
||||
if (!target) return;
|
||||
try {
|
||||
await request.get('/account', { uid: target._id });
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
Notification.error(error.message);
|
||||
}
|
||||
});
|
||||
async function handlerSwitchAccount(ev) {
|
||||
ev.preventDefault();
|
||||
const target = await selectUser('Hint::icon::switch_account');
|
||||
if (!target) return;
|
||||
try {
|
||||
await request.get('/account', { uid: target._id });
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
Notification.error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
let $trigger;
|
||||
|
||||
Reference in new issue
Block a user