]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Кнопка активности фида
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 2 Oct 2025 12:19:57 +0000 (15:19 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 2 Oct 2025 12:19:57 +0000 (15:19 +0300)
erp24/controllers/MatrixErpController.php
erp24/views/matrix_erp/index.php

index c82762b1853d0a54e7b72398f5a43ccdfd03166a..d6a15686853bd291f1235246c7dbc6275c0daf16 100644 (file)
@@ -266,6 +266,47 @@ class MatrixErpController extends Controller
         return $this->redirect('index');
     }
 
+    /**
+     * AJAX экшн для изменения статуса активности фида
+     * @return \yii\web\Response
+     */
+    public function actionToggleFeedActive()
+    {
+        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+
+        $id = Yii::$app->request->post('id');
+        $isFeedActive = Yii::$app->request->post('is_feed_active');
+
+        if (!$id) {
+            return [
+                'success' => false,
+                'message' => 'ID записи не указан'
+            ];
+        }
+
+        $matrixErp = MatrixErp::findOne($id);
+        if (!$matrixErp) {
+            return [
+                'success' => false,
+                'message' => 'Запись не найдена'
+            ];
+        }
+
+        $matrixErp->is_feed_active = (int)$isFeedActive;
+        if ($matrixErp->save()) {
+            $statusText = $isFeedActive ? 'включена' : 'отключена';
+            return [
+                'success' => true,
+                'message' => "Активность фида для товара \"{$matrixErp->name}\" {$statusText}"
+            ];
+        } else {
+            return [
+                'success' => false,
+                'message' => 'Ошибка при сохранении: ' . json_encode($matrixErp->getErrors(), JSON_UNESCAPED_UNICODE)
+            ];
+        }
+    }
+
     /**
      * Finds the MatrixErp model based on its primary key value.
      * If the model is not found, a 404 HTTP exception will be thrown.
index 5235e3f8d8a6e29b6540d0ba71a7ffb727195430..bfd69a8c50e1b237be51c84e2a142bd6b851dd30 100644 (file)
@@ -3,6 +3,7 @@
 use yii\helpers\ArrayHelper;
 use yii_app\helpers\ImageHelper;
 use yii\helpers\Html;
+use yii\helpers\Url;
 use yii\widgets\ActiveForm;
 use yii_app\services\FileService;
 
@@ -153,6 +154,7 @@ $this->params['breadcrumbs'][] = $this->title;
                                 <th>Дата начала актуальности</th>
                                 <th>Дата окончания актуальности</th>
                                 <th>Активность</th>
+                                <th>Фид товаров</th>
                                 <th></th>
                             </tr>
                             </thead>
@@ -206,11 +208,19 @@ $this->params['breadcrumbs'][] = $this->title;
                                         <td><?= $item->date_from ?></td>
                                         <td><?= $item->date_to ?></td>
                                         <td><?= (($item->active) ? 'Активна': 'Не активна') ?></td>
+                                        <td>
+                                            <input type="checkbox"
+                                                   class="feed-active-checkbox"
+                                                   data-id="<?= $item->id ?>"
+                                                   <?= $item->is_feed_active ? 'checked' : '' ?>
+                                                   onchange="toggleFeedActive(<?= $item->id ?>, this.checked)"
+                                                   onclick="event.stopPropagation()">
+                                        </td>
                                         <td><span style="white-space:nowrap;"><?= ($item->active ? $editUrl . "&nbsp;&nbsp;&nbsp;&nbsp;" . $deleteUrl : '')?></span></td>
                                     </tr>
 
                                     <tr style="display:none">
-                                        <td colspan="8">
+                                        <td colspan="11">
                                             <div class="">
                                                 <div class="panel panel-primary receipts-inline-table border-0">
                                                     <div class="tab-menu-heading p-0 border-0">
@@ -334,4 +344,15 @@ $this->params['breadcrumbs'][] = $this->title;
             </div>
         </div>
     </div>
+
+    <!-- Alert container -->
+    <div id="feed-alert-container" style="position: fixed; top: 100px; right: 20px; z-index: 9999; max-width: 400px;"></div>
+
+    <?php
+    $this->registerJsFile('@web/js/matrix-erp/index.js', ['depends' => [\yii\web\JqueryAsset::class]]);
+    $this->registerJs("
+        window.csrfToken = '" . Yii::$app->request->csrfToken . "';
+        window.matrixErpToggleFeedActiveUrl = '" . Url::to(['matrix-erp/toggle-feed-active']) . "';
+    ", \yii\web\View::POS_READY);
+    ?>
 </div>