|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- export class SovWidgets {
-
- static 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()
- }
-
- 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);
- });
- SovTools.log(myselect);
-
- return myselect;
- }
- }
-
- static setDateRange() {
- $('.date-time-range, .date-range').each(function (i, picker) {
- let 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'));
- }
- });
- });
- }
-
- static setAutoCompleteField() {
- var autocompleteFields = $('[data-lc-autocomplete-url]');
- autocompleteFields.each(function () {
- var $this = $(this),
- url = $this.data('lc-autocomplete-url');
-
- $this.autoComplete({
- //bootstrapVersion: 4,
- //noResultsText: 'Aucun résultat n\'a été trouvé.',
- resolverSettings: {
- url: url
- }
- });
- });
- }
-
- static setCollectionWidget() {
-
- $('.field-collection[data-prototype]').each(function (i, collectionWidget) {
- SovWidgetCollection.setCollectionWidgetSortable($(collectionWidget));
- SovWidgetCollection.reindexKeyCollectionWidget($(collectionWidget));
-
- SovWidgetCollection.setCollectionWidgetAdd($(collectionWidget));
- SovWidgetCollection.setCollectionWidgetDelete($(collectionWidget));
- });
- }
-
- }
|