'tableOptions' => ['class' => 'table table-bordered'],
'containerOptions' => ['style' => 'overflow:auto;'],
'rowOptions' => function($row) {
- return $row['actuality'] ? ['class'=>'table-success'] : [];
+ $id = $row['product']->id ?? null;
+ $base = $row['actuality'] ? ['class' => 'table-success'] : [];
+ return $id ? array_merge($base, ['data-id' => $id]) : $base;
},
'columns' => [
[
'contentOptions' => ['style'=>'min-width:150px;'],
'value' => function ($row, $key, $index) {
$product = $row['product'];
+ $price = $row['price'] ?? null;
$name = Html::encode($product->name . ' (' . $product->guid . ')');
$anchor = Html::a($name, ['bouquet/view', 'id' => $product->id], ['target' => '_blank']);
- return '<div class="d-flex justify-content-between">' . $anchor . '</div>';
+ $btn = Html::button('+ Добавить интервал', [
+ 'class' => 'btn btn-xs btn-outline-primary ms-2 add-actuality-row',
+ 'type' => 'button',
+ 'title' => 'Добавить интервал',
+ 'data-id' => $product->id,
+ 'data-guid' => $product->guid,
+ 'data-name' => $product->name,
+ 'data-price' => $price->price ?? null,
+ ]);
+ return '<div class="d-flex justify-content-between">' . $anchor . $btn . '</div>';
}
],
[
const monthsForNewRows = extendMonthsMap({ ...baseMonths }, 0);
const monthsForExisting = baseMonths;
+
+
let actualIdx = $('#actuality-form table tbody tr').length || 0;
$('.from-month').each(function () {
const hasActuality = $(this).data('actuality') == 1;
});
});
- const inArchiveBtns = document.getElementById('inArchiveBtn');
- const outArchiveBtns = document.getElementById('outArchiveBtn');
+ const onlyActive = document.getElementById('onlyActiveCheckbox');
+ const onlyInactive = document.getElementById('onlyInactiveCheckbox');
if (onlyActive && onlyInactive) {
onlyActive.addEventListener('change', () => { if (onlyActive.checked) { onlyInactive.checked = false; } });
onlyInactive.addEventListener('change', () => { if (onlyInactive.checked) { onlyActive.checked = false; } });
});
});
+
+ $(document).on('click', '.add-actuality-row', function(){
+ const btn = $(this);
+ const id = btn.data('id');
+ const guid = btn.data('guid');
+ const name = btn.data('name');
+ const price = btn.data('price');
+ const table = $('#actuality-form table');
+ // Все строки для этого товара
+ const $rows = table.find('tbody tr[data-id="'+ id +'"]');
+ const $lastRow = $rows.last();
+ actualIdx++;
+ console.log('add row', id, name);
+ const newRow = `
+ <tr class="table-info">
+ <td style="min-width:150px;">
+ <div class="d-flex justify-content-between">${name} (${id}) <div class="text-danger mx-5">Новая запись. Заполните интервал</div></div>
+ </td>
+ <td style="text-align:center;">
+ <div class="d-flex justify-content-between">${price}</div>
+ </td>
+ <td>
+ <input type="hidden" name="actuality[${actualIdx}][guid]" value="${guid}">
+ <input type="hidden" name="actuality[${actualIdx}][bouquet_id]" value="${id}">
+ <div class="d-flex align-items-center">
+ <select data-actuality="0" name="actuality[${actualIdx}][from]" class="form-select from-month form-select-sm me-1" style="width:auto;display:inline-block">
+ <option value="">от</option>${monthOptions}
+ </select>
+ <select name="actuality[${actualIdx}][to]" class="form-select to-month form-select-sm" style="width:auto;display:inline-block">
+ <option value="">до</option>${monthOptions}
+ </select>
+ </div>
+ </td>
+ <td style="width:60px;text-align:center;">
+
+ </td>
+
+ </tr>
+ `;
+
+ let $inserted;
+ if ($lastRow.length) {
+ $lastRow.after(newRow);
+ $inserted = $lastRow.next();
+ } else {
+ table.find('tbody').append(newRow);
+ $inserted = table.find('tbody tr').last();
+ }
+ console.log(newRow);
+ applyFromMonthLimits($inserted.find('.from-month'), monthsForNewRows);
+ syncToWithFrom($inserted.find('.from-month'));
+ });
+
})();
\ No newline at end of file