MDL-49813 quiz: add sections in the right place after page changes

This commit is contained in:
M Kassaei 2015-04-15 10:48:58 +01:00
parent df9981cfda
commit 32498c28ea
7 changed files with 50 additions and 11 deletions

View File

@ -82,7 +82,7 @@ class edit_renderer extends \plugin_renderer_base {
$output .= $this->end_section_list(); $output .= $this->end_section_list();
// Inialise the JavaScript. // Initialise the JavaScript.
$this->initialise_editing_javascript($structure, $contexts, $pagevars, $pageurl); $this->initialise_editing_javascript($structure, $contexts, $pagevars, $pageurl);
// Include the contents of any other popups required. // Include the contents of any other popups required.
@ -535,9 +535,7 @@ class edit_renderer extends \plugin_renderer_base {
// Add a new section to the add_menu if possible. This is always added to the HTML // Add a new section to the add_menu if possible. This is always added to the HTML
// then hidden with CSS when no needed, so that as things are re-ordered, etc. with // then hidden with CSS when no needed, so that as things are re-ordered, etc. with
// Ajax it can be relevaled again when necessary. // Ajax it can be relevaled again when necessary.
$returnurl = new \moodle_url($pageurl, array('addonpage' => $page)); $params = array('cmid' => $structure->get_cmid(), 'addsectionatpage' => $page);
$params = array('returnurl' => $returnurl, 'cmid' => $structure->get_cmid(),
'addonpage' => $page, 'appendqnumstring' => 'addasection', 'addsection' => '1');
$actions['addasection'] = new \action_menu_link_secondary( $actions['addasection'] = new \action_menu_link_secondary(
new \moodle_url($pageurl, $params), new \moodle_url($pageurl, $params),

View File

@ -134,13 +134,10 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
redirect($afteractionurl); redirect($afteractionurl);
} }
if (optional_param('addsection', false, PARAM_BOOL)) { if ($addsectionatpage = optional_param('addsectionatpage', false, PARAM_INT)) {
$structure->check_can_be_edited();
// Add a section to the quiz. // Add a section to the quiz.
if ($addonpage = optional_param('addonpage', 0, PARAM_INT)) { $structure->check_can_be_edited();
$structure->add_section_heading($addonpage); $structure->add_section_heading($addsectionatpage);
}
quiz_delete_previews($quiz); quiz_delete_previews($quiz);
redirect($afteractionurl); redirect($afteractionurl);
} }

View File

@ -360,3 +360,29 @@ Feature: Edit quiz page - section headings
And I click on ".numberofquestions" "css_element" And I click on ".numberofquestions" "css_element"
And I click on "Add" "link" in the ".last-add-menu" "css_element" And I click on "Add" "link" in the ".last-add-menu" "css_element"
And "a new section heading" "list_item" in the ".last-add-menu" "css_element" should not be visible And "a new section heading" "list_item" in the ".last-add-menu" "css_element" should not be visible
@javascript
Scenario: Verify sections are added in the right place afte ajax changes
Given the following "activities" exist:
| activity | name | intro | course | idnumber |
| quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | TF1 | This is question 01 |
| Test questions | truefalse | TF2 | This is question 02 |
| Test questions | truefalse | TF3 | This is question 03 |
| Test questions | truefalse | TF4 | This is question 04 |
And quiz "Quiz 1" contains the following questions:
| question | page |
| TF1 | 1 |
| TF2 | 2 |
| TF3 | 3 |
| TF4 | 4 |
When I follow "Course 1"
And I follow "Quiz 1"
And I follow "Edit quiz"
And I click on the "Remove" page break icon after question "TF1"
And I open the "Page 2" add to quiz menu
And I follow "a new section heading" in the open menu
Then "TF3" "list_item" should exist in the "Section heading ..." "list_item"

View File

@ -278,9 +278,15 @@ Y.Moodle.mod_quiz.util.page = {
// Update action-menu-1-menubar // Update action-menu-1-menubar
var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR); var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR);
menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX); menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX);
// Update action-menu-1-menu // Update action-menu-1-menu
var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU); var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU);
menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX); menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX);
// Update the URL of the add-section action.
menumenu.one('a.addasection').set('href',
menumenu.one('a.addasection').get('href').replace(/\baddsectionatpage=\d/, 'addsectionatpage=' + id));
}, this); }, this);
}, },

View File

