Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. @page
  2. @model ToDoList.Pages.ToDos.IndexModel
  3.  
  4. <h1>@Model._user.UserName's To Do List</h1>
  5.  
  6. @if (Model.ShowMessage)
  7. {
  8. <div class="alert alert-info alert-dismissible" role="alert">
  9. <button type="button" class="close" data-dismiss="alert" aria-label="close"><span></span></button>
  10. @Model.Message
  11. </div>
  12. }
  13.  
  14. <form method="post">
  15. <hr />
  16. <div asp-validation-summary="All" class="text-danger"></div>
  17. <div class="form-inline">
  18. <label>Create a new task: &nbsp;</label>
  19. <input asp-for="ToDo.Description" class="form-control" size="120" />
  20. <span asp-validation-for="ToDo.Description" class="text-danger"></span>
  21. <button type="submit" class="btn btn-primary"><i class="fas fa-plus"></i></button>
  22. </div>
  23. </form>
  24. <p></p>
  25.  
  26. @* <p>
  27. <p align="right">Filter: <button class="btn btn-primary" onclick="AllFilter()">All</button> | <button class="btn btn-primary" onclick="IncompleteFilter()">Incomplete</button> | <button class="btn btn-primary" onclick="FinishedFilter()">Finished</button></p>
  28. *@
  29.  
  30. @if (Model._user.ToDos != null && Model._user.ToDos.Count > 0)
  31. {
  32.  
  33. <form method="post">
  34. <table class="table">
  35. <thread>
  36. <tr>
  37. <th>Completed?</th>
  38. <th>@Html.DisplayNameFor(t => t.ToDos[0].Description)</th>
  39. <th>@Html.DisplayNameFor(t => t.ToDos[0].Created)</th>
  40. <th>Date/Time Completed</th>
  41. <th>&nbsp;</th>
  42. </tr>
  43. </thread>
  44. <tbody>
  45. @foreach (var todo in Model.filteredToDos)
  46. {
  47. <tr>
  48. <td><input type="checkbox" value="@todo.IsComplete" onclick="ToggleToDo(@todo.TaskID)" checked="@todo.IsComplete" /></td>
  49. @*@Html.CheckBoxFor(t => todo.IsComplete, new { id = todo.TaskID, @class = "toggle"})*@
  50. <td>@Html.DisplayFor(t => todo.Description)</td>
  51. <td>@Html.DisplayFor(t => todo.Created)</td>
  52. <td id="@todo.TaskID">
  53. @if (!todo.IsComplete)
  54. {
  55. <p></p>@*<button asp-page-handler="Edit" asp-route-id="@todo.TaskID" class="btn btn-sm btn-primary">Mark as completed</button>*@
  56. }
  57. else
  58. {
  59. @Html.DisplayFor(t => todo.Completed)
  60. }
  61. </td>
  62. <td><button asp-page-handler="Delete" asp-route-id="@todo.TaskID" class="btn btn-sm btn-danger"><i class="far fa-trash-alt"></i></button></td>
  63. </tr>
  64. }
  65. </tbody>
  66. </table>
  67. </form>
  68. }
  69.  
  70. else
  71. {
  72. <p>No tasks found.</p>
  73. }
  74.  
  75. @section Scripts {
  76. <script>
  77. function ToggleToDo(id) {
  78. console.log(id);
  79. var data = { 'TaskID': id }
  80.  
  81. $.ajax({
  82. type: "POST",
  83. url: "api/ToDo",
  84. beforeSend: function (xhr) {
  85. xhr.setRequestHeader("XSRF-TOKEN",
  86. $('input:hidden[name="__RequestVerificationToken"]').val());
  87. },
  88. contentType: "application/json; charset=utf-8",
  89. dataType: "json",
  90. data: JSON.stringify(data),
  91. success: function (response) {
  92. console.log(response.Completed);
  93. $('#' + id).empty();
  94. var completeTime = "<p>" + response.Completed + "</p>";
  95. if (response.Completed) {
  96. $('#' + id).html(completeTime);
  97. }
  98. },
  99. failure: function (response) {
  100. alert(response);
  101. console.log(response);
  102. }
  103. });
  104. }
  105. </script>
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement