|
-
- /* Notifications */
- //Notification.init() ;
-
-
- setDateRange();
-
- setAutoCompleteField();
-
-
- /* Tooltip */
- $('[data-toggle="tooltip"]').tooltip();
-
- /* Select2 */
- if ($('.select2, select.form-control').length) {
-
- $('form .form-widget>select.form-control, .select2').each(function (i, elm) {
- if (!$(this).hasClass('disable-select2')) {
- setSelect2($(elm));
- }
- });
-
- $('form select.form-control').each(function (i, elm) {
- if (!$(this).hasClass('disable-select2')) {
- setSelect2($(elm));
- }
- });
- }
-
- function setSelect2($select) {
- if (typeof $select.data('select2-id') === 'undefined') {
-
- $select.data('init', 'set')
- var options = {
- width: "100%",
- theme: "bootstrap4",
- dropdownAutoWidth: false,
- allowClear: true,
- minimumResultsForSearch: 8
- };
-
- if ($select.data('allow-clear') == 'false') {
- options.allowClear = false;
- }
- if ($select.data('width')) {
- options.width = 'auto'
- }
- if ($select.find('option[value=""]')) {
- options.placeholder = $select.find('option[value=""]').html()
- }
- /*if($select.is(':required') == false) {
- options.allowclear = true
- }*/
- var myselect = $select.select2(options);
-
- myselect.on('select2:select', function (e) {
- var event = new Event('change');
- e.target.dispatchEvent(event);
- });
- myselect.on('select2:unselect', function (e) {
- var event = new Event('change');
- e.target.dispatchEvent(event);
- });
-
- return myselect;
- }
- }
-
-
- $('.action-delete').on('click', function (e) {
- e.preventDefault();
- const formAction = $(this).attr('formaction');
-
- $('#modal-delete').modal({backdrop: true, keyboard: true})
- .off('click', '#modal-delete-button')
- .on('click', '#modal-delete-button', function () {
- let deleteForm = $('#delete-form');
- deleteForm.attr('action', formAction);
- deleteForm.submit();
- });
- });
-
-
- function setDateRange(){
-
-
- $('.date-time-range, .date-range').each(function (i, picker) {
- options = {
- autoUpdateInput: false,
- locale: {
- "format": "DD/MM/YY",
- "separator": " - ",
- "applyLabel": "Appliquer",
- "cancelLabel": "Annuler",
- "fromLabel": "Du",
- "toLabel": "au",
- "customRangeLabel": "Custom",
- "daysOfWeek": ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
- "monthNames": ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
- "firstDay": 1
- }
- };
- if ($(picker).hasClass('date-time-range')){
- options = Object.assign(options, {
- timePicker: true,
- timePickerIncrement: 30,
- timePicker24Hour: true,
- locale: {
- "format": "DD/MM/YYYY HH:mm",
- }
- });
- }
- if ($(picker).nextAll('.date-time-range-fields').find('.date-start').val()) {
- options.startDate = new Date($(picker).nextAll('.date-time-range-fields').find('.date-start').val());
- options.autoUpdateInput = true;
- }
- if ($(picker).nextAll('.date-time-range-fields').find('.date-end').val()) {
- options.endDate = new Date($(picker).nextAll('.date-time-range-fields').find('.date-end').val());
- options.autoUpdateInput = true;
- }
- $(picker).daterangepicker(options);
- $(picker).on('apply.daterangepicker', function (ev, pickerElm) {
- if ($(picker).hasClass('date-time-range')) {
- $(this).val(pickerElm.startDate.format('DD/MM/YY HH:mm') + ' - ' + pickerElm.endDate.format(options.locale.format));
- }else{
- $(this).val(pickerElm.startDate.format('DD/MM/YY') + ' - ' + pickerElm.endDate.format(options.locale.format));
- }
- if ($(picker).hasClass('date-time-range')) {
- $(picker).nextAll('.date-time-range-fields').find('.date-start').val(pickerElm.startDate.format('YYYY-MM-DD HH:mm'));
- $(picker).nextAll('.date-time-range-fields').find('.date-end').val(pickerElm.endDate.format('YYYY-MM-DD HH:mm'));
- }else{
- $(picker).nextAll('.date-time-range-fields').find('.date-start').val(pickerElm.startDate.format('YYYY-MM-DD'));
- $(picker).nextAll('.date-time-range-fields').find('.date-end').val(pickerElm.endDate.format('YYYY-MM-DD'));
- }
- });
- });
-
- }
-
-
- function setAutoCompleteField() {
- var autocompleteFields = $('[data-lc-autocomplete-url]');
-
- autocompleteFields.each(function () {
- var $this = $(this),
- url = $this.data('lc-autocomplete-url');
-
- $this.autoComplete({
- noResultsText: 'Aucun résultat n\'a été trouvé.',
- resolverSettings: {
- url: url
- }
- });
- });
- }
|