Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

widgets.js 5.0KB

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