GameGenre.cshtml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. @page
  2. @model Admin.Pages.Store.GameGenreModel
  3. @{
  4. ViewData["Title"] = "게임 장르";
  5. }
  6. <div class="container-fluid">
  7. <h3>@ViewData["Title"]</h3>
  8. <hr />
  9. <partial name="_StatusMessage" />
  10. <div class="row g-2 align-items-end mt-2">
  11. <div class="col">
  12. Total : @Model.Total
  13. </div>
  14. <div class="col text-end">
  15. <button type="button" id="btnAdd" class="btn btn-primary" form="fAdminWrite">추가</button>
  16. <button type="submit" id="btnSave" class="btn btn-success" form="fAdminWrite">저장</button>
  17. </div>
  18. </div>
  19. <div class="table-responsive">
  20. <form id="fAdminWrite" method="post" accept-charset="utf-8" autocomplete="off"></form>
  21. <table class="table table-bordered table-hover mt-3">
  22. <caption>
  23. 게임에 연결된 장르는 삭제할 수 없습니다.<br />
  24. 삭제하려면 해당 게임의 장르 선택을 먼저 해제해주세요.
  25. </caption>
  26. <colgroup>
  27. <col style="width: 5%;" />
  28. <col />
  29. <col />
  30. <col style="width: 8%;" />
  31. <col style="width: 8%;" />
  32. <col style="width: 6%;" />
  33. <col />
  34. <col />
  35. <col style="width: 8%;" />
  36. </colgroup>
  37. <thead>
  38. <tr class="text-center">
  39. <th>ID</th>
  40. <th>한글명</th>
  41. <th>영문명</th>
  42. <th>게임 수</th>
  43. <th>순서</th>
  44. <th>사용</th>
  45. <th>등록일시</th>
  46. <th>수정일시</th>
  47. <th>비고</th>
  48. </tr>
  49. </thead>
  50. <tbody id="rows">
  51. @if (Model.List == null || Model.List.Count <= 0)
  52. {
  53. <tr>
  54. <td colspan="9">No Data.</td>
  55. </tr>
  56. }
  57. else
  58. {
  59. @foreach (var row in Model.List)
  60. {
  61. var index = row.Index;
  62. <tr>
  63. <td>
  64. <input type="text" readonly class="form-control-plaintext text-center @(row.GameCount > 0 ? "text-white bg-danger" : "")" value="@row.Num" />
  65. <input type="hidden" name="request[@index].ID" readonly required form="fAdminWrite" value="@row.ID" />
  66. </td>
  67. <td>
  68. <input type="text" name="request[@index].KorName" class="form-control" maxlength="100" required form="fAdminWrite" value="@row.KorName" />
  69. </td>
  70. <td>
  71. <input type="text" name="request[@index].EngName" class="form-control" maxlength="100" form="fAdminWrite" value="@row.EngName" />
  72. </td>
  73. <td class="text-center align-middle">@row.GameCount</td>
  74. <td>
  75. <input type="number" name="request[@index].Order" class="form-control" min="-9999" max="9999" required form="fAdminWrite" value="@row.Order" />
  76. </td>
  77. <td>
  78. <div class="form-check-inline">
  79. <input class="form-check-input" type="checkbox" id="request_@(index)_IsActive" name="request[@index].IsActive" checked="@Model.Data[index].IsActive" form="fAdminWrite" value="true" />
  80. <label class="form-check-label" for="request_@(index)_IsActive">사용</label>
  81. </div>
  82. </td>
  83. <td><input type="text" readonly class="form-control-plaintext text-center" form="fAdminWrite" value="@row.CreatedAt" /></td>
  84. <td><input type="text" readonly class="form-control-plaintext text-center" form="fAdminWrite" value="@row.UpdatedAt" /></td>
  85. <td>
  86. <button type="button" class="btn btn-sm btn-danger btn-delete">삭제</button>
  87. </td>
  88. </tr>
  89. }
  90. }
  91. </tbody>
  92. </table>
  93. </div>
  94. </div>
  95. @section Scripts {
  96. <script>
  97. $(function() {
  98. let $rows = $("#rows");
  99. let total = Number(@Model.Total);
  100. $(document).on("click", "#btnAdd", function() {
  101. if (total <= 0) {
  102. $rows.empty();
  103. }
  104. let tableRow = `
  105. <tr>
  106. <td>-</td>
  107. <td>
  108. <input type="text" name="request[${total}].KorName" class="form-control" maxlength="100" required form="fAdminWrite" />
  109. </td>
  110. <td>
  111. <input type="text" name="request[${total}].EngName" class="form-control" maxlength="100" form="fAdminWrite" />
  112. </td>
  113. <td class="text-center align-middle">-</td>
  114. <td>
  115. <input type="number" name="request[${total}].Order" class="form-control" min="-9999" max="9999" required form="fAdminWrite" value="0" />
  116. </td>
  117. <td>
  118. <div class="form-check-inline">
  119. <input class="form-check-input" type="checkbox" id="request_${total}_IsActive" name="request[${total}].IsActive" checked form="fAdminWrite" value="true" />
  120. <label class="form-check-label" for="request_${total}_IsActive">사용</label>
  121. </div>
  122. </td>
  123. <td>-</td>
  124. <td>-</td>
  125. <td>
  126. <button type="button" class="btn btn-danger btn-sm btn-delete">삭제</button>
  127. </td>
  128. </tr>
  129. `;
  130. $rows.append(tableRow);
  131. total++;
  132. recalculateIndices();
  133. });
  134. $(document).on("click", "button.btn-delete", function(e) {
  135. e.target.closest("tr").remove();
  136. total--;
  137. if (total <= 0) {
  138. $rows.append(`<tr><td colspan="9">No Data.</td></tr>`);
  139. total = 0;
  140. } else {
  141. recalculateIndices();
  142. }
  143. });
  144. $(document).on("click", "#btnSave", function() {
  145. if (confirm("저장 하시겠습니까?")) {
  146. let form = document.getElementById("fAdminWrite");
  147. if (form.checkValidity()) {
  148. form.submit();
  149. } else {
  150. form.reportValidity();
  151. }
  152. }
  153. return false;
  154. });
  155. function recalculateIndices() {
  156. $rows.find("tr").each(function(index, tr) {
  157. $(tr).find("input, label").each(function() {
  158. let name = $(this).attr("name");
  159. let id = $(this).attr("id");
  160. let labelFor = $(this).attr("for");
  161. if (name) {
  162. $(this).attr("name", name.replace(/\[\d+\]/, `[${index}]`));
  163. }
  164. if (id) {
  165. $(this).attr("id", id.replace(/_\d+_/, `_${index}_`));
  166. }
  167. if (labelFor) {
  168. $(this).attr("for", labelFor.replace(/_\d+_/, `_${index}_`));
  169. }
  170. });
  171. });
  172. }
  173. });
  174. </script>
  175. }