Skip to content

Commit 724fe14

Browse files
Added bulk user deletion
1 parent 7ac838e commit 724fe14

File tree

4 files changed

+91
-45
lines changed

4 files changed

+91
-45
lines changed

src/controllers/UserController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@ public function actionUsersUpdate()
546546
$user->save();
547547
}
548548
Yii::$app->session->setFlash('success', Module::t('Statuses changed'));
549+
} else if ($action == 'Delete users') {
550+
foreach ($users as $user) {
551+
$user->delete();
552+
}
553+
Yii::$app->session->setFlash('success', Module::t('Users deleted'));
549554
} else {
550555
$cntSuccess = 0;
551556
$cntError = 0;

src/messages/ru/user.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
'Too many unsuccessful attempts. Please wait an hour before trying again.' => 'Слишком много неудачных попыток. Пожалуйста, подождите час перед следующей попыткой.',
7777
'Incorrect username or password.' => 'Неверное имя пользователя или пароль.',
7878
'Are you sure you want to delete this user?' => 'Вы уверены, что хотите удалить этого пользователя?',
79+
'Are you sure you want to delete the selected users?' => 'Вы уверены, что хотите удалить выбранных пользователей?',
80+
'Delete users' => 'Удалить пользователей',
81+
'Users deleted' => 'Пользователи удалены',
7982
'Roles Copied' => 'Роли скопированы',
8083
// actions
8184
'Create User' => 'Создать пользователя',
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use ZakharovAndrew\user\Module;
4+
use yii\helpers\Html;
5+
6+
$bootstrapVersion = Yii::$app->getModule('user')->bootstrapVersion;
7+
$classModal = "\\yii\bootstrap".($bootstrapVersion==3 ? '' : $bootstrapVersion)."\\Modal";
8+
$modalTitle = ($bootstrapVersion == 3 ? 'header' : 'title');
9+
?>
10+
11+
12+
<?php $classModal::begin([
13+
'id' => $id,
14+
$modalTitle => '<h2>'.Module::t($title).'</h2>',
15+
'footer' => ''
16+
]) ?>
17+
18+
<p style="text-align:center">
19+
<?= Module::t('Are you sure you want to reset the passwords for the selected users?') ?>
20+
</p>
21+
<div style="display:flex;justify-content: center;gap:4px;">
22+
<?= Html::submitButton(Module::t($action), ['name' => 'form-action', 'value' => $action, 'class' => 'btn btn-danger']) ?>
23+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" data-dismiss="modal"><?= Module::t('Cancel') ?></button>
24+
</div>
25+
26+
<?php $classModal::end() ?>

src/views/user/index.php

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ function loadCopiedUserId() {
295295
pointer-events: none;
296296
color: #898989;
297297
}
298+
#users tr:hover td {
299+
background-color:#e0f7fa;
300+
}
301+
298302
</style>
299303
<div class="user-index">
300304

@@ -308,39 +312,48 @@ function loadCopiedUserId() {
308312
<div id="selected-block">
309313
<p id="selected-count"></p>
310314
<?= $classButtonDropdown::widget([
311-
'label' => Module::t('Action'),
312-
'dropdown' => [
313-
'items' => [
314-
'<li>'. Html::a(Module::t('Change Status'), '#', [
315-
'class' => 'dropdown-item',
316-
'data' => [
317-
'toggle' => 'modal',
318-
'target' => '#status-modal',
319-
'bs-toggle' => 'modal',
320-
'bs-target' => '#status-modal',
321-
],
322-
]).'</li>',
323-
'<li>'. Html::a(Module::t('Add Role'), '#', [
324-
'class' => 'dropdown-item',
325-
'data' => [
326-
'toggle' => 'modal',
327-
'target' => '#role-modal',
328-
'bs-toggle' => 'modal',
329-
'bs-target' => '#role-modal',
330-
],
331-
]).'</li>',
332-
'<li>'. Html::a(Module::t('Reset password'), '#', [
333-
'class' => 'dropdown-item',
334-
'data' => [
335-
'toggle' => 'modal',
336-
'target' => '#reset-password-modal',
337-
'bs-toggle' => 'modal',
338-
'bs-target' => '#reset-password-modal',
339-
],
340-
]).'</li>',
341-
],
315+
'label' => Module::t('Action'),
316+
'dropdown' => [
317+
'items' => [
318+
'<li>'. Html::a(Module::t('Change Status'), '#', [
319+
'class' => 'dropdown-item',
320+
'data' => [
321+
'toggle' => 'modal',
322+
'target' => '#status-modal',
323+
'bs-toggle' => 'modal',
324+
'bs-target' => '#status-modal',
325+
],
326+
]).'</li>',
327+
'<li>'. Html::a(Module::t('Add Role'), '#', [
328+
'class' => 'dropdown-item',
329+
'data' => [
330+
'toggle' => 'modal',
331+
'target' => '#role-modal',
332+
'bs-toggle' => 'modal',
333+
'bs-target' => '#role-modal',
342334
],
343-
]);?>
335+
]).'</li>',
336+
'<li>'. Html::a(Module::t('Reset password'), '#', [
337+
'class' => 'dropdown-item',
338+
'data' => [
339+
'toggle' => 'modal',
340+
'target' => '#reset-password-modal',
341+
'bs-toggle' => 'modal',
342+
'bs-target' => '#reset-password-modal',
343+
],
344+
]).'</li>',
345+
'<li>'. Html::a(Module::t('Delete'), '#', [
346+
'class' => 'dropdown-item',
347+
'data' => [
348+
'toggle' => 'modal',
349+
'target' => '#delete-users-modal',
350+
'bs-toggle' => 'modal',
351+
'bs-target' => '#delete-users-modal',
352+
],
353+
]).'</li>',
354+
],
355+
],
356+
]);?>
344357
</div>
345358
</div>
346359
<div>
@@ -521,21 +534,20 @@ function loadCopiedUserId() {
521534
<select id="role_subject" class="form-control form-select"></select>
522535
</div>
523536
<?php $classModal::end() ?>
537+
538+
<?= $this->render('_confirm-action-modal', [
539+
'id' => 'reset-password-modal',
540+
'title' => 'Reset password',
541+
'message' => 'Are you sure you want to reset the passwords for the selected users?',
542+
'action' => 'Reset password'
543+
]) ?>
524544

525-
<!-- Modal form for confirming password reset for users -->
526-
<?php $classModal::begin([
527-
'id' => 'reset-password-modal',
528-
($bootstrapVersion==3 ? 'header' : 'title') => '<h2>'.Module::t('Reset password').'</h2>',
529-
'footer' => ''
530-
545+
<?= $this->render('_confirm-action-modal', [
546+
'id' => 'delete-users-modal',
547+
'title' => 'Delete users',
548+
'message' => 'Are you sure you want to delete the selected users?',
549+
'action' => 'Delete users'
531550
]) ?>
532-
533-
<p style="text-align:center"><?= Module::t('Are you sure you want to reset the passwords for the selected users?') ?></p>
534-
<div style="display:flex;justify-content: center;gap:4px;">
535-
<?= Html::submitButton(Module::t('Reset password'), ['name' => 'form-action', 'value' => 'Reset Password','class' => 'btn btn-danger']) ?>
536-
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" data-dismiss="modal"><?= Module::t('Cancel') ?></button>
537-
</div>
538-
<?php $classModal::end() ?>
539551

540552
<?= Html::endForm() ?>
541553

0 commit comments

Comments
 (0)