MDL-47603 quiz edit: qbank popup preview icon needs new window

Also, ensure that clicking the + icon adds the question on the right
page.

Bit of this fix are a bit hacky, but we have to deal with the fact there
is not a good general solution to MDL-47604.
This commit is contained in:
Tim Hunt 2014-10-10 13:40:16 +01:00
parent d3ff82257e
commit 84b45a24a1
5 changed files with 136 additions and 37 deletions

View File

@ -877,22 +877,22 @@ class edit_renderer extends \plugin_renderer_base {
// Require various strings for the command toolbox.
$this->page->requires->strings_for_js(array(
'moveleft',
'clicktohideshow',
'deletechecktype',
'deletechecktypename',
'edittitle',
'edittitleinstructions',
'show',
'emptydragdropregion',
'hide',
'clicktochangeinbrackets',
'markthistopic',
'markedthistopic',
'markthistopic',
'move',
'movesection',
'movecontent',
'moveleft',
'movesection',
'selectall',
'show',
'tocontent',
'emptydragdropregion'
), 'moodle');
$this->page->requires->strings_for_js(array(

View File

@ -24,11 +24,12 @@ YUI.add('moodle-mod_quiz-quizquestionbank', function (Y, NAME) {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
QBANKLOADING: 'div.questionbankloading',
ADDQUESTIONLINKS: 'ul.menu a.questionbank',
ADDTOQUIZCONTAINER: 'td.addtoquizaction'
QBANKLOADING: 'div.questionbankloading',
ADDQUESTIONLINKS: 'ul.menu a.questionbank',
ADDTOQUIZCONTAINER: 'td.addtoquizaction',
PREVIEWCONTAINER: 'td.previewaction',
SEARCHOPTIONS: '#advancedsearch'
};
var PARAMS = {
@ -44,6 +45,7 @@ Y.extend(POPUP, Y.Base, {
loadingDiv: '',
dialogue: null,
addonpage: 0,
searchRegionInitialised: false,
create_dialogue: function() {
// Create a dialogue on the page and hide it.
@ -60,8 +62,7 @@ Y.extend(POPUP, Y.Base, {
extraClasses: ['mod_quiz_qbank_dialogue']
};
this.dialogue = new M.core.dialogue(config);
this.dialogue.bodyNode.delegate('click', this.link_clicked,
'.paging a[href], thead tr a[href]', this);
this.dialogue.bodyNode.delegate('click', this.link_clicked, 'a[href]', this);
this.dialogue.hide();
this.loadingDiv = this.dialogue.bodyNode.getHTML();
@ -91,6 +92,7 @@ Y.extend(POPUP, Y.Base, {
hidden.set('value', this.addonpage);
}
this.initialiseSearchRegion();
this.dialogue.show();
},
@ -135,9 +137,9 @@ Y.extend(POPUP, Y.Base, {
}
M.question.qbankmanager.init();
if (Y.one('#advancedsearch')) {
M.util.init_collapsible_region(Y, "advancedsearch", "question_bank_advanced_search",
M.util.get_string('clicktohideshow'));
this.searchRegionInitialised = false;
if (this.dialogue.get('visible')) {
this.initialiseSearchRegion();
}
this.dialogue.fire('widget:contentUpdate');
@ -157,11 +159,29 @@ Y.extend(POPUP, Y.Base, {
},
link_clicked: function(e) {
// Add question to quiz. mofify the URL, then let it work as normal.
if (e.currentTarget.ancestor(CSS.ADDTOQUIZCONTAINER)) {
// These links need to work like normal, after we modify the URL.
e.currentTarget.set('href', e.currentTarget.get('href') + '&addonpage=' + this.addonpage);
return;
}
// Question preview. Needs to open in a pop-up.
if (e.currentTarget.ancestor(CSS.PREVIEWCONTAINER)) {
openpopup(e, {
url: e.currentTarget.get('href'),
name: 'questionpreview',
options: 'height=600,width=800,top=0,left=0,menubar=0,location=0,scrollbars,resizable,toolbar,status,directories=0,fullscreen=0,dependent'
});
return;
}
// Click on expand/collaspse search-options. Has its own handler.
// We should not interfere.
if (e.currentTarget.ancestor(CSS.SEARCHOPTIONS)) {
return;
}
// Anything else means reload the pop-up contents.
e.preventDefault();
this.load_content(e.currentTarget.get('search'));
},
@ -169,6 +189,19 @@ Y.extend(POPUP, Y.Base, {
options_changed: function(e) {
e.preventDefault();
this.load_content('?' + Y.IO.stringify(e.currentTarget.get('form')));
},
initialiseSearchRegion: function() {
if (this.searchRegionInitialised === true) {
return;
}
if (!Y.one(CSS.SEARCHOPTIONS)) {
return;
}
M.util.init_collapsible_region(Y, "advancedsearch", "question_bank_advanced_search",
M.util.get_string('clicktohideshow', 'moodle'));
this.searchRegionInitialised = true;
}
});

View File

@ -1 +1 @@
YUI.add("moodle-mod_quiz-quizquestionbank",function(e,t){var n={QBANKLOADING:"div.questionbankloading",ADDQUESTIONLINKS:"ul.menu a.questionbank",ADDTOQUIZCONTAINER:"td.addtoquizaction"},r={PAGE:"addonpage",HEADER:"header"},i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,e.Base,{loadingDiv:"",dialogue:null,addonpage:0,create_dialogue:function(){config={headerContent:"",bodyContent:e.one(n.QBANKLOADING),draggable:!0,modal:!0,centered:!0,width:null,visible:!1,postmethod:"form",footerContent:null,extraClasses:["mod_quiz_qbank_dialogue"]},this.dialogue=new M.core.dialogue(config),this.dialogue.bodyNode.delegate("click",this.link_clicked,".paging a[href], thead tr a[href]",this),this.dialogue.hide(),this.loadingDiv=this.dialogue.bodyNode.getHTML(),e.later(100,this,function(){this.load_content(window.location.search)})},initializer:function(){if(!e.one(n.QBANKLOADING))return;this.create_dialogue(),e.one("body").delegate("click",this.display_dialogue,n.ADDQUESTIONLINKS,this)},display_dialogue:function(e){e.preventDefault(),this.dialogue.set("headerContent",e.currentTarget.getData(r.HEADER)),this.addonpage=e.currentTarget.getData(r.PAGE);var t=this.dialogue.bodyNode.one(".modulespecificbuttonscontainer");if(t){var n=t.one("input[name=addonpage]");n||(n=t.appendChild('<input type="hidden" name="addonpage">')),n.set("value",this.addonpage)}this.dialogue.show()},load_content:function(t){this.dialogue.bodyNode.append(this.loadingDiv),window.history.replaceState&&window.history.replaceState(null,"",M.cfg.wwwroot+"/mod/quiz/edit.php"+t),e.io(M.cfg.wwwroot+"/mod/quiz/questionbank.ajax.php"+t,{method:"GET",on:{success:this.load_done,failure:this.load_failed},context:this})},load_done:function(t,n){var r=JSON.parse(n.responseText);if(!r.status||r.status!=="OK"){this.load_failed(t,n);return}this.dialogue.bodyNode.setHTML(r.contents),e.use("moodle-question-chooser",function(){M.question.init_chooser({})}),this.dialogue.bodyNode.one("form").delegate("change",this.options_changed,".searchoptions",this),this.dialogue.visible&&e.later(0,this.dialogue,this.dialogue.centerDialogue),M.question.qbankmanager.init(),e.one("#advancedsearch")&&M.util.init_collapsible_region(e,"advancedsearch","question_bank_advanced_search",M.util.get_string("clicktohideshow")),this.dialogue.fire("widget:contentUpdate"),this.dialogue.get("visible")&&(this.dialogue.hide(),this.dialogue.show())},load_failed:function(){},link_clicked:function(e){if(e.currentTarget.ancestor(n.ADDTOQUIZCONTAINER)){e.currentTarget.set("href",e.currentTarget.get("href")+"&addonpage="+this.addonpage);return}e.preventDefault(),this.load_content(e.currentTarget.get("search"))},options_changed:function(t){t.preventDefault(),this.load_content("?"+e.IO.stringify(t.currentTarget.get("form")))}}),M.mod_quiz=M.mod_quiz||{},M.mod_quiz.quizquestionbank=M.mod_quiz.quizquestionbank||{},M.mod_quiz.quizquestionbank.init=function(){return new i}},"@VERSION@",{requires:["base","event","node","io","io-form","yui-later","moodle-question-qbankmanager","moodle-core-notification-dialogue"]});
YUI.add("moodle-mod_quiz-quizquestionbank",function(e,t){var n={QBANKLOADING:"div.questionbankloading",ADDQUESTIONLINKS:"ul.menu a.questionbank",ADDTOQUIZCONTAINER:"td.addtoquizaction",PREVIEWCONTAINER:"td.previewaction",SEARCHOPTIONS:"#advancedsearch"},r={PAGE:"addonpage",HEADER:"header"},i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,e.Base,{loadingDiv:"",dialogue:null,addonpage:0,searchRegionInitialised:!1,create_dialogue:function(){config={headerContent:"",bodyContent:e.one(n.QBANKLOADING),draggable:!0,modal:!0,centered:!0,width:null,visible:!1,postmethod:"form",footerContent:null,extraClasses:["mod_quiz_qbank_dialogue"]},this.dialogue=new M.core.dialogue(config),this.dialogue.bodyNode.delegate("click",this.link_clicked,"a[href]",this),this.dialogue.hide(),this.loadingDiv=this.dialogue.bodyNode.getHTML(),e.later(100,this,function(){this.load_content(window.location.search)})},initializer:function(){if(!e.one(n.QBANKLOADING))return;this.create_dialogue(),e.one("body").delegate("click",this.display_dialogue,n.ADDQUESTIONLINKS,this)},display_dialogue:function(e){e.preventDefault(),this.dialogue.set("headerContent",e.currentTarget.getData(r.HEADER)),this.addonpage=e.currentTarget.getData(r.PAGE);var t=this.dialogue.bodyNode.one(".modulespecificbuttonscontainer");if(t){var n=t.one("input[name=addonpage]");n||(n=t.appendChild('<input type="hidden" name="addonpage">')),n.set("value",this.addonpage)}this.initialiseSearchRegion(),this.dialogue.show()},load_content:function(t){this.dialogue.bodyNode.append(this.loadingDiv),window.history.replaceState&&window.history.replaceState(null,"",M.cfg.wwwroot+"/mod/quiz/edit.php"+t),e.io(M.cfg.wwwroot+"/mod/quiz/questionbank.ajax.php"+t,{method:"GET",on:{success:this.load_done,failure:this.load_failed},context:this})},load_done:function(t,n){var r=JSON.parse(n.responseText);if(!r.status||r.status!=="OK"){this.load_failed(t,n);return}this.dialogue.bodyNode.setHTML(r.contents),e.use("moodle-question-chooser",function(){M.question.init_chooser({})}),this.dialogue.bodyNode.one("form").delegate("change",this.options_changed,".searchoptions",this),this.dialogue.visible&&e.later(0,this.dialogue,this.dialogue.centerDialogue),M.question.qbankmanager.init(),this.searchRegionInitialised=!1,this.dialogue.get("visible")&&this.initialiseSearchRegion(),this.dialogue.fire("widget:contentUpdate"),this.dialogue.get("visible")&&(this.dialogue.hide(),this.dialogue.show())},load_failed:function(){},link_clicked:function(e){if(e.currentTarget.ancestor(n.ADDTOQUIZCONTAINER)){e.currentTarget.set("href",e.currentTarget.get("href")+"&addonpage="+this.addonpage);return}if(e.currentTarget.ancestor(n.PREVIEWCONTAINER)){openpopup(e,{url:e.currentTarget.get("href"),name:"questionpreview",options:"height=600,width=800,top=0,left=0,menubar=0,location=0,scrollbars,resizable,toolbar,status,directories=0,fullscreen=0,dependent"});return}if(e.currentTarget.ancestor(n.SEARCHOPTIONS))return;e.preventDefault(),this.load_content(e.currentTarget.get("search"))},options_changed:function(t){t.preventDefault(),this.load_content("?"+e.IO.stringify(t.currentTarget.get("form")))},initialiseSearchRegion:function(){if(this.searchRegionInitialised===!0)return;if(!e.one(n.SEARCHOPTIONS))return;M.util.init_collapsible_region(e,"advancedsearch","question_bank_advanced_search",M.util.get_string("clicktohideshow","moodle")),this.searchRegionInitialised=!0}}),M.mod_quiz=M.mod_quiz||{},M.mod_quiz.quizquestionbank=M.mod_quiz.quizquestionbank||{},M.mod_quiz.quizquestionbank.init=function(){return new i}},"@VERSION@",{requires:["base","event","node","io","io-form","yui-later","moodle-question-qbankmanager","moodle-core-notification-dialogue"]});

View File

@ -24,11 +24,12 @@ YUI.add('moodle-mod_quiz-quizquestionbank', function (Y, NAME) {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
QBANKLOADING: 'div.questionbankloading',
ADDQUESTIONLINKS: 'ul.menu a.questionbank',
ADDTOQUIZCONTAINER: 'td.addtoquizaction'
QBANKLOADING: 'div.questionbankloading',
ADDQUESTIONLINKS: 'ul.menu a.questionbank',
ADDTOQUIZCONTAINER: 'td.addtoquizaction',
PREVIEWCONTAINER: 'td.previewaction',
SEARCHOPTIONS: '#advancedsearch'
};
var PARAMS = {
@ -44,6 +45,7 @@ Y.extend(POPUP, Y.Base, {
loadingDiv: '',
dialogue: null,
addonpage: 0,
searchRegionInitialised: false,
create_dialogue: function() {
// Create a dialogue on the page and hide it.
@ -60,8 +62,7 @@ Y.extend(POPUP, Y.Base, {
extraClasses: ['mod_quiz_qbank_dialogue']
};
this.dialogue = new M.core.dialogue(config);
this.dialogue.bodyNode.delegate('click', this.link_clicked,
'.paging a[href], thead tr a[href]', this);
this.dialogue.bodyNode.delegate('click', this.link_clicked, 'a[href]', this);
this.dialogue.hide();
this.loadingDiv = this.dialogue.bodyNode.getHTML();
@ -91,6 +92,7 @@ Y.extend(POPUP, Y.Base, {
hidden.set('value', this.addonpage);
}
this.initialiseSearchRegion();
this.dialogue.show();
},
@ -132,9 +134,9 @@ Y.extend(POPUP, Y.Base, {
}
M.question.qbankmanager.init();
if (Y.one('#advancedsearch')) {
M.util.init_collapsible_region(Y, "advancedsearch", "question_bank_advanced_search",
M.util.get_string('clicktohideshow'));
this.searchRegionInitialised = false;
if (this.dialogue.get('visible')) {
this.initialiseSearchRegion();
}
this.dialogue.fire('widget:contentUpdate');
@ -153,11 +155,29 @@ Y.extend(POPUP, Y.Base, {
},
link_clicked: function(e) {
// Add question to quiz. mofify the URL, then let it work as normal.
if (e.currentTarget.ancestor(CSS.ADDTOQUIZCONTAINER)) {
// These links need to work like normal, after we modify the URL.
e.currentTarget.set('href', e.currentTarget.get('href') + '&addonpage=' + this.addonpage);
return;
}
// Question preview. Needs to open in a pop-up.
if (e.currentTarget.ancestor(CSS.PREVIEWCONTAINER)) {
openpopup(e, {
url: e.currentTarget.get('href'),
name: 'questionpreview',
options: 'height=600,width=800,top=0,left=0,menubar=0,location=0,scrollbars,resizable,toolbar,status,directories=0,fullscreen=0,dependent'
});
return;
}
// Click on expand/collaspse search-options. Has its own handler.
// We should not interfere.
if (e.currentTarget.ancestor(CSS.SEARCHOPTIONS)) {
return;
}
// Anything else means reload the pop-up contents.
e.preventDefault();
this.load_content(e.currentTarget.get('search'));
},
@ -165,6 +185,19 @@ Y.extend(POPUP, Y.Base, {
options_changed: function(e) {
e.preventDefault();
this.load_content('?' + Y.IO.stringify(e.currentTarget.get('form')));
},
initialiseSearchRegion: function() {
if (this.searchRegionInitialised === true) {
return;
}
if (!Y.one(CSS.SEARCHOPTIONS)) {
return;
}
M.util.init_collapsible_region(Y, "advancedsearch", "question_bank_advanced_search",
M.util.get_string('clicktohideshow', 'moodle'));
this.searchRegionInitialised = true;
}
});

View File

@ -22,11 +22,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
QBANKLOADING: 'div.questionbankloading',
ADDQUESTIONLINKS: 'ul.menu a.questionbank',
ADDTOQUIZCONTAINER: 'td.addtoquizaction'
QBANKLOADING: 'div.questionbankloading',
ADDQUESTIONLINKS: 'ul.menu a.questionbank',
ADDTOQUIZCONTAINER: 'td.addtoquizaction',
PREVIEWCONTAINER: 'td.previewaction',
SEARCHOPTIONS: '#advancedsearch'
};
var PARAMS = {
@ -42,6 +43,7 @@ Y.extend(POPUP, Y.Base, {
loadingDiv: '',
dialogue: null,
addonpage: 0,
searchRegionInitialised: false,
create_dialogue: function() {
// Create a dialogue on the page and hide it.
@ -58,8 +60,7 @@ Y.extend(POPUP, Y.Base, {
extraClasses: ['mod_quiz_qbank_dialogue']
};
this.dialogue = new M.core.dialogue(config);
this.dialogue.bodyNode.delegate('click', this.link_clicked,
'.paging a[href], thead tr a[href]', this);
this.dialogue.bodyNode.delegate('click', this.link_clicked, 'a[href]', this);
this.dialogue.hide();
this.loadingDiv = this.dialogue.bodyNode.getHTML();
@ -89,6 +90,7 @@ Y.extend(POPUP, Y.Base, {
hidden.set('value', this.addonpage);
}
this.initialiseSearchRegion();
this.dialogue.show();
},
@ -133,9 +135,9 @@ Y.extend(POPUP, Y.Base, {
}
M.question.qbankmanager.init();
if (Y.one('#advancedsearch')) {
M.util.init_collapsible_region(Y, "advancedsearch", "question_bank_advanced_search",
M.util.get_string('clicktohideshow'));
this.searchRegionInitialised = false;
if (this.dialogue.get('visible')) {
this.initialiseSearchRegion();
}
this.dialogue.fire('widget:contentUpdate');
@ -155,11 +157,29 @@ Y.extend(POPUP, Y.Base, {
},
link_clicked: function(e) {
// Add question to quiz. mofify the URL, then let it work as normal.
if (e.currentTarget.ancestor(CSS.ADDTOQUIZCONTAINER)) {
// These links need to work like normal, after we modify the URL.
e.currentTarget.set('href', e.currentTarget.get('href') + '&addonpage=' + this.addonpage);
return;
}
// Question preview. Needs to open in a pop-up.
if (e.currentTarget.ancestor(CSS.PREVIEWCONTAINER)) {
openpopup(e, {
url: e.currentTarget.get('href'),
name: 'questionpreview',
options: 'height=600,width=800,top=0,left=0,menubar=0,location=0,scrollbars,resizable,toolbar,status,directories=0,fullscreen=0,dependent'
});
return;
}
// Click on expand/collaspse search-options. Has its own handler.
// We should not interfere.
if (e.currentTarget.ancestor(CSS.SEARCHOPTIONS)) {
return;
}
// Anything else means reload the pop-up contents.
e.preventDefault();
this.load_content(e.currentTarget.get('search'));
},
@ -167,6 +187,19 @@ Y.extend(POPUP, Y.Base, {
options_changed: function(e) {
e.preventDefault();
this.load_content('?' + Y.IO.stringify(e.currentTarget.get('form')));
},
initialiseSearchRegion: function() {
if (this.searchRegionInitialised === true) {
return;
}
if (!Y.one(CSS.SEARCHOPTIONS)) {
return;
}
M.util.init_collapsible_region(Y, "advancedsearch", "question_bank_advanced_search",
M.util.get_string('clicktohideshow', 'moodle'));
this.searchRegionInitialised = true;
}
});