assets/js/pages/properties.js   A
last analyzed

Complexity

Total Complexity 12
Complexity/F 1.33

Size

Lines of Code 69
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 44
c 0
b 0
f 0
dl 0
loc 69
rs 10
mnd 3
bc 3
fnc 9
bpm 0.3333
cpm 1.3333
noi 1
1
import 'bootstrap/js/dist/tooltip';
2
import '../../scss/pages/properties/index.scss';
3
import '../../scss/pages/properties/property.scss';
4
import '../../scss/pages/properties/filter_form.scss';
5
6
let $body = $('body');
7
let $filterForm = $('#filter-form');
8
let $sortSelect = $('#sort-select');
9
let $container = $('#property-ad-container');
10
let xhrCount = 0;
11
12
$filterForm.on('submit', function (e) {
13
    e.preventDefault();
14
15
    loadProperties();
16
});
17
18
$sortSelect.on('change', function () {
19
    loadProperties();
20
});
21
22
const loadProperties = () => {
23
    let xhrId = ++xhrCount;
24
25
    $.ajax({
26
        type: 'GET',
27
        url: Routing.generate('property_list'),
0 ignored issues
show
Bug introduced by
The variable Routing seems to be never declared. If this is a global, consider adding a /** global: Routing */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
28
        data: {
29
            filters: $filterForm
30
                .find(':input').filter(function () {
31
                    return '' !== $(this).val()
32
                })
33
                .serialize(),
34
            sort: $sortSelect.val()
35
        },
36
        beforeSend: function () {
37
            if ($body.find('.loader').length) {
38
                return;
39
            }
40
41
            $body.append('<div class="loader"></div>');
42
        },
43
        success: function (html) {
44
            if (xhrId !== xhrCount) {
45
                return;
46
            }
47
48
            $container.html(html);
49
            $('#result-count').html($container.find('> article').length);
50
            initTooltips();
51
        },
52
        complete: function () {
53
            if (xhrId !== xhrCount) {
54
                return;
55
            }
56
57
            $body.find('.loader').remove();
58
        }
59
    });
60
}
61
62
const initTooltips = () => {
63
    $('[data-toggle="tooltip"]').tooltip({animation: true});
64
}
65
66
$(function() {
67
    initTooltips();
68
    loadProperties();
69
});
70