Completed
Push — master ( 76d118...770843 )
by Xu
46:30 queued 06:15
created

src/admin/views/user-assignment/_script.js   A

Complexity

Total Complexity 11
Complexity/F 1.38

Size

Lines of Code 53
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 53
rs 10
wmc 11
mnd 1
bc 11
fnc 8
bpm 1.375
cpm 1.375
noi 5

4 Functions

Rating   Name   Duplication   Size   Complexity  
A _script.js ➔ search 0 21 1
A $(ꞌ.search[data-target]ꞌ).keyup 0 3 1
A $(ꞌ.btn-assignꞌ).click 0 15 2
A _script.js ➔ updateItems 0 6 1
1
$('i.glyphicon-refresh-animate').hide();
2
function updateItems(r) {
3
    _opts.items.avaliable = r.avaliable;
0 ignored issues
show
Bug introduced by
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...
4
    _opts.items.assigned = r.assigned;
5
    search('avaliable');
6
    search('assigned');
7
}
8
9
$('.btn-assign').click(function () {
10
    var $this = $(this);
11
    var target = $this.data('target');
12
    var items = $('select.list[data-target="' + target + '"]').val();
13
14
    if (items.length) {
15
        $this.children('i.glyphicon-refresh-animate').show();
16
        $.post($this.attr('href'), {items: items}, function (r) {
17
            updateItems(r);
18
        }).always(function () {
19
            $this.children('i.glyphicon-refresh-animate').hide();
20
        });
21
    }
22
    return false;
23
});
24
25
$('.search[data-target]').keyup(function () {
26
    search($(this).data('target'));
27
});
28
29
function search(target) {
30
    var $list = $('select.list[data-target="' + target + '"]');
31
    $list.html('');
32
    var q = $('.search[data-target="' + target + '"]').val();
33
34
    var groups = {
35
        role: [$('<optgroup label="<?=Yii::t('yuncms','Roles')?>">'), false],
0 ignored issues
show
Bug introduced by
The variable Roles seems to be never declared. If this is a global, consider adding a /** global: Roles */ 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...
Bug introduced by
The variable yuncms seems to be never declared. If this is a global, consider adding a /** global: yuncms */ 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...
36
        permission: [$('<optgroup label="<?=Yii::t('yuncms','Permission')?>">'), false],
0 ignored issues
show
Bug introduced by
The variable Permission seems to be never declared. If this is a global, consider adding a /** global: Permission */ 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...
37
    };
38
    $.each(_opts.items[target], function (name, group) {
0 ignored issues
show
Bug introduced by
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...
39
        if (name.indexOf(q) >= 0) {
40
            $('<option>').text(name).val(name).appendTo(groups[group][0]);
41
            groups[group][1] = true;
42
        }
43
    });
44
    $.each(groups, function () {
45
        if (this[1]) {
46
            $list.append(this[0]);
47
        }
48
    });
49
}
50
51
// initial
52
search('avaliable');
53
search('assigned');
54