summaryrefslogtreecommitdiffstats
path: root/extensions/MyDashboard/web/js/flags.js
blob: b1605e04e686a8d1dd5abe870354a17b3f340724 (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
/* 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. 
 */

// Flag tables
YUI({
    base: 'js/yui3/',
    combine: false
}).use("node", "datatable", "datatable-sort", "json-stringify",
          "datatable-datasource", "datasource-io", "datasource-jsonschema", function (Y) {
    // Common
    var counter = 0;
    var dataSource = {
        requestee: null,
        requester: null
    };
    var dataTable = {
        requestee: null,
        requester: null
    };

    var updateFlagTable = function (type) {
        if (!type) return;

        counter = counter + 1;

        var callback = {
            success: function(e) {
                if (e.response) {
                    Y.one("#" + type + "_flags_found").setHTML(
                        e.response.results.length + ' flags found');
                    Y.one("#" + type + "_container .status").addClass('bz_default_hidden');
                    dataTable[type].set('data', e.response.results);
                    dataTable[type].render("#" + type + "_table");
                }
            },
            failure: function(o) {
                var resp = o.responseText;
                alert("IO request failed : " + resp);
            }
        };

        var json_object = {
            version: "1.1",
            method:  "MyDashboard.run_flag_query",
            id:      counter,
            params:  { type : type }
        };

        var stringified = Y.JSON.stringify(json_object);

        Y.one("#" + type + "_container .status").removeClass('bz_default_hidden');

        dataSource[type].sendRequest({
            request: stringified,
            cfg: {
                method:  "POST",
                headers: { 'Content-Type': 'application/json' }
            },
            callback: callback
        });
    };

    // Requestee
    dataSource.requestee = new Y.DataSource.IO({ source: 'jsonrpc.cgi' });
    dataTable.requestee = new Y.DataTable({
        columns: [
            { key:"requester", label:"Requester", sortable:true },
            { key:"type", label:"Flag", sortable:true },
            { key:"bug_id", label:"Bug", sortable:true,
              formatter: '<a href="show_bug.cgi?id={value}" target="_blank">{value}</a>', allowHTML: true },
            { key:"created", label:"Created", sortable:true }
        ],
        strings: {
            emptyMessage: 'No flag data found.',
        }
    });

    dataTable.requestee.plug(Y.Plugin.DataTableSort);

    dataTable.requestee.plug(Y.Plugin.DataTableDataSource, {
        datasource: dataSource,
        initialRequest: updateFlagTable("requestee"),
    });

    dataSource.requestee.plug(Y.Plugin.DataSourceJSONSchema, {
        schema: {
            resultListLocator: "result.result.requestee",
            resultFields: ["requester", "type", "bug_id", "created"]
        }
    });

    dataTable.requestee.render("#requestee_table");

    Y.one('#requestee_refresh').on('click', function(e) {
        updateFlagTable('requestee');
    });

    // Requester
    dataSource.requester = new Y.DataSource.IO({ source: 'jsonrpc.cgi' });
    dataTable.requester = new Y.DataTable({
        columns: [
            { key:"requestee", label:"Requestee", sortable:true },
            { key:"type", label:"Flag", sortable:true },
            { key:"bug_id", label:"Bug", sortable:true,
              formatter: '<a href="show_bug.cgi?id={value}" target="_blank">{value}</a>', allowHTML: true },
            { key:"created", label:"Created", sortable:true }
        ],
        strings: {
            emptyMessage: 'No flag data found.',
        }
    });

    dataTable.requester.plug(Y.Plugin.DataTableSort);

    dataTable.requester.plug(Y.Plugin.DataTableDataSource, {
        datasource: dataSource,
        initialRequest: updateFlagTable("requester"),
    });

    dataSource.requester.plug(Y.Plugin.DataSourceJSONSchema, {
        schema: {
            resultListLocator: "result.result.requester",
            resultFields: ["requestee", "type", "bug_id", "created"]
        }
    });

    Y.one('#requester_refresh').on('click', function(e) {
        updateFlagTable('requester');
    });
});