Gitlab CSE Unil

axis_form.mustache 4.13 KB
Newer Older
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/axis_form
19
20
21
22

    Admin template for add or edit one axis.

    Context variables required for this template:
23
    * contextid - Context id
24
25
26
27
    * title - Title of the page (add or edit)
    * render - form render for adding or editing axis
    * id - form id
    * action - label of action 'edit' or 'add'
M. Chardon's avatar
M. Chardon committed
28
29
}}

M. Chardon's avatar
M. Chardon committed
30
31
32
33
34
<div class="card-header">{{title}}</div>
<div class="card-body text-primary">
    {{{render}}}
    <button type="button" class="btn btn-primary" id="axisFormSubmit">{{# str }} adminaxis_save, assignfeedback_editpdfplus {{/ str }}</button>
    <button type="button" class="btn" id="axisFormCancel">{{# str }} adminaxis_cancel, assignfeedback_editpdfplus {{/ str }}</button>
M. Chardon's avatar
M. Chardon committed
35
</div>
M. Chardon's avatar
M. Chardon committed
36

M. Chardon's avatar
M. Chardon committed
37
38
39
40
41
{{# js }}
require(['jquery','core/ajax','core/notification'], function($,ajax,notification) {
    var formid='{{id}}';
    $("#axisFormSubmit").on("click", function () {
        var form = $('#'+formid);
42
        var data = form.serialize()+"&contextid="+{{contextid}};
M. Chardon's avatar
M. Chardon committed
43
44
45
46
47
48
49
        ajax.call([
            {
                methodname: 'assignfeedback_editpdfplus_submit_axis_form',
                args: {jsonformdata: JSON.stringify(data)}
            }
        ])[0].done(function(axe) {
            if ('{{action}}' === 'add'){
M. Chardon's avatar
M. Chardon committed
50
                var divAxis = "<div id='editpdlplus_toolbar_"+axe[0].axeid+"' class='btn-group toolbar' style='display: none;'><ul></ul></div>";
M. Chardon's avatar
M. Chardon committed
51
                $('#editpdlplus_toolbars').append(divAxis);
M. Chardon's avatar
M. Chardon committed
52
                $('#assignfeedback_editpdfplus_widget_admin_div_addaxis').html("");
53
                $('#assignfeedback_editpdfplus_widget_admin_div_addaxis').hide();
M. Chardon's avatar
M. Chardon committed
54
55
                var option=new Option(axe[0].axelabel, axe[0].axeid, true, true);
                $("#editpdlplus_axes").append(option);
M. Chardon's avatar
M. Chardon committed
56
                $("#editpdlplus_axes").change();
M. Chardon's avatar
M. Chardon committed
57
                $('#editpdlplus_tool_item').html("");
M. Chardon's avatar
M. Chardon committed
58
            } else {
M. Chardon's avatar
M. Chardon committed
59
                $('#assignfeedback_editpdfplus_widget_admin_div_editaxis').html("");
60
                $('#assignfeedback_editpdfplus_widget_admin_div_editaxis').hide();
M. Chardon's avatar
M. Chardon committed
61
62
63
                $("#editpdlplus_axes option:selected").html(axe[0].axelabel);
            }
            $("#axistool").show();
64
            $("#editpdlplus_axes_worspace").show();
M. Chardon's avatar
M. Chardon committed
65
66
            $('#assignfeedback_editpdfplus_widget_admin_toolheader').show();
            $('#assignfeedback_editpdfplus_widget_admin_toolworkspace').show();
67
            $("#editpdlplus_axes").removeAttr('disabled');
M. Chardon's avatar
M. Chardon committed
68
69
70
71
        }).fail(notification.exception);
    });
    $("#axisFormCancel").on("click", function () {
        if ('{{action}}' === 'add'){
M. Chardon's avatar
M. Chardon committed
72
            $('#assignfeedback_editpdfplus_widget_admin_div_addaxis').html("");
73
            $('#assignfeedback_editpdfplus_widget_admin_div_addaxis').hide();
M. Chardon's avatar
M. Chardon committed
74
        } else {
M. Chardon's avatar
M. Chardon committed
75
            $('#assignfeedback_editpdfplus_widget_admin_div_editaxis').html("");
76
            $('#assignfeedback_editpdfplus_widget_admin_div_editaxis').hide();
M. Chardon's avatar
M. Chardon committed
77
        }
78
79
80
81
82
83
84
85
86
87
        var selectAxis = $("#editpdlplus_axes").val();
        if (selectAxis && selectAxis !== "") {
            $("#axistool").show();
            $('#assignfeedback_editpdfplus_widget_admin_toolheader').show();
            $('#assignfeedback_editpdfplus_widget_admin_toolworkspace').show();
        } else {
            $("#assignfeedback_editpdfplus_widget_admin_workspace").hide();
            $('#assignfeedback_editpdfplus_widget_admin_toolheader').hide();
            $("#editpdlplus_axes_worspace").show();
        }
88
        $("#editpdlplus_axes").removeAttr('disabled');
M. Chardon's avatar
M. Chardon committed
89
90
91
    });
});
{{/ js }}