Passed
Push — master ( c5754d...1955b9 )
by Darío
07:59 queued 02:30
created

public/js/workflow.js   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 60
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
eloc 35
nc 32
dl 0
loc 60
rs 10
c 2
b 0
f 0
wmc 6
mnd 1
bc 3
fnc 3
bpm 1
cpm 2
noi 4
1
$(function(){
2
3
    $("body").delegate(".btn-new-worksheet", "click", function(event)
4
    {
5
        event.preventDefault();
6
7
        var id_conn   = $(this).attr('data-id');
8
        var conn_name = $(this).attr('data-name');
9
10
        var call = eval($(this).attr('data-callback')) || {};
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
11
12
        call.success = call.success || new Function();
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
13
        call.before  = call.before  || new Function();
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
14
        call.error   = call.error   || new Function();
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
15
16
        var d = new Date();
17
        var n = d.getTime();
18
19
        var title = $("#worksheet-collector .worksheet-item-title").last().clone();
20
21
        if (title.hasClass('active'))
22
            title.removeClass('active');
23
24
        var other_tabs = $("div[data-tab][data-conn='" + id_conn + "']");
25
26
        var tab_index = (other_tabs.length) ? parseInt(other_tabs.last().attr('data-tab-index')) + 1 : 1;
27
28
        title.html(conn_name + "~" + tab_index + "&nbsp; <button class='ui small compact basic button btn-remove-worksheet'>x</button>").attr('data-tab', n);
29
30
        $("#worksheet-collector .worksheet-item-title").last().parent().append(title);
31
32
        var content = $("#worksheet-collector .worksheet-item-content").last().clone();
33
        content.empty().attr('data-conn', id_conn);
34
        content.empty().attr('data-tab-index', tab_index);
35
36
        $("#worksheet-collector .worksheet-item-content").last().parent().append(content);
37
38
        if (content.hasClass('active'))
39
            content.removeClass('active');
40
41
        content.attr('data-tab', n);
42
        content.load(content.attr("data-resource"), { id: n, conn: id_conn });
43
44
        $('.menu .item').tab();
45
46
        $(title).trigger('click');
47
    });
48
49
    $('.menu .item').tab();
50
51
    $("body").delegate(".btn-remove-worksheet", "click", function(event)
52
    {
53
        event.preventDefault();
54
        event.stopPropagation();
55
56
        var tab = $(this).parent().attr('data-tab');
57
        $("[data-tab='" + tab + "']").remove();
58
        $("a[data-tab='home']").trigger("click");
59
    });
60
});