You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
5.0KB

  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. var myselect = $select.select2(options);
  22. myselect.on('select2:select', function (e) {
  23. var event = new Event('change');
  24. e.target.dispatchEvent(event);
  25. });
  26. myselect.on('select2:unselect', function (e) {
  27. var event = new Event('change');
  28. e.target.dispatchEvent(event);
  29. });
  30. SovTools.log(myselect);
  31. myselect.off('select2:open')
  32. return myselect;
  33. }
  34. }
  35. static setDateRange() {
  36. $('.date-time-range, .date-range').each(function (i, picker) {
  37. let options = {
  38. autoUpdateInput: false,
  39. locale: {
  40. "format": "DD/MM/YY",
  41. "separator": " - ",
  42. "applyLabel": "Appliquer",
  43. "cancelLabel": "Annuler",
  44. "fromLabel": "Du",
  45. "toLabel": "au",
  46. "customRangeLabel": "Custom",
  47. "daysOfWeek": ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
  48. "monthNames": ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
  49. "firstDay": 1
  50. }
  51. };
  52. if ($(picker).hasClass('date-time-range')) {
  53. options = Object.assign(options, {
  54. timePicker: true,
  55. timePickerIncrement: 30,
  56. timePicker24Hour: true,
  57. locale: {
  58. "format": "DD/MM/YYYY HH:mm",
  59. }
  60. });
  61. }
  62. if ($(picker).nextAll('.date-time-range-fields').find('.date-start').val()) {
  63. options.startDate = new Date($(picker).nextAll('.date-time-range-fields').find('.date-start').val());
  64. options.autoUpdateInput = true;
  65. }
  66. if ($(picker).nextAll('.date-time-range-fields').find('.date-end').val()) {
  67. options.endDate = new Date($(picker).nextAll('.date-time-range-fields').find('.date-end').val());
  68. options.autoUpdateInput = true;
  69. }
  70. $(picker).daterangepicker(options);
  71. $(picker).on('apply.daterangepicker', function (ev, pickerElm) {
  72. if ($(picker).hasClass('date-time-range')) {
  73. $(this).val(pickerElm.startDate.format('DD/MM/YY HH:mm') + ' - ' + pickerElm.endDate.format(options.locale.format));
  74. } else {
  75. $(this).val(pickerElm.startDate.format('DD/MM/YY') + ' - ' + pickerElm.endDate.format(options.locale.format));
  76. }
  77. if ($(picker).hasClass('date-time-range')) {
  78. $(picker).nextAll('.date-time-range-fields').find('.date-start').val(pickerElm.startDate.format('YYYY-MM-DD HH:mm'));
  79. $(picker).nextAll('.date-time-range-fields').find('.date-end').val(pickerElm.endDate.format('YYYY-MM-DD HH:mm'));
  80. } else {
  81. $(picker).nextAll('.date-time-range-fields').find('.date-start').val(pickerElm.startDate.format('YYYY-MM-DD'));
  82. $(picker).nextAll('.date-time-range-fields').find('.date-end').val(pickerElm.endDate.format('YYYY-MM-DD'));
  83. }
  84. });
  85. });
  86. }
  87. static setAutoCompleteField() {
  88. var autocompleteFields = $('[data-lc-autocomplete-url]');
  89. autocompleteFields.each(function () {
  90. var $this = $(this),
  91. url = $this.data('lc-autocomplete-url');
  92. $this.autoComplete({
  93. //bootstrapVersion: 4,
  94. //noResultsText: 'Aucun résultat n\'a été trouvé.',
  95. resolverSettings: {
  96. url: url
  97. }
  98. });
  99. });
  100. }
  101. static setCollectionWidget() {
  102. $('.field-collection[data-prototype]').each(function (i, collectionWidget) {
  103. SovWidgetCollection.setCollectionWidgetSortable($(collectionWidget));
  104. SovWidgetCollection.reindexKeyCollectionWidget($(collectionWidget));
  105. SovWidgetCollection.setCollectionWidgetAdd($(collectionWidget));
  106. SovWidgetCollection.setCollectionWidgetDelete($(collectionWidget));
  107. });
  108. }
  109. }