Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
{{!
2
    This file is part of Moodle - http://moodle.org/
3
 
4
    Moodle is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8
 
9
    Moodle is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU General Public License for more details.
13
 
14
    You should have received a copy of the GNU General Public License
15
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
}}
17
{{!
18
    @template tool_analytics/restorable_models
19
 
20
    Displays the list of missing prediction models that can be restored.
21
 
22
    Classes required for JS:
23
    * The list should be wrapped within a id="restorablemodelslist" element.
24
 
25
    Data attributes required for JS:
26
    * [data-widget="toggle"] indicates the clickable element for expanding/collapsing
27
      the list of indicators used by the given model.
28
    * [data-select] indicates a clickable element used for selecting multiple checkboxes.
29
    * [data-component] should be set for checkboxes that select the particular model.
30
 
31
    Context variables required for this template:
32
    * hasdata: boolean - do we have data to display
33
    * submiturl: string - URL where the form should be submitted
34
    * backurl: string - URL where the user should be sent without making any changes
35
    * sesskey: string
36
    * components: array - list of components to display
37
        - name: string - human readable name of the component
38
        - component: string - frankenstyle name of the component
39
        - models: array - list of restorable models provided by the component
40
            + defid: string - model definition identifier
41
            + targetname: string - human readable name of the target
42
            + targetclass: string - fully qualified classname of the target
43
            + indicatorsnum: int - number of indicators
44
            + indicators: array - list of indicators
45
                ~ name: string - human readable name of the indicator
46
                ~ classname: string - fully qualified classname of the indicator
47
 
48
    Example context (json):
49
    {
50
        "hasdata": true,
51
        "submiturl": "https://example.com/moodle/admin/tool/analytics/restoredefault.php",
52
        "backurl": "https://example.com/moodle/admin/tool/analytics/index.php",
53
        "sesskey": "abcdefg123456",
54
        "components": [
55
            {
56
                "name": "Core",
57
                "component": "core",
58
                "models": [
59
                    {
60
                        "defid": "id24680aceg",
61
                        "targetname": "Courses at risk of not starting",
62
                        "targetclass": "\\core\\analytics\\target\\no_teaching",
63
                        "indicatorsnum": 2,
64
                        "indicators": [
65
                            {
66
                                "name": "There are no teachers",
67
                                "classname": "\\core\\analytics\\indicator\\no_teacher"
68
                            },
69
                            {
70
                                "name": "There are no students",
71
                                "classname": "\\core\\analytics\\indicator\\no_students"
72
                            }
73
                        ]
74
                    },
75
                    {
76
                        "defid": "id13579bdfi",
77
                        "targetname": "Students at risk of dropping out",
78
                        "targetclass": "\\core\\analytics\\target\\course_dropout",
79
                        "indicatorsnum": 1,
80
                        "indicators": [
81
                            {
82
                                "name": "Read actions amount",
83
                                "classname": "\\core\\analytics\\indicator\\read_actions"
84
                            }
85
                        ]
86
                    }
87
                ]
88
            },
89
            {
90
                "name": "Custom analytics plugin",
91
                "component": "tool_customanalytics",
92
                "models": [
93
                    {
94
                        "defid": "id566dsgffg655",
95
                        "targetname": "Cheater",
96
                        "targetclass": "\\tool_customanalytics\\analytics\\target\\cheater",
97
                        "indicatorsnum": 1,
98
                        "indicators": [
99
                            {
100
                                "name": "Copy-pasted submissions",
101
                                "classname": "\\tool_customanalytics\\analytics\\indicator\\copy_paster_submissions"
102
                            }
103
                        ]
104
                    }
105
                ]
106
            }
107
        ]
108
    }
109
}}
110
<div class="box">
111
    {{^hasdata}}
