Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.11 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Exercise Generator</title>
  6. <link rel="stylesheet" href="css/bootstrap.min.css" />
  7. <link rel="stylesheet" href="css/jquery-ui.min.css" />
  8. <link rel="stylesheet" href="css/fitbyte.css" />
  9. </head>
  10.  
  11. <body>
  12. <!-- Container. -->
  13. <div class="container">
  14.  
  15. <!-- Form. -->
  16. <form id="workoutForm">
  17. <h1 align="center">WORKOUT GENERATOR!</h1>
  18. <h4>Choose what You want to train!</h4>
  19. <div class="form-check form-check-inline">
  20. <input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
  21. <label class="form-check-label" for="inlineCheckbox1">ARMS</label>
  22. </div>
  23. <div class="form-check form-check-inline">
  24. <input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2">
  25. <label class="form-check-label" for="inlineCheckbox2">LEGS</label>
  26. </div>
  27. <div class="form-check form-check-inline">
  28. <input class="form-check-input" type="checkbox" id="inlineCheckbox3" value="option3">
  29. <label class="form-check-label" for="inlineCheckbox3">TRUNK</label>
  30. </div>
  31. <div class="form-check form-check-inline">
  32. <input class="form-check-input" type="checkbox" id="checkAll" value="option4">
  33. <label class="form-check-label" for="checkAll">WHOLE BODY</label>
  34. </div>
  35. <h4>How many exercises?</h4>
  36. <div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
  37. <div class="btn-group mr-2" role="group" aria-label="First group">
  38. <button type="button" class="btn btn-secondary btn-lg">4</button>
  39. </div>
  40. <div class="btn-group mr-2" role="group" aria-label="Second group">
  41. <button type="button" class="btn btn-secondary btn-lg">6</button>
  42. </div>
  43. <div class="btn-group mr-2" role="group" aria-label="Third group">
  44. <button type="button" class="btn btn-secondary btn-lg">8</button>
  45. </div>
  46. <div class="btn-group" role="group" aria-label="Fourth group">
  47. <button type="button" class="btn btn-secondary btn-lg">10</button>
  48. </div>
  49. <br><br />
  50. </div>
  51. <div class="form-group row">
  52. <div class="col-sm-10">
  53. <button type="submit" class="btn btn-primary">GENERATE!</button>
  54. </div>
  55. </div>
  56. </form>
  57.  
  58. <!-- Table. -->
  59.  
  60. <div class="tab-content">
  61. <div id="exercises" class="tab-pane fade show active"
  62. role="tabpanel" aria-labelledby="exercises-tab">
  63. <table class="table table-striped">
  64. <thead>
  65. <th scope="col">ID</th>
  66. <th scope="col">Exercise</th>
  67. <th scope="col">Exercise Type</th>
  68. <th scope="col">Image</th>
  69. <th></th>
  70. </thead>
  71. <tbody id="exercise_list"></tbody>
  72. </table>
  73. <button type="button" class="btn btn-primary"
  74. onclick="prepareExerciseAdd()">Add</button>
  75. </div>
  76. </div>
  77. <!-- Exercise modal. -->
  78.  
  79. <div class="modal face" id="exercise_modal" tabindex="-1" role="dialog" aria-labelledby="exercise_modal_label" aria-hidden="true">
  80. <div class="modal-dialog" role="document">
  81. <div class="modal-content">
  82. <div class="modal-header">
  83. <h5 class="modal-title" id="exercise_modal_label">Add/Edit Exercise</h5>
  84. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">x</span></button>
  85. </div>
  86. <div class="modal-body">
  87. <form name="exerciseForm">
  88. <input type="hidden" id="id" name="id" value="0" />
  89. <input type="text" id="name" name="name" class="form-control" placeholder="Exercise" /><br />
  90. <label for="type">Select exercise type:</label>
  91. <select id="type" name="type" class="form-control">
  92. <option value="ARMS">ARMS</option>
  93. <option value="LEGS">LEGS</option>
  94. <option value="TRUNK">TRUNK</option>
  95. </select> <br />
  96. <input type="text" id="image" name="image" class="form-control" placeholder="Image" />
  97. </form>
  98. </div>
  99. <div class="modal-footer">
  100. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
  101. <button type="button" class="btn btn-primary" onclick="saveExercise()" data-dismiss="modal">Submit</button>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106.  
  107. <!--License . -->
  108. </div>
  109.  
  110.  
  111.  
  112. <script src="js/jquery.min.js"></script>
  113. <script src="js/jquery-ui.min.js"></script>
  114. <script src="js/popper.min.js"></script>
  115. <script src="js/bootstrap.min.js"></script>
  116.  
  117. <script>
  118.  
  119. $(document).ready(
  120. function() {
  121. giveMeAllExercises();
  122. }
  123. );
  124.  
  125. $("#checkAll").change(function() {
  126. if($(this).is(":checked")) {
  127. $(".form-check-input").each(function() {
  128. $(this).prop('checked', true);
  129. });
  130. }
  131. else {
  132. $(".form-check-input").each(function() {
  133. $(this).prop('checked', false);
  134. });
  135. }
  136. });
  137.  
  138. $(".form-check-input").change(function() {
  139. var allSelected = true;
  140.  
  141. $(".form-check-input").each(function() {
  142. if(!$(this).is(":checked")) {
  143. $("#checkAll").prop('checked', false);
  144. allSelected = false;
  145. }
  146. });
  147.  
  148. if(allSelected)
  149. $("#checkAll").prop('checked', true);
  150. });
  151.  
  152.  
  153.  
  154. function giveMeAllExercises() {
  155. $.ajax(
  156. {
  157. method: "GET",
  158. url: "/fitbyte/exercise/list",
  159. dataType: "json",
  160. contentType: "application/json",
  161. complete: function(response) {
  162. if (response.status == '401') {
  163. window.location.href = '/fitbyte/login';
  164. }
  165. $('#exercise_list').empty();
  166. var exercises = response.responseJSON;
  167. for (var i = 0; i < exercises.length; i++) {
  168. var row = "<tr>";
  169. row = row + "<td>" + exercises[i].id + "</td>";
  170. row = row + "<td>" + exercises[i].name + "</td>";
  171. row = row + "<td>" + exercises[i].type + "</td>";
  172. row = row + "<td>" + exercises[i].image + "</td>";
  173.  
  174. row = row + "<td>";
  175. row = row + '<button class="btn btn-sm" onclick="prepareExercise(' + exercises[i].id + ');">Edit</button>&nbsp;'
  176. + '<button class ="btn btn-sm btn-danger" onclick="deleteExercise(' + exercises[i].id + ');">Delete</button>';
  177. row = row + "</td>";
  178.  
  179. row = row + "<tr>";
  180. $('#exercise_list').append(row);
  181. }
  182. }
  183. }
  184. );
  185.  
  186. }
  187.  
  188. function prepareExerciseAdd() {
  189. $('#id').val(0);
  190. $('#name').val("");
  191. $('#type').val("");
  192. $('#image').val("");
  193. $('#exercise_modal').modal('show');
  194. }
  195.  
  196. function prepareExercise(exerciseId) {
  197. $.ajax(
  198. {
  199. method: "GET",
  200. url: "/fitbyte/exercise/get/" + exerciseId,
  201. dataType: "json",
  202. contentType: "application/json",
  203. complete: function(response) {
  204. var exercise = response.responseJSON;
  205. $('#id').val(exercise.id);
  206. $('#name').val(exercise.name);
  207. $('#extype').val(exercise.type);
  208. $('#image').val(exercise.image);
  209. $('#exercise_modal').modal('show');
  210. }
  211. }
  212. );
  213. }
  214.  
  215. function saveExercise() {
  216. $.ajax(
  217. {
  218. method: "POST",
  219. url: "/fitbyte/exercise/save",
  220. dataType: "json",
  221. contentType: "application/json",
  222. data: JSON.stringify(getData($('form[name=exerciseForm]').serializeArray())),
  223. complete: function(response) {
  224. giveMeAllExercises();
  225. }
  226. }
  227. );
  228. }
  229.  
  230. function deleteExercise(exerciseId) {
  231. if (confirm('Are you sure?')) {
  232. $.ajax(
  233. {
  234. method: "POST",
  235. url: "/fitbyte/exercise/delete/" + exerciseId,
  236. dataType: "json",
  237. contentType: "application/json",
  238. complete: function(response) {
  239. giveMeAllExercises();
  240. }
  241. }
  242. );
  243. }
  244. }
  245.  
  246.  
  247. function getData(data) {
  248. var result = {};
  249. $.map(data, function(n) {
  250. result[n['name']] = n['value'];
  251. });
  252. return result;
  253. }
  254.  
  255.  
  256. </script>
  257.  
  258. </body>
  259. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement