Merge branch 'MOODLE_310_MDL-70117' of https://github.com/golenkovm/moodle into MOODL...
[moodle.git] / question / yui / src / chooser / js / chooser.js
CommitLineData
ac32c27e
ARN
1var SELECTORS = {
2 CREATENEWQUESTION: 'div.createnewquestion',
3 CREATENEWQUESTIONFORM: 'div.createnewquestion form',
6f0993cc 4 CHOOSERDIALOGUE: 'div.chooserdialoguebody',
5c1af530 5 CHOOSERHEADER: 'div.choosertitle'
ac32c27e
ARN
6};
7
8function Chooser() {
9 Chooser.superclass.constructor.apply(this, arguments);
10}
11
12Y.extend(Chooser, M.core.chooserdialogue, {
13 initializer: function() {
f87b2232
AN
14 Y.all('form').each(function(node) {
15 if (/question\/addquestion\.php/.test(node.getAttribute('action'))) {
16 node.on('submit', this.displayQuestionChooser, this);
17 }
18 }, this);
ac32c27e
ARN
19 },
20 displayQuestionChooser: function(e) {
21 var dialogue = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERDIALOGUE),
22 header = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERHEADER);
23
24 if (this.container === null) {
25 // Setup the dialogue, and then prepare the chooser if it's not already been set up.
26 this.setup_chooser_dialogue(dialogue, header, {});
27 this.prepare_chooser();
28 }
29
5c1af530
AN
30 // Update all of the hidden fields within the questionbank form.
31 var originForm = e.target.ancestor('form', true),
32 targetForm = this.container.one('form'),
33 hiddenElements = originForm.all('input[type="hidden"]');
34
35 targetForm.all('input.customfield').remove();
36 hiddenElements.each(function(field) {
37 targetForm.appendChild(field.cloneNode())
38 .removeAttribute('id')
39 .addClass('customfield');
40 });
ac32c27e
ARN
41
42 // Display the chooser dialogue.
43 this.display_chooser(e);
44 }
45}, {
46 NAME: 'questionChooser'
47});
48
49M.question = M.question || {};
50M.question.init_chooser = function(config) {
51 return new Chooser(config);
52};