112
    <p>{{#str}} restoredefaultnone, tool_analytics {{/str}}</p>
113
    <div><a href="{{backurl}}" class="btn btn-secondary">{{#str}} back {{/str}}</a></div>
114
    {{/hasdata}}
115
 
116
    {{#hasdata}}
117
    <p>{{#str}} restoredefaultinfo, tool_analytics {{/str}}</p>
118
    <form method="post" action="{{submiturl}}">
119
        <table id="restorablemodelslist" class="generaltable fullwidth">
120
            <colgroup>
121
                <col width="10%">
122
                <col width="45%">
123
                <col width="45%">
124
            </colgroup>
125
            <thead>
126
                <tr>
127
                    <th scope="col"><a href="" data-select="*">{{#str}} selectall {{/str}}</a></th>
128
                    <th scope="col">{{#str}} target, tool_analytics {{/str}}</th>
129
                    <th scope="col">{{#str}} indicators, tool_analytics {{/str}}</th>
130
                </tr>
131
            </thead>
132
            <tbody>
133
            {{#components}}
134
                <tr>
135
                    <th scope="rowgroup" colspan="3">
136
                        <span class="component-name">
137
                            <a href=""
138
                                    title="{{#str}} componentselect, tool_analytics, {{name}} {{/str}}"
139
                                    data-select="{{component}}">
140
                                {{name}}
141
                            </a>
142
                        </span>
143
                        <div><small class="component-frankenstyle">{{component}}</small></div>
144
                    </th>
145
                </tr>
146
                {{#models}}
147
                <tr>
148
                    <td>
149
                        <input data-component="{{component}}" type="checkbox" name="restoreid[]" value="{{defid}}">
150
                    </td>
151
                    <td>
152
                        <span class="target-name">{{targetname}}</span>
153
                        {{#targethelp}}
154
                            {{>core/help_icon}}
155
                        {{/targethelp}}
156
                        <div><small class="target-class">{{targetclass}}</small></div>
157
                    </td>
158
                    <td>
159
                        <a data-widget="toggle"
160
                                title="{{#str}} clicktohideshow {{/str}}"
161
                                aria-expanded="false"
162
                                aria-controls="indicators-{{defid}}"
163
                                role="button"
164
                                href="">
165
                            {{#str}} indicatorsnum, tool_analytics, {{indicatorsnum}} {{/str}}
166
                        </a>
167
                        <ul class="hidden listunstyled" id="indicators-{{defid}}">
168
                        {{#indicators}}
169
                            <li>
170
                                {{name}}
171
                                {{#indicatorhelp}}
172
                                    {{>core/help_icon}}
173
                                {{/indicatorhelp}}
174
                                <div><small>{{classname}}</small></div>
175
                            </li>
176
                        {{/indicators}}
177
                        </ul>
178
                    </td>
179
                </tr>
180
                {{/models}}
181
            {{/components}}
182
            </tbody>
183
        </table>
184
        <div>
185
            <input class="btn btn-primary" type="submit" value="{{#str}} restoredefaultsubmit, tool_analytics {{/str}}">
186
            <input class="btn btn-secondary" type="reset" value="{{#str}} componentselectnone, tool_analytics {{/str}}">
187
            <a href="{{backurl}}" class="btn btn-secondary">{{#str}} back {{/str}}</a>
188
            <input type="hidden" name="sesskey" value="{{sesskey}}">
189
        </div>
190
    </form>
191
    {{/hasdata}}
192
</div>
193
 
194
{{#js}}
195
require(['jquery'], function($) {
196
 
197
    // Toggle the visibility of the indicators list.
198
    $('#restorablemodelslist').on('click', '[data-widget="toggle"]', function(e) {
199
        e.preventDefault();
200
        var toggle = $(e.currentTarget);
201
        var listid = toggle.attr('aria-controls');
202
 
203
        $(document.getElementById(listid)).toggle();
204
 
205
        if (toggle.attr('aria-expanded') == 'false') {
206
            toggle.attr('aria-expanded', 'true');
207
        } else {
208
            toggle.attr('aria-expanded', 'false');
209
        }
210
    });
211
 
212
    // Selecting all / all in component checkboxes.
213
    $('#restorablemodelslist').on('click', '[data-select]', function(e) {
214
        e.preventDefault();
215
        var handler = $(e.currentTarget);
216
        var component = handler.attr('data-select');
217
 
218
        if (component == '*') {
219
            $('input[data-component]').prop('checked', true);
220
        } else {
221
            $('input[data-component="' + component + '"]').prop('checked', true);
222
        }
223
    });
224
});
225
{{/js}}