MDL-32729 Question: Load all hidden fields from the source form

This commit is contained in:
Andrew Nicols 2014-04-02 10:52:02 +08:00
parent f87b22327f
commit 5c1af530db
4 changed files with 37 additions and 19 deletions

View File

@ -4,8 +4,7 @@ var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialogue',
CHOOSERHEADER: 'div.choosertitle',
QBANKCATEGORY: '#qbankcategory'
CHOOSERHEADER: 'div.choosertitle'
};
function Chooser() {
@ -30,10 +29,17 @@ Y.extend(Chooser, M.core.chooserdialogue, {
this.prepare_chooser();
}
// Set the category ID in the form - this may have been updated since the dialogue
// was previously displayed so we must update it here.
this.container.one(SELECTORS.QBANKCATEGORY).set('value',
Y.one(SELECTORS.CREATENEWQUESTIONFORM).get('category').get('value'));
// Update all of the hidden fields within the questionbank form.
var originForm = e.target.ancestor('form', true),
targetForm = this.container.one('form'),
hiddenElements = originForm.all('input[type="hidden"]');
targetForm.all('input.customfield').remove();
hiddenElements.each(function(field) {
targetForm.appendChild(field.cloneNode())
.removeAttribute('id')
.addClass('customfield');
});
// Display the chooser dialogue.
this.display_chooser(e);

View File

@ -1 +1 @@
YUI.add("moodle-question-chooser",function(e,t){function r(){r.superclass.constructor.apply(this,arguments)}var n={CREATENEWQUESTION:"div.createnewquestion",CREATENEWQUESTIONFORM:"div.createnewquestion form",CHOOSERDIALOGUE:"div.chooserdialogue",CHOOSERHEADER:"div.choosertitle",QBANKCATEGORY:"#qbankcategory"};e.extend(r,M.core.chooserdialogue,{initializer:function(){e.all("form").each(function(e){/question\/addquestion\.php/.test(e.getAttribute("action"))&&e.on("submit",this.displayQuestionChooser,this)},this)},displayQuestionChooser:function(t){var r=e.one(n.CREATENEWQUESTION+" "+n.CHOOSERDIALOGUE),i=e.one(n.CREATENEWQUESTION+" "+n.CHOOSERHEADER);this.container===null&&(this.setup_chooser_dialogue(r,i,{}),this.prepare_chooser()),this.container.one(n.QBANKCATEGORY).set("value",e.one(n.CREATENEWQUESTIONFORM).get("category").get("value")),this.display_chooser(t)}},{NAME:"questionChooser"}),M.question=M.question||{},M.question.init_chooser=function(e){return new r(e)}},"@VERSION@",{requires:["moodle-core-chooserdialogue"]});
YUI.add("moodle-question-chooser",function(e,t){function r(){r.superclass.constructor.apply(this,arguments)}var n={CREATENEWQUESTION:"div.createnewquestion",CREATENEWQUESTIONFORM:"div.createnewquestion form",CHOOSERDIALOGUE:"div.chooserdialogue",CHOOSERHEADER:"div.choosertitle"};e.extend(r,M.core.chooserdialogue,{initializer:function(){e.all("form").each(function(e){/question\/addquestion\.php/.test(e.getAttribute("action"))&&e.on("submit",this.displayQuestionChooser,this)},this)},displayQuestionChooser:function(t){var r=e.one(n.CREATENEWQUESTION+" "+n.CHOOSERDIALOGUE),i=e.one(n.CREATENEWQUESTION+" "+n.CHOOSERHEADER);this.container===null&&(this.setup_chooser_dialogue(r,i,{}),this.prepare_chooser());var s=t.target.ancestor("form",!0),o=this.container.one("form"),u=s.all('input[type="hidden"]');o.all("input.customfield").remove(),u.each(function(e){o.appendChild(e.cloneNode()).removeAttribute("id").addClass("customfield")}),this.display_chooser(t)}},{NAME:"questionChooser"}),M.question=M.question||{},M.question.init_chooser=function(e){return new r(e)}},"@VERSION@",{requires:["moodle-core-chooserdialogue"]});

View File

@ -4,8 +4,7 @@ var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialogue',
CHOOSERHEADER: 'div.choosertitle',
QBANKCATEGORY: '#qbankcategory'
CHOOSERHEADER: 'div.choosertitle'
};
function Chooser() {
@ -30,10 +29,17 @@ Y.extend(Chooser, M.core.chooserdialogue, {
this.prepare_chooser();
}
// Set the category ID in the form - this may have been updated since the dialogue
// was previously displayed so we must update it here.
this.container.one(SELECTORS.QBANKCATEGORY).set('value',
Y.one(SELECTORS.CREATENEWQUESTIONFORM).get('category').get('value'));
// Update all of the hidden fields within the questionbank form.
var originForm = e.target.ancestor('form', true),
targetForm = this.container.one('form'),
hiddenElements = originForm.all('input[type="hidden"]');
targetForm.all('input.customfield').remove();
hiddenElements.each(function(field) {
targetForm.appendChild(field.cloneNode())
.removeAttribute('id')
.addClass('customfield');
});
// Display the chooser dialogue.
this.display_chooser(e);

View File

@ -2,8 +2,7 @@ var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialogue',
CHOOSERHEADER: 'div.choosertitle',
QBANKCATEGORY: '#qbankcategory'
CHOOSERHEADER: 'div.choosertitle'
};
function Chooser() {
@ -28,10 +27,17 @@ Y.extend(Chooser, M.core.chooserdialogue, {
this.prepare_chooser();
}
// Set the category ID in the form - this may have been updated since the dialogue
// was previously displayed so we must update it here.
this.container.one(SELECTORS.QBANKCATEGORY).set('value',
Y.one(SELECTORS.CREATENEWQUESTIONFORM).get('category').get('value'));
// Update all of the hidden fields within the questionbank form.
var originForm = e.target.ancestor('form', true),
targetForm = this.container.one('form'),
hiddenElements = originForm.all('input[type="hidden"]');
targetForm.all('input.customfield').remove();
hiddenElements.each(function(field) {
targetForm.appendChild(field.cloneNode())
.removeAttribute('id')
.addClass('customfield');
});
// Display the chooser dialogue.
this.display_chooser(e);