Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
var editor_querysql = null;
2
var editor_remotequerysql = null;
3
 
4
M.block_configurable_reports = {
5
 
6
    sesskey: null,
7
 
8
    init: function(Y, sesskey) {
9
        this.Y = Y;
10
        this.sesskey = sesskey;
11
 
12
        // Documentation can be found @ http://codemirror.net/
13
        editor_querysql = CodeMirror.fromTextArea(document.getElementById('id_querysql'), {
14
            mode: "text/x-mysql",
15
            rtlMoveVisually: true,
16
            indentWithTabs: true,
17
            smartIndent: true,
18
            lineNumbers: true,
19
            matchBrackets : true,
20
            autofocus: true,
21
            });
22
 
23
        editor_remotequerysql = CodeMirror.fromTextArea(document.getElementById('id_remotequerysql'), {
24
            mode: "text/x-mysql",
25
            rtlMoveVisually: true,
26
            indentWithTabs: true,
27
            smartIndent: true,
28
            lineNumbers: true,
29
            matchBrackets : true,
30
        //    autofocus: true
31
        });
32
 
33
    },
34
 
35
    loadReportCategories: function(Y, sesskey) {
36
        this.Y = Y;
37
        this.sesskey = sesskey;
38
 
39
        select_reportcategories = Y.one('#id_crreportcategories');
40
        Y.io(M.cfg.wwwroot+'/blocks/configurable_reports/repository.php', {
41
            data: 'action=listreports&sesskey=' + sesskey,
42
            context: this,
43
            method: "GET",
44
            on: {
45
                success: function(id, o) {
46
                    var response = Y.JSON.parse(o.responseText);
47
 
48
                    for(var prop in response) {
49
                        if (response.hasOwnProperty(prop)) {
50
                            option = Y.Node.create('<option value='+response[prop]["path"]+'>'+response[prop]["name"]+'</option>');
51
                            select_reportcategories.appendChild(option);
52
                        }
53
                    }
54
 
55
                },
56
                failure: function(id, o) {
57
                    // TODO use strings.
58
                    window.alert('Repository unreachable');
59
                }
60
            }
61
        });
62
 
63
    },
64
 
65
    onchange_crreportcategories : function (select_element,sesskey) {
66
        var Y = this.Y;
67
 
68
        select_reportnames = Y.one('#id_crreportnames');
69
 
70
        var xhr = Y.io(M.cfg.wwwroot+'/blocks/configurable_reports/repository.php', {
71
            data: 'action=listcategory&category='+select_element[select_element.selectedIndex].value+'&sesskey='+sesskey,
72
            context: this,
73
            method: "GET",
74
            on: {
75
                success: function(id, o) {
76
                    var response = Y.JSON.parse(o.responseText);
77
                    select_reportnames.get('childNodes').remove();
78
                    option = Y.Node.create('<option value="-1">...</option>');
79
                    select_reportnames.appendChild(option);
80
 
81
                    for(var prop in response) {
82
                        if (response.hasOwnProperty(prop)) {
83
                            option = Y.Node.create('<option value='+response[prop]["git_url"]+'>'+response[prop]["name"]+'</option>');
84
                            select_reportnames.appendChild(option);
85
                        }
86
                    }
87
                },
88
                failure: function(id, o) {
89
                    window.alert('Repository unreachable');
90
                }
91
            }
92
        });
93
    },
94
 
95
    onchange_crreportnames : function (select_element,sesskey) {
96
        var Y = this.Y;
97
 
98
        var path = select_element[select_element.selectedIndex].value;
99
        location.href = location.href + "&importurl=" + encodeURIComponent(path);
100
    },
101
 
102
    onchange_reportcategories : function (select_element,sesskey) {
103
        var Y = this.Y;
104
 
105
        //select_reportsincategory = Y.one('#id_reportsincategory');
106
        //select_reportsincategory.setHTML('');
107
 
108
        select_reportsincategory = Y.one('#id_reportsincategory');
109
        select_reportsincategory.setStyle('visibility', 'hidden');
110
        var xhr = Y.io(M.cfg.wwwroot+'/blocks/configurable_reports/list_reports_in_category.php', {
111
            data: 'category='+select_element[select_element.selectedIndex].value+'&sesskey='+sesskey,
112
            context: this,
113
            method: "GET",
114
            on: {
115
                success: function(id, o) {
116
                    var response = Y.JSON.parse(o.responseText);
117
                    var list = Y.Node.create('<select>');
118
                    option = Y.Node.create('<option value="-1">Choose...</option>');
119
                    list.appendChild(option);
120
 
121
                    for(var prop in response) {
122
                        if (response.hasOwnProperty(prop)) {
123
                            option = Y.Node.create('<option value='+response[prop]["fullname"]+'>'+response[prop]["name"]+'</option>');
124
                            list.appendChild(option);
125
                        }
126
                    }
127
                    select_reportsincategory.setStyle('visibility', 'visible');
128
                    list.setAttribute('id','id_reportsincategory');
129
                    list.setAttribute('name','reportsincategory');
130
                    list.setAttribute('onchange','M.block_configurable_reports.onchange_reportsincategory(this,"'+this.sesskey+'")');
131
                    select_reportsincategory.replace(list);
132
                },
133
                failure: function(id, o) {
134
                    if (o.statusText != 'abort') {
135
                        select_reportsincategory.setStyle('visibility', 'hidden');
136
//                        var instance = this.currentinstance;
137
//                        instance.progress.setStyle('visibility', 'hidden');
138
//                        if (o.statusText !== undefined) {
139
//                            instance.listcontainer.set('innerHTML', o.statusText);
140
//                        }
141
                    }
142
                }
143
            }
144
        });
145
    },
146
 
147
    onchange_reportsincategory : function (select_element,sesskey) {
148
        var Y = this.Y;
149
 
150
        //select_reportsincategory = Y.one('#id_reportsincategory');
151
        //select_reportsincategory.setHTML('');
152
 
153
        textarea_reportsincategory = Y.one('#id_remotequerysql');
154
        //select_reportsincategory.setStyle('visibility', 'hidden');
155
        var xhr = Y.io(M.cfg.wwwroot+'/blocks/configurable_reports/get_remote_report.php', {
156
            data: 'reportname='+select_element[select_element.selectedIndex].value+'&sesskey='+sesskey,
157
            context: this,
158
            method: "GET",
159
            on: {
160
                success: function(id, o) {
161
                    var response = Y.JSON.parse(o.responseText);
162
 
163
                    // Use regular textarea element.
164
                    textarea_reportsincategory.set('value', response);
165
 
166
                    // Use codemirror editor.
167
                    editor_remotequerysql.setValue(response);
168
                    /*
169
                    var list = Y.Node.create('<select>');
170
                    for(var prop in response) {
171
                        if (response.hasOwnProperty(prop)) {
172
                            option = Y.Node.create('<option id='+response[prop]["name"]+'>'+response[prop]["name"]+'</option>');
173
                            list.appendChild(option);
174
                        }
175
                    }
176
                    //select_reportsincategory.setStyle('visibility', 'visible');
177
                    list.setAttribute('id','id_reportsincategory');
178
                    list.setAttribute('name','reportsincategory');
179
                    list.setAttribute('onchange','M.block_configurable_reports.onchange_reportsincategory(this,"'+this.sesskey+'")');
180
                    select_reportsincategory.replace(list);
181
                    */
182
                },
183
                failure: function(id, o) {
184
                    if (o.statusText != 'abort') {
185
                        select_reportsincategory.setStyle('visibility', 'hidden');
186
//                        var instance = this.currentinstance;
187
//                        instance.progress.setStyle('visibility', 'hidden');
188
//                        if (o.statusText !== undefined) {
189
//                            instance.listcontainer.set('innerHTML', o.statusText);
190
//                        }
191
                    }
192
                }
193
            }
194
        });
195
    }
196
}
197
 
198
function menuplugin(event,args) {
199
    location.href = args.url+document.getElementById('menuplugin').value;
200
}
201