您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

155 行
5.1KB

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