Passed
Push — master ( 91e4ab...1def37 )
by Plamen
01:28
created

add/table_helper.js   A

Complexity

Total Complexity 28
Complexity/F 3.11

Size

Lines of Code 93
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 0
eloc 67
nc 1
dl 0
loc 93
rs 10
c 3
b 0
f 1
wmc 28
mnd 3
bc 25
fnc 9
bpm 2.7777
cpm 3.1111
noi 1

7 Functions

Rating   Name   Duplication   Size   Complexity  
A table_helper.RequestToUrl 0 17 5
A table_helper.GetParent 0 6 3
A table_helper.ProcessPaginationLinks 0 9 3
A table_helper.RqObject 0 7 1
A table_helper.IePrior 0 12 4
A table_helper.Init 0 20 2
A table_helper.ColumnHover 0 20 3
1
var table_helper = {
2
    Init: function(tableId){
3
        var tContainer = document.getElementById(tableId);
4
        if(!this.IePrior(9)){
5
            SetColumnsHoverEffect(tContainer, tableId);
6
        }
7
        var tfoot = tContainer.getElementsByTagName("tfoot")[0];
8
        this.ProcessPaginationLinks(tfoot);
9
        
10
        function SetColumnsHoverEffect(tContainer, tableId){
11
            var tHcells = tContainer.rows[0].cells;
12
            for(var i = 0; i < tHcells.length; i++){
13
                if(tHcells[i].firstChild.tagName === "A"){
14
                    tHcells[i].firstChild.setAttribute("onmouseover",
15
                            "table.ColumnHover('" + tableId + "'," + i + ");");
16
                    tHcells[i].firstChild.setAttribute("onmouseout",
17
                            "table.ColumnHover('" + tableId + "');");
18
                }
19
            }
20
        }
21
    },
22
    ColumnHover: function(tableContainer, index){
23
        var rows = document.getElementById(tableContainer).rows;
24
        var upto = rows.length - 1;
25
        if(typeof index === "undefined"){
26
            ColumnHoverRelease(rows, upto);
27
        }else{
28
            for(var i = 0; i < upto; i++){
29
                rows[i].cells[index].setAttribute("lang", "col-hover");
30
            }
31
        }
32
        function ColumnHoverRelease(rows, upto){
33
            for(var i = 0; i < upto; i++){
34
                for(var j = 0; j < rows[i].cells.length; j++){
35
                    if(rows[i].cells[j].lang){
36
                        rows[i].cells[j].removeAttribute("lang");
37
                    }
38
                }
39
            }
40
        };
41
    },
42
    IePrior: function(v){
43
        var rv = false;
44
        if(window.navigator.appName === 'Microsoft Internet Explorer'){
45
            var ua = window.navigator.userAgent;
46
            var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
47
            if(re.exec(ua) !== null){
48
                rv = parseFloat(RegExp.$1);
49
            }
50
            rv = rv < v ? true : false;
51
        }
52
        return rv;
53
    },
54
    GetParent: function(obj, objType){
55
        while(obj && obj.tagName !== objType.toUpperCase()){
56
            obj = obj.parentNode;
57
        }
58
        return obj;
59
    },
60
    ProcessPaginationLinks: function(tfoot){
61
        var pLinks = tfoot.querySelectorAll(".paging a");
62
        if(pLinks.length > 0){
63
            for(var j = 0; j < pLinks.length; j++){
64
                pLinks[j].setAttribute("href", "javascript:void(0);");
65
                pLinks[j].setAttribute("onclick", "return table.GoPage(this);");
66
            }
67
        }
68
    },
69
    RequestToUrl: function(rq){
70
        var url = location.pathname + ".json" + location.search;
71
        if(typeof rq === "object"){
72
            var getUrlVarName = {
73
                colNo: "col", colOrd: "ord", filter: "filter",
74
                filterBy: "filter-by", pageNo: "pg", exportType: "export",
75
                tableId: "table-id"
76
            };
77
            var flagFirst = location.search.length < 1 ? true : false;
78
            for(var r in rq){
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
79
                var clue = flagFirst === true ? "?" : "&";
80
                url += clue + getUrlVarName[r] + "=" + rq[r];
81
                flagFirst = false;
82
            }
83
        }
84
        return url;
85
    },
86
    RqObject: function(tableId){
87
        var rq = {};
88
        rq.tableId = tableId;
89
        rq.strDesc = this.strDesc;
90
        rq.strAsc = this.strAsc;
91
        return rq;
92
    }
93
};
94