Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

112 rindas
5.9KB

  1. export class SovWidgets {
  2. static setSelect2($select) {
  3. if (typeof $select.data('select2-id') === 'undefined') {
  4. $select.data('init', 'set')
  5. var options = {
  6. width: "100%",
  7. theme: "bootstrap4",
  8. dropdownAutoWidth: false,
  9. allowClear: true,
  10. minimumResultsForSearch: 8
  11. };
  12. if ($select.data('allow-clear') == 'false') {
  13. options.allowClear = false;
  14. }
  15. if ($select.data('width')) {
  16. options.width = 'auto'
  17. }
  18. if ($select.find('option[value=""]')) {
  19. options.placeholder = $select.find('option[value=""]').html()
  20. }
  21. /*if($select.is(':required') == false) {
  22. options.allowclear = true
  23. }*/
  24. var myselect = $select.select2(options);
  25. myselect.on('select2:select', function (e) {
  26. var event = new Event('change');
  27. e.target.dispatchEvent(event);
  28. });
  29. myselect.on('select2:unselect', function (e) {
  30. var event = new Event('change');
  31. e.target.dispatchEvent(event);
  32. });
  33. return myselect;
  34. }
  35. }
  36. static setDateRange() {
  37. $('.date-time-range, .date-range').each(function (i, picker) {
  38. options = {
  39. autoUpdateInput: false,
  40. locale: {
  41. "format": "DD/MM/YY",
  42. "separator": " - ",
  43. "applyLabel": "Appliquer",
  44. "cancelLabel": "Annuler",
  45. "fromLabel": "Du",
  46. "toLabel": "au",
  47. "customRangeLabel": "Custom",
  48. "daysOfWeek": ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
  49. "monthNames": ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
  50. "firstDay": 1
  51. }
  52. };
  53. if ($(picker).hasClass('date-time-range')) {
  54. options = Object.assign(options, {
  55. timePicker: true,
  56. timePickerIncrement: 30,
  57. timePicker24Hour: true,
  58. locale: {
  59. "format": "DD/MM/YYYY HH:mm",
  60. }
  61. });
  62. }
  63. if ($(picker).nextAll('.date-time-range-fields').find('.date-start').val()) {
  64. options.startDate = new Date($(picker).nextAll('.date-time-range-fields').find('.date-start').val());
  65. options.autoUpdateInput = true;
  66. }
  67. if ($(picker).nextAll('.date-time-range-fields').find('.date-end').val()) {
  68. options.endDate = new Date($(picker).nextAll('.date-time-range-fields').find('.date-end').val());
  69. options.autoUpdateInput = true;
  70. }
  71. $(picker).daterangepicker(options);
  72. $(picker).on('apply.daterangepicker', function (ev, pickerElm) {
  73. if ($(picker).hasClass('date-time-range')) {
  74. $(this).val(pickerElm.startDate.format('DD/MM/YY HH:mm') + ' - ' + pickerElm.endDate.format(options.locale.format));
  75. } else {
  76. $(this).val(pickerElm.startDate.format('DD/MM/YY') + ' - ' + pickerElm.endDate.format(options.locale.format));
  77. }
  78. if ($(picker).hasClass('date-time-range')) {
  79. $(picker).nextAll('.date-time-range-fields').find('.date-start').val(pickerElm.startDate.format('YYYY-MM-DD HH:mm'));
  80. $(picker).nextAll('.date-time-range-fields').find('.date-end').val(pickerElm.endDate.format('YYYY-MM-DD HH:mm'));
  81. } else {
  82. $(picker).nextAll('.date-time-range-fields').find('.date-start').val(pickerElm.startDate.format('YYYY-MM-DD'));
  83. $(picker).nextAll('.date-time-range-fields').find('.date-end').val(pickerElm.endDate.format('YYYY-MM-DD'));
  84. }
  85. });
  86. });
  87. }
  88. static setAutoCompleteField() {
  89. var autocompleteFields = $('[data-lc-autocomplete-url]');
  90. autocompleteFields.each(function () {
  91. var $this = $(this),
  92. url = $this.data('lc-autocomplete-url');
  93. $this.autoComplete({
  94. noResultsText: 'Aucun résultat n\'a été trouvé.',
  95. resolverSettings: {
  96. url: url
  97. }
  98. });
  99. });
  100. }
  101. }