1 |
efrain |
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.
|
|
|
12 |
//
|
|
|
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/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Additional javascript for the Workshop module form.
|
|
|
18 |
*
|
|
|
19 |
* @module mod_workshop/modform
|
|
|
20 |
* @copyright The Open University 2018
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
define(['jquery'], function($) {
|
|
|
24 |
|
|
|
25 |
var submissionTypes = {
|
|
|
26 |
text: {
|
|
|
27 |
available: null,
|
|
|
28 |
required: null,
|
|
|
29 |
requiredHidden: null
|
|
|
30 |
},
|
|
|
31 |
file: {
|
|
|
32 |
available: null,
|
|
|
33 |
required: null,
|
|
|
34 |
requiredHidden: null
|
|
|
35 |
}
|
|
|
36 |
};
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Determine whether one of the submission types has been marked as not available.
|
|
|
40 |
*
|
|
|
41 |
* If it has been marked not available, clear and disable its required checkbox. Then determine if the other submission
|
|
|
42 |
* type is available, and if it is, check and disable its required checkbox.
|
|
|
43 |
*
|
|
|
44 |
* @param {Object} checkUnavailable
|
|
|
45 |
* @param {Object} checkAvailable
|
|
|
46 |
*/
|
|
|
47 |
function checkAvailability(checkUnavailable, checkAvailable) {
|
|
|
48 |
if (!checkUnavailable.available.prop('checked')) {
|
|
|
49 |
checkUnavailable.required.prop('disabled', true);
|
|
|
50 |
checkUnavailable.required.prop('checked', false);
|
|
|
51 |
if (checkAvailable.available.prop('checked')) {
|
|
|
52 |
checkAvailable.required.prop('disabled', true);
|
|
|
53 |
checkAvailable.required.prop('checked', true);
|
|
|
54 |
// Also set the checkbox's hidden field to 1 so a 'required' value is submitted for the submission type.
|
|
|
55 |
checkAvailable.requiredHidden.val(1);
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Enable the submission type's required checkbox and uncheck it.
|
|
|
62 |
*
|
|
|
63 |
* @param {Object} submissionType
|
|
|
64 |
*/
|
|
|
65 |
function enableRequired(submissionType) {
|
|
|
66 |
submissionType.required.prop('disabled', false);
|
|
|
67 |
submissionType.required.prop('checked', false);
|
|
|
68 |
submissionType.requiredHidden.val(0);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Check which submission types have been marked as available, and disable required checkboxes as necessary.
|
|
|
73 |
*/
|
|
|
74 |
function submissionTypeChanged() {
|
|
|
75 |
checkAvailability(submissionTypes.file, submissionTypes.text);
|
|
|
76 |
checkAvailability(submissionTypes.text, submissionTypes.file);
|
|
|
77 |
if (submissionTypes.text.available.prop('checked') && submissionTypes.file.available.prop('checked')) {
|
|
|
78 |
enableRequired(submissionTypes.text);
|
|
|
79 |
enableRequired(submissionTypes.file);
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
return /** @alias module:mod_workshop/modform */ {
|
|
|
84 |
/**
|
|
|
85 |
* Find all the required fields, set up event listeners, and set the initial state of required checkboxes.
|
|
|
86 |
*/
|
|
|
87 |
init: function() {
|
|
|
88 |
submissionTypes.text.available = $('#id_submissiontypetextavailable');
|
|
|
89 |
submissionTypes.text.required = $('#id_submissiontypetextrequired');
|
|
|
90 |
submissionTypes.text.requiredHidden = $('input[name="submissiontypetextrequired"][type="hidden"]');
|
|
|
91 |
submissionTypes.file.available = $('#id_submissiontypefileavailable');
|
|
|
92 |
submissionTypes.file.required = $('#id_submissiontypefilerequired');
|
|
|
93 |
submissionTypes.file.requiredHidden = $('input[name="submissiontypefilerequired"][type="hidden"]');
|
|
|
94 |
submissionTypes.text.available.on('change', submissionTypeChanged);
|
|
|
95 |
submissionTypes.file.available.on('change', submissionTypeChanged);
|
|
|
96 |
submissionTypeChanged();
|
|
|
97 |
}
|
|
|
98 |
};
|
|
|
99 |
});
|