Skip to content

Commit a2f1ff1

Browse files
Improved the interface for the user list
1 parent 093522a commit a2f1ff1

File tree

2 files changed

+85
-36
lines changed

2 files changed

+85
-36
lines changed

src/Module.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Module extends \yii\base\Module
2121
/**
2222
* @var string Module version
2323
*/
24-
protected $version = "0.5.8";
24+
protected $version = "0.6.0";
2525

2626
/**
2727
* @var string Alias for module

src/views/user/index.php

+84-35
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use ZakharovAndrew\user\Module;
99
use ZakharovAndrew\user\models\UserRoles;
1010
use ZakharovAndrew\user\models\Roles;
11-
use yii\bootstrap\ButtonDropdown;
1211

1312
use ZakharovAndrew\user\assets\UserAssets;
1413
UserAssets::register($this);
@@ -28,6 +27,7 @@
2827
$columnVisibility = \ZakharovAndrew\user\models\User::getColumnVisibility();
2928

3029
$toggleUrl = Url::to(['/user/user/toggle-column-visibility']);
30+
$language = \Yii::$app->language;
3131

3232
$script = <<< JS
3333
$('#users-update-status').on('click', function() {
@@ -54,17 +54,53 @@
5454
});
5555
});
5656
57-
$("#settings").click(function() {
58-
if ($(".settings-modal").hasClass('show')) {
59-
$(".settings-modal").removeClass('show');
60-
} else {
61-
$(".settings-modal").addClass('show');
62-
}
63-
});
57+
$("#settings").click(function() {
58+
if ($(".settings-modal").hasClass('show')) {
59+
$(".settings-modal").removeClass('show');
60+
} else {
61+
$(".settings-modal").addClass('show');
62+
}
63+
});
64+
65+
$(".settings-modal .btn-modal-close").click(function() {
66+
$(this).parent().parent().removeClass('show');
67+
});
6468
65-
$(".settings-modal .btn-modal-close").click(function() {
66-
$(this).parent().parent().removeClass('show');
67-
});
69+
70+
const updateStatusButton = $('#users-update-status');
71+
const selectedCountLabel = $('#selected-count'); // Make sure to add an element for this in your HTML
72+
73+
// Function to update the count of selected checkboxes
74+
function updateSelectedCount() {
75+
const selectedCount = $('input[name="selection[]"]:checked').length; // Adjust the name if necessary
76+
const currentLanguage = '$language';
77+
let message;
78+
79+
if (selectedCount === 1) {
80+
message = (currentLanguage === 'ru') ? "Выбран 1 пользователь" : "1 user selected";
81+
} else if (selectedCount > 1 && selectedCount < 5) {
82+
message = (currentLanguage === 'ru') ? `Выбрано {count} пользователя` : `{count} users selected`;
83+
} else {
84+
message = (currentLanguage === 'ru') ? `Выбрано {count} пользователей` : `{count} users selected`;
85+
}
86+
87+
selectedCountLabel.text(message.replace('{count}', selectedCount));
88+
89+
// Enable or disable the button based on selection
90+
if (selectedCount > 0) {
91+
$('#selected-block').addClass('show-flex');
92+
} else {
93+
$('#selected-block').removeClass('show-flex')
94+
}
95+
}
96+
97+
// Event listener for checkbox changes
98+
$('input[name="selection[]"]').on('change', function() {
99+
updateSelectedCount();
100+
});
101+
102+
// Initial count update
103+
updateSelectedCount();
68104
69105
JS;
70106

@@ -177,19 +213,49 @@
177213
.user-index .btn-settings svg {margin-top:-5px; fill:#716d66}
178214
.user-index .btn-settings:hover svg {fill:#2196f3}
179215
.user-index .btn-settings:hover, .user-index .btn-settings:active, .user-index .btn-action:hover, .user-index .btn-action:active {background:#f3f9fe;border-color: #d0e2f1;}
216+
#selected-count {
217+
padding-top: 0.375rem;
218+
margin: 0 10px 0 15px;
219+
}
220+
#selected-block {display: flex;align-items: stretch;display:none;}
221+
.top-control-panel {
222+
display:flex;justify-content:space-between;align-items:stretch;
223+
}
224+
.show-flex {
225+
display:flex !important;
226+
}
227+
#selected-block .dropdown-toggle {
228+
background-color: #f06445;color:#fff;
229+
}
180230
</style>
181231
<div class="user-index">
182232

183233
<?php if (Yii::$app->getModule('user')->showTitle) {?><h1><?= Html::encode($this->title) ?></h1><?php } ?>
184234

185235
<?= Html::beginForm(['users-update'], 'post') ?>
186-
<p>
187-
<?= Html::a(Module::t('Create User'), ['create'], ['class' => 'btn btn-success']) ?>
188-
<?= Html::a('<span class="dashboard-icon"></span>', ['/user/dashboard/index'], ['class' => 'btn btn-settings']) ?>
189-
<?= Html::button(Module::t('Change Status'), ['class' => 'btn btn-danger', 'id' => 'users-update-status']) ?>
190-
<?= Html::button(Module::t('Add Role'), ['class' => 'btn btn-action', 'id' => 'users-add-role']) ?>
191-
<span id="settings" class="btn btn-settings"><svg height="18" width="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 489.802 489.802" xml:space="preserve"><path d="m20.701 281.901 32.1.2c4.8 24.7 14.3 48.7 28.7 70.5l-22.8 22.6c-8.2 8.1-8.2 21.2-.2 29.4l24.6 24.9c8.1 8.2 21.2 8.2 29.4.2l22.8-22.6c21.6 14.6 45.5 24.5 70.2 29.5l-.2 32.1c-.1 11.5 9.2 20.8 20.7 20.9l35 .2c11.5.1 20.8-9.2 20.9-20.7l.2-32.1c24.7-4.8 48.7-14.3 70.5-28.7l22.6 22.8c8.1 8.2 21.2 8.2 29.4.2l24.9-24.6c8.2-8.1 8.2-21.2.2-29.4l-22.6-22.8c14.6-21.6 24.5-45.5 29.5-70.2l32.1.2c11.5.1 20.8-9.2 20.9-20.7l.2-35c.1-11.5-9.2-20.8-20.7-20.9l-32.1-.2c-4.8-24.7-14.3-48.7-28.7-70.5l22.8-22.6c8.2-8.1 8.2-21.2.2-29.4l-24.6-24.9c-8.1-8.2-21.2-8.2-29.4-.2l-22.8 22.6c-21.6-14.6-45.5-24.5-70.2-29.5l.2-32.1c.1-11.5-9.2-20.8-20.7-20.9l-35-.2c-11.5-.1-20.8 9.2-20.9 20.7l-.3 32.1c-24.8 4.8-48.8 14.3-70.5 28.7l-22.6-22.8c-8.1-8.2-21.2-8.2-29.4-.2l-24.8 24.6c-8.2 8.1-8.2 21.2-.2 29.4l22.6 22.8c-14.6 21.6-24.5 45.5-29.5 70.2l-32.1-.2c-11.5-.1-20.8 9.2-20.9 20.7l-.2 35c-.1 11.4 9.2 20.8 20.7 20.9zm158.6-103.3c36.6-36.2 95.5-35.9 131.7.7s35.9 95.5-.7 131.7-95.5 35.9-131.7-.7-35.9-95.5.7-131.7z"/></svg></span>
192-
</p>
236+
237+
<div class="top-control-panel">
238+
<div style="display:flex">
239+
<?= Html::a(Module::t('Create User'), ['create'], ['class' => 'btn btn-success']) ?>
240+
<div id="selected-block">
241+
<p id="selected-count">Выбрано 0 пользователей</p>
242+
<?= $classButtonDropdown::widget([
243+
'label' => Module::t('Action'),
244+
'dropdown' => [
245+
'items' => [
246+
'<a href="#" id="users-update-status" class="dropdown-item">'.Module::t('Change Status').'</a>',
247+
'<a href="#" id="users-add-role" class="dropdown-item">'.Module::t('Add Role').'</a>',
248+
],
249+
],
250+
]);?>
251+
</div>
252+
</div>
253+
<div>
254+
<?= Html::a('<span class="dashboard-icon"></span>', ['/user/dashboard/index'], ['class' => 'btn btn-settings']) ?>
255+
<span id="settings" class="btn btn-settings"><svg height="18" width="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 489.802 489.802" xml:space="preserve"><path d="m20.701 281.901 32.1.2c4.8 24.7 14.3 48.7 28.7 70.5l-22.8 22.6c-8.2 8.1-8.2 21.2-.2 29.4l24.6 24.9c8.1 8.2 21.2 8.2 29.4.2l22.8-22.6c21.6 14.6 45.5 24.5 70.2 29.5l-.2 32.1c-.1 11.5 9.2 20.8 20.7 20.9l35 .2c11.5.1 20.8-9.2 20.9-20.7l.2-32.1c24.7-4.8 48.7-14.3 70.5-28.7l22.6 22.8c8.1 8.2 21.2 8.2 29.4.2l24.9-24.6c8.2-8.1 8.2-21.2.2-29.4l-22.6-22.8c14.6-21.6 24.5-45.5 29.5-70.2l32.1.2c11.5.1 20.8-9.2 20.9-20.7l.2-35c.1-11.5-9.2-20.8-20.7-20.9l-32.1-.2c-4.8-24.7-14.3-48.7-28.7-70.5l22.8-22.6c8.2-8.1 8.2-21.2.2-29.4l-24.6-24.9c-8.1-8.2-21.2-8.2-29.4-.2l-22.8 22.6c-21.6-14.6-45.5-24.5-70.2-29.5l.2-32.1c.1-11.5-9.2-20.8-20.7-20.9l-35-.2c-11.5-.1-20.8 9.2-20.9 20.7l-.3 32.1c-24.8 4.8-48.8 14.3-70.5 28.7l-22.6-22.8c-8.1-8.2-21.2-8.2-29.4-.2l-24.8 24.6c-8.2 8.1-8.2 21.2-.2 29.4l22.6 22.8c-14.6 21.6-24.5 45.5-29.5 70.2l-32.1-.2c-11.5-.1-20.8 9.2-20.9 20.7l-.2 35c-.1 11.4 9.2 20.8 20.7 20.9zm158.6-103.3c36.6-36.2 95.5-35.9 131.7.7s35.9 95.5-.7 131.7-95.5 35.9-131.7-.7-35.9-95.5.7-131.7z"/></svg></span>
256+
</div>
257+
</div>
258+
193259

194260
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
195261

@@ -245,7 +311,6 @@
245311
},
246312
'visible' => isset($columnVisibility['sex']) ? $columnVisibility['sex'] : true,
247313
],
248-
//created_by
249314
[
250315
'attribute' => 'created_by',
251316
'format' => 'raw',
@@ -282,11 +347,8 @@
282347
}
283348
],
284349
[
285-
286350
'format' => 'raw',
287351
'value' => function ($model) use ($classButtonDropdown) {
288-
289-
290352
return $classButtonDropdown::widget([
291353
'label' => Module::t('Action'),
292354
'dropdown' => [
@@ -302,19 +364,6 @@
302364
]);
303365
}
304366
],
305-
306-
/*[
307-
'class' => ActionColumn::className(),
308-
'urlCreator' => function ($action, $model, $key, $index, $column) {
309-
if ($action == 'view') {
310-
return Url::toRoute(['profile', 'id' => $model->id]);
311-
}
312-
if ($action == 'update') {
313-
return Url::toRoute(['edit-profile', 'id' => $model->id]);
314-
}
315-
return Url::toRoute([$action, 'id' => $model->id]);
316-
}
317-
],*/
318367
],
319368
]); ?>
320369

0 commit comments

Comments
 (0)