|
8 | 8 | use ZakharovAndrew\user\Module;
|
9 | 9 | use ZakharovAndrew\user\models\UserRoles;
|
10 | 10 | use ZakharovAndrew\user\models\Roles;
|
11 |
| -use yii\bootstrap\ButtonDropdown; |
12 | 11 |
|
13 | 12 | use ZakharovAndrew\user\assets\UserAssets;
|
14 | 13 | UserAssets::register($this);
|
|
28 | 27 | $columnVisibility = \ZakharovAndrew\user\models\User::getColumnVisibility();
|
29 | 28 |
|
30 | 29 | $toggleUrl = Url::to(['/user/user/toggle-column-visibility']);
|
| 30 | +$language = \Yii::$app->language; |
31 | 31 |
|
32 | 32 | $script = <<< JS
|
33 | 33 | $('#users-update-status').on('click', function() {
|
|
54 | 54 | });
|
55 | 55 | });
|
56 | 56 |
|
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 | + }); |
64 | 68 |
|
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(); |
68 | 104 |
|
69 | 105 | JS;
|
70 | 106 |
|
|
177 | 213 | .user-index .btn-settings svg {margin-top:-5px; fill:#716d66}
|
178 | 214 | .user-index .btn-settings:hover svg {fill:#2196f3}
|
179 | 215 | .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 | +} |
180 | 230 | </style>
|
181 | 231 | <div class="user-index">
|
182 | 232 |
|
183 | 233 | <?php if (Yii::$app->getModule('user')->showTitle) {?><h1><?= Html::encode($this->title) ?></h1><?php } ?>
|
184 | 234 |
|
185 | 235 | <?= 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 | + |
193 | 259 |
|
194 | 260 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
195 | 261 |
|
|
245 | 311 | },
|
246 | 312 | 'visible' => isset($columnVisibility['sex']) ? $columnVisibility['sex'] : true,
|
247 | 313 | ],
|
248 |
| - //created_by |
249 | 314 | [
|
250 | 315 | 'attribute' => 'created_by',
|
251 | 316 | 'format' => 'raw',
|
|
282 | 347 | }
|
283 | 348 | ],
|
284 | 349 | [
|
285 |
| - |
286 | 350 | 'format' => 'raw',
|
287 | 351 | 'value' => function ($model) use ($classButtonDropdown) {
|
288 |
| - |
289 |
| - |
290 | 352 | return $classButtonDropdown::widget([
|
291 | 353 | 'label' => Module::t('Action'),
|
292 | 354 | 'dropdown' => [
|
|
302 | 364 | ]);
|
303 | 365 | }
|
304 | 366 | ],
|
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 |
| - ],*/ |
318 | 367 | ],
|
319 | 368 | ]); ?>
|
320 | 369 |
|
|
0 commit comments