Gitlab CSE Unil

tool_form.mustache 16 KB
Newer Older
M. Chardon's avatar
M. Chardon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{{!
    This file is part of Moodle - http://moodle.org/

    Moodle is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Moodle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
}}
M. Chardon's avatar
M. Chardon committed
17
18
{{!
    @template assignfeedback_editpdfplus/tool_form
M. Chardon's avatar
M. Chardon committed
19
20
21
22
23
24
25
26
27
28
29
30

    Admin template to manage a tool.

    Context variables required for this template:
    * courseid - Course id
    * tool - current tool object to edit
    * formid - id of moodleform
    * actionurl - moodle service url to send form
    * sesskey - session key to validate form
    * map01 - picture for previsualisation for type 1
    * map02 - picture for previsualisation for type 2
    * map03 - picture for previsualisation for type 3
M. Chardon's avatar
M. Chardon committed
31
32
}}

M. Chardon's avatar
M. Chardon committed
33
<div id="toolworkspace">
M. Chardon's avatar
M. Chardon committed
34
    {{^tool.id}}<h4>{{# str }} adminaddtool, assignfeedback_editpdfplus {{/ str }}</h4>{{/tool.id}}
M. Chardon's avatar
M. Chardon committed
35
    <table>
M. Chardon's avatar
M. Chardon committed
36
        <tr>
M. Chardon's avatar
M. Chardon committed
37
38
            <td>
                {{#tool.id}}<div id="editpdlplus_tool_label" class="btn alert-info">{{tool.label}}</div>{{/tool.id}}
M. Chardon's avatar
M. Chardon committed
39
40
41
42
43
44
45
46
47
48
49
50
            </td>
            <td style="text-align: right;padding-left: 20px;">
                {{# str }} admintoolboxaction, assignfeedback_editpdfplus {{/ str }}{{#tool.id}}s{{/tool.id}} :
                <div class="btn-group">
                    <button type="button" class="btn btn-default" id="toolFormSubmit"><i class="fa fa-{{#tool.id}}save{{/tool.id}}{{^tool.id}}save{{/tool.id}}" aria-hidden="true"></i></button>
                    {{#tool.id}}
                    <button type="button" class="btn btn-default" id="toolClone"><i class="fa fa-clone" aria-hidden="true"></i></button>
                    <button type="button" class="btn btn-default" id="toolEnabled"><i class="fa fa-eye{{^tool.enabled}}-slash{{/tool.enabled}}" aria-hidden="true"></i></button>
                    <button type="button" class="btn btn-default {{^tool.removable}}disabled{{/tool.removable}}" id="toolRemove"><i class="fa fa-remove" aria-hidden="true"></i></button>
                    {{/tool.id}}
                </div>
            </td>
M. Chardon's avatar
M. Chardon committed
51
            <td class='assignfeedback_editpdfplus_widget_admin_tool_col2'>
M. Chardon's avatar
M. Chardon committed
52
53
54
55
56
57
                {{#tool.id}}
                <button type="button" class="btn btn-default" id="toolRefesh"><i class="fa fa-refresh" aria-hidden="true"></i></button>
                {{/tool.id}}
            </td>
        </tr>
        <tr>
M. Chardon's avatar
M. Chardon committed
58
            <td class='assignfeedback_editpdfplus_widget_admin_tool_col1 assignfeedback_editpdfplus_widget_admin_tool_row' colspan="2">
M. Chardon's avatar
M. Chardon committed
59
60
61
62
63
64
65
66
67
                <form id="{{formid}}" method="post" action="{{actionurl}}" class="form-horizontal">
                    <div class="panel-group" id="accordion">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <i class="fa fa-wrench" aria-hidden="true"></i>&nbsp;&nbsp;
                                <a data-toggle="collapse" href="#collapse1" data-parent="#accordion">{{# str }} admintoolboxtypetool, assignfeedback_editpdfplus {{/ str }}</a>
                            </div>
                            <div id="collapse1" class="panel-collapse collapse">
                                <div class="panel-body">
M. Chardon's avatar
M. Chardon committed
68
                                    <table>
M. Chardon's avatar
M. Chardon committed
69
70
                                        <tr>
                                            <td style="width: 25%;">
M. Chardon's avatar
M. Chardon committed
71
72
73
                                                <label class="control-label" for="typetool">
                                                    {{# str }} admintoolboxtypetool_type, assignfeedback_editpdfplus {{/ str }}
                                                </label>
M. Chardon's avatar
M. Chardon committed
74
75
76
77
78
79
80
81
82
83
                                            </td>
                                            <td>
                                                <select class="form-control" id="typetool" name="typetool">
                                                    {{# tools }}
                                                    <option value='{{id}}'>{{libelle}}</option>
                                                    {{/ tools }}
                                                </select>
                                            </td>
                                        </tr>
                                    </table>
M. Chardon's avatar
M. Chardon committed
84
                                </div>
M. Chardon's avatar
M. Chardon committed
85
86
87
                            </div>
                        </div>

M. Chardon's avatar
M. Chardon committed
88
89
90
91
92
93
94
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <i class="fa fa-bars" aria-hidden="true"></i>&nbsp;&nbsp;
                                <a data-toggle="collapse" href="#collapse2" data-parent="#accordion">{{# str }} admintoolboxtoolbardisplay, assignfeedback_editpdfplus {{/ str }}</a>
                            </div>
                            <div id="collapse2" class="panel-collapse collapse">
                                <div class="panel-body">
M. Chardon's avatar
M. Chardon committed
95
                                    <table>
M. Chardon's avatar
M. Chardon committed
96
97
                                        <tr>
                                            <td style="width: 25%;">
M. Chardon's avatar
M. Chardon committed
98
99
100
                                                <label class="control-label" for="button">
                                                    {{# str }} admintoolboxtoolbardisplay_button, assignfeedback_editpdfplus {{/ str }}
                                                </label>
M. Chardon's avatar
M. Chardon committed
101
102
103
104
105
106
107
                                            </td>
                                            <td>
                                                <input type="text" class="form-control" id="button" value="{{tool.label}}" name="button" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="width: 25%;">
M. Chardon's avatar
M. Chardon committed
108
                                                <label class="control-label" for="order">{{# str }} admintoolboxtoolbardisplay_order, assignfeedback_editpdfplus {{/ str }}</label>
M. Chardon's avatar
M. Chardon committed
109
110
111
112
113
114
115
116
                                            </td>
                                            <td>
                                                <input type="number" class="form-control" id="order" value="{{tool.order_tool}}" name="order" />
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
M. Chardon's avatar
M. Chardon committed
117
                        </div>
M. Chardon's avatar
M. Chardon committed
118
119
120
121
122
123
124
125

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <i class="fa fa-address-card-o" aria-hidden="true"></i>&nbsp;&nbsp;
                                <a data-toggle="collapse" href="#collapse3" data-parent="#accordion">{{# str }} admintoolboxcartridge, assignfeedback_editpdfplus {{/ str }}</a>
                            </div>
                            <div id="collapse3" class="panel-collapse collapse">
                                <div class="panel-body">
M. Chardon's avatar
M. Chardon committed
126
                                    <table>
M. Chardon's avatar
M. Chardon committed
127
128
                                        <tr>
                                            <td style="width: 25%;">
M. Chardon's avatar
M. Chardon committed
129
                                                <label class="control-label " for="libelle">{{# str }} admintoolboxcartridge_label, assignfeedback_editpdfplus {{/ str }}</label>
M. Chardon's avatar
M. Chardon committed
130
131
132
133
134
135
136
                                            </td>
                                            <td>
                                                <input type="text" class="form-control" id="libelle" value="{{tool.cartridge}}" name="libelle" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="width: 25%;">
M. Chardon's avatar
M. Chardon committed
137
                                                <label class="control-label " for="cartridgecolor">{{# str }} admintoolboxcartridge_color, assignfeedback_editpdfplus {{/ str }}</label>
M. Chardon's avatar
M. Chardon committed
138
139
140
141
142
143
144
145
                                            </td>
                                            <td>
                                                <input type="color" class="form-control" id="cartridgecolor" placeholder="{{^tool.cartridge_color}}-{{/tool.cartridge_color}}"
                                                       value="{{#tool.cartridge_color}}{{tool.cartridge_color}}{{/tool.cartridge_color}}" name="catridgecolor" />
                                                <input type="hidden" id="realcartridgecolor" value="{{#tool.cartridge_color}}{{tool.cartridge_color}}{{/tool.cartridge_color}}" />
                                            </td>
                                        </tr>
                                    </table>
M. Chardon's avatar
M. Chardon committed
146
                                </div>
M. Chardon's avatar
M. Chardon committed
147
148
149
150
151
152
153
154
155
156
                            </div>
                        </div>

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;&nbsp;
                                <a data-toggle="collapse" href="#collapse4" data-parent="#accordion">{{# str }} admintoolboxannotation, assignfeedback_editpdfplus {{/ str }}</a>
                            </div>
                            <div id="collapse4" class="panel-collapse collapse">
                                <div class="panel-body" style="overflow: auto;">
M. Chardon's avatar
M. Chardon committed
157
                                    <table>
M. Chardon's avatar
M. Chardon committed
158
159
                                        <tr>
                                            <td style="width: 25%;">
M. Chardon's avatar
M. Chardon committed
160
                                                <label class="control-label" for="color">{{# str }} admintoolboxannotation_color, assignfeedback_editpdfplus {{/ str }}</label>
M. Chardon's avatar
M. Chardon committed
161
162
163
164
165
166
167
168
169
                                            </td>
                                            <td>
                                                <input type="color" class="form-control" id="color" placeholder="{{^tool.colors}}-{{/tool.colors}}"
                                                       value="{{#tool.colors}}{{tool.colors}}{{/tool.colors}}" name="color" />
                                                <input type="hidden" id="realcolor" value="{{#tool.colors}}{{tool.colors}}{{/tool.colors}}" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="width: 25%;">
M. Chardon's avatar
M. Chardon committed
170
                                                <label class="control-label" for="texts">{{# str }} admintoolboxannotation_texts, assignfeedback_editpdfplus {{/ str }}</label>
M. Chardon's avatar
M. Chardon committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184
                                            </td>
                                            <td>
                                                <input type="hidden" class="form-control" id="texts" value="{{tool.texts}}" name="texts" />
                                                <ul class="textform"
                                                    data-prototype="<input  type='text' class='form-control' value='' name='text[__name__]' style='width:90%;display:inline-block;' />" 
                                                    style="list-style-type:none;padding:0px;margin-left: 0px;">
                                                    {{#tool.textsarray}}
                                                    <li><input  type='text' class='form-control' value='{{text}}' name='text[{{index}}]' style='width:90%;display:inline-block;' /></li>
                                                    {{/tool.textsarray}}
                                                </ul>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="width: 25%;">
M. Chardon's avatar
M. Chardon committed
185
                                                <label class="control-label" for="reply">{{# str }} admintoolboxannotation_reply, assignfeedback_editpdfplus {{/ str }}</label>
M. Chardon's avatar
M. Chardon committed
186
187
188
189
190
191
                                            </td>
                                            <td>
                                                <input type="checkbox" id="reply" {{#tool.reply}}checked {{/tool.reply}}name="reply" />
                                            </td>
                                        </tr>
                                    </table>
M. Chardon's avatar
M. Chardon committed
192
                                </div>
M. Chardon's avatar
M. Chardon committed
193
194
195
196
                            </div>
                        </div>
                    </div>

M. Chardon's avatar
M. Chardon committed
197
198
199
200
201
202
203
204
205
206
                    <div style='display:none;'>
                        <input type="hidden" name="toolid" value="{{tool.id}}" />
                        <input type="hidden" name="axisid" value="{{tool.axis}}" />
                        <input type="hidden" name="courseid" value="{{courseid}}" />
                        <input type="hidden" name="sesskey" value="{{sesskey}}" />
                        <input type="hidden" name="enabled" id="toolenabled" value="{{tool.enabled}}" />
                    </div>

                </form>
            </td>
M. Chardon's avatar
M. Chardon committed
207
            <td class='assignfeedback_editpdfplus_widget_admin_tool_col2 assignfeedback_editpdfplus_widget_admin_tool_row'>
M. Chardon's avatar
M. Chardon committed
208
209
210
211
                <input id='map01' type='hidden' value='{{map01}}' />
                <input id='map02' type='hidden' value='{{map02}}' />
                <input id='map03' type='hidden' value='{{map03}}' />
                <!--{{# pix }} cross, assignfeedback_editpdfplus, previsu {{/ pix }}-->
M. Chardon's avatar
M. Chardon committed
212
                <div id="canevas" style="background-image: url('{{map01}}');" class="drawingcanvas"></div>
M. Chardon's avatar
M. Chardon committed
213
214
215
            </td>
        </tr>
    </table>
M. Chardon's avatar
M. Chardon committed
216
217
218
219
220
</div>

{{# js }}
require(['jquery','core/ajax','core/notification'], function($,ajax,notification) {

M. Chardon's avatar
M. Chardon committed
221
{{#tool.id}}$("#typetool").val({{tool.type}});{{/tool.id}}
M. Chardon's avatar
M. Chardon committed
222

223
224
225
226
227
228
var $collectionHolder;

// setup an "add a tag" link
var $addTagLink = $('<a href="#" class="add_text_link"><i class="fa fa-plus"></i></a>');
var $newLinkLi = $('<li></li>').append($addTagLink);

M. Chardon's avatar
M. Chardon committed
229
$(document).ready(function() {
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Get the ul that holds the collection of tags
$collectionHolder = $('ul.textform');

// add a delete link to all of the existing tag form li elements
$collectionHolder.find('li').each(function() {
addTagFormDeleteLink($(this));
});

// add the "add a tag" anchor and li to the tags ul
$collectionHolder.append($newLinkLi);

// count the current form inputs we have (e.g. 2), use that as the new
// index when inserting a new item (e.g. 2)
$collectionHolder.data('index', $collectionHolder.find(':input').length);

$addTagLink.on('click', function(e) {
// prevent the link from creating a "#" on the URL
e.preventDefault();

// add a new tag form (see next code block)
addTagForm($collectionHolder, $newLinkLi);
});
});
function addTagForm($collectionHolder, $newLinkLi) {
// Get the data-prototype explained earlier
var prototype = $collectionHolder.data('prototype');

// get the new index
var index = $collectionHolder.data('index');

// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
var newForm = prototype.replace(/__name__/g, index);

// increase the index with one for the next item
$collectionHolder.data('index', index + 1);

// Display the form in the page in an li, before the "Add a tag" link li
var $newFormLi = $('<li></li>').append(newForm);
$newLinkLi.before($newFormLi);

// add a delete link to the new form
addTagFormDeleteLink($newFormLi);
}

function addTagFormDeleteLink($tagFormLi) {
var $removeFormA = $('<a href="#"><i class="fa fa-remove"></i></a>');
$tagFormLi.append($removeFormA);

$removeFormA.on('click', function(e) {
// prevent the link from creating a "#" on the URL
e.preventDefault();

// remove the li for the tag form
$tagFormLi.remove();
});
}

M. Chardon's avatar
M. Chardon committed
288
289
});
{{/ js }}