| | | 1 | | @using OzonDomains |
| | | 2 | | @using OzonDomains.Models |
| | | 3 | | @model StatusTransition |
| | | 4 | | |
| | | 5 | | @{ |
| | 0 | 6 | | ViewData["Title"] = "Редактировать переход"; |
| | 0 | 7 | | Layout = "~/Views/Shared/_Layout.cshtml"; |
| | 0 | 8 | | var statusList = ViewBag.StatusList as List<AppStatus> ?? new List<AppStatus>(); |
| | 0 | 9 | | var transactionTypes = ViewBag.TransactionTypes as IEnumerable<TransactionType> ?? Enumerable.Empty<TransactionType> |
| | | 10 | | } |
| | | 11 | | |
| | | 12 | | <link rel="stylesheet" href="~/css/Studio2/StatusTransition/status-transition-form.css" asp-append-version="true"/> |
| | | 13 | | |
| | 0 | 14 | | @await Html.PartialAsync("_BsxGridShell") |
| | | 15 | | |
| | | 16 | | <div class="container st-form-page py-3 bsx-surface"> |
| | | 17 | | <div class="back-link-row"> |
| | | 18 | | <a asp-action="Index" class="text-primary text-decoration-none small"> |
| | | 19 | | <i class="fas fa-arrow-left me-1"></i>К списку переходов |
| | | 20 | | </a> |
| | | 21 | | </div> |
| | | 22 | | |
| | | 23 | | <div class="card"> |
| | | 24 | | <div class="card-header"> |
| | | 25 | | <h2 class="mb-0 fs-4">Редактирование перехода</h2> |
| | | 26 | | </div> |
| | | 27 | | <div class="card-body"> |
| | 0 | 28 | | @if (TempData["StatusResult"] != null) |
| | | 29 | | { |
| | 0 | 30 | | <div class="alert alert-success alert-dismissible fade show">@TempData["StatusResult"]<button type="butt |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | <div class="st-intro"> |
| | | 34 | | <i class="fas fa-circle-info"></i> |
| | | 35 | | <div class="st-intro-text"> |
| | | 36 | | Изменение перехода влияет на доступные транзакции в меню заказа и на граф на странице |
| | | 37 | | <a asp-action="Index">«Переходы между статусами»</a>. Для одного типа транзакции допускается |
| | | 38 | | только один <strong>целевой</strong> статус. |
| | | 39 | | </div> |
| | | 40 | | </div> |
| | | 41 | | |
| | 0 | 42 | | <form asp-area="Studio2" asp-controller="StatusTransition" asp-action="Edit" asp-route-id="@Model.Id" method |
| | | 43 | | <input type="hidden" asp-for="Id" /> |
| | | 44 | | <input type="hidden" asp-for="CreatedAt" /> |
| | | 45 | | <div asp-validation-summary="All" class="alert alert-danger" data-valmsg-summary="true"></div> |
| | | 46 | | |
| | | 47 | | <div class="row g-3"> |
| | | 48 | | <div class="col-md-6"> |
| | | 49 | | <label asp-for="FromStatusId" class="form-label">Исходный статус<span class="required-mark">*</s |
| | | 50 | | <input type="hidden" asp-for="FromStatusId" data-status-hidden="from" /> |
| | | 51 | | <div class="dropdown"> |
| | | 52 | | <button type="button" class="form-select text-start d-flex align-items-center dropdown-toggl |
| | | 53 | | <span id="fromStatusCaption">Выберите статус</span> |
| | | 54 | | </button> |
| | | 55 | | <ul class="dropdown-menu" aria-labelledby="fromStatusBtn"> |
| | 0 | 56 | | @foreach (var s in statusList) |
| | | 57 | | { |
| | 0 | 58 | | var color = s.GetStatusColor(); |
| | 0 | 59 | | <li><a class="dropdown-item dropdown-status-item" href="#" data-status-id="@s.Id" da |
| | 0 | 60 | | @s.Name |
| | | 61 | | </a></li> |
| | | 62 | | } |
| | | 63 | | </ul> |
| | | 64 | | </div> |
| | | 65 | | <div class="field-hint">Статус заказа до выполнения транзакции.</div> |
| | | 66 | | </div> |
| | | 67 | | <div class="col-md-6"> |
| | | 68 | | <label asp-for="ToStatusId" class="form-label">Целевой статус<span class="required-mark">*</span |
| | | 69 | | <input type="hidden" asp-for="ToStatusId" data-status-hidden="to" /> |
| | | 70 | | <div class="dropdown"> |
| | | 71 | | <button type="button" class="form-select text-start d-flex align-items-center dropdown-toggl |
| | | 72 | | <span id="toStatusCaption">Выберите статус</span> |
| | | 73 | | </button> |
| | | 74 | | <ul class="dropdown-menu" aria-labelledby="toStatusBtn"> |
| | 0 | 75 | | @foreach (var s in statusList) |
| | | 76 | | { |
| | 0 | 77 | | var color = s.GetStatusColor(); |
| | 0 | 78 | | <li><a class="dropdown-item dropdown-status-item" href="#" data-status-id="@s.Id" da |
| | 0 | 79 | | @s.Name |
| | | 80 | | </a></li> |
| | | 81 | | } |
| | | 82 | | </ul> |
| | | 83 | | </div> |
| | | 84 | | <div class="field-hint">Статус после успешного выполнения транзакции.</div> |
| | | 85 | | </div> |
| | | 86 | | <div class="col-12"> |
| | | 87 | | <label asp-for="TransactionType" class="form-label">Тип транзакции<span class="required-mark">*< |
| | | 88 | | <input type="hidden" asp-for="TransactionType" id="TransactionTypeHidden" /> |
| | | 89 | | <div class="dropdown dropdown-type w-100"> |
| | | 90 | | <button type="button" class="form-select text-start d-flex align-items-center dropdown-toggl |
| | | 91 | | <span id="transactionTypeCaption"><i class="fas fa-circle me-2"></i>Выберите тип</span> |
| | | 92 | | </button> |
| | | 93 | | <ul class="dropdown-menu w-100" id="transactionTypeDropdownMenu" aria-labelledby="transactio |
| | 0 | 94 | | @foreach (var t in transactionTypes) |
| | | 95 | | { |
| | 0 | 96 | | var icon = t.GetTransactionTypeIcon(); |
| | 0 | 97 | | var name = t.GetDisplayName(); |
| | 0 | 98 | | <li><a class="dropdown-item transaction-type-item" href="#" data-type-value="@((int) |
| | 0 | 99 | | <i class="@icon me-2"></i>@name |
| | | 100 | | </a></li> |
| | | 101 | | } |
| | | 102 | | </ul> |
| | | 103 | | </div> |
| | | 104 | | </div> |
| | | 105 | | <div class="col-md-6"> |
| | | 106 | | <label asp-for="DisplayName" class="form-label">Название перехода (для UI)</label> |
| | | 107 | | <input asp-for="DisplayName" class="form-control" maxlength="100" /> |
| | | 108 | | </div> |
| | | 109 | | <div class="col-md-6"> |
| | | 110 | | <label asp-for="DisplayOrder" class="form-label">Порядок отображения</label> |
| | | 111 | | <input asp-for="DisplayOrder" class="form-control" type="number" placeholder="Необязательно" /> |
| | | 112 | | </div> |
| | | 113 | | <div class="col-12"> |
| | | 114 | | <label asp-for="Description" class="form-label">Описание</label> |
| | | 115 | | <textarea asp-for="Description" class="form-control" rows="2" maxlength="500"></textarea> |
| | | 116 | | </div> |
| | | 117 | | <div class="col-md-6"> |
| | | 118 | | <label asp-for="SystemName" class="form-label">Системное имя</label> |
| | | 119 | | <input asp-for="SystemName" class="form-control" maxlength="50" /> |
| | | 120 | | </div> |
| | | 121 | | <div class="col-md-6"> |
| | | 122 | | <label asp-for="Conditions" class="form-label">Условия (JSON/текст)</label> |
| | | 123 | | <input asp-for="Conditions" class="form-control" id="ConditionsInput" maxlength="1000" placehold |
| | | 124 | | </div> |
| | | 125 | | <div class="col-12"> |
| | | 126 | | <div class="form-check"> |
| | | 127 | | <input asp-for="IsActive" class="form-check-input" /> |
| | | 128 | | <label asp-for="IsActive" class="form-check-label">Активен</label> |
| | | 129 | | </div> |
| | | 130 | | </div> |
| | | 131 | | <div class="col-12"> |
| | | 132 | | <div class="form-check"> |
| | | 133 | | <input asp-for="IsRepeatable" class="form-check-input" /> |
| | | 134 | | <label asp-for="IsRepeatable" class="form-check-label">Изменение в обе стороны</label> |
| | | 135 | | </div> |
| | | 136 | | </div> |
| | | 137 | | </div> |
| | | 138 | | |
| | | 139 | | <div class="mt-4 d-flex gap-2"> |
| | | 140 | | <button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i>Сохранить</button> |
| | | 141 | | <a asp-area="Studio2" asp-controller="StatusTransition" asp-action="Index" class="btn btn-outline-se |
| | | 142 | | </div> |
| | | 143 | | </form> |
| | | 144 | | </div> |
| | | 145 | | </div> |
| | | 146 | | </div> |
| | | 147 | | |
| | | 148 | | @section Scripts { |
| | | 149 | | <partial name="_ValidationScriptsPartial" /> |
| | | 150 | | <script> |
| | | 151 | | (function () { |
| | 0 | 152 | | var statusList = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(statusList.Select(s => new { s.Id, s.Na |
| | 0 | 153 | | var fromId = @(Model?.FromStatusId ?? 0); |
| | 0 | 154 | | var toId = @(Model?.ToStatusId ?? 0); |
| | 0 | 155 | | var typeVal = @((int)(Model?.TransactionType ?? 0)); |
| | | 156 | | |
| | | 157 | | function setStatusCaption(target, id) { |
| | | 158 | | var s = statusList.find(function(x) { return x.Id === id; }); |
| | | 159 | | var cap = document.getElementById(target + 'StatusCaption'); |
| | | 160 | | var hid = document.querySelector('input[data-status-hidden="' + target + '"]'); |
| | | 161 | | if (s && cap && hid) { |
| | | 162 | | hid.value = id; |
| | | 163 | | cap.innerHTML = '<span class="status-badge" style="background-color:' + s.Color + '40; color: var(-- |
| | | 164 | | updateConditions(); |
| | | 165 | | } |
| | | 166 | | } |
| | | 167 | | function setTypeCaption(val, name, icon) { |
| | | 168 | | var cap = document.getElementById('transactionTypeCaption'); |
| | | 169 | | var hid = document.getElementById('TransactionTypeHidden'); |
| | | 170 | | if (cap && hid) { |
| | | 171 | | hid.value = (val === undefined || val === null) ? '' : String(val); |
| | | 172 | | cap.innerHTML = (icon && name) ? ('<i class="' + icon + ' me-2"></i>' + name) : '<i class="fas fa-ci |
| | | 173 | | } |
| | | 174 | | } |
| | | 175 | | function updateConditions() { |
| | | 176 | | var fromHid = document.querySelector('input[data-status-hidden="from"]'); |
| | | 177 | | var toHid = document.querySelector('input[data-status-hidden="to"]'); |
| | | 178 | | var conditionsInput = document.getElementById('ConditionsInput'); |
| | | 179 | | if (!conditionsInput || !fromHid || !toHid) return; |
| | | 180 | | var fromIdVal = parseInt(fromHid.value, 10); |
| | | 181 | | var toIdVal = parseInt(toHid.value, 10); |
| | | 182 | | if (fromIdVal && toIdVal) { |
| | | 183 | | var fromS = statusList.find(function(x) { return x.Id === fromIdVal; }); |
| | | 184 | | var toS = statusList.find(function(x) { return x.Id === toIdVal; }); |
| | | 185 | | if (fromS && toS) |
| | | 186 | | conditionsInput.value = 'Заказ должен находиться в «' + fromS.Name + '» для перехода в «' + toS. |
| | | 187 | | } |
| | | 188 | | } |
| | | 189 | | |
| | | 190 | | document.querySelectorAll('.dropdown-status-item').forEach(function(el) { |
| | | 191 | | el.addEventListener('click', function(e) { |
| | | 192 | | e.preventDefault(); |
| | | 193 | | var target = this.getAttribute('data-target'); |
| | | 194 | | var id = parseInt(this.getAttribute('data-status-id'), 10); |
| | | 195 | | setStatusCaption(target, id); |
| | | 196 | | }); |
| | | 197 | | }); |
| | | 198 | | document.querySelectorAll('.transaction-type-item').forEach(function(el) { |
| | | 199 | | el.addEventListener('click', function(e) { |
| | | 200 | | e.preventDefault(); |
| | | 201 | | setTypeCaption(parseInt(el.getAttribute('data-type-value'), 10), el.getAttribute('data-type-name'), |
| | | 202 | | }); |
| | | 203 | | }); |
| | | 204 | | |
| | | 205 | | if (fromId) setStatusCaption('from', fromId); |
| | | 206 | | if (toId) setStatusCaption('to', toId); |
| | | 207 | | if (typeVal !== undefined && typeVal !== null) { |
| | | 208 | | var typeOpt = document.querySelector('.transaction-type-item[data-type-value="' + typeVal + '"]'); |
| | | 209 | | if (typeOpt) setTypeCaption(typeVal, typeOpt.getAttribute('data-type-name'), typeOpt.getAttribute('data- |
| | | 210 | | } |
| | | 211 | | updateConditions(); |
| | | 212 | | })(); |
| | | 213 | | </script> |
| | | 214 | | } |