admin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Admin JavaScript for the QDR Temporary Shared Storage plugin
  3. */
  4. (function($) {
  5. 'use strict';
  6. // Initialize datepickers on dynamically created elements
  7. function initDatepickers() {
  8. $('.qdr-tss-datepicker').datepicker({
  9. dateFormat: 'yy-mm-dd',
  10. changeMonth: true,
  11. changeYear: true
  12. });
  13. }
  14. // Format file size to human readable format
  15. function formatFileSize(bytes) {
  16. if (bytes === 0) return '0 Bytes';
  17. const k = 1024;
  18. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  19. const i = Math.floor(Math.log(bytes) / Math.log(k));
  20. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  21. }
  22. // Format date to local format
  23. function formatDate(dateString) {
  24. if (!dateString || dateString === '0000-00-00 00:00:00') {
  25. return '-';
  26. }
  27. var date = new Date(dateString);
  28. // Check if date is valid
  29. if (isNaN(date.getTime())) {
  30. return dateString;
  31. }
  32. return date.toLocaleString();
  33. }
  34. // Set active sort indicators
  35. function updateSortIndicators(orderBy, order) {
  36. // Remove all indicators
  37. $('.qdr-tss-table th').removeClass('sorted asc desc');
  38. // Add indicator to current sort column
  39. var $th = $('.qdr-tss-table th[data-sort="' + orderBy + '"]');
  40. $th.addClass('sorted ' + order.toLowerCase());
  41. }
  42. // Initialize tooltips
  43. function initTooltips() {
  44. $('.qdr-tss-tooltip').tooltip({
  45. position: {
  46. my: 'center bottom-20',
  47. at: 'center top',
  48. using: function(position, feedback) {
  49. $(this).css(position);
  50. $('<div>')
  51. .addClass('arrow')
  52. .addClass(feedback.vertical)
  53. .addClass(feedback.horizontal)
  54. .appendTo(this);
  55. }
  56. }
  57. });
  58. }
  59. // Document ready
  60. $(function() {
  61. // Initialize datepickers on page load
  62. initDatepickers();
  63. // Initialize tooltips
  64. initTooltips();
  65. // Add button for refreshing the list
  66. $('#qdr-tss-items-list').on('updated', function() {
  67. initTooltips();
  68. });
  69. });
  70. })(jQuery);