summaryrefslogtreecommitdiffstats
path: root/extensions/MyDashboard/web/js/mydashboard.js
blob: 25529d8c8961dcc0779f94a998e3a8232f0bb2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, v. 2.0. 
 */

YAHOO.namespace('MyDashboard');

var MD = YAHOO.MyDashboard;

MD.showQuerySection = function () {
    var query_select = YAHOO.util.Dom.get('query');
    var selected_value = '';
    for (var i = 0, l = query_select.options.length; i < l; i++) {
        if (query_select.options[i].selected) {
            selected_value = query_select.options[i].value;
        }
    }
    for (var i = 0, l = MD.full_query_list.length; i < l; i++) {
        var query = MD.full_query_list[i];
        if (selected_value == MD.full_query_list[i]) {
            YAHOO.util.Dom.removeClass(query + '_container', 'bz_default_hidden');
        }
        else {
            YAHOO.util.Dom.addClass(query + '_container', 'bz_default_hidden');
        }
    }
}

MD.query_column_defs = [
    { key:"id", label:"ID", sortable:true, sortOptions:{ sortFunction: MD.sortBugIdLinks } },
    { key:"updated", label:"Updated", sortable:true },
    { key:"bug_status", label:"Status", sortable:true },
    { key:"summary", label:"Summary", sortable:true },
];

MD.query_fields = [
    { key:"id" },
    { key:"updated" },
    { key:"bug_status" },
    { key:"summary" }
];

MD.requestee_column_defs = [
  { key:"requester", label:"Requester", sortable:true },
  { key:"flag", label:"Flag", sortable:true },
  { key:"bug", label:"Bug", sortable:true },
  { key:"created", label:"Created", sortable:true }
];

MD.requestee_fields = [
  { key:"requester" },
  { key:"flag" },
  { key:"bug" },
  { key:"created" }
];

MD.requester_column_defs = [
  { key:"requestee", label:"Requestee", sortable:true },
  { key:"flag", label:"Flag", sortable:true },
  { key:"bug", label:"Bug", sortable:true },
  { key:"created", label:"Created", sortable:true }
];

MD.requester_fields = [
  { key:"requestee" },
  { key:"flag" },
  { key:"bug" },
  { key:"created" }
];

MD.addStatListener = function (div_name, table_name, column_defs, fields, options) {
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.StatsFromMarkup = new function() {
            this.myDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get(table_name));
            this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
            this.myDataSource.responseSchema = { fields:fields };
            this.myDataTable = new YAHOO.widget.DataTable(div_name, column_defs, this.myDataSource, options);
            this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow);
            this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow);
        };
    });
}

// Custom sort handler to sort by bug id inside an anchor tag
MD.sortBugIdLinks = function (a, b, desc) {
    // Deal with empty values
    if (!YAHOO.lang.isValue(a)) {
        return (!YAHOO.lang.isValue(b)) ? 0 : 1;
    }
    else if(!YAHOO.lang.isValue(b)) {
        return -1;
    }
    // Now we need to pull out the ID text and convert to Numbers
    // First we do 'a'
    var container = document.createElement("bug_id_link");
    container.innerHTML = a.getData("id");
    var anchors = container.getElementsByTagName("a");
    var text = anchors[0].textContent;
    if (text === undefined) text = anchors[0].innerText;
    var new_a = new Number(text);
    // Then we do 'b'
    container.innerHTML = b.getData("id");
    anchors = container.getElementsByTagName("a");
    text = anchors[0].textContent;
    if (text == undefined) text = anchors[0].innerText;
    var new_b = new Number(text);

    if (!desc) {
        return YAHOO.util.Sort.compare(new_a, new_b);
    }
    else {
        return YAHOO.util.Sort.compare(new_b, new_a);
    }
}

// Custom sort handler for bug severities
MD.sortBugSeverity = function (a, b, desc) {
    // Deal with empty values
    if (!YAHOO.lang.isValue(a)) {
        return (!YAHOO.lang.isValue(b)) ? 0 : 1;
    }
    else if(!YAHOO.lang.isValue(b)) {
        return -1;
    }

    var new_a = new Number(MD.severities[YAHOO.lang.trim(a.getData('bug_severity'))]);
    var new_b = new Number(MD.severities[YAHOO.lang.trim(b.getData('bug_severity'))]);

    if (!desc) {
        return YAHOO.util.Sort.compare(new_a, new_b);
    }
    else {
        return YAHOO.util.Sort.compare(new_b, new_a);
    }
}

// Custom sort handler for bug priorities
MD.sortBugPriority = function (a, b, desc) {
    // Deal with empty values
    if (!YAHOO.lang.isValue(a)) {
        return (!YAHOO.lang.isValue(b)) ? 0 : 1;
    }
    else if(!YAHOO.lang.isValue(b)) {
        return -1;
    }

    var new_a = new Number(MD.priorities[YAHOO.lang.trim(a.getData('priority'))]);
    var new_b = new Number(MD.priorities[YAHOO.lang.trim(b.getData('priority'))]);

    if (!desc) {
        return YAHOO.util.Sort.compare(new_a, new_b);
    }
    else {
        return YAHOO.util.Sort.compare(new_b, new_a);
    }
}