app-todo.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*=========================================================================================
  2. File Name: app-todo.js
  3. Description: app-todo
  4. ----------------------------------------------------------------------------------------
  5. Item name: Vuexy - Vuejs, HTML & Laravel Admin Dashboard Template
  6. Author: PIXINVENT
  7. Author URL: http://www.themeforest.net/user/pixinvent
  8. ==========================================================================================*/
  9. $(function () {
  10. "use strict";
  11. var $curr_title, $curr_desc, $curr_info, $curr_fav, $curr_chipVal;
  12. // if it is not touch device
  13. if (!$.app.menu.is_touch_device()) {
  14. // --------------------------------------------
  15. // Sidebar menu scrollbar
  16. // --------------------------------------------
  17. if ($('.todo-application .sidebar-menu-list').length > 0) {
  18. var content = new PerfectScrollbar('.sidebar-menu-list', {
  19. theme: "dark"
  20. });
  21. }
  22. // --------------------------------------------
  23. // Todo task list scrollbar
  24. // --------------------------------------------
  25. if ($('.todo-application .todo-task-list').length > 0) {
  26. var sidebar_todo = new PerfectScrollbar('.todo-task-list', {
  27. theme: "dark"
  28. });
  29. }
  30. }
  31. // if it is a touch device
  32. else {
  33. $(".sidebar-menu-list").css("overflow", "scroll");
  34. $(".todo-task-list").css("overflow", "scroll");
  35. }
  36. // Info star click
  37. $(document).on("click", ".todo-application .todo-item-info i", function (e) {
  38. $(this).parent('.todo-item-info').toggleClass("success");
  39. e.stopPropagation();
  40. });
  41. // Favorite star click
  42. $(document).on("click", ".todo-application .todo-item-favorite i", function (e) {
  43. $(this).parent('.todo-item-favorite').toggleClass("warning");
  44. e.stopPropagation();
  45. });
  46. // Main menu toggle should hide app menu
  47. $('.menu-toggle').on('click', function (e) {
  48. $('.app-content .sidebar-left').removeClass('show');
  49. $('.app-content .app-content-overlay').removeClass('show');
  50. });
  51. // On sidebar close click
  52. $(".todo-application .sidebar-close-icon").on('click', function () {
  53. $('.sidebar-left').removeClass('show');
  54. $('.app-content-overlay').removeClass('show');
  55. });
  56. // Todo sidebar toggle
  57. $('.sidebar-toggle').on('click', function (e) {
  58. e.stopPropagation();
  59. $('.app-content .sidebar-left').toggleClass('show');
  60. $('.app-content .app-content-overlay').addClass('show');
  61. });
  62. $('.app-content .app-content-overlay').on('click', function (e) {
  63. $('.app-content .sidebar-left').removeClass('show');
  64. $('.app-content .app-content-overlay').removeClass('show');
  65. });
  66. // Add class active on click of sidebar filters list
  67. $(".todo-application .list-group-filters a").on('click', function () {
  68. if ($('.todo-application .list-group-filters a').hasClass('active')) {
  69. $('.todo-application .list-group-filters a').removeClass('active');
  70. }
  71. $(this).addClass("active");
  72. });
  73. // For chat sidebar on small screen
  74. if ($(window).width() > 992) {
  75. if ($('.todo-application .app-content-overlay').hasClass('show')) {
  76. $('.todo-application .app-content-overlay').removeClass('show');
  77. }
  78. }
  79. // On add new item, clear modal popup fields
  80. $(".add-task button").on('click', function (e) {
  81. $('.modal .new-todo-item-title').val("");
  82. $('.modal .new-todo-item-desc').val("");
  83. $('.modal .dropdown-menu input').prop("checked", false);
  84. if ($('.modal .todo-item-info').hasClass('success')) { $('.modal .todo-item-info').removeClass('success') }
  85. if ($('.modal .todo-item-favorite').hasClass('warning')) { $('.modal .todo-item-favorite').removeClass('warning') }
  86. });
  87. // To add new todo list item
  88. $(".add-todo-item").on('click', function (e) {
  89. e.preventDefault();
  90. var todoInfo = "",
  91. todoFav = "",
  92. todoChip = "";
  93. var todoTitle = $(".new-todo-item-title").val();
  94. var todoDesc = $(".new-todo-item-desc").val();
  95. if ($(".modal.show .todo-item-info").hasClass('success')) {
  96. todoInfo = " success";
  97. }
  98. if ($(".modal.show .todo-item-favorite").hasClass('warning')) {
  99. todoFav = " warning";
  100. }
  101. // Chip calculation loop
  102. var selected = $('.modal .dropdown-menu input:checked');
  103. selected.each(function () {
  104. todoChip += '<div class="chip mb-0">' +
  105. '<div class="chip-body">' +
  106. '<span class="chip-text" data-value="' + $(this).data('value') + '"><span class="bullet bullet-' + $(this).data('color') + ' bullet-xs"></span> ' + $(this).data('value') + '</span>' +
  107. '</div>' +
  108. '</div>';
  109. });
  110. // HTML Output
  111. if (todoTitle != "") {
  112. $(".todo-task-list-wrapper").append('<li class="todo-item" style="animation-delay: 0s;" data-toggle="modal" data-target="#editTaskModal">' +
  113. '<div class="todo-title-wrapper d-flex justify-content-between mb-50">' +
  114. '<div class="todo-title-area d-flex align-items-center">' +
  115. '<div class="title-wrapper d-flex">' +
  116. '<div class="vs-checkbox-con">' +
  117. '<input type="checkbox" >' +
  118. '<span class="vs-checkbox vs-checkbox-sm">' +
  119. '<span class="vs-checkbox--check">' +
  120. '<i class="vs-icon feather icon-check"></i>' +
  121. '</span>' +
  122. '</span>' +
  123. '</div>' +
  124. '<h6 class="todo-title mt-50 mx-50">' + todoTitle + '</h6>' +
  125. '</div>' +
  126. '<div class="chip-wrapper">' + todoChip + '</div>' +
  127. '</div>' +
  128. '<div class="float-right todo-item-action d-flex">' +
  129. '<a class="todo-item-info' + todoInfo + '"><i class="feather icon-info"></i></a>' +
  130. '<a class="todo-item-favorite' + todoFav + '"><i class="feather icon-star"></i></a>' +
  131. '<a class="todo-item-delete"><i class="feather icon-trash"></i></a>' +
  132. '</div>' +
  133. '</div>' +
  134. '<p class="mb-0 todo-desc truncate">' + todoDesc + '</p>' +
  135. '</li>');
  136. }
  137. $('#form-edit-todo .edit-todo-item-title').val(todoTitle);
  138. $('#form-edit-todo .edit-todo-item-desc').val(todoDesc);
  139. $('#form-edit-todo .dropdown-menu input').prop("checked", false);
  140. if ($('#form-edit-todo .edit-todo-item-info').hasClass('success')) { $('#form-edit-todo .edit-todo-item-info').addClass('success') }
  141. if ($('#form-edit-todo .edit-todo-item-favorite').hasClass('warning')) { $('#form-edit-todo .edit-todo-item-favorite').addClass('warning') }
  142. });
  143. // To update todo list item
  144. $(document).on('click', ".todo-task-list-wrapper .todo-item", function (e) {
  145. // Saving all values in variable
  146. $curr_title = $(this).find('.todo-title'); // Set path for Current Title, use this variable when updating title
  147. $curr_desc = $(this).find('.todo-desc'); // Set path for Current Description, use this variable when updating Description
  148. $curr_info = $(this).find('.todo-item-info'); // Set path for Current info, use this variable when updating info
  149. $curr_fav = $(this).find('.todo-item-favorite'); // Set path for Current favorite, use this variable when updating favorite
  150. $curr_chipVal = $(this).find('.chip-wrapper'); // Set path for Chips, use this variable when updating chip value
  151. var $title = $(this).find('.todo-title').html();
  152. var $desc = $(this).find('.todo-desc').html();
  153. var $info = $(this).find('.todo-item-info');
  154. var $fav = $(this).find('.todo-item-favorite');
  155. $('#form-edit-todo .dropdown-menu input').prop("checked", false);
  156. // Checkbox checked as per chips
  157. var selected = $(this).find('.chip');
  158. selected.each(function () {
  159. var chipVal = $(this).find('.chip-text').data('value');
  160. $('#form-edit-todo .dropdown-menu input[data-value="' + chipVal + '"]').prop("checked", true);
  161. });
  162. // apply all variable values to fields
  163. $('#form-edit-todo .edit-todo-item-title').val($title);
  164. $('#form-edit-todo .edit-todo-item-desc').val($desc);
  165. if ($('#form-edit-todo .todo-item-info').hasClass('success')) { $('#form-edit-todo .todo-item-info').removeClass('success') }
  166. if ($('#form-edit-todo .edit-todo-item-favorite').hasClass('warning')) { $('#form-edit-todo .edit-todo-item-favorite').removeClass('warning') }
  167. if ($($info).hasClass('success')) {
  168. $('#form-edit-todo .todo-item-info').addClass('success');
  169. }
  170. if ($($fav).hasClass('warning')) {
  171. $('#form-edit-todo .edit-todo-item-favorite').addClass('warning');
  172. }
  173. });
  174. // Updating Data Values to Fields
  175. $('.update-todo-item').on('click', function () {
  176. var $edit_title = $('#form-edit-todo .edit-todo-item-title').val();
  177. var $edit_desc = $('#form-edit-todo .edit-todo-item-desc').val();
  178. var $edit_info = $('#form-edit-todo .todo-item-info i');
  179. var $edit_fav = $('#form-edit-todo .todo-item-favorite i');
  180. $($curr_title).text($edit_title);
  181. $($curr_desc).text($edit_desc);
  182. if ($($curr_info).hasClass('success')) { $($curr_info).removeClass('success') }
  183. if ($($curr_fav).hasClass('warning')) { $($curr_fav).removeClass('warning') }
  184. if ($($edit_info).parent('.todo-item-info').hasClass('success')) {
  185. $curr_info.addClass('success');
  186. }
  187. if ($($edit_fav).parent('.todo-item-favorite').hasClass('warning')) {
  188. $curr_fav.addClass('warning');
  189. }
  190. // Chip calculation loop
  191. var $edit_selected = $('#form-edit-todo .dropdown-menu input:checked');
  192. var $edit_todoChip = "";
  193. $edit_selected.each(function () {
  194. $edit_todoChip += '<div class="chip mb-0">' +
  195. '<div class="chip-body">' +
  196. '<span class="chip-text" data-value="' + $(this).data('value') + '"><span class="bullet bullet-' + $(this).data('color') + ' bullet-xs"></span> ' + $(this).data('value') + '</span>' +
  197. '</div>' +
  198. '</div>';
  199. });
  200. $curr_chipVal.empty();
  201. $($curr_chipVal).append($edit_todoChip);
  202. });
  203. //EVENT DELETION
  204. $(document).on('click', '.todo-item-delete', function (e) {
  205. var item = this;
  206. e.stopPropagation();
  207. $(item).closest('.todo-item').remove();
  208. })
  209. // Complete task strike through
  210. $(document).on('click', '.todo-item input', function (event) {
  211. event.stopPropagation();
  212. $(this).closest('.todo-item').toggleClass("completed");
  213. });
  214. // Filter
  215. $("#todo-search").on("keyup", function () {
  216. var value = $(this).val().toLowerCase();
  217. if (value != "") {
  218. $(".todo-item").filter(function () {
  219. $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
  220. });
  221. var tbl_row = $(".todo-item:visible").length; //here tbl_test is table name
  222. //Check if table has row or not
  223. if (tbl_row == 0) {
  224. if (!$('.no-results').hasClass('show')) {
  225. $('.no-results').addClass('show');
  226. }
  227. }
  228. else {
  229. $('.no-results').removeClass('show');
  230. }
  231. }
  232. else {
  233. // If filter box is empty
  234. $(".todo-item").show();
  235. if ($('.no-results').hasClass('show')) {
  236. $('.no-results').removeClass('show');
  237. }
  238. }
  239. });
  240. });
  241. $(window).on("resize", function () {
  242. // remove show classes from sidebar and overlay if size is > 992
  243. if ($(window).width() > 992) {
  244. if ($('.app-content .app-content-overlay').hasClass('show')) {
  245. $('.app-content .sidebar-left').removeClass('show');
  246. $('.app-content .app-content-overlay').removeClass('show');
  247. }
  248. }
  249. });