Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * JavaScript required by the question type chooser pop-up.
18
 *
19
 * @module moodle-question-chooser
20
 */
21
 
22
Y.log("The moodle-question-chooser module has been deprecated. " +
23
    "Please use moodle-qbank_editquestion-chooser instead.", 'moodle-core-notification', 'warn');
24
 
25
var SELECTORS = {
26
    CREATENEWQUESTION: 'div.createnewquestion',
27
    CREATENEWQUESTIONFORM: 'div.createnewquestion form',
28
    CHOOSERDIALOGUE: 'div.chooserdialoguebody',
29
    CHOOSERHEADER: 'div.choosertitle'
30
};
31
 
32
function Chooser() {
33
    Chooser.superclass.constructor.apply(this, arguments);
34
}
35
 
36
Y.extend(Chooser, M.core.chooserdialogue, {
37
    initializer: function() {
38
        Y.all('form').each(function(node) {
39
            if (/question\/addquestion\.php/.test(node.getAttribute('action'))) {
40
                node.on('submit', this.displayQuestionChooser, this);
41
            }
42
        }, this);
43
    },
44
    displayQuestionChooser: function(e) {
45
        var dialogue = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERDIALOGUE),
46
            header = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERHEADER);
47
 
48
        if (this.container === null) {
49
            // Setup the dialogue, and then prepare the chooser if it's not already been set up.
50
            this.setup_chooser_dialogue(dialogue, header, {});
51
            this.prepare_chooser();
52
        }
53
 
54
        // Update all of the hidden fields within the questionbank form.
55
        var originForm = e.target.ancestor('form', true),
56
            targetForm = this.container.one('form'),
57
            hiddenElements = originForm.all('input[type="hidden"]');
58
 
59
        targetForm.all('input.customfield').remove();
60
        hiddenElements.each(function(field) {
61
            targetForm.appendChild(field.cloneNode())
62
                .removeAttribute('id')
63
                .addClass('customfield');
64
        });
65
 
66
        // Display the chooser dialogue.
67
        this.display_chooser(e);
68
    }
69
}, {
70
    NAME: 'questionChooser'
71
});
72
 
73
M.question = M.question || {};
74
M.question.init_chooser = function(config) {
75
    return new Chooser(config);
76
};