use yii\helpers\ArrayHelper;
use yii\web\BadRequestHttpException;
use yii\web\Response;
+use yii_app\records\AdminGroup;
use yii_app\records\BouquetComposition;
use yii_app\records\BouquetCompositionMatrixTypeHistory;
use yii_app\records\MatrixBouquetActuality;
throw new NotFoundHttpException('The requested page does not exist.');
}
+
+ private function checkAccess() {
+ $groupId = Yii::$app->user->identity->group_id;
+
+ if (!in_array($groupId, [
+ AdminGroup::GROUP_IT,
+ AdminGroup::GROUP_BUSH_CHEF_FLORIST,
+ AdminGroup::GROUP_BUSH_DIRECTOR,
+ AdminGroup::GROUP_RS_DIRECTOR,
+ ], true)) {
+ return $this->render('/site/index');
+ }
+
+ return null;
+ }
}
])->label(false) ?>
</div>
<div class="mb-3">
- <?= $formFilter->field($filter, 'is_archive')->checkbox([
- 'label' => 'Архивные',
- 'uncheck' => 0,
- 'checked' => (bool)$filter->is_archive,
- 'id' => 'isArchiveCheckbox'
- ])->label(false) ?>
+<!-- --><?php //= $formFilter->field($filter, 'is_archive')->checkbox([
+// 'label' => 'Архивные',
+// 'uncheck' => 0,
+// 'checked' => (bool)$filter->is_archive,
+// 'id' => 'isArchiveCheckbox'
+// ])->label(false) ?>
</div>
'contentOptions' => ['style'=>'width:160px; text-align:center;'],
'value' => function ($row, $key, $index) {
$product = $row['product'];
- $btnArchOn = Html::button('В архив', [
- 'class' => 'btn btn-xs btn-danger ms-2 add-actuality-row',
+ $actuality = $row['actuality'];
+ $btnArchOnOptions = [
+ 'class' => 'btn btn-xs btn-danger ms-2 add-actuality-row archiv-in-btn',
'type' => 'button',
'title' => 'В архив',
- 'data-guid' => $product->id,
+ 'data-archiv-in' => $actuality ? $actuality->id : $product->id,
+ 'data-id' => $product->id,
'data-name' => $product->name,
- ]);
- $btnArchOff = Html::button('Из архива', [
- 'class' => 'btn btn-xs btn-secondary ms-2 add-actuality-row',
+ ];
+ if ($actuality && $actuality->is_archive == 1) {
+ $btnArchOnOptions['disabled'] = true;
+ }
+
+ $btnArchOffOptions = [
+ 'class' => 'btn btn-xs btn-secondary ms-2 add-actuality-row archiv-out-btn',
'type' => 'button',
'title' => 'Из архива',
- 'data-guid' => $product->id,
+ 'data-archiv-out' => $actuality ? $actuality->id : $product->id,
+ 'data-id' => $product->id,
'data-name' => $product->name,
- ]);
- return '<div class="d-flex justify-content-start">' . $btnArchOn . $btnArchOff . '</div>';
+ ];
+
+ if ($actuality && $actuality->is_archive == 0 || !$actuality) {
+ $btnArchOffOptions['disabled'] = true;
+ }
+
+ $btnArchOn = Html::button('В архив', $btnArchOnOptions);
+ $btnArchOff = Html::button('Из архива', $btnArchOffOptions);
+ //return '<div class="d-flex justify-content-start">' . $btnArchOn . $btnArchOff . '</div>';
+ return '<div class="d-flex justify-content-start">' . '</div>';
}
],
});
- const onlyActive = document.getElementById('onlyActiveCheckbox');
- const onlyInactive = document.getElementById('onlyInactiveCheckbox');
+
+ document.querySelectorAll('.archiv-in-btn[data-archiv-in]').forEach(btn => {
+ btn.addEventListener('click', () => {
+ const targetId = btn.getAttribute('data-archiv-in');
+ if (!confirm('Отправить в архив?')) {
+ return;
+ }
+
+ $.ajax({
+ url: '/matrix-bouquet-actuality/ajax-delete',
+ type: 'POST',
+ data: {id: targetId, _csrf: yii.getCsrfToken()},
+ success: function (response) {
+ if (response.success) {
+
+ alert(response.message);
+ } else {
+ alert('Ошибка: ' + response.message);
+ }
+ },
+ error: function () {
+ alert('Произошла ошибка при удалении');
+ }
+ });
+ });
+ });
+
+ document.querySelectorAll('.archiv-out-btn[data-archiv-out]').forEach(btn => {
+ btn.addEventListener('click', () => {
+ const targetId = btn.getAttribute('data-archiv-out');
+ if (!confirm('Убрать из архива?')) {
+ return;
+ }
+
+ $.ajax({
+ url: '/matrix-bouquet-actuality/ajax-delete',
+ type: 'POST',
+ data: {id: targetId, _csrf: yii.getCsrfToken()},
+ success: function (response) {
+ if (response.success) {
+
+ alert(response.message);
+ } else {
+ alert('Ошибка: ' + response.message);
+ }
+ },
+ error: function () {
+ alert('Произошла ошибка при удалении');
+ }
+ });
+ });
+ });
+
+ const inArchiveBtns = document.getElementById('inArchiveBtn');
+ const outArchiveBtns = document.getElementById('outArchiveBtn');
if (onlyActive && onlyInactive) {
onlyActive.addEventListener('change', () => { if (onlyActive.checked) { onlyInactive.checked = false; } });
onlyInactive.addEventListener('change', () => { if (onlyInactive.checked) { onlyActive.checked = false; } });