page-users.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. $("#menu-users").addClass("active");
  2. var app = new Vue({
  3. el: "#app",
  4. data: {
  5. users: null,
  6. recentUsers: []
  7. },
  8. mounted: function() {
  9. this.getUsersSince();
  10. },
  11. methods: {
  12. findUsers(searchTerm) {
  13. if (searchTerm.length < 1) {
  14. return false;
  15. }
  16. $.ajax({
  17. url: "/api/user/search/" + searchTerm,
  18. method: "GET",
  19. success: function(data) {
  20. app.users = data;
  21. },
  22. error: toast.defaultAjaxError
  23. });
  24. },
  25. getUsersSince: function() {
  26. let timeLength = Date.now() - 86400000; // 24 hours
  27. $.ajax({
  28. url: "/api/user/since/" + timeLength,
  29. method: "GET",
  30. success: function(data) {
  31. app.recentUsers = data;
  32. },
  33. error: toast.defaultAjaxError
  34. });
  35. },
  36. displayNewUserModal: function() {
  37. $("#newUserModal")
  38. .modal("destroy")
  39. .modal({
  40. onApprove: function() {
  41. let form = $("#newUserForm");
  42. let formData = new FormData(form[0]);
  43. $.ajax({
  44. url: "/api/user/create/",
  45. method: "POST",
  46. data: formData,
  47. cache: false,
  48. contentType: false,
  49. processData: false,
  50. success: function(data) {
  51. app.recentUsers.unshift(data);
  52. },
  53. error: toast.defaultAjaxError
  54. });
  55. }
  56. })
  57. .modal("show");
  58. },
  59. millisToDate: millisToDate
  60. }
  61. });