diff --git a/mod/quiz/classes/output/edit_renderer.php b/mod/quiz/classes/output/edit_renderer.php index 021a19fb4a821..59c95e9e7afd3 100644 --- a/mod/quiz/classes/output/edit_renderer.php +++ b/mod/quiz/classes/output/edit_renderer.php @@ -1150,6 +1150,8 @@ protected function initialise_editing_javascript(structure $structure, $this->page->requires->strings_for_js(array( 'addpagebreak', + 'cannotremoveallsectionslots', + 'cannotremoveslots', 'confirmremovesectionheading', 'confirmremovequestion', 'dragtoafter', diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index 8c8af73743ea0..1bfa3813a7340 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -137,6 +137,8 @@ $string['cannotloadquestion'] = 'Could not load question options'; $string['cannotloadtypeinfo'] = 'Unable to load questiontype specific question information'; $string['cannotopen'] = 'Cannot open export file ({$a})'; +$string['cannotremoveallsectionslots'] = 'You have selected all questions of the \'{$a}\' section heading. It is not allowed to remove all questions under a section heading.'; +$string['cannotremoveslots'] = 'Can not remove questions'; $string['cannotrestore'] = 'Could not restore question sessions'; $string['cannotreviewopen'] = 'You cannot review this attempt, it is still open.'; $string['cannotsavelayout'] = 'Could not save layout'; diff --git a/mod/quiz/styles.css b/mod/quiz/styles.css index 2cc020f02f7a2..1a22b69b70175 100644 --- a/mod/quiz/styles.css +++ b/mod/quiz/styles.css @@ -1184,11 +1184,9 @@ table#categoryquestions { display: none; } -#page-mod-quiz-edit.select-multiple .mod-quiz-edit-content .section-heading, +#page-mod-quiz-edit.select-multiple .mod-quiz-edit-content .section-heading a, #page-mod-quiz-edit.select-multiple .mod-quiz-edit-content .section-heading form, -#page-mod-quiz-edit.select-multiple .mod-quiz-edit-content .section-heading .instancesectioncontainer, -#page-mod-quiz-edit.select-multiple .mod-quiz-edit-content .section-heading .instanceshufflequestions, -#page-mod-quiz-edit.select-multiple .mod-quiz-edit-content .section-heading .instancesectioncontainer h3 { +#page-mod-quiz-edit.select-multiple .mod-quiz-edit-content .section-heading .instanceshufflequestions { display: none; } diff --git a/mod/quiz/tests/behat/editing_remove_multiple_questions.feature b/mod/quiz/tests/behat/editing_remove_multiple_questions.feature index 7d5c9be341d19..4e6d8407b5ca0 100644 --- a/mod/quiz/tests/behat/editing_remove_multiple_questions.feature +++ b/mod/quiz/tests/behat/editing_remove_multiple_questions.feature @@ -167,3 +167,74 @@ Feature: Edit quiz page - remove multiple questions When I click on "Deselect all" "link" Then the field "selectquestion-3" matches value "0" + + @javascript + Scenario: Delete multiple questions from sections + Given the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | truefalse | Question A | First question | + | Test questions | truefalse | Question B | Second question | + | Test questions | truefalse | Question C | Third question | + | Test questions | truefalse | Question D | Fourth question | + | Test questions | truefalse | Question E | Fifth question | + | Test questions | truefalse | Question F | Sixth question | + And quiz "Quiz 1" contains the following questions: + | question | page | + | Question A | 1 | + | Question B | 2 | + | Question C | 3 | + | Question D | 4 | + | Question E | 5 | + | Question F | 6 | + And quiz "Quiz 1" contains the following sections: + | heading | firstslot | shuffle | + | Section 1 | 1 | 0 | + | Section 2 | 2 | 0 | + | Section 3 | 4 | 0 | + And I navigate to "Edit quiz" in current page administration + + When I click on "Select multiple items" "button" + And I click on "selectquestion-3" "checkbox" + And I click on "selectquestion-5" "checkbox" + And I click on "selectquestion-6" "checkbox" + And I click on "Delete selected" "button" + And I click on "Yes" "button" in the "Confirm" "dialogue" + + Then I should see "Question A" on quiz page "1" + And I should see "Question B" on quiz page "2" + And I should see "Question D" on quiz page "3" + And I should not see "Question C" + And I should not see "Question E" + And I should not see "Question F" + + @javascript + Scenario: Attempting to delete all questions of a sections + Given the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | truefalse | Question A | First question | + | Test questions | truefalse | Question B | Second question | + | Test questions | truefalse | Question C | Third question | + | Test questions | truefalse | Question D | Fourth question | + | Test questions | truefalse | Question E | Fifth question | + | Test questions | truefalse | Question F | Sixth question | + And quiz "Quiz 1" contains the following questions: + | question | page | + | Question A | 1 | + | Question B | 2 | + | Question C | 3 | + | Question D | 4 | + | Question E | 5 | + | Question F | 6 | + And quiz "Quiz 1" contains the following sections: + | heading | firstslot | shuffle | + | Section 1 | 1 | 0 | + | Section 2 | 2 | 0 | + | Section 3 | 4 | 0 | + And I navigate to "Edit quiz" in current page administration + + When I click on "Select multiple items" "button" + And I click on "selectquestion-2" "checkbox" + And I click on "selectquestion-3" "checkbox" + And I click on "Delete selected" "button" + + Then I should see "Can not remove questions" diff --git a/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes-debug.js b/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes-debug.js index e1af1d1f76a83..780bc3ce2ce81 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes-debug.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes-debug.js @@ -64,6 +64,7 @@ var CSS = { NUMQUESTIONS: '.numberofquestions', PAGECONTENT: 'div#page-content', PAGELI: 'li.page', + SECTIONLI: 'li.section', SECTIONUL: 'ul.section', SECTIONFORM: '.instancesectioncontainer form', SECTIONINPUT: 'input[name=section]', @@ -337,7 +338,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON).setAttribute('disabled', 'disabled'); // Assign the delete method to the delete multiple button. - Y.delegate('click', this.delete_multiple_with_confirmation, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this); + Y.delegate('click', this.delete_multiple_action, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this); // Enable the delete all button only when at least one slot is selected. Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTMULTIPLECHECKBOX, this); @@ -439,7 +440,6 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @param {EventFacade} ev The event that was fired. * @param {Node} button The button that triggered this action. * @param {Node} activity The activity node that this action will be performed on. - * @chainable */ delete_with_confirmation: function(ev, button, activity) { // Prevent the default button action. @@ -481,13 +481,62 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { }, this); }, + /** + * Finds the section that would become empty if we remove the selected slots. + * + * @protected + * @method find_sections_that_would_become_empty + * @returns {String} The name of the first section found + */ + find_sections_that_would_become_empty: function() { + var section; + var sectionnodes = Y.all(SELECTOR.SECTIONLI); + + if (sectionnodes.size() > 1) { + sectionnodes.some(function(node) { + var sectionname = node.one(SELECTOR.INSTANCESECTION).getContent(); + var checked = node.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':checked'); + var unchecked = node.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':not(:checked)'); + + if (!checked.isEmpty() && unchecked.isEmpty()) { + section = sectionname; + } + + return section; + }); + } + + return section; + }, + + /** + * Takes care of what needs to happen when the user clicks on the delete multiple button. + * + * @protected + * @method delete_multiple_action + * @param {EventFacade} ev The event that was fired. + */ + delete_multiple_action: function(ev) { + var problemsection = this.find_sections_that_would_become_empty(); + + if (problemsection) { + var alert = new M.core.alert({ + title: M.util.get_string('cannotremoveslots', 'quiz'), + message: M.util.get_string('cannotremoveallsectionslots', 'quiz', problemsection) + }); + + alert.show(); + } else { + this.delete_multiple_with_confirmation(ev); + } + }, + /** * Deletes the given activities or resources after confirmation. * * @protected * @method delete_multiple_with_confirmation * @param {EventFacade} ev The event that was fired. - * @chainable */ delete_multiple_with_confirmation: function(ev) { ev.preventDefault(); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes-min.js b/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes-min.js index 4bbeaf8ab156d..05aa0cf0837d9 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes-min.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes-min.js @@ -1,3 +1,3 @@ -YUI.add("moodle-mod_quiz-toolboxes",function(e,t){var n={ACTIVITYINSTANCE:"activityinstance",AVAILABILITYINFODIV:"div.availabilityinfo",CONTENTWITHOUTLINK:"contentwithoutlink",CONDITIONALHIDDEN:"conditionalhidden",DIMCLASS:"dimmed",DIMMEDTEXT:"dimmed_text",EDITINSTRUCTIONS:"editinstructions",EDITINGMAXMARK:"editor_displayed",HIDE:"hide",JOIN:"page_join",MODINDENTCOUNT:"mod-indent-",MODINDENTHUGE:"mod-indent-huge",PAGE:"page",SECTIONHIDDENCLASS:"hidden",SECTIONIDPREFIX:"section-",SELECTMULTIPLE:"select-multiple",SLOT:"slot",SHOW:"editing_show",TITLEEDITOR:"titleeditor"},r={ACTIONAREA:".actions",ACTIONLINKTEXT:".actionlinktext",ACTIVITYACTION:"a.cm-edit-action[data-action], a.editing_maxmark, a.editing_section, input.shuffle_questions",ACTIVITYFORM:"span.instancemaxmarkcontainer form",ACTIVITYINSTANCE:"."+n.ACTIVITYINSTANCE,SECTIONINSTANCE:".sectioninstance",ACTIVITYLI:"li.activity, li.section",ACTIVITYMAXMARK:"input[name=maxmark]",COMMANDSPAN:".commands",CONTENTAFTERLINK:"div.contentafterlink",CONTENTWITHOUTLINK:"div.contentwithoutlink",DELETESECTIONICON:"a.editing_delete .icon",DESELECTALL:"#questiondeselectall",EDITMAXMARK:"a.editing_maxmark",EDITSECTION:"a.editing_section",EDITSECTIONICON:"a.editing_section .icon",EDITSHUFFLEQUESTIONSACTION:"input.cm-edit-action[data-action]",EDITSHUFFLEAREA:".instanceshufflequestions .shuffle-progress",HIDE:"a.editing_hide",HIGHLIGHT:"a.editing_highlight",INSTANCENAME:"span.instancename",INSTANCEMAXMARK:"span.instancemaxmark",INSTANCESECTION:"span.instancesection",INSTANCESECTIONAREA:"div.section-heading",MODINDENTDIV:".mod-indent",MODINDENTOUTER:".mod-indent-outer",NUMQUESTIONS:".numberofquestions",PAGECONTENT:"div#page-content",PAGELI:"li.page",SECTIONUL:"ul.section",SECTIONFORM:".instancesectioncontainer form",SECTIONINPUT:"input[name=section]",SELECTMULTIPLEBUTTON:"#selectmultiplecommand",SELECTMULTIPLECANCELBUTTON:"#selectmultiplecancelcommand",SELECTMULTIPLECHECKBOX:".select-multiple-checkbox",SELECTMULTIPLEDELETEBUTTON:"#selectmultipledeletecommand",SELECTALL:"#questionselectall",SHOW:"a."+n.SHOW,SLOTLI:"li.slot",SUMMARKS:".mod_quiz_summarks"},i=e.one(document.body);M.mod_quiz=M.mod_quiz||{};var s=function(){s.superclass.constructor.apply(this,arguments)};e.extend(s,e.Base,{send_request:function(t,n,i,s){t||(t={});var o=this.get("config").pageparams,u;for(u in o)t[u]=o[u];t.sesskey=M.cfg.sesskey,t.courseid=this.get("courseid"),t.quizid=this.get("quizid");var a=M.cfg.wwwroot+this.get("ajaxurl"),f=[],l={method:"POST",data:t,on:{success:function(t,s){try{f=e.JSON.parse(s.responseText),f.error&&new M.core.ajaxException(f)}catch(o){}f.hasOwnProperty("newsummarks")&&e.one(r.SUMMARKS).setHTML(f.newsummarks),f.hasOwnProperty("newnumquestions")&&e.one(r.NUMQUESTIONS).setHTML(M.util.get_string("numquestionsx","quiz",f.newnumquestions)),i&&e.bind(i,this,f)(),n&&window.setTimeout(function(){n.hide()},400)},failure:function(e,t){n&&n.hide(),new M.core.ajaxException(t)}},context:this};if(s)for(u in s)l[u]=s[u];return n&&n.show(),e.io(a,l),this}},{NAME:"mod_quiz-toolbox",ATTRS:{courseid:{value:0},quizid:{value:0},ajaxurl:{value:null},config:{value:{}}}});var o=function(){o.superclass.constructor.apply(this,arguments)};e.extend(o,s,{editmaxmarkevents:[],NODE_PAGE:1,NODE_SLOT:2,NODE_JOIN:3,initializer:function(){M.mod_quiz.quizbase.register_module(this),e.delegate("click",this.handle_data_action,i,r.ACTIVITYACTION,this),e.delegate("click",this.handle_data_action,i,r.DEPENDENCY_LINK,this),this.initialise_select_multiple()},initialise_select_multiple:function(){e.one(r.SELECTMULTIPLEBUTTON).on("click",function(t){t.preventDefault(),e.one("body").addClass(n.SELECTMULTIPLE)}),e.one(r.SELECTMULTIPLECANCELBUTTON).on("click",function(t){t.preventDefault(),e.one("body").removeClass(n.SELECTMULTIPLE)}),e.one(r.SELECTALL).on("click",function(t){t.preventDefault(),e.all(r.SELECTMULTIPLECHECKBOX).set("checked","checked")}),e.one(r.DESELECTALL).on("click",function(t){t.preventDefault(),e.all(r.SELECTMULTIPLECHECKBOX).set("checked","")}),e.one(r.SELECTMULTIPLEDELETEBUTTON).setAttribute("disabled","disabled"),e.delegate("click",this.delete_multiple_with_confirmation,i,r.SELECTMULTIPLEDELETEBUTTON,this),e.delegate("click",this.toggle_select_all_buttons_enabled,i,r.SELECTMULTIPLECHECKBOX,this),e.delegate("click",this.toggle_select_all_buttons_enabled,i,r.SELECTALL,this),e.delegate("click",this.toggle_select_all_buttons_enabled,i,r.DESELECTALL,this)},handle_data_action:function(e){var t=e.target;t.test("a")||(t=t.ancestor(r.ACTIVITYACTION));var n=t.getData("action"),i=t.ancestor(r.ACTIVITYLI);if(!t.test("a")||!n||!i)return;switch(n){case"editmaxmark":this.edit_maxmark(e,t,i,n);break;case"delete":this.delete_with_confirmation(e,t,i,n);break;case"addpagebreak":case"removepagebreak":this.update_page_break(e,t,i,n);break;case"adddependency":case"removedependency":this.update_dependency(e,t,i,n);break;default:}},add_spinner:function(t){var n=t.one(r.ACTIONAREA);return n?M.util.add_spinner(e,n):null},toggle_select_all_buttons_enabled:function(){var t=e.all(r.SELECTMULTIPLECHECKBOX+":checked"),n=e.one(r.SELECTMULTIPLEDELETEBUTTON);t&&!t.isEmpty()?n.removeAttribute("disabled"):n.setAttribute("disabled","disabled")},delete_with_confirmation:function(t,n,r){t.preventDefault();var i=r,s="",o=M.util.get_string("pluginname","qtype_"+i.getAttribute("class").match(/qtype_([^\s]*)/)[1]);s=M.util.get_string("confirmremovequestion","quiz",o);var u=new M.core.confirm({question:s,modal:!0});u.on("complete-yes",function(){var n=this.add_spinner(i),r={"class":"resource",action:"DELETE",id:e.Moodle.mod_quiz.util.slot.getId(i)};this.send_request(r,n,function(n){n.deleted&&(e.Moodle.mod_quiz.util.slot.remove(i),this.reorganise_edit_page(),M.core.actionmenu&&M.core.actionmenu.instance&&M.core.actionmenu.instance.hideMenu(t))})},this)},delete_multiple_with_confirmation:function(t){t.preventDefault();var i="",s=[];e.all(r.SELECTMULTIPLECHECKBOX+":checked").each(function(t){var n=e.Moodle.mod_quiz.util.slot. -getSlotFromComponent(t);i+=i===""?"":",",i+=e.Moodle.mod_quiz.util.slot.getId(n),s.push(n)});var o=e.one("div.mod-quiz-edit-content");if(!s||!s.length)return;var u=new M.core.confirm({question:M.util.get_string("areyousureremoveselected","quiz"),modal:!0});u.on("complete-yes",function(){var t=this.add_spinner(o),s={"class":"resource",field:"deletemultiple",ids:i};this.send_request(s,t,function(t){t.deleted&&(e.all(r.SELECTMULTIPLECHECKBOX+":checked").each(function(t){e.Moodle.mod_quiz.util.slot.remove(t.ancestor("li.activity"))}),this.reorganise_edit_page(),e.one("body").removeClass(n.SELECTMULTIPLE))})},this)},edit_maxmark:function(t,i,s){var o=s.one(r.INSTANCEMAXMARK),u=s.one(r.ACTIVITYINSTANCE),a=o.get("firstChild"),f=a.get("data"),l=f,c,h=o,p={"class":"resource",field:"getmaxmark",id:e.Moodle.mod_quiz.util.slot.getId(s)};t.preventDefault(),this.send_request(p,null,function(r){M.core.actionmenu&&M.core.actionmenu.instance&&M.core.actionmenu.instance.hideMenu(t),r.instancemaxmark&&(l=r.instancemaxmark);var i=e.Node.create('
'),o=e.Node.create('').set("innerHTML",M.util.get_string("edittitleinstructions","moodle")),a=e.Node.create('').setAttrs({value:l,autocomplete:"off","aria-describedby":"id_editinstructions",maxLength:"12",size:parseInt(this.get("config").questiondecimalpoints,10)+2});i.appendChild(a),i.setData("anchor",h),u.insert(o,"before"),h.replace(i),s.addClass(n.EDITINGMAXMARK),a.focus().select(),c=a.on("blur",this.edit_maxmark_cancel,this,s,!1),this.editmaxmarkevents.push(c),c=a.on("key",this.edit_maxmark_cancel,"esc",this,s,!0),this.editmaxmarkevents.push(c),c=i.on("submit",this.edit_maxmark_submit,this,s,f),this.editmaxmarkevents.push(c)})},edit_maxmark_submit:function(t,n,i){t.preventDefault();var s=e.Lang.trim(n.one(r.ACTIVITYFORM+" "+r.ACTIVITYMAXMARK).get("value")),o=this.add_spinner(n);this.edit_maxmark_clear(n),n.one(r.INSTANCEMAXMARK).setContent(s);if(s!==null&&s!==""&&s!==i){var u={"class":"resource",field:"updatemaxmark",maxmark:s,id:e.Moodle.mod_quiz.util.slot.getId(n)};this.send_request(u,o,function(e){e.instancemaxmark&&n.one(r.INSTANCEMAXMARK).setContent(e.instancemaxmark)})}},edit_maxmark_cancel:function(e,t,n){n&&e.preventDefault(),this.edit_maxmark_clear(t)},edit_maxmark_clear:function(t){(new e.EventHandle(this.editmaxmarkevents)).detach();var i=t.one(r.ACTIVITYFORM),s=t.one("#id_editinstructions");i&&i.replace(i.getData("anchor")),s&&s.remove(),t.removeClass(n.EDITINGMAXMARK),e.later(100,this,function(){t.one(r.EDITMAXMARK).focus()}),e.one("input[name=maxmark")||e.one("body").append('')},update_page_break:function(t,n,r,i){t.preventDefault();var s=r.next("li.activity.slot"),o=this.add_spinner(s),u=i==="removepagebreak"?1:2,a={"class":"resource",field:"updatepagebreak",id:e.Moodle.mod_quiz.util.slot.getId(s),value:u};return this.send_request(a,o,function(t){if(t.slots){if(i==="addpagebreak")e.Moodle.mod_quiz.util.page.add(r);else{var n=r.next(e.Moodle.mod_quiz.util.page.SELECTORS.PAGE);e.Moodle.mod_quiz.util.page.remove(n,!0)}this.reorganise_edit_page()}}),this},update_dependency:function(t,n,r,i){t.preventDefault();var s=this.add_spinner(r),o={"class":"resource",field:"updatedependency",id:e.Moodle.mod_quiz.util.slot.getId(r),value:i==="adddependency"?1:0};return this.send_request(o,s,function(t){t.hasOwnProperty("requireprevious")&&e.Moodle.mod_quiz.util.slot.updateDependencyIcon(r,t.requireprevious)}),this},reorganise_edit_page:function(){e.Moodle.mod_quiz.util.slot.reorderSlots(),e.Moodle.mod_quiz.util.slot.reorderPageBreaks(),e.Moodle.mod_quiz.util.page.reorderPages(),e.Moodle.mod_quiz.util.slot.updateOneSlotSections(),e.Moodle.mod_quiz.util.slot.updateAllDependencyIcons()},NAME:"mod_quiz-resource-toolbox",ATTRS:{courseid:{value:0},quizid:{value:0}}}),M.mod_quiz.resource_toolbox=null,M.mod_quiz.init_resource_toolbox=function(e){return M.mod_quiz.resource_toolbox=new o(e),M.mod_quiz.resource_toolbox};var u=function(){u.superclass.constructor.apply(this,arguments)};e.extend(u,s,{editsectionevents:[],initializer:function(){M.mod_quiz.quizbase.register_module(this),i.delegate("key",this.handle_data_action,"down:enter",r.ACTIVITYACTION,this),e.delegate("click",this.handle_data_action,i,r.ACTIVITYACTION,this),e.delegate("change",this.handle_data_action,i,r.EDITSHUFFLEQUESTIONSACTION,this)},handle_data_action:function(e){var t=e.target;!t.test("a")&&!t.test("input[data-action]")&&(t=t.ancestor(r.ACTIVITYACTION));var n=t.getData("action"),i=t.ancestor(r.ACTIVITYLI);if(!t.test("a")&&!t.test("input[data-action]")||!n||!i)return;switch(n){case"edit_section_title":this.edit_section_title(e,t,i,n);break;case"shuffle_questions":this.edit_shuffle_questions(e,t,i,n);break;case"deletesection":this.delete_section_with_confirmation(e,t,i,n);break;default:}},delete_section_with_confirmation:function(t,n,i){t.preventDefault();var s=new M.core.confirm({question:M.util.get_string("confirmremovesectionheading","quiz",i.get("aria-label")),modal:!0});s.on("complete-yes",function(){var t=M.util.add_spinner(e,i.one(r.ACTIONAREA)),n={"class":"section",action:"DELETE",id:i.get("id").replace("section-","")};this.send_request(n,t,function(e){e.deleted&&window.location.reload(!0)})},this)},edit_section_title:function(t,i,s){var o=s.get("id").replace("section-",""),u=s.one(r.INSTANCESECTION),a,f=u,l={"class":"section",field:"getsectiontitle",id:o};t.preventDefault(),this.send_request(l,null,function(t){var r=t.instancesection,i=e.Node.create(''),o=e.Node.create('').set("innerHTML",M.util.get_string("edittitleinstructions","moodle")),l=e.Node.create('').setAttrs({value:r,autocomplete:"off","aria-describedby":"id_editinstructions",maxLength:"255"});i.appendChild(l),i.setData("anchor" -,f),u.insert(o,"before"),f.replace(i),l.focus().select(),a=l.on("blur",this.edit_section_title_cancel,this,s,!1),this.editsectionevents.push(a),a=l.on("key",this.edit_section_title_cancel,"esc",this,s,!0),this.editsectionevents.push(a),a=i.on("submit",this.edit_section_title_submit,this,s,r),this.editsectionevents.push(a)})},edit_section_title_submit:function(t,n,i){t.preventDefault();var s=e.Lang.trim(n.one(r.SECTIONFORM+" "+r.SECTIONINPUT).get("value")),o=M.util.add_spinner(e,n.one(r.INSTANCESECTIONAREA));this.edit_section_title_clear(n);if(s!==null&&s!==i){n.one(r.INSTANCESECTION).setContent(s);var u={"class":"section",field:"updatesectiontitle",newheading:s,id:n.get("id").replace("section-","")};this.send_request(u,o,function(e){if(e){n.one(r.INSTANCESECTION).setContent(e.instancesection),n.one(r.EDITSECTIONICON).set("title",M.util.get_string("sectionheadingedit","quiz",e.instancesection)),n.one(r.EDITSECTIONICON).set("alt",M.util.get_string("sectionheadingedit","quiz",e.instancesection));var t=n.one(r.DELETESECTIONICON);t&&(t.set("title",M.util.get_string("sectionheadingremove","quiz",e.instancesection)),t.set("alt",M.util.get_string("sectionheadingremove","quiz",e.instancesection)))}})}},edit_section_title_cancel:function(e,t,n){n&&e.preventDefault(),this.edit_section_title_clear(t)},edit_section_title_clear:function(t){(new e.EventHandle(this.editsectionevents)).detach();var n=t.one(r.SECTIONFORM),i=t.one("#id_editinstructions");n&&n.replace(n.getData("anchor")),i&&i.remove(),e.later(100,this,function(){t.one(r.EDITSECTION).focus()}),e.one("input[name=section]")||e.one("body").append('')},edit_shuffle_questions:function(t,n,i){var s;i.one(r.EDITSHUFFLEQUESTIONSACTION).get("checked")?s=1:s=0;var o={"class":"section",field:"updateshufflequestions",id:i.get("id").replace("section-",""),newshuffle:s};t.preventDefault();var u=M.util.add_spinner(e,i.one(r.EDITSHUFFLEAREA));this.send_request(o,u)}},{NAME:"mod_quiz-section-toolbox",ATTRS:{courseid:{value:0},quizid:{value:0}}}),M.mod_quiz.init_section_toolbox=function(e){return new u(e)}},"@VERSION@",{requires:["base","node","event","event-key","io","moodle-mod_quiz-quizbase","moodle-mod_quiz-util-slot","moodle-core-notification-ajaxexception"]}); +YUI.add("moodle-mod_quiz-toolboxes",function(e,t){var n={ACTIVITYINSTANCE:"activityinstance",AVAILABILITYINFODIV:"div.availabilityinfo",CONTENTWITHOUTLINK:"contentwithoutlink",CONDITIONALHIDDEN:"conditionalhidden",DIMCLASS:"dimmed",DIMMEDTEXT:"dimmed_text",EDITINSTRUCTIONS:"editinstructions",EDITINGMAXMARK:"editor_displayed",HIDE:"hide",JOIN:"page_join",MODINDENTCOUNT:"mod-indent-",MODINDENTHUGE:"mod-indent-huge",PAGE:"page",SECTIONHIDDENCLASS:"hidden",SECTIONIDPREFIX:"section-",SELECTMULTIPLE:"select-multiple",SLOT:"slot",SHOW:"editing_show",TITLEEDITOR:"titleeditor"},r={ACTIONAREA:".actions",ACTIONLINKTEXT:".actionlinktext",ACTIVITYACTION:"a.cm-edit-action[data-action], a.editing_maxmark, a.editing_section, input.shuffle_questions",ACTIVITYFORM:"span.instancemaxmarkcontainer form",ACTIVITYINSTANCE:"."+n.ACTIVITYINSTANCE,SECTIONINSTANCE:".sectioninstance",ACTIVITYLI:"li.activity, li.section",ACTIVITYMAXMARK:"input[name=maxmark]",COMMANDSPAN:".commands",CONTENTAFTERLINK:"div.contentafterlink",CONTENTWITHOUTLINK:"div.contentwithoutlink",DELETESECTIONICON:"a.editing_delete .icon",DESELECTALL:"#questiondeselectall",EDITMAXMARK:"a.editing_maxmark",EDITSECTION:"a.editing_section",EDITSECTIONICON:"a.editing_section .icon",EDITSHUFFLEQUESTIONSACTION:"input.cm-edit-action[data-action]",EDITSHUFFLEAREA:".instanceshufflequestions .shuffle-progress",HIDE:"a.editing_hide",HIGHLIGHT:"a.editing_highlight",INSTANCENAME:"span.instancename",INSTANCEMAXMARK:"span.instancemaxmark",INSTANCESECTION:"span.instancesection",INSTANCESECTIONAREA:"div.section-heading",MODINDENTDIV:".mod-indent",MODINDENTOUTER:".mod-indent-outer",NUMQUESTIONS:".numberofquestions",PAGECONTENT:"div#page-content",PAGELI:"li.page",SECTIONLI:"li.section",SECTIONUL:"ul.section",SECTIONFORM:".instancesectioncontainer form",SECTIONINPUT:"input[name=section]",SELECTMULTIPLEBUTTON:"#selectmultiplecommand",SELECTMULTIPLECANCELBUTTON:"#selectmultiplecancelcommand",SELECTMULTIPLECHECKBOX:".select-multiple-checkbox",SELECTMULTIPLEDELETEBUTTON:"#selectmultipledeletecommand",SELECTALL:"#questionselectall",SHOW:"a."+n.SHOW,SLOTLI:"li.slot",SUMMARKS:".mod_quiz_summarks"},i=e.one(document.body);M.mod_quiz=M.mod_quiz||{};var s=function(){s.superclass.constructor.apply(this,arguments)};e.extend(s,e.Base,{send_request:function(t,n,i,s){t||(t={});var o=this.get("config").pageparams,u;for(u in o)t[u]=o[u];t.sesskey=M.cfg.sesskey,t.courseid=this.get("courseid"),t.quizid=this.get("quizid");var a=M.cfg.wwwroot+this.get("ajaxurl"),f=[],l={method:"POST",data:t,on:{success:function(t,s){try{f=e.JSON.parse(s.responseText),f.error&&new M.core.ajaxException(f)}catch(o){}f.hasOwnProperty("newsummarks")&&e.one(r.SUMMARKS).setHTML(f.newsummarks),f.hasOwnProperty("newnumquestions")&&e.one(r.NUMQUESTIONS).setHTML(M.util.get_string("numquestionsx","quiz",f.newnumquestions)),i&&e.bind(i,this,f)(),n&&window.setTimeout(function(){n.hide()},400)},failure:function(e,t){n&&n.hide(),new M.core.ajaxException(t)}},context:this};if(s)for(u in s)l[u]=s[u];return n&&n.show(),e.io(a,l),this}},{NAME:"mod_quiz-toolbox",ATTRS:{courseid:{value:0},quizid:{value:0},ajaxurl:{value:null},config:{value:{}}}});var o=function(){o.superclass.constructor.apply(this,arguments)};e.extend(o,s,{editmaxmarkevents:[],NODE_PAGE:1,NODE_SLOT:2,NODE_JOIN:3,initializer:function(){M.mod_quiz.quizbase.register_module(this),e.delegate("click",this.handle_data_action,i,r.ACTIVITYACTION,this),e.delegate("click",this.handle_data_action,i,r.DEPENDENCY_LINK,this),this.initialise_select_multiple()},initialise_select_multiple:function(){e.one(r.SELECTMULTIPLEBUTTON).on("click",function(t){t.preventDefault(),e.one("body").addClass(n.SELECTMULTIPLE)}),e.one(r.SELECTMULTIPLECANCELBUTTON).on("click",function(t){t.preventDefault(),e.one("body").removeClass(n.SELECTMULTIPLE)}),e.one(r.SELECTALL).on("click",function(t){t.preventDefault(),e.all(r.SELECTMULTIPLECHECKBOX).set("checked","checked")}),e.one(r.DESELECTALL).on("click",function(t){t.preventDefault(),e.all(r.SELECTMULTIPLECHECKBOX).set("checked","")}),e.one(r.SELECTMULTIPLEDELETEBUTTON).setAttribute("disabled","disabled"),e.delegate("click",this.delete_multiple_action,i,r.SELECTMULTIPLEDELETEBUTTON,this),e.delegate("click",this.toggle_select_all_buttons_enabled,i,r.SELECTMULTIPLECHECKBOX,this),e.delegate("click",this.toggle_select_all_buttons_enabled,i,r.SELECTALL,this),e.delegate("click",this.toggle_select_all_buttons_enabled,i,r.DESELECTALL,this)},handle_data_action:function(e){var t=e.target;t.test("a")||(t=t.ancestor(r.ACTIVITYACTION));var n=t.getData("action"),i=t.ancestor(r.ACTIVITYLI);if(!t.test("a")||!n||!i)return;switch(n){case"editmaxmark":this.edit_maxmark(e,t,i,n);break;case"delete":this.delete_with_confirmation(e,t,i,n);break;case"addpagebreak":case"removepagebreak":this.update_page_break(e,t,i,n);break;case"adddependency":case"removedependency":this.update_dependency(e,t,i,n);break;default:}},add_spinner:function(t){var n=t.one(r.ACTIONAREA);return n?M.util.add_spinner(e,n):null},toggle_select_all_buttons_enabled:function(){var t=e.all(r.SELECTMULTIPLECHECKBOX+":checked"),n=e.one(r.SELECTMULTIPLEDELETEBUTTON);t&&!t.isEmpty()?n.removeAttribute("disabled"):n.setAttribute("disabled","disabled")},delete_with_confirmation:function(t,n,r){t.preventDefault();var i=r,s="",o=M.util.get_string("pluginname","qtype_"+i.getAttribute("class").match(/qtype_([^\s]*)/)[1]);s=M.util.get_string("confirmremovequestion","quiz",o);var u=new M.core.confirm({question:s,modal:!0});u.on("complete-yes",function(){var n=this.add_spinner(i),r={"class":"resource",action:"DELETE",id:e.Moodle.mod_quiz.util.slot.getId(i)};this.send_request(r,n,function(n){n.deleted&&(e.Moodle.mod_quiz.util.slot.remove(i),this.reorganise_edit_page(),M.core.actionmenu&&M.core.actionmenu.instance&&M.core.actionmenu.instance.hideMenu(t))})},this)},find_sections_that_would_become_empty:function(){var t,n=e.all(r.SECTIONLI);return n.size()>1&&n.some(function(e){var n=e.one(r.INSTANCESECTION).getContent(),i=e +.all(r.SELECTMULTIPLECHECKBOX+":checked"),s=e.all(r.SELECTMULTIPLECHECKBOX+":not(:checked)");return!i.isEmpty()&&s.isEmpty()&&(t=n),t}),t},delete_multiple_action:function(e){var t=this.find_sections_that_would_become_empty();if(t){var n=new M.core.alert({title:M.util.get_string("cannotremoveslots","quiz"),message:M.util.get_string("cannotremoveallsectionslots","quiz",t)});n.show()}else this.delete_multiple_with_confirmation(e)},delete_multiple_with_confirmation:function(t){t.preventDefault();var i="",s=[];e.all(r.SELECTMULTIPLECHECKBOX+":checked").each(function(t){var n=e.Moodle.mod_quiz.util.slot.getSlotFromComponent(t);i+=i===""?"":",",i+=e.Moodle.mod_quiz.util.slot.getId(n),s.push(n)});var o=e.one("div.mod-quiz-edit-content");if(!s||!s.length)return;var u=new M.core.confirm({question:M.util.get_string("areyousureremoveselected","quiz"),modal:!0});u.on("complete-yes",function(){var t=this.add_spinner(o),s={"class":"resource",field:"deletemultiple",ids:i};this.send_request(s,t,function(t){t.deleted&&(e.all(r.SELECTMULTIPLECHECKBOX+":checked").each(function(t){e.Moodle.mod_quiz.util.slot.remove(t.ancestor("li.activity"))}),this.reorganise_edit_page(),e.one("body").removeClass(n.SELECTMULTIPLE))})},this)},edit_maxmark:function(t,i,s){var o=s.one(r.INSTANCEMAXMARK),u=s.one(r.ACTIVITYINSTANCE),a=o.get("firstChild"),f=a.get("data"),l=f,c,h=o,p={"class":"resource",field:"getmaxmark",id:e.Moodle.mod_quiz.util.slot.getId(s)};t.preventDefault(),this.send_request(p,null,function(r){M.core.actionmenu&&M.core.actionmenu.instance&&M.core.actionmenu.instance.hideMenu(t),r.instancemaxmark&&(l=r.instancemaxmark);var i=e.Node.create(''),o=e.Node.create('').set("innerHTML",M.util.get_string("edittitleinstructions","moodle")),a=e.Node.create('').setAttrs({value:l,autocomplete:"off","aria-describedby":"id_editinstructions",maxLength:"12",size:parseInt(this.get("config").questiondecimalpoints,10)+2});i.appendChild(a),i.setData("anchor",h),u.insert(o,"before"),h.replace(i),s.addClass(n.EDITINGMAXMARK),a.focus().select(),c=a.on("blur",this.edit_maxmark_cancel,this,s,!1),this.editmaxmarkevents.push(c),c=a.on("key",this.edit_maxmark_cancel,"esc",this,s,!0),this.editmaxmarkevents.push(c),c=i.on("submit",this.edit_maxmark_submit,this,s,f),this.editmaxmarkevents.push(c)})},edit_maxmark_submit:function(t,n,i){t.preventDefault();var s=e.Lang.trim(n.one(r.ACTIVITYFORM+" "+r.ACTIVITYMAXMARK).get("value")),o=this.add_spinner(n);this.edit_maxmark_clear(n),n.one(r.INSTANCEMAXMARK).setContent(s);if(s!==null&&s!==""&&s!==i){var u={"class":"resource",field:"updatemaxmark",maxmark:s,id:e.Moodle.mod_quiz.util.slot.getId(n)};this.send_request(u,o,function(e){e.instancemaxmark&&n.one(r.INSTANCEMAXMARK).setContent(e.instancemaxmark)})}},edit_maxmark_cancel:function(e,t,n){n&&e.preventDefault(),this.edit_maxmark_clear(t)},edit_maxmark_clear:function(t){(new e.EventHandle(this.editmaxmarkevents)).detach();var i=t.one(r.ACTIVITYFORM),s=t.one("#id_editinstructions");i&&i.replace(i.getData("anchor")),s&&s.remove(),t.removeClass(n.EDITINGMAXMARK),e.later(100,this,function(){t.one(r.EDITMAXMARK).focus()}),e.one("input[name=maxmark")||e.one("body").append('')},update_page_break:function(t,n,r,i){t.preventDefault();var s=r.next("li.activity.slot"),o=this.add_spinner(s),u=i==="removepagebreak"?1:2,a={"class":"resource",field:"updatepagebreak",id:e.Moodle.mod_quiz.util.slot.getId(s),value:u};return this.send_request(a,o,function(t){if(t.slots){if(i==="addpagebreak")e.Moodle.mod_quiz.util.page.add(r);else{var n=r.next(e.Moodle.mod_quiz.util.page.SELECTORS.PAGE);e.Moodle.mod_quiz.util.page.remove(n,!0)}this.reorganise_edit_page()}}),this},update_dependency:function(t,n,r,i){t.preventDefault();var s=this.add_spinner(r),o={"class":"resource",field:"updatedependency",id:e.Moodle.mod_quiz.util.slot.getId(r),value:i==="adddependency"?1:0};return this.send_request(o,s,function(t){t.hasOwnProperty("requireprevious")&&e.Moodle.mod_quiz.util.slot.updateDependencyIcon(r,t.requireprevious)}),this},reorganise_edit_page:function(){e.Moodle.mod_quiz.util.slot.reorderSlots(),e.Moodle.mod_quiz.util.slot.reorderPageBreaks(),e.Moodle.mod_quiz.util.page.reorderPages(),e.Moodle.mod_quiz.util.slot.updateOneSlotSections(),e.Moodle.mod_quiz.util.slot.updateAllDependencyIcons()},NAME:"mod_quiz-resource-toolbox",ATTRS:{courseid:{value:0},quizid:{value:0}}}),M.mod_quiz.resource_toolbox=null,M.mod_quiz.init_resource_toolbox=function(e){return M.mod_quiz.resource_toolbox=new o(e),M.mod_quiz.resource_toolbox};var u=function(){u.superclass.constructor.apply(this,arguments)};e.extend(u,s,{editsectionevents:[],initializer:function(){M.mod_quiz.quizbase.register_module(this),i.delegate("key",this.handle_data_action,"down:enter",r.ACTIVITYACTION,this),e.delegate("click",this.handle_data_action,i,r.ACTIVITYACTION,this),e.delegate("change",this.handle_data_action,i,r.EDITSHUFFLEQUESTIONSACTION,this)},handle_data_action:function(e){var t=e.target;!t.test("a")&&!t.test("input[data-action]")&&(t=t.ancestor(r.ACTIVITYACTION));var n=t.getData("action"),i=t.ancestor(r.ACTIVITYLI);if(!t.test("a")&&!t.test("input[data-action]")||!n||!i)return;switch(n){case"edit_section_title":this.edit_section_title(e,t,i,n);break;case"shuffle_questions":this.edit_shuffle_questions(e,t,i,n);break;case"deletesection":this.delete_section_with_confirmation(e,t,i,n);break;default:}},delete_section_with_confirmation:function(t,n,i){t.preventDefault();var s=new M.core.confirm({question:M.util.get_string("confirmremovesectionheading","quiz",i.get("aria-label")),modal:!0});s.on("complete-yes",function(){var t=M.util.add_spinner(e,i.one(r.ACTIONAREA)),n={"class":"section",action:"DELETE",id:i.get("id").replace("section-","")};this.send_request(n,t,function(e){e.deleted&&window.location.reload(!0)})},this)},edit_section_title +:function(t,i,s){var o=s.get("id").replace("section-",""),u=s.one(r.INSTANCESECTION),a,f=u,l={"class":"section",field:"getsectiontitle",id:o};t.preventDefault(),this.send_request(l,null,function(t){var r=t.instancesection,i=e.Node.create(''),o=e.Node.create('').set("innerHTML",M.util.get_string("edittitleinstructions","moodle")),l=e.Node.create('').setAttrs({value:r,autocomplete:"off","aria-describedby":"id_editinstructions",maxLength:"255"});i.appendChild(l),i.setData("anchor",f),u.insert(o,"before"),f.replace(i),l.focus().select(),a=l.on("blur",this.edit_section_title_cancel,this,s,!1),this.editsectionevents.push(a),a=l.on("key",this.edit_section_title_cancel,"esc",this,s,!0),this.editsectionevents.push(a),a=i.on("submit",this.edit_section_title_submit,this,s,r),this.editsectionevents.push(a)})},edit_section_title_submit:function(t,n,i){t.preventDefault();var s=e.Lang.trim(n.one(r.SECTIONFORM+" "+r.SECTIONINPUT).get("value")),o=M.util.add_spinner(e,n.one(r.INSTANCESECTIONAREA));this.edit_section_title_clear(n);if(s!==null&&s!==i){n.one(r.INSTANCESECTION).setContent(s);var u={"class":"section",field:"updatesectiontitle",newheading:s,id:n.get("id").replace("section-","")};this.send_request(u,o,function(e){if(e){n.one(r.INSTANCESECTION).setContent(e.instancesection),n.one(r.EDITSECTIONICON).set("title",M.util.get_string("sectionheadingedit","quiz",e.instancesection)),n.one(r.EDITSECTIONICON).set("alt",M.util.get_string("sectionheadingedit","quiz",e.instancesection));var t=n.one(r.DELETESECTIONICON);t&&(t.set("title",M.util.get_string("sectionheadingremove","quiz",e.instancesection)),t.set("alt",M.util.get_string("sectionheadingremove","quiz",e.instancesection)))}})}},edit_section_title_cancel:function(e,t,n){n&&e.preventDefault(),this.edit_section_title_clear(t)},edit_section_title_clear:function(t){(new e.EventHandle(this.editsectionevents)).detach();var n=t.one(r.SECTIONFORM),i=t.one("#id_editinstructions");n&&n.replace(n.getData("anchor")),i&&i.remove(),e.later(100,this,function(){t.one(r.EDITSECTION).focus()}),e.one("input[name=section]")||e.one("body").append('')},edit_shuffle_questions:function(t,n,i){var s;i.one(r.EDITSHUFFLEQUESTIONSACTION).get("checked")?s=1:s=0;var o={"class":"section",field:"updateshufflequestions",id:i.get("id").replace("section-",""),newshuffle:s};t.preventDefault();var u=M.util.add_spinner(e,i.one(r.EDITSHUFFLEAREA));this.send_request(o,u)}},{NAME:"mod_quiz-section-toolbox",ATTRS:{courseid:{value:0},quizid:{value:0}}}),M.mod_quiz.init_section_toolbox=function(e){return new u(e)}},"@VERSION@",{requires:["base","node","event","event-key","io","moodle-mod_quiz-quizbase","moodle-mod_quiz-util-slot","moodle-core-notification-ajaxexception"]}); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes.js b/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes.js index e1af1d1f76a83..780bc3ce2ce81 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-toolboxes/moodle-mod_quiz-toolboxes.js @@ -64,6 +64,7 @@ var CSS = { NUMQUESTIONS: '.numberofquestions', PAGECONTENT: 'div#page-content', PAGELI: 'li.page', + SECTIONLI: 'li.section', SECTIONUL: 'ul.section', SECTIONFORM: '.instancesectioncontainer form', SECTIONINPUT: 'input[name=section]', @@ -337,7 +338,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON).setAttribute('disabled', 'disabled'); // Assign the delete method to the delete multiple button. - Y.delegate('click', this.delete_multiple_with_confirmation, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this); + Y.delegate('click', this.delete_multiple_action, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this); // Enable the delete all button only when at least one slot is selected. Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTMULTIPLECHECKBOX, this); @@ -439,7 +440,6 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @param {EventFacade} ev The event that was fired. * @param {Node} button The button that triggered this action. * @param {Node} activity The activity node that this action will be performed on. - * @chainable */ delete_with_confirmation: function(ev, button, activity) { // Prevent the default button action. @@ -481,13 +481,62 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { }, this); }, + /** + * Finds the section that would become empty if we remove the selected slots. + * + * @protected + * @method find_sections_that_would_become_empty + * @returns {String} The name of the first section found + */ + find_sections_that_would_become_empty: function() { + var section; + var sectionnodes = Y.all(SELECTOR.SECTIONLI); + + if (sectionnodes.size() > 1) { + sectionnodes.some(function(node) { + var sectionname = node.one(SELECTOR.INSTANCESECTION).getContent(); + var checked = node.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':checked'); + var unchecked = node.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':not(:checked)'); + + if (!checked.isEmpty() && unchecked.isEmpty()) { + section = sectionname; + } + + return section; + }); + } + + return section; + }, + + /** + * Takes care of what needs to happen when the user clicks on the delete multiple button. + * + * @protected + * @method delete_multiple_action + * @param {EventFacade} ev The event that was fired. + */ + delete_multiple_action: function(ev) { + var problemsection = this.find_sections_that_would_become_empty(); + + if (problemsection) { + var alert = new M.core.alert({ + title: M.util.get_string('cannotremoveslots', 'quiz'), + message: M.util.get_string('cannotremoveallsectionslots', 'quiz', problemsection) + }); + + alert.show(); + } else { + this.delete_multiple_with_confirmation(ev); + } + }, + /** * Deletes the given activities or resources after confirmation. * * @protected * @method delete_multiple_with_confirmation * @param {EventFacade} ev The event that was fired. - * @chainable */ delete_multiple_with_confirmation: function(ev) { ev.preventDefault(); diff --git a/mod/quiz/yui/src/toolboxes/js/resource.js b/mod/quiz/yui/src/toolboxes/js/resource.js index d88930353cbda..0626f6c63f614 100644 --- a/mod/quiz/yui/src/toolboxes/js/resource.js +++ b/mod/quiz/yui/src/toolboxes/js/resource.js @@ -104,7 +104,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON).setAttribute('disabled', 'disabled'); // Assign the delete method to the delete multiple button. - Y.delegate('click', this.delete_multiple_with_confirmation, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this); + Y.delegate('click', this.delete_multiple_action, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this); // Enable the delete all button only when at least one slot is selected. Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTMULTIPLECHECKBOX, this); @@ -206,7 +206,6 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @param {EventFacade} ev The event that was fired. * @param {Node} button The button that triggered this action. * @param {Node} activity The activity node that this action will be performed on. - * @chainable */ delete_with_confirmation: function(ev, button, activity) { // Prevent the default button action. @@ -248,13 +247,62 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { }, this); }, + /** + * Finds the section that would become empty if we remove the selected slots. + * + * @protected + * @method find_sections_that_would_become_empty + * @returns {String} The name of the first section found + */ + find_sections_that_would_become_empty: function() { + var section; + var sectionnodes = Y.all(SELECTOR.SECTIONLI); + + if (sectionnodes.size() > 1) { + sectionnodes.some(function(node) { + var sectionname = node.one(SELECTOR.INSTANCESECTION).getContent(); + var checked = node.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':checked'); + var unchecked = node.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':not(:checked)'); + + if (!checked.isEmpty() && unchecked.isEmpty()) { + section = sectionname; + } + + return section; + }); + } + + return section; + }, + + /** + * Takes care of what needs to happen when the user clicks on the delete multiple button. + * + * @protected + * @method delete_multiple_action + * @param {EventFacade} ev The event that was fired. + */ + delete_multiple_action: function(ev) { + var problemsection = this.find_sections_that_would_become_empty(); + + if (problemsection) { + var alert = new M.core.alert({ + title: M.util.get_string('cannotremoveslots', 'quiz'), + message: M.util.get_string('cannotremoveallsectionslots', 'quiz', problemsection) + }); + + alert.show(); + } else { + this.delete_multiple_with_confirmation(ev); + } + }, + /** * Deletes the given activities or resources after confirmation. * * @protected * @method delete_multiple_with_confirmation * @param {EventFacade} ev The event that was fired. - * @chainable */ delete_multiple_with_confirmation: function(ev) { ev.preventDefault(); diff --git a/mod/quiz/yui/src/toolboxes/js/toolbox.js b/mod/quiz/yui/src/toolboxes/js/toolbox.js index 5d46deb098999..642b25537741d 100644 --- a/mod/quiz/yui/src/toolboxes/js/toolbox.js +++ b/mod/quiz/yui/src/toolboxes/js/toolbox.js @@ -62,6 +62,7 @@ var CSS = { NUMQUESTIONS: '.numberofquestions', PAGECONTENT: 'div#page-content', PAGELI: 'li.page', + SECTIONLI: 'li.section', SECTIONUL: 'ul.section', SECTIONFORM: '.instancesectioncontainer form', SECTIONINPUT: 'input[name=section]',