GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 7c7dc7...8c45e1 )
by
unknown
05:43
created

report.js ➔ setupAutocomplete   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 79
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 56
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 79
rs 8.44

1 Function

Rating   Name   Duplication   Size   Complexity  
B report.js ➔ ... ➔ $(ꞌ.sylius-autocompleteꞌ).each 0 77 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var handleTimePeriodEndTodayCheckboxChange = function () {
2
    var $timePeriodEndToday = $('#timePeriod_end_today');
3
    var isChecked = $timePeriodEndToday.get(0).checked;
4
5
    if (!isChecked) {
6
        var now = new Date();
7
8
        $('#odiseo_sylius_report_dataFetcherConfiguration_timePeriod_end_year').val(now.getFullYear());
9
        $('#odiseo_sylius_report_dataFetcherConfiguration_timePeriod_end_month').val(now.getMonth() + 1);
10
        $('#odiseo_sylius_report_dataFetcherConfiguration_timePeriod_end_day').val(now.getDate());
11
    }
12
13
    $timePeriodEndToday.closest('.field').find('select').prop('disabled', isChecked);
14
};
15
16
var setupAutocomplete = function () {
17
    $('.sylius-autocomplete').each(function(idx, el) {
18
        var element = $(el);
19
        var criteriaName = element
20
            .data('criteria-name');
21
        var choiceName = element
22
            .data('choice-name');
23
        var choiceValue = element
24
            .data('choice-value');
25
        var autocompleteValue = element
26
            .find('input.autocomplete')
27
            .val();
28
        var loadForEditUrl = element
29
            .data('load-edit-url');
30
31
        element
32
            .dropdown({
33
                delay: {
34
                    search: 250
35
                },
36
                minCharacters: 3,
37
                forceSelection: false,
38
                apiSettings: {
39
                    dataType: 'JSON',
40
                    cache: false,
41
                    beforeSend: function beforeSend(settings) {
42
                        /* eslint-disable-next-line no-param-reassign */
43
                        settings.data[criteriaName] = settings.urlData.query;
44
45
                        return settings;
46
                    },
47
                    onResponse: function onResponse(response) {
48
                        return {
49
                            success: true,
50
                            results: response.map(function (item) {
51
                                return {
52
                                    name: item[choiceName],
53
                                    value: item[choiceValue]
54
                                };
55
                            })
56
                        };
57
                    }
58
                }
59
            });
60
61
        if (autocompleteValue.split(',')
62
            .filter(String).length > 0) {
63
            var menuElement = element
64
                .find('div.menu');
65
66
            menuElement.api({
67
                on: 'now',
68
                method: 'GET',
69
                url: loadForEditUrl,
70
                beforeSend: function beforeSend(settings) {
71
                    /* eslint-disable-next-line no-param-reassign */
72
                    settings.data[choiceValue] = autocompleteValue.split(',')
73
                        .filter(String);
74
75
                    return settings;
76
                },
77
                onSuccess: function onSuccess(response) {
78
                    response.forEach(function (item) {
79
                        menuElement.append($('<div class="item" data-value="' + item[choiceValue] + '">' + item[choiceName] + '</div>'));
80
                    });
81
                }
82
            });
83
        }
84
85
        window.setTimeout(function () {
86
            element
87
                .dropdown('set selected', element
88
                    .find('input.autocomplete')
89
                    .val()
90
                    .split(',')
91
                    .filter(String));
92
        }, 5000);
93
    });
94
};
95
96
var setupForms = function () {
97
    $('#odiseo_sylius_report_dataFetcher_configuration .ui.toggle.checkbox').checkbox();
98
    $('#odiseo_sylius_report_dataFetcher_configuration .ui.dropdown').dropdown();
99
100
    setupAutocomplete();
101
};
102
103
(function ($) {
104
    'use strict';
105
106
    $(document).ready(function()
107
    {
108
        setupForms();
109
        handleTimePeriodEndTodayCheckboxChange();
110
111
        $('#odiseo_sylius_report_renderer').handlePrototypes({
112
            'prototypePrefix': 'odiseo_sylius_report_renderer_renderers',
113
            'containerSelector': '#odiseo_sylius_report_renderer_configuration'
114
        });
115
        $('#odiseo_sylius_report_dataFetcher').handlePrototypes({
116
            'prototypePrefix': 'odiseo_sylius_report_dataFetcher_dataFetchers',
117
            'containerSelector': '#odiseo_sylius_report_dataFetcher_configuration'
118
        });
119
        $('#odiseo_sylius_report_dataFetcher').on('change', function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
120
            handleTimePeriodEndTodayCheckboxChange();
121
            setupForms();
122
        });
123
        $('#timePeriod_end_today').on('change', function () {
124
            handleTimePeriodEndTodayCheckboxChange();
125
        })
126
    });
127
})( jQuery );