Issues (81)

views/menu/_script.js (4 issues)

1
$('#parent_name').autocomplete({
2
    source: function (request, response) {
3
        var result = [];
4
        var limit = 10;
5
        var term = request.term.toLowerCase();
6
        $.each(_opts.menus, function () {
0 ignored issues
show
The variable _opts seems to be never declared. If this is a global, consider adding a /** global: _opts */ 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...
7
            var menu = this;
8
            if (term == '' || menu.name.toLowerCase().indexOf(term) >= 0 ||
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if term == "" || menu.name....se().indexOf(term) >= 0 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
9
                (menu.parent_name && menu.parent_name.toLowerCase().indexOf(term) >= 0) ||
10
                (menu.route && menu.route.toLowerCase().indexOf(term) >= 0)) {
11
                result.push(menu);
12
                limit--;
13
                if (limit <= 0) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if limit <= 0 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
14
                    return false;
15
                }
16
            }
17
        });
18
        response(result);
19
    },
20
    focus: function (event, ui) {
21
        $('#parent_name').val(ui.item.name);
22
        return false;
23
    },
24
    select: function (event, ui) {
25
        $('#parent_name').val(ui.item.name);
26
        $('#parent_id').val(ui.item.id);
27
        return false;
28
    },
29
    search: function () {
30
        $('#parent_id').val('');
31
    }
32
}).autocomplete("instance")._renderItem = function (ul, item) {
33
    return $("<li>")
34
        .append($('<a>').append($('<b>').text(item.name)).append('<br>')
35
            .append($('<i>').text(item.parent_name + ' | ' + item.route)))
36
        .appendTo(ul);
37
};
38
39
$('#route').autocomplete({
40
    source: _opts.routes,
0 ignored issues
show
The variable _opts seems to be never declared. If this is a global, consider adding a /** global: _opts */ 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...
41
});