@ -1 +1 @@
YUI.add("moodle-mod_quiz-util-page",function(e,t){e.namespace("Moodle.mod_quiz.util.page"),e.Moodle.mod_quiz.util.page={CSS:{PAGE:"page"},CONSTANTS:{ACTIONMENUIDPREFIX:"action-menu-",ACTIONMENUBARIDSUFFIX:"-menubar",ACTIONMENUMENUIDSUFFIX:"-menu",PAGEIDPREFIX:"page-",PAGENUMBERPREFIX:M.util.get_string("page","moodle")+" "},SELECTORS:{ACTIONMENU:"div.moodle-actionmenu",ACTIONMENUBAR:"ul.menubar",ACTIONMENUMENU:"ul.menu",PAGE:"li.page",INSTANCENAME:".instancename",NUMBER:"h4"},getPageFromComponent:function(t){return e.one(t).ancestor(this.SELECTORS.PAGE,!0)},getPageFromSlot:function(t){return e.one(t).previous(this.SELECTORS.PAGE)},getId:function(e){var t=e.get("id").replace(this.CONSTANTS.PAGEIDPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},setId:function(e,t){e.set("id",this.CONSTANTS.PAGEIDPREFIX+t)},getName:function(e){var t=e.one(this.SELECTORS.INSTANCENAME);return t?t.get("firstChild").get("data"):null},getNumber:function(e){var t=e.one(this.SELECTORS.NUMBER).get("text").replace(this.CONSTANTS.PAGENUMBERPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},setNumber:function(e,t){e.one(this.SELECTORS.NUMBER).set("text",this.CONSTANTS.PAGENUMBERPREFIX+t)},getPages:function(){return e.all(e.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT+" "+e.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL+" "+this.SELECTORS.PAGE)},isPage:function(e){return e?e.hasClass(this.CSS.PAGE):!1},isEmpty:function(e){var t=e.next("li.activity");return t?!t.hasClass("slot"):!0},add:function(t){var n=this.getNumber(this.getPageFromSlot(t))+1,r=M.mod_quiz.resource_toolbox.get("config").pagehtml;r=r.replace(/%%PAGENUMBER%%/g,n);var i=e.Node.create(r);return YUI().use("dd-drop",function(e){var t=new e.DD.Drop({node:i,groups:M.mod_quiz.dragres.groups});i.drop=t}),t.insert(i,"after"),M.core.actionmenu.newDOMNode(i),i},remove:function(t,n){var r=t.previous(e.Moodle.mod_quiz.util.slot.SELECTORS.SLOT);!n&&r&&e.Moodle.mod_quiz.util.slot.removePageBreak(r),t.remove()},reorderPages:function(){var e=this.getPages(),t=0;e.each(function(e){if(this.isEmpty(e)){var n=e.next("li.slot")?!0:!1;this.remove(e,n);return}t++,this.setNumber(e,t),this.setId(e,t)},this),this.reorderActionMenus()},reorderActionMenus:function(){var e=this.getActionMenus();e.each(function(t,n){var r=e.item(n-1),i=0;r&&(i=this.getActionMenuId(r));var s=i+1;this.setActionMenuId(t,s);var o=t.one(this.SELECTORS.ACTIONMENUBAR);o.set("id",this.CONSTANTS.ACTIONMENUIDPREFIX+s+this.CONSTANTS.ACTIONMENUBARIDSUFFIX);var u=t.one(this.SELECTORS.ACTIONMENUMENU);u.set("id",this.CONSTANTS.ACTIONMENUIDPREFIX+s+this.CONSTANTS.ACTIONMENUMENUIDSUFFIX)},this)},getActionMenus:function(){return e.all(e.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT+" "+e.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL+" "+this.SELECTORS.ACTIONMENU)},getActionMenuId:function(e){var t=e.get("id").replace(this.CONSTANTS.ACTIONMENUIDPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},setActionMenuId:function(e,t){e.set("id",this.CONSTANTS.ACTIONMENUIDPREFIX+t)}}},"@VERSION@",{requires:["node","moodle-mod_quiz-util-base"]}); YUI.add("moodle-mod_quiz-util-page",function(e,t){e.namespace("Moodle.mod_quiz.util.page"),e.Moodle.mod_quiz.util.page={CSS:{PAGE:"page"},CONSTANTS:{ACTIONMENUIDPREFIX:"action-menu-",ACTIONMENUBARIDSUFFIX:"-menubar",ACTIONMENUMENUIDSUFFIX:"-menu",PAGEIDPREFIX:"page-",PAGENUMBERPREFIX:M.util.get_string("page","moodle")+" "},SELECTORS:{ACTIONMENU:"div.moodle-actionmenu",ACTIONMENUBAR:"ul.menubar",ACTIONMENUMENU:"ul.menu",PAGE:"li.page",INSTANCENAME:".instancename",NUMBER:"h4"},getPageFromComponent:function(t){return e.one(t).ancestor(this.SELECTORS.PAGE,!0)},getPageFromSlot:function(t){return e.one(t).previous(this.SELECTORS.PAGE)},getId:function(e){var t=e.get("id").replace(this.CONSTANTS.PAGEIDPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},setId:function(e,t){e.set("id",this.CONSTANTS.PAGEIDPREFIX+t)},getName:function(e){var t=e.one(this.SELECTORS.INSTANCENAME);return t?t.get("firstChild").get("data"):null},getNumber:function(e){var t=e.one(this.SELECTORS.NUMBER).get("text").replace(this.CONSTANTS.PAGENUMBERPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},setNumber:function(e,t){e.one(this.SELECTORS.NUMBER).set("text",this.CONSTANTS.PAGENUMBERPREFIX+t)},getPages:function(){return e.all(e.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT+" "+e.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL+" "+this.SELECTORS.PAGE)},isPage:function(e){return e?e.hasClass(this.CSS.PAGE):!1},isEmpty:function(e){var t=e.next("li.activity");return t?!t.hasClass("slot"):!0},add:function(t){var n=this.getNumber(this.getPageFromSlot(t))+1,r=M.mod_quiz.resource_toolbox.get("config").pagehtml;r=r.replace(/%%PAGENUMBER%%/g,n);var i=e.Node.create(r);return YUI().use("dd-drop",function(e){var t=new e.DD.Drop({node:i,groups:M.mod_quiz.dragres.groups});i.drop=t}),t.insert(i,"after"),M.core.actionmenu.newDOMNode(i),i},remove:function(t,n){var r=t.previous(e.Moodle.mod_quiz.util.slot.SELECTORS.SLOT);!n&&r&&e.Moodle.mod_quiz.util.slot.removePageBreak(r),t.remove()},reorderPages:function(){var e=this.getPages(),t=0;e.each(function(e){if(this.isEmpty(e)){var n=e.next("li.slot")?!0:!1;this.remove(e,n);return}t++,this.setNumber(e,t),this.setId(e,t)},this),this.reorderActionMenus()},reorderActionMenus:function(){var e=this.getActionMenus();e.each(function(t,n){var r=e.item(n-1),i=0;r&&(i=this.getActionMenuId(r));var s=i+1;this.setActionMenuId(t,s);var o=t.one(this.SELECTORS.ACTIONMENUBAR);o.set("id",this.CONSTANTS.ACTIONMENUIDPREFIX+s+this.CONSTANTS.ACTIONMENUBARIDSUFFIX);var u=t.one(this.SELECTORS.ACTIONMENUMENU);u.set("id",this.CONSTANTS.ACTIONMENUIDPREFIX+s+this.CONSTANTS.ACTIONMENUMENUIDSUFFIX),u.one("a.addasection").set("href",u.one("a.addasection").get("href").replace(/\baddsectionatpage=\d/,"addsectionatpage="+s))},this)},getActionMenus:function(){return e.all(e.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT+" "+e.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL+" "+this.SELECTORS.ACTIONMENU)},getActionMenuId:function(e){var t=e.get("id").replace(this.CONSTANTS.ACTIONMENUIDPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},setActionMenuId:function(e,t){e.set("id",this.CONSTANTS.ACTIONMENUIDPREFIX+t)}}},"@VERSION@",{requires:["node","moodle-mod_quiz-util-base"]});

View File

@ -278,9 +278,15 @@ Y.Moodle.mod_quiz.util.page = {
// Update action-menu-1-menubar // Update action-menu-1-menubar
var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR); var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR);
menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX); menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX);
// Update action-menu-1-menu // Update action-menu-1-menu
var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU); var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU);
menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX); menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX);
// Update the URL of the add-section action.
menumenu.one('a.addasection').set('href',
menumenu.one('a.addasection').get('href').replace(/\baddsectionatpage=\d/, 'addsectionatpage=' + id));
}, this); }, this);
}, },

View File

@ -276,9 +276,15 @@ Y.Moodle.mod_quiz.util.page = {
// Update action-menu-1-menubar // Update action-menu-1-menubar
var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR); var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR);
menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX); menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX);
// Update action-menu-1-menu // Update action-menu-1-menu
var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU); var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU);
menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX); menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX);
// Update the URL of the add-section action.
menumenu.one('a.addasection').set('href',
menumenu.one('a.addasection').get('href').replace(/\baddsectionatpage=\d/, 'addsectionatpage=' + id));
}, this); }, this);
}, },