]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-302 Редактирование букета
authormarina <m.zozirova@gmail.com>
Fri, 21 Feb 2025 10:50:52 +0000 (13:50 +0300)
committermarina <m.zozirova@gmail.com>
Fri, 21 Feb 2025 10:50:52 +0000 (13:50 +0300)
erp24/records/BouquetComposition.php
erp24/views/bouquet/_form.php
erp24/views/bouquet/_product_edit.php
erp24/views/bouquet/_product_list.php
erp24/views/bouquet/create.php
erp24/views/bouquet/index.php
erp24/views/bouquet/view.php
erp24/web/js/bouquet/bouquet.js
erp24/widgets/DualList.php

index a696f1354ac4882ab21962d87cf263aabdecb9fd..f006ed7f6cc318f594d20be6fc3f38891251e4d8 100644 (file)
@@ -216,9 +216,11 @@ class BouquetComposition extends ActiveRecord
 
     public static function disabledButtons($isCreate = false)
     {
-        if (!$isCreate || date('d') > 10) {
+        if ($isCreate) {
             return false;
         }
-        return true;
+
+        return date('d') > 10;
     }
+
 }
index 9bad651c70d98279b9bb3bbc97721af985703e34..477cb5d0426192b2bacc2ab652b4d86e7e6d9cbe 100644 (file)
@@ -248,7 +248,9 @@ $form = ActiveForm::begin([
     <div class="row">
         <div class="col-md-10"></div>
         <div class="col-md-2">
-            <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success w-100', 'disabled' => $disabledButtons]) ?>
+            <?= Html::submitButton('Сохранить', [
+                    'class' => 'btn btn-success btn-save w-100',
+                'disabled' => BouquetComposition::disabledButtons(!$id)]) ?>
         </div>
     </div>
 <?php ActiveForm::end(); ?>
\ No newline at end of file
index 49332ae039c9fae8f087fb5561ea591193aecf33..dbf0f56a720e17f7922da6ecf11e46035eccc078 100644 (file)
@@ -1,5 +1,7 @@
 <?php use app\widgets\DualList;
 use yii\helpers\Html;
+use yii_app\records\BouquetComposition;
+
 ?>
 <?= DualList::widget([
     'name' => 'products',
@@ -18,9 +20,7 @@ use yii\helpers\Html;
 
 <div class="row">
     <div class="col-md-6 position-relative">
-        <!-- Обертка для перекрытия текста -->
         <div class="pt-2 position-relative content-wrapper">
-            <!-- Прелоадер -->
             <div class="loader-overlay d-none">
                 <div class="spinner-border text-primary" role="status"></div>
             </div>
@@ -37,7 +37,7 @@ use yii\helpers\Html;
             <?= Html::button('Рассчитать', ['class' => 'btn btn-warning calculate-btn w-100']) ?>
         </div>
     <div class="col-md-2 d-flex justify-content-end align-items-end px-3 w-100">
-        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success w-100']) ?>
+        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success w-100', 'disabled' => BouquetComposition::disabledButtons()]) ?>
     </div>
     <?php } else { ?>
         <div class="col-md-4 d-flex justify-content-end align-items-end px-3 w-100">
index d1b160194fdcf7ab08613fcbf8489c8a4be841e4..ae20dc367a6ab786e9349e0b7f503e44c3fec51f 100644 (file)
@@ -34,6 +34,8 @@
         </div>
     </div>
     <div class="col-md-4">
-        <?= Html::a('Редактировать',  Url::to("/bouquet/update?id=$model->id"), ['class' => $model && !BouquetComposition::disabledButtons()? 'btn btn-warning w-100' : 'btn btn-warning w-100 disabled']) ?>
+        <?= Html::a('Редактировать', Url::to(["/bouquet/update", "id" => $model->id]), [
+            'class' => 'btn btn-warning btn-edit w-100' . ($model && !BouquetComposition::disabledButtons() ? '' : ' disabled')
+        ]) ?>
     </div>
 </div>
\ No newline at end of file
index 59997c0705a9ddf8f44d3aa58f867d13dec23df7..b9f3e0a0a3d9c41417d7e76d8849baf7d00a7d69 100644 (file)
@@ -32,7 +32,7 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO
         'processUrls' => [],
         'availableItems' => $availableItems,
         'model' => null,
-        'disabledButtons' => \yii_app\records\BouquetComposition::disabledButtons(true)
+        'id' => null
     ]); ?>
 </div>
 
index a783c7c018ce77463aa3d069670a79e00660d96a..345b964609154b194bf27c497b106453f5181164 100644 (file)
@@ -11,10 +11,8 @@ use yii_app\records\MatrixType;
 use yii_app\records\Products1c;
 
 /** @var yii\web\View $this */
-
 $this->title = 'Содержание матрицы';
 ?>
-
 <div class="bouquet-index p-4">
     <h1><?= Html::encode($this->title) ?></h1>
 
@@ -57,7 +55,7 @@ $this->title = 'Содержание матрицы';
                     ]) ?>
             </div>
             <div class="text-center mt-2">
-                <?= Html::a('Редактировать', Url::to('/matrix-type'), ['class' => 'text-decoration-none', 'target' => '_blank', 'disabled' => BouquetComposition::disabledButtons()]) ?>
+                <?= Html::a('Редактировать', Url::to('/matrix-type'), ['class' => 'text-decoration-none', 'target' => '_blank']) ?>
             </div>
         </div>
 
