選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

153 行
4.9KB

  1. export class SovTools {
  2. static log(value) {
  3. try {
  4. console.log(value);
  5. } catch {
  6. }
  7. }
  8. static arrayRemove(arr, value) {
  9. return arr.filter(function (ele) {
  10. return ele != value;
  11. });
  12. }
  13. static toPlainText(html) {
  14. let scratchDiv = document.createElement('div');
  15. scratchDiv.innerHTML = html;
  16. return scratchDiv.textContent;
  17. }
  18. static getDateFormatted(date, separator) {
  19. if (date) {
  20. var date = new Date(date);
  21. var _d = date.getDate(),
  22. d = _d > 9 ? _d : '0' + _d,
  23. _m = date.getMonth() + 1,
  24. m = _m > 9 ? _m : '0' + _m,
  25. formatted = d + separator + m + separator + date.getFullYear();
  26. return formatted;
  27. } else {
  28. return '';
  29. }
  30. }
  31. static getUrlParameter(sParam) {
  32. var sPageURL = window.location.search.substring(1),
  33. sURLVariables = sPageURL.split('&'),
  34. sParameterName,
  35. i;
  36. for (i = 0; i < sURLVariables.length; i++) {
  37. sParameterName = sURLVariables[i].split('=');
  38. if (sParameterName[0] === sParam) {
  39. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  40. }
  41. }
  42. }
  43. static indexOfFirstDigit(input) {
  44. let i = 0;
  45. for (; input[i] < '0' || input[i] > '9'; i++) ;
  46. return i == input.length ? -1 : i;
  47. }
  48. static indexOfLastDigit(input) {
  49. let i = input.length - 1;
  50. for (; input[i] < '0' || input[i] > '9'; i--) ;
  51. return i == input.length ? -1 : i;
  52. }
  53. static formatNumber(number, toFixed) {
  54. if (number) return Number(number.replace(',', '.')).toFixed(toFixed);
  55. else return null;
  56. }
  57. static formatNumberWithoutRounding(number, toFixed) {
  58. if (number) {
  59. let factor = Math.pow(10, toFixed);
  60. return Math.floor(number * factor) / factor
  61. } else {
  62. return null
  63. }
  64. }
  65. static formatNumberWithoutFixed(number) {
  66. if (typeof number == 'string') number = number.replace(',', '.');
  67. if (number) return Number(number);
  68. else return null;
  69. }
  70. static getUrlParameter(sParam) {
  71. var sPageURL = window.location.search.substring(1),
  72. sURLVariables = sPageURL.split('&'),
  73. sParameterName,
  74. i;
  75. for (i = 0; i < sURLVariables.length; i++) {
  76. sParameterName = sURLVariables[i].split('=');
  77. if (sParameterName[0] === sParam) {
  78. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  79. }
  80. }
  81. };
  82. static readFlashMessages(flashMessages) {
  83. var currentFlash = new Array();
  84. for (var type in flashMessages) {
  85. for (var key in flashMessages[type]) {
  86. if (!currentFlash.includes(flashMessages[type][key])) {
  87. currentFlash.push(flashMessages[type][key]);
  88. SovNotification.add(type, flashMessages[type][key]);
  89. }
  90. }
  91. }
  92. }
  93. static checkFormValidity(formId) {
  94. if (!document.getElementById(formId.substr(1)).checkValidity()) {
  95. document.getElementById(formId.substr(1)).reportValidity()
  96. return false;
  97. } else {
  98. return true;
  99. }
  100. }
  101. static initCountSmsCharacter(countSmsTextareaClass) {
  102. $(countSmsTextareaClass).each(function () {
  103. $(this).after('<div class="count-sms-character-info"></div>');
  104. SovTools.displaySmsTotalCharacter($(this));
  105. $(this).on('keyup', function () {
  106. SovTools.displaySmsTotalCharacter($(this));
  107. });
  108. })
  109. }
  110. static displaySmsTotalCharacter($textarea) {
  111. var totalCharacter = $textarea.val().length;
  112. var totalCharacterCurrentSms = totalCharacter % 160;
  113. if (totalCharacterCurrentSms == 0 && totalCharacter > 0) {
  114. totalCharacterCurrentSms = 160;
  115. }
  116. let totalSms = Math.ceil(totalCharacter / 160);
  117. $textarea.next().html(totalCharacterCurrentSms + '/160 -<strong>' + totalSms + ' sms</strong>');
  118. }
  119. static displayPageNeedToReload(){
  120. const reloadDiv = document.createElement('div');
  121. reloadDiv.id = 'page-need-to-reload';
  122. // Ajoute le bouton à l'intérieur de ce div
  123. reloadDiv.innerHTML = '<button id="reload-btn" style="display: none;" type="button" class="btn btn-info" onclick="window.location.reload()">Recharger la page</button>';
  124. // Ajoute le div à la fin du body
  125. document.body.appendChild(reloadDiv);
  126. //Affichage du bouton recharger la page après 5 sec
  127. let button = document.getElementById("reload-btn");
  128. setTimeout(() => {
  129. button.style.display = "block";
  130. }, 3000);
  131. }
  132. }