MDL-38466 filters: Redos protection and unit tests
[moodle.git] / mod / lti / submissions.js
blob2f4e730b5a636cb5718a53db328a640f1e3c57fc
1 // This file is part of Moodle - http://moodle.org/
2 //
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16 /**
17  * Javascript extensions for LTI submission viewer.
18  *
19  * @package    mod
20  * @subpackage lti
21  * @copyright  Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com)
22  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  * @author     Chris Scribner
24  */
25 (function(){
26     var Y;
28     M.mod_lti = M.mod_lti || {};
30     M.mod_lti.submissions = {
31         init: function(yui3){
32             if(yui3){
33                 Y = yui3;
34             }
36             this.setupTable();
37         },
39         setupTable: function(){
40             var lti_submissions_table = Y.YUI2.util.Dom.get('lti_submissions_table');
42             var dataSource = new Y.YUI2.util.DataSource(lti_submissions_table);
44             var configuredColumns = [
45                 { key: "user", label: "User", sortable:true },
46                 { key: "date", label: "Submission Date", sortable:true, formatter: 'date' },
47                 { key: "grade",
48                   label: "Grade",
49                   sortable:true,
50                   formatter: function(cell, record, column, data){
51                       cell.innerHTML = parseFloat(data).toFixed(1) + '%';
52                   }
53                 }
54             ];
56             dataSource.responseType = Y.YUI2.util.DataSource.TYPE_HTMLTABLE;
57             dataSource.responseSchema = {
58                 fields: [
59                     { key: "user" },
60                     { key: "date", parser: "date" },
61                     { key: "grade", parser: "number" },
62                 ]
63             };
65             new Y.YUI2.widget.DataTable("lti_submissions_table_container", configuredColumns, dataSource,
66                 {
67                     sortedBy: {key:"date", dir:"desc"}
68                 }
69             );
71             Y.one('#lti_submissions_table_container').setStyle('display', '');
72         }
73     }
74 })();