@@ -133,15 +131,15 @@ $this->title = 'Содержание матрицы';
 
                                 <div class='col-md-2 d-flex flex-column gap-2'>
                                     <div class='card bg-transparent border-0' style='aspect-ratio: 1/1; width: 100%; flex: 1;'>
-                                " .  Html::tag('video', '', [
-                                    'class' => 'video-preview',
-                                    'src' => Url::to($model->presentation->url ?? null),
-                                    'style' => 'width: 100%; height: 100%; object-fit: cover;',
-                                    'autoplay' => true,
-                                    'muted' => true,
-                                    'loop' => true,
-                                    'playsinline' => true
-                                ]) . "
+                                " . Html::tag('video', '', [
+                                'class' => 'video-preview',
+                                'src' => Url::to($model->presentation->url ?? null),
+                                'style' => 'width: 100%; height: 100%; object-fit: cover;',
+                                'autoplay' => true,
+                                'muted' => true,
+                                'loop' => true,
+                                'playsinline' => true
+                            ]) . "
                                         <div class='text-center bg-transparent fw-bold p-0 m-0'>Презентация</div>
                                     </div>
                                     <div class='card' style='aspect-ratio: 1/1; width: 100%; flex: 1;'> " .
@@ -153,7 +151,7 @@ $this->title = 'Содержание матрицы';
 
                                 <div class='col-md-2 d-flex flex-column gap-2'>
                                 <div class='card bg-transparent border-0' style='aspect-ratio: 1/1; width: 100%; flex: 1;'> " .
-                           Html::tag('video', '', [
+                            Html::tag('video', '', [
                                 'class' => 'video-preview',
                                 'src' => Url::to($model->buildProcess->url ?? null),
                                 'style' => 'width: 100%; height: 100%; object-fit: cover;',
@@ -173,9 +171,16 @@ $this->title = 'Содержание матрицы';
                                 <div class='row mt-auto text-center'>
                                     <div class='col-md-7'></div>
                                     <div class='col-md-2'>
-                                        " . Html::a('Редактировать', Url::to(['/bouquet/view', 'id' => $model['id']]), [
-                                'class' => 'btn btn-warning'
-                            ]) . "
+                                        " .
+                            Html::a('Редактировать', Url::to(['/bouquet/view', 'id' => $model['id']]), [
+                                'class' => 'btn btn-warning btn-edit' .
+                                    ((Yii::$app->request->get('year') < date('Y') || // Если год в прошлом → disabled
+                                        (Yii::$app->request->get('year') == date('Y') && Yii::$app->request->get('month') < date('m')) ||
+                                        (Yii::$app->request->get('year') == date('Y') && Yii::$app->request->get('month') == date('m') && BouquetComposition::disabledButtons()) ||
+                                        (Yii::$app->request->get('year') == date('Y') && Yii::$app->request->get('month') == date('m') + 1 &&BouquetComposition::disabledButtons())
+                                    ) ? ' disabled' : ''),
+                            ])
+                            . "
                                     </div>
                                 </div>
                             </div>
index 66387c36c354bd50d7d913668c4b0bf89208c7c7..d0433cfc9694ea40291a85ab802b15ee558d345f 100644 (file)
@@ -29,7 +29,7 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO
         'photoFiles' => $photoFiles,
         'videoUrls' => $videoUrls,
         'processUrls' => $processUrls,
-        'disabledButtons' => \yii_app\records\BouquetComposition::disabledButtons(),
+        'id' => $model->id
     ]); ?>
 </div>
 
index 67765fb139ed52a21a5b163c1d902063f5c03961..bf323e9cff94e0209b977e7532d73c755b3fa581 100644 (file)
@@ -7,14 +7,27 @@ document.addEventListener('DOMContentLoaded', function () {
         });
     });
 });
+
 $(document).ready(function () {
     if (window.location.pathname.includes('/bouquet/view')) {
         $('.year-picker, .month-picker').on('change', function () {
+
             let year = $('.year-picker').val();
             let month = $('.month-picker').val();
             let urlParams = new URLSearchParams(window.location.search);
             let id = urlParams.get('id');
 
+
+            let currentYear = new Date().getFullYear();
+            let currentMonth = new Date().getMonth() + 1;
+
+            if (year >= currentYear && month > currentMonth) {
+                $('.btn-edit').removeClass('disabled')
+                $('.btn-save').prop('disabled', false);
+            } else {
+                $('.btn-edit').addClass('disabled')
+                $('.btn-save').prop('disabled', true);
+            }
             if (!id) {
                 return;
             }
index 97b915d964b55b1d4b0339c4c7d468b0c31e3e55..f9fa93508e8bb72b587b40717e4c321454104b3e 100644 (file)
@@ -355,6 +355,12 @@ $('#{$id}-selected-container').on('click', '.selected-item', function() {
     $(this).addClass('selected');
 });
 
+// Убираем выделение при клике вне элемента
+$(document).on('click', function(e) {
+    if (!$(e.target).closest('.selected-item').length) {
+        $('#{$id}-selected-container .selected-item').removeClass('selected');
+    }
+});
 
 // Фильтрация доступных элементов
 $('#{$id}-filter-available').on('input', function() {