1 |
efrain |
1 |
/**
|
|
|
2 |
* JavaScript for form editing course completed condition.
|
|
|
3 |
*
|
|
|
4 |
* @module moodle-availability_coursecompleted-form
|
|
|
5 |
*/
|
|
|
6 |
|
|
|
7 |
M.availability_coursecompleted = M.availability_coursecompleted || {};
|
|
|
8 |
|
|
|
9 |
// Class M.availability_coursecompleted.form @extends M.core_availability.plugin.
|
|
|
10 |
M.availability_coursecompleted.form = Y.Object(M.core_availability.plugin);
|
|
|
11 |
|
|
|
12 |
// Options available for selection.
|
|
|
13 |
M.availability_coursecompleted.form.completed = null;
|
|
|
14 |
|
|
|
15 |
/**
|
|
|
16 |
* Initialises this plugin.
|
|
|
17 |
*
|
|
|
18 |
* @method initInner
|
|
|
19 |
* @param {boolean} completed Is completed or not
|
|
|
20 |
*/
|
|
|
21 |
M.availability_coursecompleted.form.initInner = function(completed) {
|
|
|
22 |
this.completed = completed;
|
|
|
23 |
};
|
|
|
24 |
|
|
|
25 |
M.availability_coursecompleted.form.getNode = function(json) {
|
|
|
26 |
// Create HTML structure.
|
|
|
27 |
var tit = M.util.get_string('title', 'availability_coursecompleted');
|
|
|
28 |
var html = '<label class="form-group"><span class="p-r-1">' + tit + '</span>';
|
|
|
29 |
html += '<span class="availability-coursecompleted"><select class="custom-select" name="id" title=' + tit + '>';
|
|
|
30 |
html += '<option value="choose">' + M.util.get_string('choosedots', 'moodle') + '</option>';
|
|
|
31 |
html += '<option value="1">' + M.util.get_string('yes', 'moodle') + '</option>';
|
|
|
32 |
html += '<option value="0">' + M.util.get_string('no', 'moodle') + '</option>';
|
|
|
33 |
html += '</select></span></label>';
|
|
|
34 |
var node = Y.Node.create('<span class="form-inline">' + html + '</span>');
|
|
|
35 |
|
|
|
36 |
// Set initial values (leave default 'choose' if creating afresh).
|
|
|
37 |
if (json.creating === undefined) {
|
|
|
38 |
if (json.id !== undefined && node.one('select[name=id] > option[value=' + json.id + ']')) {
|
|
|
39 |
node.one('select[name=id]').set('value', '' + json.id);
|
|
|
40 |
} else if (json.id === undefined) {
|
|
|
41 |
node.one('select[name=id]').set('value', 'choose');
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
// Add event handlers (first time only).
|
|
|
46 |
if (!M.availability_coursecompleted.form.addedEvents) {
|
|
|
47 |
M.availability_coursecompleted.form.addedEvents = true;
|
|
|
48 |
var root = Y.one('.availability-field');
|
|
|
49 |
root.delegate('change', function() {
|
|
|
50 |
// Just update the form fields.
|
|
|
51 |
M.core_availability.form.update();
|
|
|
52 |
}, '.availability_coursecompleted select');
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
return node;
|
|
|
56 |
};
|
|
|
57 |
|
|
|
58 |
M.availability_coursecompleted.form.fillValue = function(value, node) {
|
|
|
59 |
var selected = node.one('select[name=id]').get('value');
|
|
|
60 |
if (selected === 'choose') {
|
|
|
61 |
value.id = '';
|
|
|
62 |
} else {
|
|
|
63 |
value.id = selected;
|
|
|
64 |
}
|
|
|
65 |
};
|
|
|
66 |
|
|
|
67 |
M.availability_coursecompleted.form.fillErrors = function(errors, node) {
|
|
|
68 |
var selected = node.one('select[name=id]').get('value');
|
|
|
69 |
if (selected === 'choose') {
|
|
|
70 |
errors.push('availability_coursecompleted:missing');
|
|
|
71 |
}
|
|
|
72 |
};
|