| | | 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 | | Переход описывает правило: «когда для заказа выполняется транзакция такого-то <strong>типа</strong>, |
| | | 37 | | он должен находиться в <strong>исходном статусе</strong>, и после выполнения переходит в <strong>цел |
| | | 38 | | Эти правила используются в подсказках и кнопках на странице заказов, а весь список переходов |
| | | 39 | | визуально показан на графе на странице <a asp-action="Index">«Переходы между статусами»</a>. |
| | | 40 | | </div> |
| | | 41 | | </div> |
| | | 42 | | |
| | | 43 | | <form asp-area="Studio2" asp-controller="StatusTransition" asp-action="Create" method="post"> |
| | | 44 | | <div asp-validation-summary="All" class="alert alert-danger" data-valmsg-summary="true"></div> |
| | | 45 | | |
| | | 46 | | <div class="row g-3"> |
| | | 47 | | <div class="col-md-6"> |
| | | 48 | | <label asp-for="FromStatusId" class="form-label">Исходный статус<span class="required-mark">*</s |
| | | 49 | | <select asp-for="FromStatusId" class="form-select custom-select-init status-select" id="FromStat |
| | | 50 | | <option value="">Выберите статус</option> |
| | 0 | 51 | | @foreach (var s in statusList) |
| | | 52 | | { |
| | 0 | 53 | | var color = s.GetStatusColor(); |
| | 0 | 54 | | <option value="@s.Id" data-color="@color">@(s.Name)@(s.IsFinal ? " · финальный" : "")</o |
| | | 55 | | } |
| | | 56 | | </select> |
| | | 57 | | <div class="field-hint">Статус, в котором заказ должен находиться ДО выполнения транзакции — ина |
| | | 58 | | </div> |
| | | 59 | | <div class="col-md-6"> |
| | | 60 | | <label asp-for="ToStatusId" class="form-label">Целевой статус<span class="required-mark">*</span |
| | | 61 | | <select asp-for="ToStatusId" class="form-select custom-select-init status-select" id="ToStatusId |
| | | 62 | | <option value="">Выберите статус</option> |
| | 0 | 63 | | @foreach (var s in statusList) |
| | | 64 | | { |
| | 0 | 65 | | var color = s.GetStatusColor(); |
| | 0 | 66 | | <option value="@s.Id" data-color="@color">@(s.Name)@(s.IsFinal ? " · финальный" : "")</o |
| | | 67 | | } |
| | | 68 | | </select> |
| | | 69 | | <div class="field-hint">Статус, в который заказ перейдёт ПОСЛЕ успешного выполнения транзакции. |
| | | 70 | | </div> |
| | | 71 | | |
| | | 72 | | <div class="col-12"> |
| | | 73 | | <label asp-for="TransactionType" class="form-label">Тип транзакции<span class="required-mark">*< |
| | | 74 | | <select asp-for="TransactionType" class="form-select custom-select-init" id="TransactionTypeSele |
| | | 75 | | <option value="">— выберите тип —</option> |
| | 0 | 76 | | @foreach (var t in transactionTypes) |
| | | 77 | | { |
| | 0 | 78 | | <option value="@((int)t)">@t.GetDisplayName()</option> |
| | | 79 | | } |
| | | 80 | | </select> |
| | | 81 | | <div class="field-hint"> |
| | | 82 | | Действие, которое запускает переход (кнопка/API-вызов в системе). Для одного типа транзакции |
| | | 83 | | существовать только один целевой статус — если попытаться завести второй, система откажет |
| | | 84 | | с ошибкой о дубликате, чтобы не было неоднозначности «куда переводить заказ». |
| | | 85 | | </div> |
| | | 86 | | </div> |
| | | 87 | | |
| | | 88 | | <div class="section-title">Отображение</div> |
| | | 89 | | <div class="col-md-6"> |
| | | 90 | | <label asp-for="DisplayName" class="form-label">Название перехода (для UI)</label> |
| | | 91 | | <input asp-for="DisplayName" class="form-control" maxlength="100" placeholder="Необязательно" id |
| | | 92 | | <div class="field-hint">Как переход подпишется в истории заказа и графе. Если оставить пустым — |
| | | 93 | | </div> |
| | | 94 | | <div class="col-md-6"> |
| | | 95 | | <label asp-for="DisplayOrder" class="form-label">Порядок отображения</label> |
| | | 96 | | <input asp-for="DisplayOrder" class="form-control" type="number" placeholder="Необязательно" /> |
| | | 97 | | <div class="field-hint">Влияет только на порядок сортировки в списках/легенде. Меньше — выше. Мо |
| | | 98 | | </div> |
| | | 99 | | <div class="col-12"> |
| | | 100 | | <label asp-for="Description" class="form-label">Описание</label> |
| | | 101 | | <textarea asp-for="Description" class="form-control" rows="2" maxlength="500"></textarea> |
| | | 102 | | <div class="field-hint">Свободный комментарий для администраторов — нигде в интерфейсе заказов н |
| | | 103 | | </div> |
| | | 104 | | |
| | | 105 | | <div class="section-title">Технические поля (необязательно)</div> |
| | | 106 | | <div class="col-md-6"> |
| | | 107 | | <label asp-for="SystemName" class="form-label">Системное имя</label> |
| | | 108 | | <input asp-for="SystemName" class="form-control" maxlength="50" placeholder="Латиницей, для лого |
| | | 109 | | <div class="field-hint">Не используется автоматически бизнес-логикой — служит меткой для поиска |
| | | 110 | | </div> |
| | | 111 | | <div class="col-md-6"> |
| | | 112 | | <label asp-for="Conditions" class="form-label">Условия (текст)</label> |
| | | 113 | | <input asp-for="Conditions" class="form-control" id="ConditionsInput" maxlength="1000" placehold |
| | | 114 | | <div class="field-hint">Человекочитаемое описание условия — подставляется автоматически по стату |
| | | 115 | | </div> |
| | | 116 | | |
| | | 117 | | <div class="col-12"> |
| | | 118 | | <div class="form-check"> |
| | | 119 | | <input asp-for="IsActive" class="form-check-input" checked /> |
| | | 120 | | <label asp-for="IsActive" class="form-check-label">Активен</label> |
| | | 121 | | </div> |
| | | 122 | | <div class="field-hint ms-4">Неактивные переходы не предлагаются на странице заказов, но остаютс |
| | | 123 | | </div> |
| | | 124 | | <div class="col-12"> |
| | | 125 | | <div class="form-check"> |
| | | 126 | | <input asp-for="IsRepeatable" class="form-check-input" /> |
| | | 127 | | <label asp-for="IsRepeatable" class="form-check-label">Переход можно выполнять повторно</lab |
| | | 128 | | </div> |
| | | 129 | | <div class="field-hint ms-4">Отметьте, если один и тот же заказ логично переводить по этому прав |
| | | 130 | | </div> |
| | | 131 | | </div> |
| | | 132 | | |
| | | 133 | | <div class="mt-4 d-flex gap-2"> |
| | | 134 | | <button type="submit" class="btn btn-primary"><i class="fas fa-plus me-1"></i>Создать</button> |
| | | 135 | | <a asp-area="Studio2" asp-controller="StatusTransition" asp-action="Index" class="btn btn-outline-se |
| | | 136 | | </div> |
| | | 137 | | </form> |
| | | 138 | | </div> |
| | | 139 | | </div> |
| | | 140 | | </div> |
| | | 141 | | |
| | | 142 | | @section Scripts { |
| | | 143 | | <partial name="_ValidationScriptsPartial" /> |
| | | 144 | | <script> |
| | | 145 | | (function () { |
| | | 146 | | // Раскрывающиеся списки статусов/типа транзакции — тот же переиспользуемый |
| | | 147 | | // компонент custom-select.js, что и на других страницах Studio2 (Orders и т.д.), |
| | | 148 | | // подключён глобально в _Layout.cshtml, поэтому явно инициализировать не нужно. |
| | 0 | 149 | | var statusList = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(statusList.Select(s => new { s.Id, s.Na |
| | 0 | 150 | | var transactionTypeNames = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(transactionTypes.ToDictionary |
| | | 151 | | |
| | | 152 | | function updateConditions() { |
| | | 153 | | var fromSel = document.getElementById('FromStatusId'); |
| | | 154 | | var toSel = document.getElementById('ToStatusId'); |
| | | 155 | | var conditionsInput = document.getElementById('ConditionsInput'); |
| | | 156 | | if (!fromSel || !toSel || !conditionsInput) return; |
| | | 157 | | |
| | | 158 | | var fromId = parseInt(fromSel.value, 10); |
| | | 159 | | var toId = parseInt(toSel.value, 10); |
| | | 160 | | if (!fromId || !toId) return; |
| | | 161 | | |
| | | 162 | | var fromS = statusList.find(function (x) { return x.Id === fromId; }); |
| | | 163 | | var toS = statusList.find(function (x) { return x.Id === toId; }); |
| | | 164 | | if (fromS && toS) { |
| | | 165 | | conditionsInput.value = 'Заказ должен находиться в «' + fromS.Name + '» для перехода в «' + toS.Name |
| | | 166 | | } |
| | | 167 | | } |
| | | 168 | | |
| | | 169 | | document.getElementById('FromStatusId')?.addEventListener('change', updateConditions); |
| | | 170 | | document.getElementById('ToStatusId')?.addEventListener('change', updateConditions); |
| | | 171 | | |
| | | 172 | | document.getElementById('TransactionTypeSelect')?.addEventListener('change', function () { |
| | | 173 | | var displayNameInput = document.getElementById('DisplayNameInput'); |
| | | 174 | | var name = transactionTypeNames[this.value]; |
| | | 175 | | if (displayNameInput && name && !displayNameInput.value) { |
| | | 176 | | displayNameInput.value = name; |
| | | 177 | | } |
| | | 178 | | }); |
| | | 179 | | |
| | | 180 | | updateConditions(); |
| | | 181 | | })(); |
| | | 182 | | </script> |
| | | 183 | | } |