dashboard.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Dashboard configuration
  4. *
  5. * Demo dashboard configuration. Contains charts and plugin initializations
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var Dashboard = function () {
  11. //
  12. // Setup module components
  13. //
  14. // Setup Daterangepicker
  15. var _componentDaterange = function() {
  16. if (!$().daterangepicker) {
  17. console.warn('Warning - daterangepicker.js is not loaded.');
  18. return;
  19. }
  20. // Initialize
  21. $('.daterange-ranges').daterangepicker(
  22. {
  23. startDate: moment().subtract(29, 'days'),
  24. endDate: moment(),
  25. minDate: '01/01/2015',
  26. maxDate: '12/31/2019',
  27. dateLimit: { days: 60 },
  28. parentEl: '.content-inner',
  29. ranges: {
  30. 'Today': [moment(), moment()],
  31. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  32. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  33. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  34. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  35. 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  36. },
  37. opens: $('html').attr('dir') == 'rtl' ? 'right' : 'left',
  38. applyClass: 'btn-sm btn-secondary btn-block',
  39. cancelClass: 'btn-sm btn-light btn-block',
  40. locale: {
  41. format: 'MM/DD/YYYY',
  42. direction: $('html').attr('dir') == 'rtl' ? 'rtl' : 'ltr'
  43. }
  44. },
  45. function(start, end) {
  46. $('.daterange-ranges span').html(start.format('MMMM D') + ' - ' + end.format('MMMM D'));
  47. }
  48. );
  49. $('.daterange-ranges span').html(moment().subtract(29, 'days').format('MMMM D') + ' - ' + moment().format('MMMM D'));
  50. };
  51. // Use first letter as an icon
  52. var _componentIconLetter = function() {
  53. // Grab first letter and insert to the icon
  54. $('.table tr').each(function() {
  55. // Title
  56. var $title = $(this).find('.letter-icon-title'),
  57. letter = $title.eq(0).text().charAt(0).toUpperCase();
  58. // Icon
  59. var $icon = $(this).find('.letter-icon');
  60. $icon.eq(0).text(letter);
  61. });
  62. };
  63. //
  64. // Return objects assigned to module
  65. //
  66. return {
  67. initComponents: function() {
  68. _componentDaterange();
  69. _componentIconLetter();
  70. }
  71. }
  72. }();
  73. // Initialize module
  74. // ------------------------------
  75. document.addEventListener('DOMContentLoaded', function() {
  76. Dashboard.initComponents();
  77. });