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