diff --git a/lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-debug.js b/lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-debug.js index af66f37e467..d086ba00ca6 100644 --- a/lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-debug.js +++ b/lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-debug.js @@ -561,6 +561,9 @@ Y.extend(DRAGDROP, Y.Base, { M.core.dragdrop.keydraghandle.focus(); M.core.dragdrop.keydragcontainer = null; } + if (M.core.dragdrop.dropui) { + M.core.dragdrop.dropui.destroy(); + } }, /** diff --git a/lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-min.js b/lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-min.js index 991fbbb94b2..559fab605b2 100644 --- a/lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-min.js +++ b/lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-core-dragdrop",function(e,t){var n={pix:"i/move_2d",largepix:"i/dragdrop",component:"moodle",cssclass:"moodle-core-dragdrop-draghandle"},r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,e.Base,{goingup:null,absgoingup:null,samenodeclass:null,parentnodeclass:null,samenodelabel:null,parentnodelabel:null,groups:[],lastdroptarget:null,initializer:function(){e.DD.DDM.on("drag:start",this.global_drag_start,this),e.DD.DDM.on("drag:end",this.global_drag_end,this),e.DD.DDM.on("drag:drag",this.global_drag_drag,this),e.DD.DDM.on("drop:over",this.global_drop_over,this),e.DD.DDM.on("drop:hit",this.global_drop_hit,this),e.DD.DDM.on("drag:dropmiss",this.global_drag_dropmiss,this),e.one(e.config.doc.body).delegate("key",this.global_keydown,"down:32, enter, esc","."+n.cssclass,this),e.one(e.config.doc.body).delegate("click",this.global_keydown,"."+n.cssclass,this)},get_drag_handle:function(t,r,i,s){var o=n.pix;s&&(o=n.largepix);var u=e.Node.create("").setStyle("cursor","move").setAttrs({src:M.util.image_url(o,n.component),alt:t});i&&u.addClass(i);var a=e.Node.create("").addClass(r).setAttribute("title",t).setAttribute("tabIndex",0).setAttribute("data-draggroups",this.groups).setAttribute("role","button");return a.appendChild(u),a.addClass(n.cssclass),a},lock_drag_handle:function(e,t){e.removeHandle("."+t)},unlock_drag_handle:function(e,t){e.addHandle("."+t),e.get("activeHandle").focus()},ajax_failure:function(e){var t={name:e.status+" "+e.statusText,message:e.responseText};return new M.core.exception(t)},in_group:function(t){var n=!1;return e.each(this.groups,function(e){t._groups[e]&&(n=!0)},this),n},global_drag_start:function(e){var t=e.target;if(!this.in_group(t))return;t.get("node").setStyle("opacity",".25"),t.get("dragNode").setStyles({opacity:".75",borderColor:t.get("node").getStyle("borderColor"),backgroundColor:t.get("node").getStyle("backgroundColor")}),t.get("dragNode").empty(),this.drag_start(e)},global_drag_end:function(e){var t=e.target;if(!this.in_group(t))return;t.get("node").setStyles({visibility:"",opacity:"1"}),this.drag_end(e)},global_drag_drag:function(e){var t=e.target,n=e.info;if(!this.in_group(t))return;n.start[1]n.xy[1]&&(this.absgoingup=!1),n.delta[1]<0?this.goingup=!0:n.delta[1]>0&&(this.goingup=!1),this.drag_drag(e)},global_drop_over:function(e){if(!e.drop||!e.drop.inGroup(this.groups))return;var t=e.drag.get("node"),n=e.drop.get("node");this.lastdroptarget=e.drop;if(n.hasClass(this.samenodeclass)){var r;this.goingup?r="before":r="after",n.insert(t,r)}else(n.hasClass(this.parentnodeclass)||n.test('[data-droptarget="1"]'))&&!n.contains(t)&&(this.goingup?n.append(t):n.prepend(t));this.drop_over(e)},global_drag_dropmiss:function(e){e.drag=e.target,e.drop=this.lastdroptarget;if(!this.in_group(e.drag))return;if(!e.drop||!e.drop.inGroup(this.groups))return;this.drag_dropmiss(e)},global_drop_hit:function(e){if(!e.drop||!e.drop.inGroup(this.groups))return;this.drop_hit(e)},find_element_text:function(t){var n=t.all("h2, h3, h4, h5, span, p, div.no-overflow, div.dimmed_text"),r="";return n.each(function(){r===""&&e.Lang.trim(this.get("text"))!==""&&(r=this.get("text"))}),r!==""?r:M.util.get_string("emptydragdropregion","moodle")},global_start_keyboard_drag:function(t,n,r){M.core.dragdrop.keydragcontainer=r,M.core.dragdrop.keydraghandle=n;var i=this.find_element_text(r),s=M.util.get_string("movecontent","moodle",i),o=e.Node.create("");o.addClass("dragdrop-keyboard-drag");var u,a,f=e.all("."+this.samenodeclass+", ."+this.parentnodeclass);f.each(function(t){var n=!1,s=t;if(t.drop&&t.drop.inGroup(this.groups)&&t.drop.get("node")!==r)n=!0;else{var f=t.getAttribute("data-draggroups").split(" "),l,c;for(l=0;l"),listlink=e.Node.create(""),i=this.find_element_text(s),this.samenodelabel&&t.hasClass(this.samenodeclass)?a=M.util.get_string(this.samenodelabel.identifier,this.samenodelabel.component,i):this.parentnodelabel&&t.hasClass(this.parentnodeclass)?a=M.util.get_string(this.parentnodelabel.identifier,this.parentnodelabel.component,i):a=M.util.get_string("tocontent","moodle",i),listlink.setContent(a),listlink.setAttribute("data-drop-target",t.get("id")),listlink.setAttribute("tabindex","0"),listlink.on("click",this.global_keyboard_drop,this),listlink.on("key",this.global_keyboard_drop,"down:enter,32",this),u.append(listlink),o.append(u))},this),M.core.dragdrop.dropui=new M.core.dialogue({headerContent:s,bodyContent:o,draggable:!0,visible:!0,center:!0,modal:!0}),M.core.dragdrop.dropui.after("visibleChange",function(e){e.prevVal&&!e.newVal&&this.global_cancel_keyboard_drag()},this),o.one("a")&&o.one("a").focus()},simulated_drag_drop_event:function(e,t){var n=function(e){this.node=e};n.prototype.get=function(e){return e==="node"||e==="dragNode"||e==="dropNode"?this.node:e==="activeHandle"?this.node.one(".editing_move"):null},n.prototype.inGroup=function(){return!0},n.prototype.addHandle=function(){},n.prototype.removeHandle=function(){},this.drop=new n(t),this.drag=new n(e),this.target=this.drop},global_keyboard_drop:function(t){var n=M.core.dragdrop.keydragcontainer,r=e.one("#"+t.target.getAttribute("data-drop-target"));M.core.dragdrop.dropui.hide(),t.preventDefault();var i=new this.simulated_drag_drop_event(n,n),s=new this.simulated_drag_drop_event(n,r);this.drag_start(i),this.global_drop_over(s),r.hasClass(this.parentnodeclass)&&r.contains(n)&&r.prepend(n),this.global_drop_hit(s)},global_cancel_keyboard_drag:function(){M.core.dragdrop.keydragcontainer&&(M.core.dragdrop.keydraghandle.focus(),M.core.dragdrop.keydragcontainer=null)},global_keydown:function(e){var t=e.target.ancestor("."+n.cssclass,!0),r,i;if(t===null)return;if(e.keyCode===27){this.global_cancel_keyboard_drag(),e.preventDefault();return}if(!t.hasClass(n.cssclass))return;if(e. -keyCode!==13&&e.keyCode!==32&&e.type!=="click")return;i=t.getAttribute("data-draggroups").split(" ");var s,o,u=!1;for(s=0;s").setStyle("cursor","move").setAttrs({src:M.util.image_url(o,n.component),alt:t});i&&u.addClass(i);var a=e.Node.create("").addClass(r).setAttribute("title",t).setAttribute("tabIndex",0).setAttribute("data-draggroups",this.groups).setAttribute("role","button");return a.appendChild(u),a.addClass(n.cssclass),a},lock_drag_handle:function(e,t){e.removeHandle("."+t)},unlock_drag_handle:function(e,t){e.addHandle("."+t),e.get("activeHandle").focus()},ajax_failure:function(e){var t={name:e.status+" "+e.statusText,message:e.responseText};return new M.core.exception(t)},in_group:function(t){var n=!1;return e.each(this.groups,function(e){t._groups[e]&&(n=!0)},this),n},global_drag_start:function(e){var t=e.target;if(!this.in_group(t))return;t.get("node").setStyle("opacity",".25"),t.get("dragNode").setStyles({opacity:".75",borderColor:t.get("node").getStyle("borderColor"),backgroundColor:t.get("node").getStyle("backgroundColor")}),t.get("dragNode").empty(),this.drag_start(e)},global_drag_end:function(e){var t=e.target;if(!this.in_group(t))return;t.get("node").setStyles({visibility:"",opacity:"1"}),this.drag_end(e)},global_drag_drag:function(e){var t=e.target,n=e.info;if(!this.in_group(t))return;n.start[1]n.xy[1]&&(this.absgoingup=!1),n.delta[1]<0?this.goingup=!0:n.delta[1]>0&&(this.goingup=!1),this.drag_drag(e)},global_drop_over:function(e){if(!e.drop||!e.drop.inGroup(this.groups))return;var t=e.drag.get("node"),n=e.drop.get("node");this.lastdroptarget=e.drop;if(n.hasClass(this.samenodeclass)){var r;this.goingup?r="before":r="after",n.insert(t,r)}else(n.hasClass(this.parentnodeclass)||n.test('[data-droptarget="1"]'))&&!n.contains(t)&&(this.goingup?n.append(t):n.prepend(t));this.drop_over(e)},global_drag_dropmiss:function(e){e.drag=e.target,e.drop=this.lastdroptarget;if(!this.in_group(e.drag))return;if(!e.drop||!e.drop.inGroup(this.groups))return;this.drag_dropmiss(e)},global_drop_hit:function(e){if(!e.drop||!e.drop.inGroup(this.groups))return;this.drop_hit(e)},find_element_text:function(t){var n=t.all("h2, h3, h4, h5, span, p, div.no-overflow, div.dimmed_text"),r="";return n.each(function(){r===""&&e.Lang.trim(this.get("text"))!==""&&(r=this.get("text"))}),r!==""?r:M.util.get_string("emptydragdropregion","moodle")},global_start_keyboard_drag:function(t,n,r){M.core.dragdrop.keydragcontainer=r,M.core.dragdrop.keydraghandle=n;var i=this.find_element_text(r),s=M.util.get_string("movecontent","moodle",i),o=e.Node.create("
    ");o.addClass("dragdrop-keyboard-drag");var u,a,f=e.all("."+this.samenodeclass+", ."+this.parentnodeclass);f.each(function(t){var n=!1,s=t;if(t.drop&&t.drop.inGroup(this.groups)&&t.drop.get("node")!==r)n=!0;else{var f=t.getAttribute("data-draggroups").split(" "),l,c;for(l=0;l"),listlink=e.Node.create(""),i=this.find_element_text(s),this.samenodelabel&&t.hasClass(this.samenodeclass)?a=M.util.get_string(this.samenodelabel.identifier,this.samenodelabel.component,i):this.parentnodelabel&&t.hasClass(this.parentnodeclass)?a=M.util.get_string(this.parentnodelabel.identifier,this.parentnodelabel.component,i):a=M.util.get_string("tocontent","moodle",i),listlink.setContent(a),listlink.setAttribute("data-drop-target",t.get("id")),listlink.setAttribute("tabindex","0"),listlink.on("click",this.global_keyboard_drop,this),listlink.on("key",this.global_keyboard_drop,"down:enter,32",this),u.append(listlink),o.append(u))},this),M.core.dragdrop.dropui=new M.core.dialogue({headerContent:s,bodyContent:o,draggable:!0,visible:!0,center:!0,modal:!0}),M.core.dragdrop.dropui.after("visibleChange",function(e){e.prevVal&&!e.newVal&&this.global_cancel_keyboard_drag()},this),o.one("a")&&o.one("a").focus()},simulated_drag_drop_event:function(e,t){var n=function(e){this.node=e};n.prototype.get=function(e){return e==="node"||e==="dragNode"||e==="dropNode"?this.node:e==="activeHandle"?this.node.one(".editing_move"):null},n.prototype.inGroup=function(){return!0},n.prototype.addHandle=function(){},n.prototype.removeHandle=function(){},this.drop=new n(t),this.drag=new n(e),this.target=this.drop},global_keyboard_drop:function(t){var n=M.core.dragdrop.keydragcontainer,r=e.one("#"+t.target.getAttribute("data-drop-target"));M.core.dragdrop.dropui.hide(),t.preventDefault();var i=new this.simulated_drag_drop_event(n,n),s=new this.simulated_drag_drop_event(n,r);this.drag_start(i),this.global_drop_over(s),r.hasClass(this.parentnodeclass)&&r.contains(n)&&r.prepend(n),this.global_drop_hit(s)},global_cancel_keyboard_drag:function(){M.core.dragdrop.keydragcontainer&&(M.core.dragdrop.keydraghandle.focus(),M.core.dragdrop.keydragcontainer=null),M.core.dragdrop.dropui&&M.core.dragdrop.dropui.destroy()},global_keydown:function(e){var t=e.target.ancestor("."+n.cssclass,!0),r,i;if(t===null)return;if(e.keyCode===27){this.global_cancel_keyboard_drag(),e.preventDefault +();return}if(!t.hasClass(n.cssclass))return;if(e.keyCode!==13&&e.keyCode!==32&&e.type!=="click")return;i=t.getAttribute("data-draggroups").split(" ");var s,o,u=!1;for(s=0;send_section_list(); // Inialise the JavaScript. - $this->initialise_editing_javascript($quizobj->get_course(), $quizobj->get_quiz()); + $this->initialise_editing_javascript($quizobj->get_course(), $quizobj->get_quiz(), + $structure, $contexts, $pagevars, $pageurl); // Include the contents of any other popups required. if ($structure->can_be_edited()) { @@ -361,6 +362,38 @@ class edit_renderer extends \plugin_renderer_base { public function question_row(structure $structure, $question, $contexts, $pagevars, $pageurl) { $output = ''; + $output .= $this->page_row($structure, $question, $contexts, $pagevars, $pageurl); + + // Page split/join icon. + $joinhtml = ''; + if ($structure->can_be_edited() && !$structure->is_last_slot_in_quiz($question->slot)) { + $joinhtml = $this->page_split_join_button($structure->get_quiz(), + $question, !$structure->is_last_slot_on_page($question->slot)); + } + + // Question HTML. + $questionhtml = $this->question($structure, $question, $pageurl); + $questionclasses = 'activity ' . $question->qtype . ' qtype_' . $question->qtype . ' slot'; + + $output .= html_writer::tag('li', $questionhtml . $joinhtml, + array('class' => $questionclasses, 'id' => 'slot-' . $question->slotid)); + + return $output; + } + + /** + * Displays one question with the surrounding controls. + * + * @param structure $structure object containing the structure of the quiz. + * @param \stdClass $question data from the question and quiz_slots tables. + * @param \question_edit_contexts $contexts the relevant question bank contexts. + * @param array $pagevars the variables from {@link \question_edit_setup()}. + * @param \moodle_url $pageurl the canonical URL of this page. + * @return string HTML to output. + */ + public function page_row(structure $structure, $question, $contexts, $pagevars, $pageurl) { + $output = ''; + // Put page in a span for easier styling. $page = html_writer::tag('span', get_string('page') . ' ' . $question->page, array('class' => 'text')); @@ -378,20 +411,6 @@ class edit_renderer extends \plugin_renderer_base { array('class' => 'pagenumber activity yui3-dd-drop page', 'id' => 'page-' . $question->page)); } - // Page split/join icon. - $joinhtml = ''; - if ($structure->can_be_edited() && !$structure->is_last_slot_in_quiz($question->slot)) { - $joinhtml = $this->page_split_join_button($structure->get_quiz(), - $question, !$structure->is_last_slot_on_page($question->slot)); - } - - // Question HTML. - $questionhtml = $this->question($structure, $question, $pageurl); - $questionclasses = 'activity ' . $question->qtype . ' qtype_' . $question->qtype . ' slot'; - - $output .= html_writer::tag('li', $questionhtml . $joinhtml, - array('class' => $questionclasses, 'id' => 'slot-' . $question->slotid)); - return $output; } @@ -644,8 +663,8 @@ class edit_renderer extends \plugin_renderer_base { * * @param \stdClass $quiz the quiz settings from the database. * @param \stdClass $question data from the question and quiz_slots tables. - * @param string $insertpagebreak if true, show an insert page break icon. - * Else show a join pages icon. + * @param bool $insertpagebreak if true, show an insert page break icon. + * else show a join pages icon. * @return string HTML to output. */ public function page_split_join_button($quiz, $question, $insertpagebreak) { @@ -653,13 +672,13 @@ class edit_renderer extends \plugin_renderer_base { 'slot' => $question->slot, 'repag' => $insertpagebreak ? 2 : 1, 'sesskey' => sesskey())); if ($insertpagebreak) { - $title = get_string('splitpages', 'quiz'); + $title = get_string('addpagebreak', 'quiz'); $image = $this->pix_icon('e/insert_page_break', $title); - $action = 'unlinkpage'; + $action = 'addpagebreak'; } else { - $title = get_string('joinpages', 'quiz'); + $title = get_string('removepagebreak', 'quiz'); $image = $this->pix_icon('e/remove_page_break', $title); - $action = 'linkpage'; + $action = 'removepagebreak'; } // Disable the link if quiz has attempts. @@ -668,7 +687,7 @@ class edit_renderer extends \plugin_renderer_base { $disabled = "disabled"; } return html_writer::span($this->action_link($url, $image, null, array('title' => $title, - 'class' => 'page_split_join', 'disabled' => $disabled, 'data-action' => $action)), + 'class' => 'page_split_join cm-edit-action', 'disabled' => $disabled, 'data-action' => $action)), 'page_split_join_wrapper'); } @@ -837,17 +856,23 @@ class edit_renderer extends \plugin_renderer_base { * * @param \stdClass $course the course settings from the database. * @param \stdClass $quiz the quiz settings from the database. + * @param structure $structure object containing the structure of the quiz. + * @param \question_edit_contexts $contexts the relevant question bank contexts. + * @param array $pagevars the variables from {@link \question_edit_setup()}. + * @param \moodle_url $pageurl the canonical URL of this page. * @return bool Always returns true */ - protected function initialise_editing_javascript($course, $quiz) { + protected function initialise_editing_javascript($course, $quiz, structure $structure, + \question_edit_contexts $contexts, array $pagevars, \moodle_url $pageurl) { $config = new \stdClass(); $config->resourceurl = '/mod/quiz/edit_rest.php'; $config->sectionurl = '/mod/quiz/edit_rest.php'; $config->pageparams = array(); $config->questiondecimalpoints = $quiz->questiondecimalpoints; + $config->pagehtml = $this->new_page_template($structure, $contexts, $pagevars, $pageurl); + $config->addpageiconhtml = $this->add_page_icon_template($structure, $quiz); - // Include toolboxes. $this->page->requires->yui_module('moodle-mod_quiz-toolboxes', 'M.mod_quiz.init_resource_toolbox', array(array( @@ -857,6 +882,9 @@ class edit_renderer extends \plugin_renderer_base { 'config' => $config, )) ); + unset($config->pagehtml); + unset($config->addpageiconhtml); + $this->page->requires->yui_module('moodle-mod_quiz-toolboxes', 'M.mod_quiz.init_section_toolbox', array(array( @@ -868,7 +896,6 @@ class edit_renderer extends \plugin_renderer_base { )) ); - // Include course dragdrop. $this->page->requires->yui_module('moodle-mod_quiz-dragdrop', 'M.mod_quiz.init_section_dragdrop', array(array( 'courseid' => $course->id, @@ -900,15 +927,19 @@ class edit_renderer extends \plugin_renderer_base { 'movecontent', 'moveleft', 'movesection', + 'page', + 'question', 'selectall', 'show', 'tocontent', ), 'moodle'); $this->page->requires->strings_for_js(array( + 'addpagebreak', 'confirmremovequestion', 'dragtoafter', 'dragtostart', + 'removepagebreak', ), 'quiz'); foreach (\question_bank::get_all_qtypes() as $qtype => $notused) { @@ -918,6 +949,61 @@ class edit_renderer extends \plugin_renderer_base { return true; } + /** + * HTML for a page, with ids stripped, so it can be used as a javascript template. + * + * @param structure $structure object containing the structure of the quiz. + * @param \question_edit_contexts $contexts the relevant question bank contexts. + * @param array $pagevars the variables from {@link \question_edit_setup()}. + * @param \moodle_url $pageurl the canonical URL of this page. + * @return string HTML for a new page. + */ + protected function new_page_template(structure $structure, + \question_edit_contexts $contexts, array $pagevars, \moodle_url $pageurl) { + if (!$structure->has_questions()) { + return ''; + } + + $question = $structure->get_question_in_slot(1); + $pagehtml = $this->page_row($structure, $question, $contexts, $pagevars, $pageurl); + + // Normalise the page number. + $pagenumber = $question->page; + $strcontexts = array(); + $strcontexts[] = 'page-'; + $strcontexts[] = get_string('page') . ' '; + $strcontexts[] = 'addonpage%3D'; + $strcontexts[] = 'addonpage='; + $strcontexts[] = 'addonpage="'; + $strcontexts[] = get_string('addquestionfrombanktopage', 'quiz', ''); + $strcontexts[] = 'data-addonpage%3D'; + $strcontexts[] = 'action-menu-'; + + foreach ($strcontexts as $strcontext) { + $pagehtml = str_replace($strcontext . $pagenumber, $strcontext . '%%PAGENUMBER%%', $pagehtml); + } + + return $pagehtml; + } + + /** + * HTML for a page, with ids stripped, so it can be used as a javascript template. + * + * @param structure $structure object containing the structure of the quiz. + * @param \stdClass $quiz the quiz settings. + * @return string HTML for a new icon + */ + protected function add_page_icon_template(structure $structure, $quiz) { + + if (!$structure->has_questions()) { + return ''; + } + + $question = $structure->get_question_in_slot(1); + $html = $this->page_split_join_button($quiz, $question, true); + return str_replace('&slot=1&', '&slot=%%SLOT%%&', $html); + } + /** * Return the contents of the question bank, to be displayed in the question-bank pop-up. * diff --git a/mod/quiz/edit_rest.php b/mod/quiz/edit_rest.php index 55b09fa74f3..1896d34c63d 100644 --- a/mod/quiz/edit_rest.php +++ b/mod/quiz/edit_rest.php @@ -105,7 +105,7 @@ switch($requestmethod) { echo json_encode(array('instancemaxmark' => quiz_format_question_grade($quiz, $maxmark), 'newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades))); break; - case 'linkslottopage': + case 'updatepagebreak': require_capability('mod/quiz:manage', $modcontext); $slots = $structure->update_page_break($quiz, $id, $value); $json = array(); @@ -133,7 +133,8 @@ switch($requestmethod) { $structure->remove_slot($quiz, $slot->slot); quiz_delete_previews($quiz); quiz_update_sumgrades($quiz); - echo json_encode(array('newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades))); + echo json_encode(array('newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades), + 'deleted' => true)); break; } break; diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index 76143fb06ac..9b9409557f5 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -41,6 +41,7 @@ $string['addnewgroupoverride'] = 'Add group override'; $string['addnewpagesafterselected'] = 'Add new pages after selected questions'; $string['addnewquestionsqbank'] = 'Add questions to the category {$a->catname}: {$a->link}'; $string['addnewuseroverride'] = 'Add user override'; +$string['addpagebreak'] = 'Add page break'; $string['addpagehere'] = 'Add page here'; $string['addquestion'] = 'Add question'; $string['addquestionfrombanktopage'] = 'Add from the question bank to page {$a}'; @@ -431,7 +432,6 @@ $string['invalidquizid'] = 'Invalid quiz ID'; $string['invalidsource'] = 'The source is not accepted as valid.'; $string['invalidsourcetype'] = 'Invalid source type.'; $string['invalidstateid'] = 'Invalid state id'; -$string['joinpages'] = 'Remove page break'; $string['lastanswer'] = 'Your last answer was'; $string['layout'] = 'Layout'; $string['layoutasshown'] = 'Page layout as shown.'; @@ -694,6 +694,7 @@ $string['regradingquiz'] = 'Regrading quiz "{$a}"'; $string['remove'] = 'Remove'; $string['removeallquizattempts'] = 'Delete all quiz attempts'; $string['removeemptypage'] = 'Remove empty page'; +$string['removepagebreak'] = 'Remove page break'; $string['removeselected'] = 'Remove selected'; $string['rename'] = 'Rename'; $string['renderingserverconnectfailed'] = 'The server {$a} failed to process an RQP request. Check that the URL is correct.'; @@ -833,7 +834,6 @@ $string['sortsubmit'] = 'Sort questions'; $string['sorttypealpha'] = 'Sort by type, name'; $string['specificapathnotonquestion'] = 'The specified file path is not on the specified question'; $string['specificquestionnotonquiz'] = 'Specified question is not on the specified quiz'; -$string['splitpages'] = 'Add page break'; $string['startagain'] = 'Start again'; $string['startattempt'] = 'Start attempt'; $string['startedon'] = 'Started on'; @@ -912,7 +912,7 @@ $string['xhtml'] = 'XHTML'; $string['youneedtoenrol'] = 'You need to enrol in this course before you can attempt this quiz'; $string['yourfinalgradeis'] = 'Your final grade for this quiz is {$a}.'; -// Deprecated since Moodle 2.8 +// Deprecated since Moodle 2.8. $string['categories'] = 'Categories'; $string['category'] = 'Category'; diff --git a/mod/quiz/tests/behat/behat_mod_quiz.php b/mod/quiz/tests/behat/behat_mod_quiz.php index 5886d454d37..0b430581de1 100644 --- a/mod/quiz/tests/behat/behat_mod_quiz.php +++ b/mod/quiz/tests/behat/behat_mod_quiz.php @@ -128,6 +128,22 @@ class behat_mod_quiz extends behat_question_base { ); } + /** + * Check whether a particular question is not on a particular page of the quiz on the Edit quiz page. + * @Given /^I should not see "(?P(?:[^"]|\\")*)" on quiz page "(?P\d+)"$/ + * @param string $questionname the name of the question we are looking for. + * @param number $pagenumber the page it should be found on. + * @return array of steps. + */ + public function i_should_not_see_on_quiz_page($questionname, $pagenumber) { + $xpath = "//li[contains(., '" . $this->escape($questionname) . + "')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " . + $pagenumber . "')]]"; + return array( + new Given('"' . $xpath . '" "xpath_element" should not exist'), + ); + } + /** * Check whether one question comes before another on the Edit quiz page. * The two questions must be on the same page. @@ -153,13 +169,24 @@ class behat_mod_quiz extends behat_question_base { * @return array of steps. */ public function should_have_number_on_the_edit_quiz_page($questionname, $number) { - $xpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) . - "')]//span[@class = 'slotnumber' and normalize-space(text()) = '" . $this->escape($number) . "']"; + $xpath = "//li[contains(@class, 'slot') and contains(., '" . $this->escape($questionname) . + "')]//span[contains(@class, 'slotnumber') and normalize-space(text()) = '" . $this->escape($number) . "']"; return array( new Given('"' . $xpath . '" "xpath_element" should exist'), ); } + /** + * Get the xpath for a partcular add/remove page-break icon. + * @param string $addorremoves 'Add' or 'Remove'. + * @param string $questionname the name of the question before the icon. + * @return string the requried xpath. + */ + protected function get_xpath_page_break_icon_after_question($addorremoves, $questionname) { + return "//li[contains(@class, 'slot') and contains(., '" . $this->escape($questionname) . + "')]//a[contains(@class, 'page_split_join') and @title = '" . $addorremoves . " page break']"; + } + /** * Click the add or remove page-break icon after a particular question. * @When /^I click on the "(Add|Remove)" page break icon after question "(?P(?:[^"]|\\")*)"$/ @@ -168,8 +195,50 @@ class behat_mod_quiz extends behat_question_base { * @return array of steps. */ public function i_click_on_the_page_break_icon_after_question($addorremoves, $questionname) { - $xpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) . - "')]//a[@class = 'page_split_join' and @title = '" . $addorremoves . " page break']"; + $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); + return array( + new Given('I click on "' . $xpath . '" "xpath_element"'), + ); + } + + /** + * Assert the add or remove page-break icon after a particular question exists. + * @When /^the "(Add|Remove)" page break icon after question "(?P(?:[^"]|\\")*)" should exist$/ + * @param string $addorremoves 'Add' or 'Remove'. + * @param string $questionname the name of the question before the icon to click. + * @return array of steps. + */ + public function the_page_break_icon_after_question_should_exist($addorremoves, $questionname) { + $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); + return array( + new Given('"' . $xpath . '" "xpath_element" should exist'), + ); + } + + /** + * Assert the add or remove page-break icon after a particular question does not exist. + * @When /^the "(Add|Remove)" page break icon after question "(?P(?:[^"]|\\")*)" should not exist$/ + * @param string $addorremoves 'Add' or 'Remove'. + * @param string $questionname the name of the question before the icon to click. + * @return array of steps. + */ + public function the_page_break_icon_after_question_should_not_exist($addorremoves, $questionname) { + $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); + return array( + new Given('"' . $xpath . '" "xpath_element" should not exist'), + ); + } + + /** + * Check the add or remove page-break link after a particular question contains the given parameters in its url. + * @When /^the "(Add|Remove)" page break link after question "(?P(?:[^"]|\\")*) should contain:"$/ + * @param string $addorremoves 'Add' or 'Remove'. + * @param string $questionname the name of the question before the icon to click. + * @param TableNode $paramdata with data for checking the page break url + * @return array of steps. + */ + public function the_page_break_link_after_question_should_contain($addorremoves, $questionname, $paramdata) { + $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); return array( new Given('I click on "' . $xpath . '" "xpath_element"'), ); @@ -210,4 +279,21 @@ class behat_mod_quiz extends behat_question_base { 'and I drop it in "' . $destinationxpath . '" "xpath_element"'), ); } + + /** + * Delete a question on the Edit quiz page by first clicking on the Delete icon, + * then clicking one of the "After ..." links. + * @When /^I delete "(?P(?:[^"]|\\")*)" in the quiz by clicking the delete icon$/ + * @param string $questionname the name of the question we are looking for. + * @return array of steps. + */ + public function i_delete_question_by_clicking_the_delete_icon($questionname) { + $slotxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) . + "')]"; + $deletexpath = "//a[contains(@class, 'editing_delete')]"; + return array( + new Given('I click on "' . $slotxpath . $deletexpath . '" "xpath_element"'), + new Given('I click on "Yes" "button" in the "Confirm" "dialogue"'), + ); + } } diff --git a/mod/quiz/tests/behat/editing_click_delete_icon.feature b/mod/quiz/tests/behat/editing_click_delete_icon.feature new file mode 100644 index 00000000000..e1253fc530e --- /dev/null +++ b/mod/quiz/tests/behat/editing_click_delete_icon.feature @@ -0,0 +1,118 @@ +@mod @mod_quiz +Feature: Edit quiz page - delete + In order to change the layout of a quiz I built + As a teacher + I need to be able to delete questions. + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | T1 | Teacher1 | teacher1@moodle.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | name | course | idnumber | + | quiz | Quiz 1 | C1 | quiz1 | + And I log in as "teacher1" + And I follow "Course 1" + + @javascript + Scenario: Delete questions by clicking on the delete icon. + And I add a "True/False" question to the "Quiz 1" quiz with: + | Question name | Question A | + | Question text | Answer me | + And I add a "True/False" question to the "Quiz 1" quiz with: + | Question name | Question B | + | Question text | Answer again | + And I add a "True/False" question to the "Quiz 1" quiz with: + | Question name | Question C | + | Question text | And again | + And I click on the "Add" page break icon after question "Question B" + + # Confirm the starting point. + Then I should see "Question A" on quiz page "1" + And I should see "Question B" on quiz page "1" + And I should see "Question C" on quiz page "2" + And I should see "Total of marks: 3.00" + + # Delete last question in last page. Page contains multiple questions + When I delete "Question C" in the quiz by clicking the delete icon + Then I should see "Question A" on quiz page "1" + And I should see "Question B" on quiz page "1" + And I should not see "Question C" on quiz page "2" + And I should see "Total of marks: 2.00" + + # Delete last question in last page. The page contains multiple questions and there are multiple pages. + When I click on the "Add" page break icon after question "Question A" + Then I should see "Question B" on quiz page "2" + And the "Remove" page break icon after question "Question A" should exist + And I delete "Question B" in the quiz by clicking the delete icon + Then I should see "Question A" on quiz page "1" + And I should not see "Page 2" + And I should not see "Question B" on quiz page "2" + And the "Remove" page break icon after question "Question A" should not exist + And I should see "Total of marks: 1.00" + + # Delete last remaining question in the last remaining page. + And I delete "Question A" in the quiz by clicking the delete icon + Then I should not see "Question A" on quiz page "1" + And I should not see "Page 1" + And I should see "Total of marks: 0.00" + + @javascript @edit_quiz_delete_start + Scenario: Delete questions from the start of the list. + # Add more questions. + When I add a "Description" question to the "Quiz 1" quiz with: + | Question name | Question A | + | Question text | Answer A | + + And I add a "True/False" question to the "Quiz 1" quiz with: + | Question name | Question B | + | Question text | Answer B | + + And I add a "Description" question to the "Quiz 1" quiz with: + | Question name | Question C | + | Question text | Answer C | + + And I add a "True/False" question to the "Quiz 1" quiz with: + | Question name | Question D | + | Question text | Answer D | + + And I add a "True/False" question to the "Quiz 1" quiz with: + | Question name | Question E | + | Question text | Answer E | + + Then "Question A" should have number "i" on the edit quiz page + And "Question B" should have number "1" on the edit quiz page + And "Question C" should have number "i" on the edit quiz page + And "Question D" should have number "2" on the edit quiz page + And "Question E" should have number "3" on the edit quiz page + + # Delete from first question in the last remaining page. Are the page breaks updated? + When I delete "Question A" in the quiz by clicking the delete icon + Then "Question B" should have number "1" on the edit quiz page + And "Question C" should have number "i" on the edit quiz page + And "Question D" should have number "2" on the edit quiz page + And "Question E" should have number "3" on the edit quiz page + + When I click on the "Add" page break icon after question "Question C" + Then I should see "Page 1" + And I should see "Question B" on quiz page "1" + And I should see "Question C" on quiz page "1" + Then I should see "Page 2" + And I should see "Question D" on quiz page "2" + And I should see "Question E" on quiz page "2" + + # Test reorder of pages + When I click on the "Add" page break icon after question "Question B" + Then I should see "Page 1" + And I should see "Question B" on quiz page "1" + Then I should see "Page 2" + And I should see "Question C" on quiz page "2" + Then I should see "Page 3" + And I should see "Question D" on quiz page "3" + And I should see "Question E" on quiz page "3" diff --git a/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop-debug.js b/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop-debug.js index b1d586c1d60..10ddabd9da1 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop-debug.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop-debug.js @@ -313,7 +313,6 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, { this.groups = ['resource']; this.samenodeclass = CSS.ACTIVITY; this.parentnodeclass = CSS.SECTION; - //this.resourcedraghandle = this.get_drag_handle(M.util.get_string('movecoursemodule', 'moodle'), CSS.EDITINGMOVE, CSS.ICONCLASS, true); this.resourcedraghandle = this.get_drag_handle(M.str.moodle.move, CSS.EDITINGMOVE, CSS.ICONCLASS, true); this.samenodelabel = { @@ -467,12 +466,11 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, { var responsetext = Y.JSON.parse(response.responseText); var params = {element: dragnode, visible: responsetext.visible}; M.mod_quiz.quizbase.invoke_function('set_visibility_resource_ui', params); - Y.Moodle.mod_quiz.util.slot.reorder_slots(); this.unlock_drag_handle(drag, CSS.EDITINGMOVE); window.setTimeout(function() { spinner.hide(); }, 250); - window.location.reload(true); + M.mod_quiz.resource_toolbox.reorganise_edit_page(); }, failure: function(tid, response) { this.ajax_failure(response); @@ -556,7 +554,9 @@ M.mod_quiz.init_resource_dragdrop = function(params) { "moodle-core-dragdrop", "moodle-core-notification", "moodle-mod_quiz-quizbase", - "moodle-mod_quiz-util", + "moodle-mod_quiz-util-base", + "moodle-mod_quiz-util-page", + "moodle-mod_quiz-util-slot", "moodle-course-util" ] }); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop-min.js b/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop-min.js index bdc012617af..bbf82b012f2 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop-min.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop-min.js @@ -1,2 +1,2 @@ YUI.add("moodle-mod_quiz-dragdrop",function(e,t){var n={ACTIONAREA:".actions",ACTIVITY:"activity",ACTIVITYINSTANCE:"activityinstance",CONTENT:"content",COURSECONTENT:"mod-quiz-edit-content",EDITINGMOVE:"editing_move",ICONCLASS:"iconsmall",JUMPMENU:"jumpmenu",LEFT:"left",LIGHTBOX:"lightbox",MOVEDOWN:"movedown",MOVEUP:"moveup",PAGE:"page",PAGECONTENT:"page-content",RIGHT:"right",SECTION:"section",SECTIONADDMENUS:"section_add_menus",SECTIONHANDLE:"section-handle",SLOTS:"slots",SUMMARY:"summary",SECTIONDRAGGABLE:"sectiondraggable"},r={PAGE:"li.page",SLOT:"li.slot"},i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,M.core.dragdrop,{sectionlistselector:null,initializer:function(){this.groups=[n.SECTIONDRAGGABLE],this.samenodeclass=M.mod_quiz.edit.get_sectionwrapperclass(),this.parentnodeclass=M.mod_quiz.edit.get_containerclass();if(e.Node.one("."+n.JUMPMENU))return!1;this.sectionlistselector=M.mod_quiz.edit.get_section_wrapper(e);if(this.sectionlistselector){this.sectionlistselector="."+n.COURSECONTENT+" "+this.sectionlistselector,this.setup_for_section(this.sectionlistselector);var t=new e.DD.Delegate({container:"."+n.COURSECONTENT,nodes:"."+n.SECTIONDRAGGABLE,target:!0,handles:["."+n.LEFT],dragConfig:{groups:this.groups}});t.dd.plug(e.Plugin.DDProxy,{moveOnEnd:!1}),t.dd.plug(e.Plugin.DDConstrained,{constrain:"#"+n.PAGECONTENT,stickY:!0}),t.dd.plug(e.Plugin.DDWinScroll)}},setup_for_section:function(t){e.Node.all(t).each(function(t){var r=e.Moodle.core_course.util.section.getId(t);if(r>0){var i=t.one("."+n.RIGHT+" a."+n.MOVEDOWN),s=t.one("."+n.RIGHT+" a."+n.MOVEUP),o=M.util.get_string("movesection","moodle",r),u=t.one("."+n.LEFT);(i||s)&&u&&(u.setStyle("cursor","move"),u.appendChild(this.get_drag_handle(o,n.SECTIONHANDLE,"icon",!0)),s&&s.remove(),i&&i.remove(),t.addClass(n.SECTIONDRAGGABLE))}},this)},drag_start:function(t){var r=t.target,i=e.Node.create("<"+M.mod_quiz.edit.get_containernode()+">");i.addClass(M.mod_quiz.edit.get_containerclass());var s=e.Node.create("<"+M.mod_quiz.edit.get_sectionwrappernode()+">");s.addClass(M.mod_quiz.edit.get_sectionwrapperclass()),s.setStyle("margin",0),s.setContent(r.get("node").get("innerHTML")),i.appendChild(s),r.get("dragNode").setContent(i),r.get("dragNode").addClass(n.COURSECONTENT)},drag_dropmiss:function(e){this.drop_hit(e)},get_section_index:function(t){var r="."+n.COURSECONTENT+" "+M.mod_quiz.edit.get_section_selector(e),i=e.all(r),s=i.indexOf(t),o=i.indexOf(e.one("#section-0"));return s-o},drop_hit:function(t){var r=t.drag,i=r.get("node"),s=e.Moodle.core_course.util.section.getId(i),o=s,u=this.get_section_index(i),a=u;if(s===u)return;o>a&&(o=u,a=s),r.get("dragNode").removeClass(n.COURSECONTENT);var f=e.Node.all(this.sectionlistselector),l=M.util.add_lightbox(e,i),c={},h=this.get("config").pageparams,p;for(p in h){if(!h.hasOwnProperty(p))continue;c[p]=h[p]}c.sesskey=M.cfg.sesskey,c.courseid=this.get("courseid"),c.quizid=this.get("quizid"),c["class"]="section",c.field="move",c.id=s,c.value=u;var d=M.cfg.wwwroot+this.get("ajaxurl");e.io(d,{method:"POST",data:c,on:{start:function(){l.show()},success:function(t,n){try{var r=e.JSON.parse(n.responseText);r.error&&new M.core.ajaxException(r),M.mod_quiz.edit.process_sections(e,f,r,o,a)}catch(i){}var s,u=!1;do{u=!1;for(s=o;s<=a;s++)if(e.Moodle.core_course.util.section.getId(f.item(s-1))>e.Moodle.core_course.util.section.getId(f.item(s))){var c=f.item(s-1).get("id");f.item(s-1).set("id",f.item(s).get("id")),f.item(s).set("id",c),M.mod_quiz.edit.swap_sections(e,s-1,s),u=!0}a-=1}while(u);window.setTimeout(function(){l.hide()},250)},failure:function(e,t){this.ajax_failure(t),l.hide()}},context:this})}},{NAME:"mod_quiz-dragdrop-section",ATTRS:{courseid:{value:null},quizid:{value:null},ajaxurl:{value:0},config:{value:0}}}),M.mod_quiz=M.mod_quiz||{},M.mod_quiz.init_section_dragdrop=function(e){new i(e)};var s=function(){s.superclass.constructor.apply(this,arguments)};e.extend(s,M.core.dragdrop,{initializer:function(){this.groups=["resource"],this.samenodeclass=n.ACTIVITY,this.parentnodeclass=n.SECTION,this.resourcedraghandle=this.get_drag_handle(M.str.moodle.move,n.EDITINGMOVE,n.ICONCLASS,!0),this.samenodelabel={identifier:"dragtoafter",component:"quiz"},this.parentnodelabel={identifier:"dragtostart",component:"quiz"};var t=M.mod_quiz.edit.get_section_selector(e);if(t){t="."+n.COURSECONTENT+" "+t,this.setup_for_section(t);var r=t.slice(n.COURSECONTENT.length+2)+" li."+n.ACTIVITY,i=new e.DD.Delegate({container:"."+n.COURSECONTENT,nodes:r,target:!0,handles:["."+n.EDITINGMOVE],dragConfig:{groups:this.groups}});i.dd.plug(e.Plugin.DDProxy,{moveOnEnd:!1,cloneNode:!0}),i.dd.plug(e.Plugin.DDConstrained,{constrain:"#"+n.SLOTS}),i.dd.plug(e.Plugin.DDWinScroll),M.mod_quiz.quizbase.register_module(this),M.mod_quiz.dragres=this}},setup_for_section:function(t){e.Node.all(t).each(function(t){var r=t.one("."+n.CONTENT+" ul."+n.SECTION);r||(r=e.Node.create("
      "),r.addClass(n.SECTION),t.one("."+n.CONTENT+" div."+n.SUMMARY).insert(r,"after")),r.setAttribute("data-draggroups",this.groups.join(" ")),new e.DD.Drop({node:r,groups:this.groups,padding:"20 0 20 0"}),this.setup_for_resource("#"+t.get("id")+" li."+n.ACTIVITY)},this)},setup_for_resource:function(t){e.Node.all(t).each(function(e){var t=e.one("a."+n.EDITINGMOVE);t&&t.replace(this.resourcedraghandle.cloneNode(!0))},this)},drag_start:function(e){var t=e.target;t.get("dragNode").setContent(t.get("node").get("innerHTML")),t.get("dragNode").all("img.iconsmall").setStyle("vertical-align","baseline")},drag_dropmiss:function(e){this.drop_hit(e)},drop_hit:function(t){var i=t.drag,s=i.get("node"),o=t.drop.get("node"),u=s.one(n.ACTIONAREA),a=M.util.add_spinner(e,u),f={},l=this.get("config").pageparams,c;for(c in l)f[c]=l[c];f.sesskey=M.cfg.sesskey,f.courseid=this.get("courseid"),f.quizid=this.get("quizid"),f["class"]="resource",f.field="move",f.id=Number(e.Moodle.mod_quiz. -util.slot.getId(s)),f.sectionId=e.Moodle.core_course.util.section.getId(o.ancestor(M.mod_quiz.edit.get_section_wrapper(e),!0));var h=s.previous(r.SLOT);h&&(f.previousid=Number(e.Moodle.mod_quiz.util.slot.getId(h)));var p=s.previous(r.PAGE);p&&(f.page=Number(e.Moodle.mod_quiz.util.page.getId(p)));var d=M.cfg.wwwroot+this.get("ajaxurl");e.io(d,{method:"POST",data:f,on:{start:function(){this.lock_drag_handle(i,n.EDITINGMOVE),a.show()},success:function(t,r){var o=e.JSON.parse(r.responseText),u={element:s,visible:o.visible};M.mod_quiz.quizbase.invoke_function("set_visibility_resource_ui",u),e.Moodle.mod_quiz.util.slot.reorder_slots(),this.unlock_drag_handle(i,n.EDITINGMOVE),window.setTimeout(function(){a.hide()},250),window.location.reload(!0)},failure:function(e,t){this.ajax_failure(t),this.unlock_drag_handle(i,n.SECTIONHANDLE),a.hide(),window.location.reload(!0)}},context:this})},global_drop_over:function(e){if(!e.drop||!e.drop.inGroup(this.groups))return;var t=e.drag.get("node"),n=e.drop.get("node");this.lastdroptarget=e.drop;if(n.hasClass(this.samenodeclass)){var r;this.goingup?r="before":r="after",n.insert(t,r)}else(n.hasClass(this.parentnodeclass)||n.test('[data-droptarget="1"]'))&&!n.contains(t)&&(this.goingup?n.append(t):n.prepend(t));this.drop_over(e)}},{NAME:"mod_quiz-dragdrop-resource",ATTRS:{courseid:{value:null},quizid:{value:null},ajaxurl:{value:0},config:{value:0}}}),M.mod_quiz=M.mod_quiz||{},M.mod_quiz.init_resource_dragdrop=function(e){new s(e)}},"@VERSION@",{requires:["base","node","io","dom","dd","dd-scroll","moodle-core-dragdrop","moodle-core-notification","moodle-mod_quiz-quizbase","moodle-mod_quiz-util","moodle-course-util"]}); +util.slot.getId(s)),f.sectionId=e.Moodle.core_course.util.section.getId(o.ancestor(M.mod_quiz.edit.get_section_wrapper(e),!0));var h=s.previous(r.SLOT);h&&(f.previousid=Number(e.Moodle.mod_quiz.util.slot.getId(h)));var p=s.previous(r.PAGE);p&&(f.page=Number(e.Moodle.mod_quiz.util.page.getId(p)));var d=M.cfg.wwwroot+this.get("ajaxurl");e.io(d,{method:"POST",data:f,on:{start:function(){this.lock_drag_handle(i,n.EDITINGMOVE),a.show()},success:function(t,r){var o=e.JSON.parse(r.responseText),u={element:s,visible:o.visible};M.mod_quiz.quizbase.invoke_function("set_visibility_resource_ui",u),this.unlock_drag_handle(i,n.EDITINGMOVE),window.setTimeout(function(){a.hide()},250),M.mod_quiz.resource_toolbox.reorganise_edit_page()},failure:function(e,t){this.ajax_failure(t),this.unlock_drag_handle(i,n.SECTIONHANDLE),a.hide(),window.location.reload(!0)}},context:this})},global_drop_over:function(e){if(!e.drop||!e.drop.inGroup(this.groups))return;var t=e.drag.get("node"),n=e.drop.get("node");this.lastdroptarget=e.drop;if(n.hasClass(this.samenodeclass)){var r;this.goingup?r="before":r="after",n.insert(t,r)}else(n.hasClass(this.parentnodeclass)||n.test('[data-droptarget="1"]'))&&!n.contains(t)&&(this.goingup?n.append(t):n.prepend(t));this.drop_over(e)}},{NAME:"mod_quiz-dragdrop-resource",ATTRS:{courseid:{value:null},quizid:{value:null},ajaxurl:{value:0},config:{value:0}}}),M.mod_quiz=M.mod_quiz||{},M.mod_quiz.init_resource_dragdrop=function(e){new s(e)}},"@VERSION@",{requires:["base","node","io","dom","dd","dd-scroll","moodle-core-dragdrop","moodle-core-notification","moodle-mod_quiz-quizbase","moodle-mod_quiz-util-base","moodle-mod_quiz-util-page","moodle-mod_quiz-util-slot","moodle-course-util"]}); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop.js b/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop.js index 76c7621c214..58da56f770c 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-dragdrop/moodle-mod_quiz-dragdrop.js @@ -308,7 +308,6 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, { this.groups = ['resource']; this.samenodeclass = CSS.ACTIVITY; this.parentnodeclass = CSS.SECTION; - //this.resourcedraghandle = this.get_drag_handle(M.util.get_string('movecoursemodule', 'moodle'), CSS.EDITINGMOVE, CSS.ICONCLASS, true); this.resourcedraghandle = this.get_drag_handle(M.str.moodle.move, CSS.EDITINGMOVE, CSS.ICONCLASS, true); this.samenodelabel = { @@ -462,12 +461,11 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, { var responsetext = Y.JSON.parse(response.responseText); var params = {element: dragnode, visible: responsetext.visible}; M.mod_quiz.quizbase.invoke_function('set_visibility_resource_ui', params); - Y.Moodle.mod_quiz.util.slot.reorder_slots(); this.unlock_drag_handle(drag, CSS.EDITINGMOVE); window.setTimeout(function() { spinner.hide(); }, 250); - window.location.reload(true); + M.mod_quiz.resource_toolbox.reorganise_edit_page(); }, failure: function(tid, response) { this.ajax_failure(response); @@ -551,7 +549,9 @@ M.mod_quiz.init_resource_dragdrop = function(params) { "moodle-core-dragdrop", "moodle-core-notification", "moodle-mod_quiz-quizbase", - "moodle-mod_quiz-util", + "moodle-mod_quiz-util-base", + "moodle-mod_quiz-util-page", + "moodle-mod_quiz-util-slot", "moodle-course-util" ] }); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-quizbase/moodle-mod_quiz-quizbase-debug.js b/mod/quiz/yui/build/moodle-mod_quiz-quizbase/moodle-mod_quiz-quizbase-debug.js index a035d447275..8e0c43c55d4 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-quizbase/moodle-mod_quiz-quizbase-debug.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-quizbase/moodle-mod_quiz-quizbase-debug.js @@ -79,9 +79,9 @@ M.mod_quiz.edit.swap_sections = function(Y, node1, node2) { SECTIONADDMENUS : 'section_add_menus' }; - var sectionlist = Y.Node.all('.'+CSS.COURSECONTENT+' '+M.mod_quiz.edit.get_section_selector(Y)); + var sectionlist = Y.Node.all('.' + CSS.COURSECONTENT + ' ' + M.mod_quiz.edit.get_section_selector(Y)); // Swap menus. - sectionlist.item(node1).one('.'+CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.'+CSS.SECTIONADDMENUS)); + sectionlist.item(node1).one('.' + CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.' + CSS.SECTIONADDMENUS)); }; /** @@ -117,7 +117,7 @@ M.mod_quiz.edit.process_sections = function(Y, sectionlist, response, sectionfro for (var i = sectionfrom; i <= sectionto; i++) { // Update section title. - sectionlist.item(i).one('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]); + sectionlist.item(i).one('.' + CSS.SECTIONNAME).setContent(response.sectiontitles[i]); // Update move icon. ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-quizbase/moodle-mod_quiz-quizbase.js b/mod/quiz/yui/build/moodle-mod_quiz-quizbase/moodle-mod_quiz-quizbase.js index eebd3435128..bb24c94fbb4 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-quizbase/moodle-mod_quiz-quizbase.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-quizbase/moodle-mod_quiz-quizbase.js @@ -79,9 +79,9 @@ M.mod_quiz.edit.swap_sections = function(Y, node1, node2) { SECTIONADDMENUS : 'section_add_menus' }; - var sectionlist = Y.Node.all('.'+CSS.COURSECONTENT+' '+M.mod_quiz.edit.get_section_selector(Y)); + var sectionlist = Y.Node.all('.' + CSS.COURSECONTENT + ' ' + M.mod_quiz.edit.get_section_selector(Y)); // Swap menus. - sectionlist.item(node1).one('.'+CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.'+CSS.SECTIONADDMENUS)); + sectionlist.item(node1).one('.' + CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.' + CSS.SECTIONADDMENUS)); }; /** @@ -117,7 +117,7 @@ M.mod_quiz.edit.process_sections = function(Y, sectionlist, response, sectionfro for (var i = sectionfrom; i <= sectionto; i++) { // Update section title. - sectionlist.item(i).one('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]); + sectionlist.item(i).one('.' + CSS.SECTIONNAME).setContent(response.sectiontitles[i]); // Update move icon. ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE); 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 aece0a61743..e005dd683ea 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 @@ -311,10 +311,10 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // The user is deleting the activity. this.delete_with_confirmation(ev, node, activity, action); break; - case 'linkpage': - case 'unlinkpage': - // The user is linking or unlinking pages. - this.link_page(ev, node, activity, action); + case 'addpagebreak': + case 'removepagebreak': + // The user is adding or removing a page break. + this.update_page_break(ev, node, activity, action); break; default: // Nothing to do here! @@ -350,10 +350,10 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @chainable */ delete_with_confirmation: function(ev, button, activity) { - // Prevent the default button action + // Prevent the default button action. ev.preventDefault(); - // Get the element we're working on + // Get the element we're working on. var element = activity, // Create confirm string (different if element has or does not have name) confirmstring = '', @@ -370,19 +370,24 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // If it is confirmed. confirm.on('complete-yes', function() { - // Actually remove the element. - element.remove(); - Y.Moodle.mod_quiz.util.slot.reorder_slots(); + var spinner = this.add_spinner(element); var data = { 'class': 'resource', 'action': 'DELETE', 'id': Y.Moodle.mod_quiz.util.slot.getId(element) }; - this.send_request(data); - if (M.core.actionmenu && M.core.actionmenu.instance) { - M.core.actionmenu.instance.hideMenu(); - } - window.location.reload(true); + this.send_request(data, spinner, function(response) { + if (response.deleted) { + // Actually remove the element. + Y.Moodle.mod_quiz.util.slot.remove(element); + this.reorganise_edit_page(); + if (M.core.actionmenu && M.core.actionmenu.instance) { + M.core.actionmenu.instance.hideMenu(); + } + } else { + window.location.reload(true); + } + }); }, this); @@ -425,12 +430,12 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { M.core.actionmenu.instance.hideMenu(); } - // Try to retrieve the existing string from the server + // Try to retrieve the existing string from the server. if (response.instancemaxmark) { maxmarktext = response.instancemaxmark; } - // Create the editor and submit button + // Create the editor and submit button. var editform = Y.Node.create('
      '); var editinstructions = Y.Node.create('') .set('innerHTML', M.util.get_string('edittitleinstructions', 'moodle')); @@ -442,7 +447,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { 'size' : parseInt(this.get('config').questiondecimalpoints, 10) + 2 }); - // Clear the existing content and put the editor in + // Clear the existing content and put the editor in. editform.appendChild(editor); editform.setData('anchor', anchor); instance.insert(editinstructions, 'before'); @@ -457,7 +462,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // We hide various components whilst editing: activity.addClass(CSS.EDITINGMAXMARK); - // Focus and select the editor text + // Focus and select the editor text. editor.focus().select(); // Cancel the edit if we lose focus or the escape key is pressed. @@ -482,7 +487,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @param {String} originalmaxmark The original maxmark the activity or resource had. */ edit_maxmark_submit : function(ev, activity, originalmaxmark) { - // We don't actually want to submit anything + // We don't actually want to submit anything. ev.preventDefault(); var newmaxmark = Y.Lang.trim(activity.one(SELECTOR.ACTIVITYFORM + ' ' + SELECTOR.ACTIVITYMAXMARK).get('value')); var spinner = this.add_spinner(activity); @@ -560,97 +565,59 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * the other slots * * @protected - * @method link_page + * @method update_page_break * @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 */ - link_page: function(ev, button, activity, action) { + update_page_break: function(ev, button, activity, action) { // Prevent the default button action ev.preventDefault(); - activity = activity.next('li.activity.slot'); - var spinner = this.add_spinner(activity), + nextactivity = activity.next('li.activity.slot'); + var spinner = this.add_spinner(nextactivity), slotid = 0; - var value = action === 'linkpage' ? 1:2; + var value = action === 'removepagebreak' ? 1 : 2; var data = { 'class': 'resource', - 'field': 'linkslottopage', + 'field': 'updatepagebreak', 'id': slotid, 'value': value }; - slotid = Y.Moodle.mod_quiz.util.slot.getId(activity); + slotid = Y.Moodle.mod_quiz.util.slot.getId(nextactivity); if (slotid) { data.id = Number(slotid); } this.send_request(data, spinner, function(response) { - window.location.reload(true); -// if (response.slots) { -// this.repaginate_slots(response.slots); -// } + if (response.slots) { + if (action === 'addpagebreak') { + Y.Moodle.mod_quiz.util.page.add(activity); + } else { + var page = activity.next(Y.Moodle.mod_quiz.util.page.SELECTORS.PAGE); + Y.Moodle.mod_quiz.util.page.remove(page, true); + } + this.reorganise_edit_page(); + } else { + window.location.reload(true); + } }); return this; }, - repaginate_slots: function(slots) { - this.slots = slots; - var section = Y.one(SELECTOR.PAGECONTENT + ' ' + SELECTOR.SECTIONUL), - activities = section.all(SELECTOR.ACTIVITYLI); - activities.each(function(node) { - // What element is it? page/slot/link - // what is the current slot? - var type; - var slot; - if(node.hasClass(CSS.PAGE)){ - type = this.NODE_PAGE; - slot = node.next(SELECTOR.SLOTLI); - } else if (node.hasClass(CSS.SLOT)){ - type = this.NODE_SLOT; - slot = node; - } else if (node.hasClass(CSS.JOIN)){ - type = this.NODE_JOIN; - slot = node.previous(SELECTOR.SLOTLI); - } - - // getSlotnumber() Should be a method of util.slot - var slotnumber = Number(Y.Moodle.mod_quiz.util.slot.getNumber(slot)); - if(!type){ - // Nothing we can do. - return; - } - - // Is it correct? - if(!this.slots.hasOwnProperty(slotnumber)){ - // An error. We should handle this. - return; - } - - var slotdata = this.slots[slotnumber]; - - if(type === this.NODE_PAGE){ - // Get page number - var pagenumber = Y.Moodle.mod_quiz.util.page.getNumber(node); - // Is the page number correct? - if (slotdata.page === pagenumber) { - console.log('slotdata.page == pagenumber return'); - return; - } - - if (pagenumber < slotdata.page) { - // Remove page node. - node.remove(); - } - else { - // Add page node. - console.log('pagenumber > slotdata.page update page number'); - } - - } - }, this); + /** + * Reorganise the UI after every edit action. + * + * @protected + * @method reorganise_edit_page + */ + reorganise_edit_page: function() { + Y.Moodle.mod_quiz.util.slot.reorderSlots(); + Y.Moodle.mod_quiz.util.slot.reorderPageBreaks(); + Y.Moodle.mod_quiz.util.page.reorderPages(); }, NAME : 'mod_quiz-resource-toolbox', 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 4dc2ceb1f20..963665b9506 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,2 +1,2 @@ -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",MODULEIDPREFIX:"slot-",PAGE:"page",SECTIONHIDDENCLASS:"hidden",SECTIONIDPREFIX:"section-",SLOT:"slot",SHOW:"editing_show",TITLEEDITOR:"titleeditor"},r={ACTIONAREA:".actions",ACTIONLINKTEXT:".actionlinktext",ACTIVITYACTION:"a.cm-edit-action[data-action], a.editing_maxmark",ACTIVITYFORM:"span.instancemaxmarkcontainer form",ACTIVITYICON:"img.activityicon",ACTIVITYINSTANCE:"."+n.ACTIVITYINSTANCE,ACTIVITYLINK:"."+n.ACTIVITYINSTANCE+" > a",ACTIVITYLI:"li.activity",ACTIVITYMAXMARK:"input[name=maxmark]",COMMANDSPAN:".commands",CONTENTAFTERLINK:"div.contentafterlink",CONTENTWITHOUTLINK:"div.contentwithoutlink",EDITMAXMARK:"a.editing_maxmark",HIDE:"a.editing_hide",HIGHLIGHT:"a.editing_highlight",INSTANCENAME:"span.instancename",INSTANCEMAXMARK:"span.instancemaxmark",MODINDENTDIV:".mod-indent",MODINDENTOUTER:".mod-indent-outer",PAGECONTENT:"div#page-content",PAGELI:"li.page",SECTIONUL:"ul.section",SHOW:"a."+n.SHOW,SHOWHIDE:"a.editing_showhide",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.newsummarks&&e.one(r.SUMMARKS).setHTML(f.newsummarks),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),i.delegate("key",this.handle_data_action,"down:enter",r.ACTIVITYACTION,this),e.delegate("click",this.handle_data_action,i,r.ACTIVITYACTION,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"linkpage":case"unlinkpage":this.link_page(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},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});return u.on("complete-yes",function(){i.remove(),e.Moodle.mod_quiz.util.slot.reorder_slots();var t={"class":"resource",action:"DELETE",id:e.Moodle.mod_quiz.util.slot.getId(i)};this.send_request(t),M.core.actionmenu&&M.core.actionmenu.instance&&M.core.actionmenu.instance.hideMenu(),window.location.reload(!0)},this),this},edit_maxmark:function(t,i,s){var o=e.Moodle.mod_quiz.util.slot.getId(s),u=s.one(r.INSTANCEMAXMARK),a=s.one(r.ACTIVITYINSTANCE),f=u.get("firstChild"),l=f.get("data"),c=l,h,p=u,d={"class":"resource",field:"getmaxmark",id:o};t.preventDefault(),this.send_request(d,null,function(t){M.core.actionmenu&&M.core.actionmenu.instance&&M.core.actionmenu.instance.hideMenu(),t.instancemaxmark&&(c=t.instancemaxmark);var r=e.Node.create(''),i=e.Node.create('').set("innerHTML",M.util.get_string("edittitleinstructions","moodle")),o=e.Node.create('').setAttrs({value:c,autocomplete:"off","aria-describedby":"id_editinstructions",maxLength:"12",size:parseInt(this.get("config").questiondecimalpoints,10)+2});r.appendChild(o),r.setData("anchor",p),a.insert(i,"before"),p.replace(r);var u="left";right_to_left()&&(u="right"),s.addClass(n.EDITINGMAXMARK),o.focus().select(),h=o.on("blur",this.edit_maxmark_cancel,this,s,!1),this.editmaxmarkevents.push(h),h=o.on("key",this.edit_maxmark_cancel,"esc",this,s,!0),this.editmaxmarkevents.push(h),h=r.on("submit",this.edit_maxmark_submit,this,s,l),this.editmaxmarkevents.push(h)})},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('')},link_page:function(t,n,r,i){t.preventDefault(),r=r.next("li.activity.slot");var s=this.add_spinner(r),o=0,u=i==="linkpage"?1:2,a={"class" -:"resource",field:"linkslottopage",id:o,value:u};return o=e.Moodle.mod_quiz.util.slot.getId(r),o&&(a.id=Number(o)),this.send_request(a,s,function(e){window.location.reload(!0)}),this},repaginate_slots:function(t){this.slots=t;var i=e.one(r.PAGECONTENT+" "+r.SECTIONUL),s=i.all(r.ACTIVITYLI);s.each(function(t){var i,s;t.hasClass(n.PAGE)?(i=this.NODE_PAGE,s=t.next(r.SLOTLI)):t.hasClass(n.SLOT)?(i=this.NODE_SLOT,s=t):t.hasClass(n.JOIN)&&(i=this.NODE_JOIN,s=t.previous(r.SLOTLI));var o=Number(e.Moodle.mod_quiz.util.slot.getNumber(s));if(!i)return;if(!this.slots.hasOwnProperty(o))return;var u=this.slots[o];if(i===this.NODE_PAGE){var a=e.Moodle.mod_quiz.util.page.getNumber(t);if(u.page===a){console.log("slotdata.page == pagenumber return");return}a slotdata.page update page number")}},this)},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,{initializer:function(){M.mod_quiz.quizbase.register_module(this),e.delegate("click",this.toggle_highlight,r.PAGECONTENT,r.SECTIONLI+" "+r.HIGHLIGHT,this),e.delegate("click",this.toggle_hide_section,r.PAGECONTENT,r.SECTIONLI+" "+r.SHOWHIDE,this)},toggle_hide_section:function(t){t.preventDefault();var i=t.target.ancestor(M.mod_quiz.format.get_section_selector(e)),s=t.target.ancestor("a",!0),o=s.one("img"),u,a,f;i.hasClass(n.SECTIONHIDDENCLASS)?(i.removeClass(n.SECTIONHIDDENCLASS),u=1,a="show",f="hide"):(i.addClass(n.SECTIONHIDDENCLASS),u=0,a="hide",f="show");var l=M.util.get_string(f+"fromothers","format_"+this.get("format"));o.setAttrs({alt:l,src:M.util.image_url("i/"+f)}),s.set("title",l);var c={"class":"section",field:"visible",id:e.Moodle.core_course.util.section.getId(i.ancestor(M.mod_quiz.edit.get_section_wrapper(e),!0)),value:u},h=M.util.add_lightbox(e,i);h.show(),this.send_request(c,h,function(t){var n=i.all(r.ACTIVITYLI);n.each(function(n){var i;n.one(r.SHOW)?i=n.one(r.SHOW):i=n.one(r.HIDE);var s=e.Moodle.mod_quiz.util.slot.getId(n);e.Array.indexOf(t.resourcestotoggle,""+s)!==-1&&M.mod_quiz.resource_toolbox.handle_resource_dim(i,n,a)},this)})},toggle_highlight:function(t){t.preventDefault();var n=t.target.ancestor(M.mod_quiz.edit.get_section_selector(e)),i=t.target.ancestor("a",!0),s=i.one("img"),o=n.hasClass("current"),u=0,a=M.util.get_string("markthistopic","moodle");e.one(r.PAGECONTENT).all(M.mod_quiz.edit.get_section_selector(e)+".current "+r.HIGHLIGHT).set("title",a),e.one(r.PAGECONTENT).all(M.mod_quiz.edit.get_section_selector(e)+".current "+r.HIGHLIGHT+" img").set("alt",a).set("src",M.util.image_url("i/marker")),e.one(r.PAGECONTENT).all(M.mod_quiz.edit.get_section_selector(e)).removeClass("current");if(!o){n.addClass("current"),u=e.Moodle.core_course.util.section.getId(n.ancestor(M.mod_quiz.edit.get_section_wrapper(e),!0));var f=M.util.get_string("markedthistopic","moodle");i.set("title",f),s.set("alt",f).set("src",M.util.image_url("i/marked"))}var l={"class":"course",field:"marker",value:u},c=M.util.add_lightbox(e,n);c.show(),this.send_request(l,c)}},{NAME:"mod_quiz-section-toolbox",ATTRS:{courseid:{value:0},quizid:{value:0},format:{value:"topics"}}}),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",MODULEIDPREFIX:"slot-",PAGE:"page",SECTIONHIDDENCLASS:"hidden",SECTIONIDPREFIX:"section-",SLOT:"slot",SHOW:"editing_show",TITLEEDITOR:"titleeditor"},r={ACTIONAREA:".actions",ACTIONLINKTEXT:".actionlinktext",ACTIVITYACTION:"a.cm-edit-action[data-action], a.editing_maxmark",ACTIVITYFORM:"span.instancemaxmarkcontainer form",ACTIVITYICON:"img.activityicon",ACTIVITYINSTANCE:"."+n.ACTIVITYINSTANCE,ACTIVITYLINK:"."+n.ACTIVITYINSTANCE+" > a",ACTIVITYLI:"li.activity",ACTIVITYMAXMARK:"input[name=maxmark]",COMMANDSPAN:".commands",CONTENTAFTERLINK:"div.contentafterlink",CONTENTWITHOUTLINK:"div.contentwithoutlink",EDITMAXMARK:"a.editing_maxmark",HIDE:"a.editing_hide",HIGHLIGHT:"a.editing_highlight",INSTANCENAME:"span.instancename",INSTANCEMAXMARK:"span.instancemaxmark",MODINDENTDIV:".mod-indent",MODINDENTOUTER:".mod-indent-outer",PAGECONTENT:"div#page-content",PAGELI:"li.page",SECTIONUL:"ul.section",SHOW:"a."+n.SHOW,SHOWHIDE:"a.editing_showhide",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.newsummarks&&e.one(r.SUMMARKS).setHTML(f.newsummarks),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),i.delegate("key",this.handle_data_action,"down:enter",r.ACTIVITYACTION,this),e.delegate("click",this.handle_data_action,i,r.ACTIVITYACTION,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;default:}},add_spinner:function(t){var n=t.one(r.ACTIONAREA);return n?M.util.add_spinner(e,n):null},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});return u.on("complete-yes",function(){var t=this.add_spinner(i),n={"class":"resource",action:"DELETE",id:e.Moodle.mod_quiz.util.slot.getId(i)};this.send_request(n,t,function(t){t.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()):window.location.reload(!0)})},this),this},edit_maxmark:function(t,i,s){var o=e.Moodle.mod_quiz.util.slot.getId(s),u=s.one(r.INSTANCEMAXMARK),a=s.one(r.ACTIVITYINSTANCE),f=u.get("firstChild"),l=f.get("data"),c=l,h,p=u,d={"class":"resource",field:"getmaxmark",id:o};t.preventDefault(),this.send_request(d,null,function(t){M.core.actionmenu&&M.core.actionmenu.instance&&M.core.actionmenu.instance.hideMenu(),t.instancemaxmark&&(c=t.instancemaxmark);var r=e.Node.create(''),i=e.Node.create('').set("innerHTML",M.util.get_string("edittitleinstructions","moodle")),o=e.Node.create('').setAttrs({value:c,autocomplete:"off","aria-describedby":"id_editinstructions",maxLength:"12",size:parseInt(this.get("config").questiondecimalpoints,10)+2});r.appendChild(o),r.setData("anchor",p),a.insert(i,"before"),p.replace(r);var u="left";right_to_left()&&(u="right"),s.addClass(n.EDITINGMAXMARK),o.focus().select(),h=o.on("blur",this.edit_maxmark_cancel,this,s,!1),this.editmaxmarkevents.push(h),h=o.on("key",this.edit_maxmark_cancel,"esc",this,s,!0),this.editmaxmarkevents.push(h),h=r.on("submit",this.edit_maxmark_submit,this,s,l),this.editmaxmarkevents.push(h)})},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(),nextactivity= +r.next("li.activity.slot");var s=this.add_spinner(nextactivity),o=0,u=i==="removepagebreak"?1:2,a={"class":"resource",field:"updatepagebreak",id:o,value:u};return o=e.Moodle.mod_quiz.util.slot.getId(nextactivity),o&&(a.id=Number(o)),this.send_request(a,s,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()}else window.location.reload(!0)}),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()},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,{initializer:function(){M.mod_quiz.quizbase.register_module(this),e.delegate("click",this.toggle_highlight,r.PAGECONTENT,r.SECTIONLI+" "+r.HIGHLIGHT,this),e.delegate("click",this.toggle_hide_section,r.PAGECONTENT,r.SECTIONLI+" "+r.SHOWHIDE,this)},toggle_hide_section:function(t){t.preventDefault();var i=t.target.ancestor(M.mod_quiz.format.get_section_selector(e)),s=t.target.ancestor("a",!0),o=s.one("img"),u,a,f;i.hasClass(n.SECTIONHIDDENCLASS)?(i.removeClass(n.SECTIONHIDDENCLASS),u=1,a="show",f="hide"):(i.addClass(n.SECTIONHIDDENCLASS),u=0,a="hide",f="show");var l=M.util.get_string(f+"fromothers","format_"+this.get("format"));o.setAttrs({alt:l,src:M.util.image_url("i/"+f)}),s.set("title",l);var c={"class":"section",field:"visible",id:e.Moodle.core_course.util.section.getId(i.ancestor(M.mod_quiz.edit.get_section_wrapper(e),!0)),value:u},h=M.util.add_lightbox(e,i);h.show(),this.send_request(c,h,function(t){var n=i.all(r.ACTIVITYLI);n.each(function(n){var i;n.one(r.SHOW)?i=n.one(r.SHOW):i=n.one(r.HIDE);var s=e.Moodle.mod_quiz.util.slot.getId(n);e.Array.indexOf(t.resourcestotoggle,""+s)!==-1&&M.mod_quiz.resource_toolbox.handle_resource_dim(i,n,a)},this)})},toggle_highlight:function(t){t.preventDefault();var n=t.target.ancestor(M.mod_quiz.edit.get_section_selector(e)),i=t.target.ancestor("a",!0),s=i.one("img"),o=n.hasClass("current"),u=0,a=M.util.get_string("markthistopic","moodle");e.one(r.PAGECONTENT).all(M.mod_quiz.edit.get_section_selector(e)+".current "+r.HIGHLIGHT).set("title",a),e.one(r.PAGECONTENT).all(M.mod_quiz.edit.get_section_selector(e)+".current "+r.HIGHLIGHT+" img").set("alt",a).set("src",M.util.image_url("i/marker")),e.one(r.PAGECONTENT).all(M.mod_quiz.edit.get_section_selector(e)).removeClass("current");if(!o){n.addClass("current"),u=e.Moodle.core_course.util.section.getId(n.ancestor(M.mod_quiz.edit.get_section_wrapper(e),!0));var f=M.util.get_string("markedthistopic","moodle");i.set("title",f),s.set("alt",f).set("src",M.util.image_url("i/marked"))}var l={"class":"course",field:"marker",value:u},c=M.util.add_lightbox(e,n);c.show(),this.send_request(l,c)}},{NAME:"mod_quiz-section-toolbox",ATTRS:{courseid:{value:0},quizid:{value:0},format:{value:"topics"}}}),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 aece0a61743..e005dd683ea 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 @@ -311,10 +311,10 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // The user is deleting the activity. this.delete_with_confirmation(ev, node, activity, action); break; - case 'linkpage': - case 'unlinkpage': - // The user is linking or unlinking pages. - this.link_page(ev, node, activity, action); + case 'addpagebreak': + case 'removepagebreak': + // The user is adding or removing a page break. + this.update_page_break(ev, node, activity, action); break; default: // Nothing to do here! @@ -350,10 +350,10 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @chainable */ delete_with_confirmation: function(ev, button, activity) { - // Prevent the default button action + // Prevent the default button action. ev.preventDefault(); - // Get the element we're working on + // Get the element we're working on. var element = activity, // Create confirm string (different if element has or does not have name) confirmstring = '', @@ -370,19 +370,24 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // If it is confirmed. confirm.on('complete-yes', function() { - // Actually remove the element. - element.remove(); - Y.Moodle.mod_quiz.util.slot.reorder_slots(); + var spinner = this.add_spinner(element); var data = { 'class': 'resource', 'action': 'DELETE', 'id': Y.Moodle.mod_quiz.util.slot.getId(element) }; - this.send_request(data); - if (M.core.actionmenu && M.core.actionmenu.instance) { - M.core.actionmenu.instance.hideMenu(); - } - window.location.reload(true); + this.send_request(data, spinner, function(response) { + if (response.deleted) { + // Actually remove the element. + Y.Moodle.mod_quiz.util.slot.remove(element); + this.reorganise_edit_page(); + if (M.core.actionmenu && M.core.actionmenu.instance) { + M.core.actionmenu.instance.hideMenu(); + } + } else { + window.location.reload(true); + } + }); }, this); @@ -425,12 +430,12 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { M.core.actionmenu.instance.hideMenu(); } - // Try to retrieve the existing string from the server + // Try to retrieve the existing string from the server. if (response.instancemaxmark) { maxmarktext = response.instancemaxmark; } - // Create the editor and submit button + // Create the editor and submit button. var editform = Y.Node.create(''); var editinstructions = Y.Node.create('') .set('innerHTML', M.util.get_string('edittitleinstructions', 'moodle')); @@ -442,7 +447,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { 'size' : parseInt(this.get('config').questiondecimalpoints, 10) + 2 }); - // Clear the existing content and put the editor in + // Clear the existing content and put the editor in. editform.appendChild(editor); editform.setData('anchor', anchor); instance.insert(editinstructions, 'before'); @@ -457,7 +462,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // We hide various components whilst editing: activity.addClass(CSS.EDITINGMAXMARK); - // Focus and select the editor text + // Focus and select the editor text. editor.focus().select(); // Cancel the edit if we lose focus or the escape key is pressed. @@ -482,7 +487,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @param {String} originalmaxmark The original maxmark the activity or resource had. */ edit_maxmark_submit : function(ev, activity, originalmaxmark) { - // We don't actually want to submit anything + // We don't actually want to submit anything. ev.preventDefault(); var newmaxmark = Y.Lang.trim(activity.one(SELECTOR.ACTIVITYFORM + ' ' + SELECTOR.ACTIVITYMAXMARK).get('value')); var spinner = this.add_spinner(activity); @@ -560,97 +565,59 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * the other slots * * @protected - * @method link_page + * @method update_page_break * @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 */ - link_page: function(ev, button, activity, action) { + update_page_break: function(ev, button, activity, action) { // Prevent the default button action ev.preventDefault(); - activity = activity.next('li.activity.slot'); - var spinner = this.add_spinner(activity), + nextactivity = activity.next('li.activity.slot'); + var spinner = this.add_spinner(nextactivity), slotid = 0; - var value = action === 'linkpage' ? 1:2; + var value = action === 'removepagebreak' ? 1 : 2; var data = { 'class': 'resource', - 'field': 'linkslottopage', + 'field': 'updatepagebreak', 'id': slotid, 'value': value }; - slotid = Y.Moodle.mod_quiz.util.slot.getId(activity); + slotid = Y.Moodle.mod_quiz.util.slot.getId(nextactivity); if (slotid) { data.id = Number(slotid); } this.send_request(data, spinner, function(response) { - window.location.reload(true); -// if (response.slots) { -// this.repaginate_slots(response.slots); -// } + if (response.slots) { + if (action === 'addpagebreak') { + Y.Moodle.mod_quiz.util.page.add(activity); + } else { + var page = activity.next(Y.Moodle.mod_quiz.util.page.SELECTORS.PAGE); + Y.Moodle.mod_quiz.util.page.remove(page, true); + } + this.reorganise_edit_page(); + } else { + window.location.reload(true); + } }); return this; }, - repaginate_slots: function(slots) { - this.slots = slots; - var section = Y.one(SELECTOR.PAGECONTENT + ' ' + SELECTOR.SECTIONUL), - activities = section.all(SELECTOR.ACTIVITYLI); - activities.each(function(node) { - // What element is it? page/slot/link - // what is the current slot? - var type; - var slot; - if(node.hasClass(CSS.PAGE)){ - type = this.NODE_PAGE; - slot = node.next(SELECTOR.SLOTLI); - } else if (node.hasClass(CSS.SLOT)){ - type = this.NODE_SLOT; - slot = node; - } else if (node.hasClass(CSS.JOIN)){ - type = this.NODE_JOIN; - slot = node.previous(SELECTOR.SLOTLI); - } - - // getSlotnumber() Should be a method of util.slot - var slotnumber = Number(Y.Moodle.mod_quiz.util.slot.getNumber(slot)); - if(!type){ - // Nothing we can do. - return; - } - - // Is it correct? - if(!this.slots.hasOwnProperty(slotnumber)){ - // An error. We should handle this. - return; - } - - var slotdata = this.slots[slotnumber]; - - if(type === this.NODE_PAGE){ - // Get page number - var pagenumber = Y.Moodle.mod_quiz.util.page.getNumber(node); - // Is the page number correct? - if (slotdata.page === pagenumber) { - console.log('slotdata.page == pagenumber return'); - return; - } - - if (pagenumber < slotdata.page) { - // Remove page node. - node.remove(); - } - else { - // Add page node. - console.log('pagenumber > slotdata.page update page number'); - } - - } - }, this); + /** + * Reorganise the UI after every edit action. + * + * @protected + * @method reorganise_edit_page + */ + reorganise_edit_page: function() { + Y.Moodle.mod_quiz.util.slot.reorderSlots(); + Y.Moodle.mod_quiz.util.slot.reorderPageBreaks(); + Y.Moodle.mod_quiz.util.page.reorderPages(); }, NAME : 'mod_quiz-resource-toolbox', diff --git a/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page-debug.js b/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page-debug.js index 7882b6f5ae0..d71f03887a0 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page-debug.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page-debug.js @@ -16,13 +16,23 @@ Y.namespace('Moodle.mod_quiz.util.page'); * @static */ Y.Moodle.mod_quiz.util.page = { + CSS: { + PAGE : 'page' + }, CONSTANTS: { - PAGEIDPREFIX : 'page-', - PAGENUMBERPREFIX : 'Page ' + 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' + INSTANCENAME: '.instancename', + NUMBER: 'span.text' }, /** @@ -37,7 +47,18 @@ Y.Moodle.mod_quiz.util.page = { }, /** - * Determines the page ID for the provided page. + * Retrieve the page item from one of it's previous siblings. + * + * @method getPageFromSlot + * @param pagecomponent {Node} The component Node. + * @return {Node|null} The Page Node. + */ + getPageFromSlot: function(slot) { + return Y.one(slot).previous(this.SELECTORS.PAGE); + }, + + /** + * Returns the page ID for the provided page. * * @method getId * @param page {Node} The page to find an ID for. @@ -56,6 +77,18 @@ Y.Moodle.mod_quiz.util.page = { return false; }, + /** + * Updates the page id for the provided page. + * + * @method setId + * @param page {Node} The page to update the number for. + * @param id int The id value. + * @return void + */ + setId: function(page, id) { + page.set('id', this.CONSTANTS.PAGEIDPREFIX + id); + }, + /** * Determines the page name for the provided page. * @@ -79,8 +112,8 @@ Y.Moodle.mod_quiz.util.page = { * @return {Number|false} The number of the page in question or false if no number was found. */ getNumber: function(page) { - // We perform a simple substitution operation to get the ID. - var number = page.get('text').replace( + // We perform a simple substitution operation to get the number. + var number = page.one(this.SELECTORS.NUMBER).get('text').replace( this.CONSTANTS.PAGENUMBERPREFIX, ''); // Attempt to validate the ID. @@ -89,6 +122,206 @@ Y.Moodle.mod_quiz.util.page = { return number; } return false; + }, + + /** + * Updates the page number for the provided page. + * + * @method setNumber + * @param page {Node} The page to update the number for. + * @return void + */ + setNumber: function(page, number) { + page.one(this.SELECTORS.NUMBER).set('text', this.CONSTANTS.PAGENUMBERPREFIX + number); + }, + + /** + * Returns a list of all page elements. + * + * @method getPages + * @return {node[]} An array containing page nodes. + */ + getPages: function() { + return Y.all(Y.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT + ' ' + Y.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL + ' ' + this.SELECTORS.PAGE); + }, + + /** + * Is the given element a page element? + * + * @method isPage + * @param page Page node + * @return boolean + */ + isPage: function(page) { + if (!page) { + return false; + } + return page.hasClass(this.CSS.PAGE); + }, + + /** + * Does the page have atleast one slot? + * + * @method isEmpty + * @param page Page node + * @return boolean + */ + isEmpty: function(page) { + var activity = page.next('li.activity'); + if (!activity) { + return true; + } + return !activity.hasClass('slot'); + }, + + /** + * Add a page and related elements to the list of slots. + * + * @method add + * @param beforenode Int | Node | HTMLElement | String to add + * @return page Page node + */ + add: function(beforenode) { + var pagenumber = this.getNumber(this.getPageFromSlot(beforenode)) + 1; + var pagehtml = M.mod_quiz.resource_toolbox.get('config').pagehtml; + + // Normalise the page number. + pagehtml = pagehtml.replace(/%%PAGENUMBER%%/g, pagenumber); + + // Create the page node. + var page = Y.Node.create(pagehtml); + + // Assign is as a drop target. + YUI().use('dd-drop', function(Y) { + var drop = new Y.DD.Drop({ + node: page, + groups: M.mod_quiz.dragres.groups + }); + page.drop = drop; + }); + + // Insert in the correct place. + beforenode.insert(page, 'after'); + + // Enhance the add menu to make if fully visible and clickable. + M.core.actionmenu.newDOMNode(page); + return page; + }, + + /** + * Remove a page and related elements from the list of slots. + * + * @method remove + * @param page Page node + * @return void + */ + remove: function(page, keeppagebreak) { + // Remove page break from previous slot. + var previousslot = page.previous(Y.Moodle.mod_quiz.util.slot.SELECTORS.SLOT); + if (!keeppagebreak && previousslot) { + Y.Moodle.mod_quiz.util.slot.removePageBreak(previousslot); + } + page.remove(); + }, + + /** + * Reset the order of the numbers given to each page. + * + * @method reorderPages + * @return void + */ + reorderPages: function() { + // Get list of page nodes. + var pages = this.getPages(), currentpagenumber = 0; + // Loop through pages incrementing the number each time. + pages.each(function(page) { + // Is the page empty? + if (this.isEmpty(page)) { + var keeppagebreak = page.next('li.slot') ? true : false; + this.remove(page, keeppagebreak); + return; + } + + currentpagenumber++; + // Set page number. + this.setNumber(page, currentpagenumber); + this.setId(page, currentpagenumber); + }, this); + + // Reorder action menus + this.reorderActionMenus(); + }, + + /** + * Reset the order of the numbers given to each action menu. + * + * @method reorderActionMenus + * @return void + */ + reorderActionMenus: function() { + // Get list of action menu nodes. + var actionmenus = this.getActionMenus(); + // Loop through pages incrementing the number each time. + actionmenus.each(function(actionmenu, key) { + var previousActionMenu = actionmenus.item(key - 1); + previousActionMenunumber = 0; + if (previousActionMenu) { + previousActionMenunumber = this.getActionMenuId(previousActionMenu); + } + var id = previousActionMenunumber + 1; + + // Set menu id. + this.setActionMenuId(actionmenu, id); + + // Update action-menu-1-menubar + var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR); + menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX); + // Update action-menu-1-menu + var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU); + menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX); + }, this); + }, + + /** + * Returns a list of all page elements. + * + * @method getActionMenus + * @return {node[]} An array containing page nodes. + */ + getActionMenus: function() { + return Y.all(Y.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT + ' ' + Y.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL + ' ' + this.SELECTORS.ACTIONMENU); + }, + + /** + * Returns the ID for the provided action menu. + * + * @method getId + * @param actionmenu {Node} The actionmenu to find an ID for. + * @return {Number|false} The ID of the actionmenu in question or false if no ID was found. + */ + getActionMenuId: function(actionmenu) { + // We perform a simple substitution operation to get the ID. + var id = actionmenu.get('id').replace( + this.CONSTANTS.ACTIONMENUIDPREFIX, ''); + + // Attempt to validate the ID. + id = parseInt(id, 10); + if (typeof id === 'number' && isFinite(id)) { + return id; + } + return false; + }, + + /** + * Updates the page id for the provided page. + * + * @method setId + * @param page {Node} The page to update the number for. + * @param id int The id value. + * @return void + */ + setActionMenuId: function(actionmenu, id) { + actionmenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id); } }; diff --git a/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page-min.js b/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page-min.js index 24de48ea012..2e23af26501 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page-min.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page-min.js @@ -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={CONSTANTS:{PAGEIDPREFIX:"page-",PAGENUMBERPREFIX:"Page "},SELECTORS:{PAGE:"li.page",INSTANCENAME:".instancename"},getPageFromComponent:function(t){return e.one(t).ancestor(this.SELECTORS.PAGE,!0)},getId:function(e){var t=e.get("id").replace(this.CONSTANTS.PAGEIDPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},getName:function(e){var t=e.one(this.SELECTORS.INSTANCENAME);return t?t.get("firstChild").get("data"):null},getNumber:function(e){var t=e.get("text").replace(this.CONSTANTS.PAGENUMBERPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1}}},"@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:"span.text"},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);previousActionMenunumber=0,r&&(previousActionMenunumber=this.getActionMenuId(r));var i=previousActionMenunumber+1;this.setActionMenuId(t,i);var s=t.one(this.SELECTORS.ACTIONMENUBAR);s.set("id",this.CONSTANTS.ACTIONMENUIDPREFIX+i+this.CONSTANTS.ACTIONMENUBARIDSUFFIX);var o=t.one(this.SELECTORS.ACTIONMENUMENU);o.set("id",this.CONSTANTS.ACTIONMENUIDPREFIX+i+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"]}); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page.js b/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page.js index 7882b6f5ae0..d71f03887a0 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-util-page/moodle-mod_quiz-util-page.js @@ -16,13 +16,23 @@ Y.namespace('Moodle.mod_quiz.util.page'); * @static */ Y.Moodle.mod_quiz.util.page = { + CSS: { + PAGE : 'page' + }, CONSTANTS: { - PAGEIDPREFIX : 'page-', - PAGENUMBERPREFIX : 'Page ' + 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' + INSTANCENAME: '.instancename', + NUMBER: 'span.text' }, /** @@ -37,7 +47,18 @@ Y.Moodle.mod_quiz.util.page = { }, /** - * Determines the page ID for the provided page. + * Retrieve the page item from one of it's previous siblings. + * + * @method getPageFromSlot + * @param pagecomponent {Node} The component Node. + * @return {Node|null} The Page Node. + */ + getPageFromSlot: function(slot) { + return Y.one(slot).previous(this.SELECTORS.PAGE); + }, + + /** + * Returns the page ID for the provided page. * * @method getId * @param page {Node} The page to find an ID for. @@ -56,6 +77,18 @@ Y.Moodle.mod_quiz.util.page = { return false; }, + /** + * Updates the page id for the provided page. + * + * @method setId + * @param page {Node} The page to update the number for. + * @param id int The id value. + * @return void + */ + setId: function(page, id) { + page.set('id', this.CONSTANTS.PAGEIDPREFIX + id); + }, + /** * Determines the page name for the provided page. * @@ -79,8 +112,8 @@ Y.Moodle.mod_quiz.util.page = { * @return {Number|false} The number of the page in question or false if no number was found. */ getNumber: function(page) { - // We perform a simple substitution operation to get the ID. - var number = page.get('text').replace( + // We perform a simple substitution operation to get the number. + var number = page.one(this.SELECTORS.NUMBER).get('text').replace( this.CONSTANTS.PAGENUMBERPREFIX, ''); // Attempt to validate the ID. @@ -89,6 +122,206 @@ Y.Moodle.mod_quiz.util.page = { return number; } return false; + }, + + /** + * Updates the page number for the provided page. + * + * @method setNumber + * @param page {Node} The page to update the number for. + * @return void + */ + setNumber: function(page, number) { + page.one(this.SELECTORS.NUMBER).set('text', this.CONSTANTS.PAGENUMBERPREFIX + number); + }, + + /** + * Returns a list of all page elements. + * + * @method getPages + * @return {node[]} An array containing page nodes. + */ + getPages: function() { + return Y.all(Y.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT + ' ' + Y.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL + ' ' + this.SELECTORS.PAGE); + }, + + /** + * Is the given element a page element? + * + * @method isPage + * @param page Page node + * @return boolean + */ + isPage: function(page) { + if (!page) { + return false; + } + return page.hasClass(this.CSS.PAGE); + }, + + /** + * Does the page have atleast one slot? + * + * @method isEmpty + * @param page Page node + * @return boolean + */ + isEmpty: function(page) { + var activity = page.next('li.activity'); + if (!activity) { + return true; + } + return !activity.hasClass('slot'); + }, + + /** + * Add a page and related elements to the list of slots. + * + * @method add + * @param beforenode Int | Node | HTMLElement | String to add + * @return page Page node + */ + add: function(beforenode) { + var pagenumber = this.getNumber(this.getPageFromSlot(beforenode)) + 1; + var pagehtml = M.mod_quiz.resource_toolbox.get('config').pagehtml; + + // Normalise the page number. + pagehtml = pagehtml.replace(/%%PAGENUMBER%%/g, pagenumber); + + // Create the page node. + var page = Y.Node.create(pagehtml); + + // Assign is as a drop target. + YUI().use('dd-drop', function(Y) { + var drop = new Y.DD.Drop({ + node: page, + groups: M.mod_quiz.dragres.groups + }); + page.drop = drop; + }); + + // Insert in the correct place. + beforenode.insert(page, 'after'); + + // Enhance the add menu to make if fully visible and clickable. + M.core.actionmenu.newDOMNode(page); + return page; + }, + + /** + * Remove a page and related elements from the list of slots. + * + * @method remove + * @param page Page node + * @return void + */ + remove: function(page, keeppagebreak) { + // Remove page break from previous slot. + var previousslot = page.previous(Y.Moodle.mod_quiz.util.slot.SELECTORS.SLOT); + if (!keeppagebreak && previousslot) { + Y.Moodle.mod_quiz.util.slot.removePageBreak(previousslot); + } + page.remove(); + }, + + /** + * Reset the order of the numbers given to each page. + * + * @method reorderPages + * @return void + */ + reorderPages: function() { + // Get list of page nodes. + var pages = this.getPages(), currentpagenumber = 0; + // Loop through pages incrementing the number each time. + pages.each(function(page) { + // Is the page empty? + if (this.isEmpty(page)) { + var keeppagebreak = page.next('li.slot') ? true : false; + this.remove(page, keeppagebreak); + return; + } + + currentpagenumber++; + // Set page number. + this.setNumber(page, currentpagenumber); + this.setId(page, currentpagenumber); + }, this); + + // Reorder action menus + this.reorderActionMenus(); + }, + + /** + * Reset the order of the numbers given to each action menu. + * + * @method reorderActionMenus + * @return void + */ + reorderActionMenus: function() { + // Get list of action menu nodes. + var actionmenus = this.getActionMenus(); + // Loop through pages incrementing the number each time. + actionmenus.each(function(actionmenu, key) { + var previousActionMenu = actionmenus.item(key - 1); + previousActionMenunumber = 0; + if (previousActionMenu) { + previousActionMenunumber = this.getActionMenuId(previousActionMenu); + } + var id = previousActionMenunumber + 1; + + // Set menu id. + this.setActionMenuId(actionmenu, id); + + // Update action-menu-1-menubar + var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR); + menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX); + // Update action-menu-1-menu + var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU); + menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX); + }, this); + }, + + /** + * Returns a list of all page elements. + * + * @method getActionMenus + * @return {node[]} An array containing page nodes. + */ + getActionMenus: function() { + return Y.all(Y.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT + ' ' + Y.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL + ' ' + this.SELECTORS.ACTIONMENU); + }, + + /** + * Returns the ID for the provided action menu. + * + * @method getId + * @param actionmenu {Node} The actionmenu to find an ID for. + * @return {Number|false} The ID of the actionmenu in question or false if no ID was found. + */ + getActionMenuId: function(actionmenu) { + // We perform a simple substitution operation to get the ID. + var id = actionmenu.get('id').replace( + this.CONSTANTS.ACTIONMENUIDPREFIX, ''); + + // Attempt to validate the ID. + id = parseInt(id, 10); + if (typeof id === 'number' && isFinite(id)) { + return id; + } + return false; + }, + + /** + * Updates the page id for the provided page. + * + * @method setId + * @param page {Node} The page to update the number for. + * @param id int The id value. + * @return void + */ + setActionMenuId: function(actionmenu, id) { + actionmenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id); } }; diff --git a/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot-debug.js b/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot-debug.js index 38e3e0ad10f..9992cdfb0d1 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot-debug.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot-debug.js @@ -16,14 +16,22 @@ Y.namespace('Moodle.mod_quiz.util.slot'); * @static */ Y.Moodle.mod_quiz.util.slot = { + CSS: { + SLOT : 'slot', + QUESTIONTYPEDESCRIPTION : 'qtype_description' + }, CONSTANTS: { - SLOTIDPREFIX : 'slot-' + SLOTIDPREFIX : 'slot-', + QUESTION : M.util.get_string('question', 'moodle') }, SELECTORS: { SLOT: 'li.slot', INSTANCENAME: '.instancename', NUMBER: 'span.slotnumber', PAGECONTENT : 'div#page-content', + PAGEBREAK : 'span.page_split_join_wrapper', + ICON : 'img.smallicon', + QUESTIONTYPEDESCRIPTION : '.qtype_description', SECTIONUL : 'ul.section' }, @@ -81,7 +89,12 @@ Y.Moodle.mod_quiz.util.slot = { * @return {Number|false} The number of the slot in question or false if no number was found. */ getNumber: function(slot) { - var number = slot.one(this.SELECTORS.NUMBER).get('text'); + if (!slot) { + return false; + } + // We perform a simple substitution operation to get the number. + var number = slot.one(this.SELECTORS.NUMBER).get('text').replace( + this.CONSTANTS.QUESTION, ''); // Attempt to validate the ID. number = parseInt(number, 10); if (typeof number === 'number' && isFinite(number)) { @@ -98,7 +111,8 @@ Y.Moodle.mod_quiz.util.slot = { * @return void */ setNumber: function(slot, number) { - slot.one(this.SELECTORS.NUMBER).set('text', number); + var numbernode = slot.one(this.SELECTORS.NUMBER); + numbernode.setHTML('' + this.CONSTANTS.QUESTION + ' ' + number); }, /** @@ -112,7 +126,19 @@ Y.Moodle.mod_quiz.util.slot = { }, /** - * Returns the previous slot to the give slot. + * Returns a list of all slot elements on the page that have numbers. Excudes description questions. + * + * @method getSlots + * @return {node[]} An array containing slot nodes. + */ + getNumberedSlots: function() { + var selector = this.SELECTORS.PAGECONTENT + ' ' + this.SELECTORS.SECTIONUL; + selector += ' ' + this.SELECTORS.SLOT + ':not(' + this.SELECTORS.QUESTIONTYPEDESCRIPTION + ')'; + return Y.all(selector); + }, + + /** + * Returns the previous slot to the given slot. * * @method getPrevious * @param slot Slot node @@ -122,27 +148,191 @@ Y.Moodle.mod_quiz.util.slot = { return slot.previous(this.SELECTORS.SLOT); }, + /** + * Returns the previous numbered slot to the given slot. + * + * Ignores slots containing description question types. + * + * @method getPrevious + * @param slot Slot node + * @return {node|false} The previous slot node or false. + */ + getPreviousNumbered: function(slot) { + return slot.previous(this.SELECTORS.SLOT + ':not(' + this.SELECTORS.QUESTIONTYPEDESCRIPTION + ')'); + }, + /** * Reset the order of the numbers given to each slot. * - * @method reorder_slots + * @method reorderSlots * @return void */ - reorder_slots: function() { + reorderSlots: function() { // Get list of slot nodes. var slots = this.getSlots(); // Loop through slots incrementing the number each time. slots.each(function(slot) { - var previousSlot = this.getPrevious(slot), - previousslotnumber = 0; - if(previousSlot){ + + if (!Y.Moodle.mod_quiz.util.page.getPageFromSlot(slot)) { + // Move the next page to the front. + var nextpage = slot.next(Y.Moodle.mod_quiz.util.page.SELECTORS.PAGE); + slot.swap(nextpage); + } + + var previousSlot = this.getPreviousNumbered(slot); + previousslotnumber = 0; + if (slot.hasClass(this.CSS.QUESTIONTYPEDESCRIPTION)) { + return; + } + + if (previousSlot) { previousslotnumber = this.getNumber(previousSlot); } // Set slot number. this.setNumber(slot, previousslotnumber + 1); }, this); + }, + /** + * Remove a slot and related elements from the list of slots. + * + * @method remove + * @param slot Slot node + * @return void + */ + remove: function(slot) { + var page = Y.Moodle.mod_quiz.util.page.getPageFromSlot(slot); + slot.remove(); + // Is the page empty. + if (!Y.Moodle.mod_quiz.util.page.isEmpty(page)) { + return; + } + // If so remove it. Including add menu and page break. + Y.Moodle.mod_quiz.util.page.remove(page); + }, + + /** + * Returns a list of all page break elements on the page. + * + * @method getPageBreaks + * @return {node[]} An array containing page break nodes. + */ + getPageBreaks: function() { + var selector = this.SELECTORS.PAGECONTENT + ' ' + this.SELECTORS.SECTIONUL; + selector += ' ' + this.SELECTORS.SLOT + this.SELECTORS.PAGEBREAK; + return Y.all(selector); + }, + + /** + * Retrieve the page break element item from the given slot. + * + * @method getPageBreak + * @param slot Slot node + * @return {Node|null} The Page Break Node. + */ + getPageBreak: function(slot) { + return Y.one(slot).one(this.SELECTORS.PAGEBREAK); + }, + + /** + * Add a page break and related elements to the list of slots. + * + * @method addPageBreak + * @param beforenode Int | Node | HTMLElement | String to add + * @return pagebreak PageBreak node + */ + addPageBreak: function(slot) { + var nodetext = M.mod_quiz.resource_toolbox.get('config').addpageiconhtml; + nodetext = nodetext.replace('%%SLOT%%', this.getNumber(slot)); + var pagebreak = Y.Node.create(nodetext); + slot.one('div').insert(pagebreak, 'after'); + return pagebreak; + }, + + /** + * Remove a pagebreak from the given slot. + * + * @method removePageBreak + * @param slot Slot node + * @return boolean + */ + removePageBreak: function(slot) { + var pagebreak = this.getPageBreak(slot); + if (!pagebreak) { + return false; + } + pagebreak.remove(); + return true; + }, + + /** + * Reorder each pagebreak by iterating through each related slot. + * + * @method reorderPageBreaks + * @return void + */ + reorderPageBreaks: function() { + // Get list of slot nodes. + var slots = this.getSlots(), slotnumber = 0; + // Loop through slots incrementing the number each time. + slots.each (function(slot, key) { + slotnumber++; + var pagebreak = this.getPageBreak(slot); + // Last slot won't have a page break. + if (!pagebreak && key === slots.size() - 1) { + return; + } + + // No pagebreak and not last slot. Add one. + if (!pagebreak && key !== slots.size() - 1) { + pagebreak = this.addPageBreak(slot); + } + + // Remove last page break if there is one. + if (pagebreak && key === slots.size() - 1) { + this.removePageBreak(slot); + } + + // Get page break anchor element. + var pagebreaklink = pagebreak.get('childNodes').item(0); + + // Get the correct title. + var action = '', iconname = ''; + if (Y.Moodle.mod_quiz.util.page.isPage(slot.next('li.activity'))) { + action = 'removepagebreak'; + iconname = 'e/remove_page_break'; + } else { + action = 'addpagebreak'; + iconname = 'e/insert_page_break'; + } + + // Update the link and image titles + pagebreaklink.set('title', M.util.get_string(action, 'quiz')); + pagebreaklink.setData('action', action); + // Update the image title. + var icon = pagebreaklink.one(this.SELECTORS.ICON); + icon.set('title', M.util.get_string(action, 'quiz')); + icon.set('alt', M.util.get_string(action, 'quiz')); + + // Update the image src. + icon.set('src', M.util.image_url(iconname)); + + // Get anchor url parameters as an associative array. + var params = Y.QueryString.parse(pagebreaklink.get('href')); + // Update slot number. + params.slot = slotnumber; + // Create the new url. + var newurl = ''; + for (var index in params) { + if (newurl.length) { + newurl += "&"; + } + newurl += index + "=" + params[index]; + } + // Update the anchor. + pagebreaklink.set('href', newurl); + }, this); } }; diff --git a/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot-min.js b/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot-min.js index ff750afa6c0..2c13207743a 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot-min.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot-min.js @@ -1 +1 @@ -YUI.add("moodle-mod_quiz-util-slot",function(e,t){e.namespace("Moodle.mod_quiz.util.slot"),e.Moodle.mod_quiz.util.slot={CONSTANTS:{SLOTIDPREFIX:"slot-"},SELECTORS:{SLOT:"li.slot",INSTANCENAME:".instancename",NUMBER:"span.slotnumber",PAGECONTENT:"div#page-content",SECTIONUL:"ul.section"},getSlotFromComponent:function(t){return e.one(t).ancestor(this.SELECTORS.SLOT,!0)},getId:function(e){var t=e.get("id").replace(this.CONSTANTS.SLOTIDPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},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");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},setNumber:function(e,t){e.one(this.SELECTORS.NUMBER).set("text",t)},getSlots:function(){return e.all(this.SELECTORS.PAGECONTENT+" "+this.SELECTORS.SECTIONUL+" "+this.SELECTORS.SLOT)},getPrevious:function(e){return e.previous(this.SELECTORS.SLOT)},reorder_slots:function(){var e=this.getSlots();e.each(function(e){var t=this.getPrevious(e),n=0;t&&(n=this.getNumber(t)),this.setNumber(e,n+1)},this)}}},"@VERSION@",{requires:["node","moodle-mod_quiz-util-base"]}); +YUI.add("moodle-mod_quiz-util-slot",function(e,t){e.namespace("Moodle.mod_quiz.util.slot"),e.Moodle.mod_quiz.util.slot={CSS:{SLOT:"slot",QUESTIONTYPEDESCRIPTION:"qtype_description"},CONSTANTS:{SLOTIDPREFIX:"slot-",QUESTION:M.util.get_string("question","moodle")},SELECTORS:{SLOT:"li.slot",INSTANCENAME:".instancename",NUMBER:"span.slotnumber",PAGECONTENT:"div#page-content",PAGEBREAK:"span.page_split_join_wrapper",ICON:"img.smallicon",QUESTIONTYPEDESCRIPTION:".qtype_description",SECTIONUL:"ul.section"},getSlotFromComponent:function(t){return e.one(t).ancestor(this.SELECTORS.SLOT,!0)},getId:function(e){var t=e.get("id").replace(this.CONSTANTS.SLOTIDPREFIX,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},getName:function(e){var t=e.one(this.SELECTORS.INSTANCENAME);return t?t.get("firstChild").get("data"):null},getNumber:function(e){if(!e)return!1;var t=e.one(this.SELECTORS.NUMBER).get("text").replace(this.CONSTANTS.QUESTION,"");return t=parseInt(t,10),typeof t=="number"&&isFinite(t)?t:!1},setNumber:function(e,t){var n=e.one(this.SELECTORS.NUMBER);n.setHTML(''+this.CONSTANTS.QUESTION+" "+t)},getSlots:function(){return e.all(this.SELECTORS.PAGECONTENT+" "+this.SELECTORS.SECTIONUL+" "+this.SELECTORS.SLOT)},getNumberedSlots:function(){var t=this.SELECTORS.PAGECONTENT+" "+this.SELECTORS.SECTIONUL;return t+=" "+this.SELECTORS.SLOT+":not("+this.SELECTORS.QUESTIONTYPEDESCRIPTION+")",e.all(t)},getPrevious:function(e){return e.previous(this.SELECTORS.SLOT)},getPreviousNumbered:function(e){return e.previous(this.SELECTORS.SLOT+":not("+this.SELECTORS.QUESTIONTYPEDESCRIPTION+")")},reorderSlots:function(){var t=this.getSlots();t.each(function(t){if(!e.Moodle.mod_quiz.util.page.getPageFromSlot(t)){var n=t.next(e.Moodle.mod_quiz.util.page.SELECTORS.PAGE);t.swap(n)}var r=this.getPreviousNumbered(t);previousslotnumber=0;if(t.hasClass(this.CSS.QUESTIONTYPEDESCRIPTION))return;r&&(previousslotnumber=this.getNumber(r)),this.setNumber(t,previousslotnumber+1)},this)},remove:function(t){var n=e.Moodle.mod_quiz.util.page.getPageFromSlot(t);t.remove();if(!e.Moodle.mod_quiz.util.page.isEmpty(n))return;e.Moodle.mod_quiz.util.page.remove(n)},getPageBreaks:function(){var t=this.SELECTORS.PAGECONTENT+" "+this.SELECTORS.SECTIONUL;return t+=" "+this.SELECTORS.SLOT+this.SELECTORS.PAGEBREAK,e.all(t)},getPageBreak:function(t){return e.one(t).one(this.SELECTORS.PAGEBREAK)},addPageBreak:function(t){var n=M.mod_quiz.resource_toolbox.get("config").addpageiconhtml;n=n.replace("%%SLOT%%",this.getNumber(t));var r=e.Node.create(n);return t.one("div").insert(r,"after"),r},removePageBreak:function(e){var t=this.getPageBreak(e);return t?(t.remove(),!0):!1},reorderPageBreaks:function(){var t=this.getSlots(),n=0;t.each(function(r,i){n++;var s=this.getPageBreak(r);if(!s&&i===t.size()-1)return;!s&&i!==t.size()-1&&(s=this.addPageBreak(r)),s&&i===t.size()-1&&this.removePageBreak(r);var o=s.get("childNodes").item(0),u="",a="";e.Moodle.mod_quiz.util.page.isPage(r.next("li.activity"))?(u="removepagebreak",a="e/remove_page_break"):(u="addpagebreak",a="e/insert_page_break"),o.set("title",M.util.get_string(u,"quiz")),o.setData("action",u);var f=o.one(this.SELECTORS.ICON);f.set("title",M.util.get_string(u,"quiz")),f.set("alt",M.util.get_string(u,"quiz")),f.set("src",M.util.image_url(a));var l=e.QueryString.parse(o.get("href"));l.slot=n;var c="";for(var h in l)c.length&&(c+="&"),c+=h+"="+l[h];o.set("href",c)},this)}}},"@VERSION@",{requires:["node","moodle-mod_quiz-util-base"]}); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot.js b/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot.js index 38e3e0ad10f..9992cdfb0d1 100644 --- a/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot.js +++ b/mod/quiz/yui/build/moodle-mod_quiz-util-slot/moodle-mod_quiz-util-slot.js @@ -16,14 +16,22 @@ Y.namespace('Moodle.mod_quiz.util.slot'); * @static */ Y.Moodle.mod_quiz.util.slot = { + CSS: { + SLOT : 'slot', + QUESTIONTYPEDESCRIPTION : 'qtype_description' + }, CONSTANTS: { - SLOTIDPREFIX : 'slot-' + SLOTIDPREFIX : 'slot-', + QUESTION : M.util.get_string('question', 'moodle') }, SELECTORS: { SLOT: 'li.slot', INSTANCENAME: '.instancename', NUMBER: 'span.slotnumber', PAGECONTENT : 'div#page-content', + PAGEBREAK : 'span.page_split_join_wrapper', + ICON : 'img.smallicon', + QUESTIONTYPEDESCRIPTION : '.qtype_description', SECTIONUL : 'ul.section' }, @@ -81,7 +89,12 @@ Y.Moodle.mod_quiz.util.slot = { * @return {Number|false} The number of the slot in question or false if no number was found. */ getNumber: function(slot) { - var number = slot.one(this.SELECTORS.NUMBER).get('text'); + if (!slot) { + return false; + } + // We perform a simple substitution operation to get the number. + var number = slot.one(this.SELECTORS.NUMBER).get('text').replace( + this.CONSTANTS.QUESTION, ''); // Attempt to validate the ID. number = parseInt(number, 10); if (typeof number === 'number' && isFinite(number)) { @@ -98,7 +111,8 @@ Y.Moodle.mod_quiz.util.slot = { * @return void */ setNumber: function(slot, number) { - slot.one(this.SELECTORS.NUMBER).set('text', number); + var numbernode = slot.one(this.SELECTORS.NUMBER); + numbernode.setHTML('' + this.CONSTANTS.QUESTION + ' ' + number); }, /** @@ -112,7 +126,19 @@ Y.Moodle.mod_quiz.util.slot = { }, /** - * Returns the previous slot to the give slot. + * Returns a list of all slot elements on the page that have numbers. Excudes description questions. + * + * @method getSlots + * @return {node[]} An array containing slot nodes. + */ + getNumberedSlots: function() { + var selector = this.SELECTORS.PAGECONTENT + ' ' + this.SELECTORS.SECTIONUL; + selector += ' ' + this.SELECTORS.SLOT + ':not(' + this.SELECTORS.QUESTIONTYPEDESCRIPTION + ')'; + return Y.all(selector); + }, + + /** + * Returns the previous slot to the given slot. * * @method getPrevious * @param slot Slot node @@ -122,27 +148,191 @@ Y.Moodle.mod_quiz.util.slot = { return slot.previous(this.SELECTORS.SLOT); }, + /** + * Returns the previous numbered slot to the given slot. + * + * Ignores slots containing description question types. + * + * @method getPrevious + * @param slot Slot node + * @return {node|false} The previous slot node or false. + */ + getPreviousNumbered: function(slot) { + return slot.previous(this.SELECTORS.SLOT + ':not(' + this.SELECTORS.QUESTIONTYPEDESCRIPTION + ')'); + }, + /** * Reset the order of the numbers given to each slot. * - * @method reorder_slots + * @method reorderSlots * @return void */ - reorder_slots: function() { + reorderSlots: function() { // Get list of slot nodes. var slots = this.getSlots(); // Loop through slots incrementing the number each time. slots.each(function(slot) { - var previousSlot = this.getPrevious(slot), - previousslotnumber = 0; - if(previousSlot){ + + if (!Y.Moodle.mod_quiz.util.page.getPageFromSlot(slot)) { + // Move the next page to the front. + var nextpage = slot.next(Y.Moodle.mod_quiz.util.page.SELECTORS.PAGE); + slot.swap(nextpage); + } + + var previousSlot = this.getPreviousNumbered(slot); + previousslotnumber = 0; + if (slot.hasClass(this.CSS.QUESTIONTYPEDESCRIPTION)) { + return; + } + + if (previousSlot) { previousslotnumber = this.getNumber(previousSlot); } // Set slot number. this.setNumber(slot, previousslotnumber + 1); }, this); + }, + /** + * Remove a slot and related elements from the list of slots. + * + * @method remove + * @param slot Slot node + * @return void + */ + remove: function(slot) { + var page = Y.Moodle.mod_quiz.util.page.getPageFromSlot(slot); + slot.remove(); + // Is the page empty. + if (!Y.Moodle.mod_quiz.util.page.isEmpty(page)) { + return; + } + // If so remove it. Including add menu and page break. + Y.Moodle.mod_quiz.util.page.remove(page); + }, + + /** + * Returns a list of all page break elements on the page. + * + * @method getPageBreaks + * @return {node[]} An array containing page break nodes. + */ + getPageBreaks: function() { + var selector = this.SELECTORS.PAGECONTENT + ' ' + this.SELECTORS.SECTIONUL; + selector += ' ' + this.SELECTORS.SLOT + this.SELECTORS.PAGEBREAK; + return Y.all(selector); + }, + + /** + * Retrieve the page break element item from the given slot. + * + * @method getPageBreak + * @param slot Slot node + * @return {Node|null} The Page Break Node. + */ + getPageBreak: function(slot) { + return Y.one(slot).one(this.SELECTORS.PAGEBREAK); + }, + + /** + * Add a page break and related elements to the list of slots. + * + * @method addPageBreak + * @param beforenode Int | Node | HTMLElement | String to add + * @return pagebreak PageBreak node + */ + addPageBreak: function(slot) { + var nodetext = M.mod_quiz.resource_toolbox.get('config').addpageiconhtml; + nodetext = nodetext.replace('%%SLOT%%', this.getNumber(slot)); + var pagebreak = Y.Node.create(nodetext); + slot.one('div').insert(pagebreak, 'after'); + return pagebreak; + }, + + /** + * Remove a pagebreak from the given slot. + * + * @method removePageBreak + * @param slot Slot node + * @return boolean + */ + removePageBreak: function(slot) { + var pagebreak = this.getPageBreak(slot); + if (!pagebreak) { + return false; + } + pagebreak.remove(); + return true; + }, + + /** + * Reorder each pagebreak by iterating through each related slot. + * + * @method reorderPageBreaks + * @return void + */ + reorderPageBreaks: function() { + // Get list of slot nodes. + var slots = this.getSlots(), slotnumber = 0; + // Loop through slots incrementing the number each time. + slots.each (function(slot, key) { + slotnumber++; + var pagebreak = this.getPageBreak(slot); + // Last slot won't have a page break. + if (!pagebreak && key === slots.size() - 1) { + return; + } + + // No pagebreak and not last slot. Add one. + if (!pagebreak && key !== slots.size() - 1) { + pagebreak = this.addPageBreak(slot); + } + + // Remove last page break if there is one. + if (pagebreak && key === slots.size() - 1) { + this.removePageBreak(slot); + } + + // Get page break anchor element. + var pagebreaklink = pagebreak.get('childNodes').item(0); + + // Get the correct title. + var action = '', iconname = ''; + if (Y.Moodle.mod_quiz.util.page.isPage(slot.next('li.activity'))) { + action = 'removepagebreak'; + iconname = 'e/remove_page_break'; + } else { + action = 'addpagebreak'; + iconname = 'e/insert_page_break'; + } + + // Update the link and image titles + pagebreaklink.set('title', M.util.get_string(action, 'quiz')); + pagebreaklink.setData('action', action); + // Update the image title. + var icon = pagebreaklink.one(this.SELECTORS.ICON); + icon.set('title', M.util.get_string(action, 'quiz')); + icon.set('alt', M.util.get_string(action, 'quiz')); + + // Update the image src. + icon.set('src', M.util.image_url(iconname)); + + // Get anchor url parameters as an associative array. + var params = Y.QueryString.parse(pagebreaklink.get('href')); + // Update slot number. + params.slot = slotnumber; + // Create the new url. + var newurl = ''; + for (var index in params) { + if (newurl.length) { + newurl += "&"; + } + newurl += index + "=" + params[index]; + } + // Update the anchor. + pagebreaklink.set('href', newurl); + }, this); } }; diff --git a/mod/quiz/yui/src/dragdrop/js/resource.js b/mod/quiz/yui/src/dragdrop/js/resource.js index f4fdd460742..74d284e1a83 100644 --- a/mod/quiz/yui/src/dragdrop/js/resource.js +++ b/mod/quiz/yui/src/dragdrop/js/resource.js @@ -14,7 +14,6 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, { this.groups = ['resource']; this.samenodeclass = CSS.ACTIVITY; this.parentnodeclass = CSS.SECTION; - //this.resourcedraghandle = this.get_drag_handle(M.util.get_string('movecoursemodule', 'moodle'), CSS.EDITINGMOVE, CSS.ICONCLASS, true); this.resourcedraghandle = this.get_drag_handle(M.str.moodle.move, CSS.EDITINGMOVE, CSS.ICONCLASS, true); this.samenodelabel = { @@ -168,12 +167,11 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, { var responsetext = Y.JSON.parse(response.responseText); var params = {element: dragnode, visible: responsetext.visible}; M.mod_quiz.quizbase.invoke_function('set_visibility_resource_ui', params); - Y.Moodle.mod_quiz.util.slot.reorder_slots(); this.unlock_drag_handle(drag, CSS.EDITINGMOVE); window.setTimeout(function() { spinner.hide(); }, 250); - window.location.reload(true); + M.mod_quiz.resource_toolbox.reorganise_edit_page(); }, failure: function(tid, response) { this.ajax_failure(response); diff --git a/mod/quiz/yui/src/dragdrop/meta/dragdrop.json b/mod/quiz/yui/src/dragdrop/meta/dragdrop.json index f80f8ed6387..b1998ac7b8c 100644 --- a/mod/quiz/yui/src/dragdrop/meta/dragdrop.json +++ b/mod/quiz/yui/src/dragdrop/meta/dragdrop.json @@ -10,7 +10,9 @@ "moodle-core-dragdrop", "moodle-core-notification", "moodle-mod_quiz-quizbase", - "moodle-mod_quiz-util", + "moodle-mod_quiz-util-base", + "moodle-mod_quiz-util-page", + "moodle-mod_quiz-util-slot", "moodle-course-util" ] } diff --git a/mod/quiz/yui/src/quizbase/js/quizbase.js b/mod/quiz/yui/src/quizbase/js/quizbase.js index db05ce194be..06a0f858874 100644 --- a/mod/quiz/yui/src/quizbase/js/quizbase.js +++ b/mod/quiz/yui/src/quizbase/js/quizbase.js @@ -77,9 +77,9 @@ M.mod_quiz.edit.swap_sections = function(Y, node1, node2) { SECTIONADDMENUS : 'section_add_menus' }; - var sectionlist = Y.Node.all('.'+CSS.COURSECONTENT+' '+M.mod_quiz.edit.get_section_selector(Y)); + var sectionlist = Y.Node.all('.' + CSS.COURSECONTENT + ' ' + M.mod_quiz.edit.get_section_selector(Y)); // Swap menus. - sectionlist.item(node1).one('.'+CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.'+CSS.SECTIONADDMENUS)); + sectionlist.item(node1).one('.' + CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.' + CSS.SECTIONADDMENUS)); }; /** @@ -115,7 +115,7 @@ M.mod_quiz.edit.process_sections = function(Y, sectionlist, response, sectionfro for (var i = sectionfrom; i <= sectionto; i++) { // Update section title. - sectionlist.item(i).one('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]); + sectionlist.item(i).one('.' + CSS.SECTIONNAME).setContent(response.sectiontitles[i]); // Update move icon. ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE); diff --git a/mod/quiz/yui/src/toolboxes/js/resource.js b/mod/quiz/yui/src/toolboxes/js/resource.js index ba27dfdde94..fce93b16a77 100644 --- a/mod/quiz/yui/src/toolboxes/js/resource.js +++ b/mod/quiz/yui/src/toolboxes/js/resource.js @@ -101,10 +101,10 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // The user is deleting the activity. this.delete_with_confirmation(ev, node, activity, action); break; - case 'linkpage': - case 'unlinkpage': - // The user is linking or unlinking pages. - this.link_page(ev, node, activity, action); + case 'addpagebreak': + case 'removepagebreak': + // The user is adding or removing a page break. + this.update_page_break(ev, node, activity, action); break; default: // Nothing to do here! @@ -140,10 +140,10 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @chainable */ delete_with_confirmation: function(ev, button, activity) { - // Prevent the default button action + // Prevent the default button action. ev.preventDefault(); - // Get the element we're working on + // Get the element we're working on. var element = activity, // Create confirm string (different if element has or does not have name) confirmstring = '', @@ -160,19 +160,24 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // If it is confirmed. confirm.on('complete-yes', function() { - // Actually remove the element. - element.remove(); - Y.Moodle.mod_quiz.util.slot.reorder_slots(); + var spinner = this.add_spinner(element); var data = { 'class': 'resource', 'action': 'DELETE', 'id': Y.Moodle.mod_quiz.util.slot.getId(element) }; - this.send_request(data); - if (M.core.actionmenu && M.core.actionmenu.instance) { - M.core.actionmenu.instance.hideMenu(); - } - window.location.reload(true); + this.send_request(data, spinner, function(response) { + if (response.deleted) { + // Actually remove the element. + Y.Moodle.mod_quiz.util.slot.remove(element); + this.reorganise_edit_page(); + if (M.core.actionmenu && M.core.actionmenu.instance) { + M.core.actionmenu.instance.hideMenu(); + } + } else { + window.location.reload(true); + } + }); }, this); @@ -215,12 +220,12 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { M.core.actionmenu.instance.hideMenu(); } - // Try to retrieve the existing string from the server + // Try to retrieve the existing string from the server. if (response.instancemaxmark) { maxmarktext = response.instancemaxmark; } - // Create the editor and submit button + // Create the editor and submit button. var editform = Y.Node.create(''); var editinstructions = Y.Node.create('') .set('innerHTML', M.util.get_string('edittitleinstructions', 'moodle')); @@ -232,7 +237,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { 'size' : parseInt(this.get('config').questiondecimalpoints, 10) + 2 }); - // Clear the existing content and put the editor in + // Clear the existing content and put the editor in. editform.appendChild(editor); editform.setData('anchor', anchor); instance.insert(editinstructions, 'before'); @@ -247,7 +252,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { // We hide various components whilst editing: activity.addClass(CSS.EDITINGMAXMARK); - // Focus and select the editor text + // Focus and select the editor text. editor.focus().select(); // Cancel the edit if we lose focus or the escape key is pressed. @@ -272,7 +277,7 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * @param {String} originalmaxmark The original maxmark the activity or resource had. */ edit_maxmark_submit : function(ev, activity, originalmaxmark) { - // We don't actually want to submit anything + // We don't actually want to submit anything. ev.preventDefault(); var newmaxmark = Y.Lang.trim(activity.one(SELECTOR.ACTIVITYFORM + ' ' + SELECTOR.ACTIVITYMAXMARK).get('value')); var spinner = this.add_spinner(activity); @@ -350,97 +355,59 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, { * the other slots * * @protected - * @method link_page + * @method update_page_break * @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 */ - link_page: function(ev, button, activity, action) { + update_page_break: function(ev, button, activity, action) { // Prevent the default button action ev.preventDefault(); - activity = activity.next('li.activity.slot'); - var spinner = this.add_spinner(activity), + nextactivity = activity.next('li.activity.slot'); + var spinner = this.add_spinner(nextactivity), slotid = 0; - var value = action === 'linkpage' ? 1:2; + var value = action === 'removepagebreak' ? 1 : 2; var data = { 'class': 'resource', - 'field': 'linkslottopage', + 'field': 'updatepagebreak', 'id': slotid, 'value': value }; - slotid = Y.Moodle.mod_quiz.util.slot.getId(activity); + slotid = Y.Moodle.mod_quiz.util.slot.getId(nextactivity); if (slotid) { data.id = Number(slotid); } this.send_request(data, spinner, function(response) { - window.location.reload(true); -// if (response.slots) { -// this.repaginate_slots(response.slots); -// } + if (response.slots) { + if (action === 'addpagebreak') { + Y.Moodle.mod_quiz.util.page.add(activity); + } else { + var page = activity.next(Y.Moodle.mod_quiz.util.page.SELECTORS.PAGE); + Y.Moodle.mod_quiz.util.page.remove(page, true); + } + this.reorganise_edit_page(); + } else { + window.location.reload(true); + } }); return this; }, - repaginate_slots: function(slots) { - this.slots = slots; - var section = Y.one(SELECTOR.PAGECONTENT + ' ' + SELECTOR.SECTIONUL), - activities = section.all(SELECTOR.ACTIVITYLI); - activities.each(function(node) { - // What element is it? page/slot/link - // what is the current slot? - var type; - var slot; - if(node.hasClass(CSS.PAGE)){ - type = this.NODE_PAGE; - slot = node.next(SELECTOR.SLOTLI); - } else if (node.hasClass(CSS.SLOT)){ - type = this.NODE_SLOT; - slot = node; - } else if (node.hasClass(CSS.JOIN)){ - type = this.NODE_JOIN; - slot = node.previous(SELECTOR.SLOTLI); - } - - // getSlotnumber() Should be a method of util.slot - var slotnumber = Number(Y.Moodle.mod_quiz.util.slot.getNumber(slot)); - if(!type){ - // Nothing we can do. - return; - } - - // Is it correct? - if(!this.slots.hasOwnProperty(slotnumber)){ - // An error. We should handle this. - return; - } - - var slotdata = this.slots[slotnumber]; - - if(type === this.NODE_PAGE){ - // Get page number - var pagenumber = Y.Moodle.mod_quiz.util.page.getNumber(node); - // Is the page number correct? - if (slotdata.page === pagenumber) { - console.log('slotdata.page == pagenumber return'); - return; - } - - if (pagenumber < slotdata.page) { - // Remove page node. - node.remove(); - } - else { - // Add page node. - console.log('pagenumber > slotdata.page update page number'); - } - - } - }, this); + /** + * Reorganise the UI after every edit action. + * + * @protected + * @method reorganise_edit_page + */ + reorganise_edit_page: function() { + Y.Moodle.mod_quiz.util.slot.reorderSlots(); + Y.Moodle.mod_quiz.util.slot.reorderPageBreaks(); + Y.Moodle.mod_quiz.util.page.reorderPages(); }, NAME : 'mod_quiz-resource-toolbox', diff --git a/mod/quiz/yui/src/util/js/page.js b/mod/quiz/yui/src/util/js/page.js index 39f49db5017..b20596f236f 100644 --- a/mod/quiz/yui/src/util/js/page.js +++ b/mod/quiz/yui/src/util/js/page.js @@ -14,13 +14,23 @@ Y.namespace('Moodle.mod_quiz.util.page'); * @static */ Y.Moodle.mod_quiz.util.page = { + CSS: { + PAGE : 'page' + }, CONSTANTS: { - PAGEIDPREFIX : 'page-', - PAGENUMBERPREFIX : 'Page ' + 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' + INSTANCENAME: '.instancename', + NUMBER: 'span.text' }, /** @@ -35,7 +45,18 @@ Y.Moodle.mod_quiz.util.page = { }, /** - * Determines the page ID for the provided page. + * Retrieve the page item from one of it's previous siblings. + * + * @method getPageFromSlot + * @param pagecomponent {Node} The component Node. + * @return {Node|null} The Page Node. + */ + getPageFromSlot: function(slot) { + return Y.one(slot).previous(this.SELECTORS.PAGE); + }, + + /** + * Returns the page ID for the provided page. * * @method getId * @param page {Node} The page to find an ID for. @@ -54,6 +75,18 @@ Y.Moodle.mod_quiz.util.page = { return false; }, + /** + * Updates the page id for the provided page. + * + * @method setId + * @param page {Node} The page to update the number for. + * @param id int The id value. + * @return void + */ + setId: function(page, id) { + page.set('id', this.CONSTANTS.PAGEIDPREFIX + id); + }, + /** * Determines the page name for the provided page. * @@ -77,8 +110,8 @@ Y.Moodle.mod_quiz.util.page = { * @return {Number|false} The number of the page in question or false if no number was found. */ getNumber: function(page) { - // We perform a simple substitution operation to get the ID. - var number = page.get('text').replace( + // We perform a simple substitution operation to get the number. + var number = page.one(this.SELECTORS.NUMBER).get('text').replace( this.CONSTANTS.PAGENUMBERPREFIX, ''); // Attempt to validate the ID. @@ -87,5 +120,205 @@ Y.Moodle.mod_quiz.util.page = { return number; } return false; + }, + + /** + * Updates the page number for the provided page. + * + * @method setNumber + * @param page {Node} The page to update the number for. + * @return void + */ + setNumber: function(page, number) { + page.one(this.SELECTORS.NUMBER).set('text', this.CONSTANTS.PAGENUMBERPREFIX + number); + }, + + /** + * Returns a list of all page elements. + * + * @method getPages + * @return {node[]} An array containing page nodes. + */ + getPages: function() { + return Y.all(Y.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT + ' ' + Y.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL + ' ' + this.SELECTORS.PAGE); + }, + + /** + * Is the given element a page element? + * + * @method isPage + * @param page Page node + * @return boolean + */ + isPage: function(page) { + if (!page) { + return false; + } + return page.hasClass(this.CSS.PAGE); + }, + + /** + * Does the page have atleast one slot? + * + * @method isEmpty + * @param page Page node + * @return boolean + */ + isEmpty: function(page) { + var activity = page.next('li.activity'); + if (!activity) { + return true; + } + return !activity.hasClass('slot'); + }, + + /** + * Add a page and related elements to the list of slots. + * + * @method add + * @param beforenode Int | Node | HTMLElement | String to add + * @return page Page node + */ + add: function(beforenode) { + var pagenumber = this.getNumber(this.getPageFromSlot(beforenode)) + 1; + var pagehtml = M.mod_quiz.resource_toolbox.get('config').pagehtml; + + // Normalise the page number. + pagehtml = pagehtml.replace(/%%PAGENUMBER%%/g, pagenumber); + + // Create the page node. + var page = Y.Node.create(pagehtml); + + // Assign is as a drop target. + YUI().use('dd-drop', function(Y) { + var drop = new Y.DD.Drop({ + node: page, + groups: M.mod_quiz.dragres.groups + }); + page.drop = drop; + }); + + // Insert in the correct place. + beforenode.insert(page, 'after'); + + // Enhance the add menu to make if fully visible and clickable. + M.core.actionmenu.newDOMNode(page); + return page; + }, + + /** + * Remove a page and related elements from the list of slots. + * + * @method remove + * @param page Page node + * @return void + */ + remove: function(page, keeppagebreak) { + // Remove page break from previous slot. + var previousslot = page.previous(Y.Moodle.mod_quiz.util.slot.SELECTORS.SLOT); + if (!keeppagebreak && previousslot) { + Y.Moodle.mod_quiz.util.slot.removePageBreak(previousslot); + } + page.remove(); + }, + + /** + * Reset the order of the numbers given to each page. + * + * @method reorderPages + * @return void + */ + reorderPages: function() { + // Get list of page nodes. + var pages = this.getPages(), currentpagenumber = 0; + // Loop through pages incrementing the number each time. + pages.each(function(page) { + // Is the page empty? + if (this.isEmpty(page)) { + var keeppagebreak = page.next('li.slot') ? true : false; + this.remove(page, keeppagebreak); + return; + } + + currentpagenumber++; + // Set page number. + this.setNumber(page, currentpagenumber); + this.setId(page, currentpagenumber); + }, this); + + // Reorder action menus + this.reorderActionMenus(); + }, + + /** + * Reset the order of the numbers given to each action menu. + * + * @method reorderActionMenus + * @return void + */ + reorderActionMenus: function() { + // Get list of action menu nodes. + var actionmenus = this.getActionMenus(); + // Loop through pages incrementing the number each time. + actionmenus.each(function(actionmenu, key) { + var previousActionMenu = actionmenus.item(key - 1); + previousActionMenunumber = 0; + if (previousActionMenu) { + previousActionMenunumber = this.getActionMenuId(previousActionMenu); + } + var id = previousActionMenunumber + 1; + + // Set menu id. + this.setActionMenuId(actionmenu, id); + + // Update action-menu-1-menubar + var menubar = actionmenu.one(this.SELECTORS.ACTIONMENUBAR); + menubar.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUBARIDSUFFIX); + // Update action-menu-1-menu + var menumenu = actionmenu.one(this.SELECTORS.ACTIONMENUMENU); + menumenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id + this.CONSTANTS.ACTIONMENUMENUIDSUFFIX); + }, this); + }, + + /** + * Returns a list of all page elements. + * + * @method getActionMenus + * @return {node[]} An array containing page nodes. + */ + getActionMenus: function() { + return Y.all(Y.Moodle.mod_quiz.util.slot.SELECTORS.PAGECONTENT + ' ' + Y.Moodle.mod_quiz.util.slot.SELECTORS.SECTIONUL + ' ' + this.SELECTORS.ACTIONMENU); + }, + + /** + * Returns the ID for the provided action menu. + * + * @method getId + * @param actionmenu {Node} The actionmenu to find an ID for. + * @return {Number|false} The ID of the actionmenu in question or false if no ID was found. + */ + getActionMenuId: function(actionmenu) { + // We perform a simple substitution operation to get the ID. + var id = actionmenu.get('id').replace( + this.CONSTANTS.ACTIONMENUIDPREFIX, ''); + + // Attempt to validate the ID. + id = parseInt(id, 10); + if (typeof id === 'number' && isFinite(id)) { + return id; + } + return false; + }, + + /** + * Updates the page id for the provided page. + * + * @method setId + * @param page {Node} The page to update the number for. + * @param id int The id value. + * @return void + */ + setActionMenuId: function(actionmenu, id) { + actionmenu.set('id', this.CONSTANTS.ACTIONMENUIDPREFIX + id); } }; diff --git a/mod/quiz/yui/src/util/js/slot.js b/mod/quiz/yui/src/util/js/slot.js index 4fc216e3406..38b37fbcb84 100644 --- a/mod/quiz/yui/src/util/js/slot.js +++ b/mod/quiz/yui/src/util/js/slot.js @@ -14,14 +14,22 @@ Y.namespace('Moodle.mod_quiz.util.slot'); * @static */ Y.Moodle.mod_quiz.util.slot = { + CSS: { + SLOT : 'slot', + QUESTIONTYPEDESCRIPTION : 'qtype_description' + }, CONSTANTS: { - SLOTIDPREFIX : 'slot-' + SLOTIDPREFIX : 'slot-', + QUESTION : M.util.get_string('question', 'moodle') }, SELECTORS: { SLOT: 'li.slot', INSTANCENAME: '.instancename', NUMBER: 'span.slotnumber', PAGECONTENT : 'div#page-content', + PAGEBREAK : 'span.page_split_join_wrapper', + ICON : 'img.smallicon', + QUESTIONTYPEDESCRIPTION : '.qtype_description', SECTIONUL : 'ul.section' }, @@ -79,7 +87,12 @@ Y.Moodle.mod_quiz.util.slot = { * @return {Number|false} The number of the slot in question or false if no number was found. */ getNumber: function(slot) { - var number = slot.one(this.SELECTORS.NUMBER).get('text'); + if (!slot) { + return false; + } + // We perform a simple substitution operation to get the number. + var number = slot.one(this.SELECTORS.NUMBER).get('text').replace( + this.CONSTANTS.QUESTION, ''); // Attempt to validate the ID. number = parseInt(number, 10); if (typeof number === 'number' && isFinite(number)) { @@ -96,7 +109,8 @@ Y.Moodle.mod_quiz.util.slot = { * @return void */ setNumber: function(slot, number) { - slot.one(this.SELECTORS.NUMBER).set('text', number); + var numbernode = slot.one(this.SELECTORS.NUMBER); + numbernode.setHTML('' + this.CONSTANTS.QUESTION + ' ' + number); }, /** @@ -110,7 +124,19 @@ Y.Moodle.mod_quiz.util.slot = { }, /** - * Returns the previous slot to the give slot. + * Returns a list of all slot elements on the page that have numbers. Excudes description questions. + * + * @method getSlots + * @return {node[]} An array containing slot nodes. + */ + getNumberedSlots: function() { + var selector = this.SELECTORS.PAGECONTENT + ' ' + this.SELECTORS.SECTIONUL; + selector += ' ' + this.SELECTORS.SLOT + ':not(' + this.SELECTORS.QUESTIONTYPEDESCRIPTION + ')'; + return Y.all(selector); + }, + + /** + * Returns the previous slot to the given slot. * * @method getPrevious * @param slot Slot node @@ -120,26 +146,190 @@ Y.Moodle.mod_quiz.util.slot = { return slot.previous(this.SELECTORS.SLOT); }, + /** + * Returns the previous numbered slot to the given slot. + * + * Ignores slots containing description question types. + * + * @method getPrevious + * @param slot Slot node + * @return {node|false} The previous slot node or false. + */ + getPreviousNumbered: function(slot) { + return slot.previous(this.SELECTORS.SLOT + ':not(' + this.SELECTORS.QUESTIONTYPEDESCRIPTION + ')'); + }, + /** * Reset the order of the numbers given to each slot. * - * @method reorder_slots + * @method reorderSlots * @return void */ - reorder_slots: function() { + reorderSlots: function() { // Get list of slot nodes. var slots = this.getSlots(); // Loop through slots incrementing the number each time. slots.each(function(slot) { - var previousSlot = this.getPrevious(slot), - previousslotnumber = 0; - if(previousSlot){ + + if (!Y.Moodle.mod_quiz.util.page.getPageFromSlot(slot)) { + // Move the next page to the front. + var nextpage = slot.next(Y.Moodle.mod_quiz.util.page.SELECTORS.PAGE); + slot.swap(nextpage); + } + + var previousSlot = this.getPreviousNumbered(slot); + previousslotnumber = 0; + if (slot.hasClass(this.CSS.QUESTIONTYPEDESCRIPTION)) { + return; + } + + if (previousSlot) { previousslotnumber = this.getNumber(previousSlot); } // Set slot number. this.setNumber(slot, previousslotnumber + 1); }, this); + }, + /** + * Remove a slot and related elements from the list of slots. + * + * @method remove + * @param slot Slot node + * @return void + */ + remove: function(slot) { + var page = Y.Moodle.mod_quiz.util.page.getPageFromSlot(slot); + slot.remove(); + // Is the page empty. + if (!Y.Moodle.mod_quiz.util.page.isEmpty(page)) { + return; + } + // If so remove it. Including add menu and page break. + Y.Moodle.mod_quiz.util.page.remove(page); + }, + + /** + * Returns a list of all page break elements on the page. + * + * @method getPageBreaks + * @return {node[]} An array containing page break nodes. + */ + getPageBreaks: function() { + var selector = this.SELECTORS.PAGECONTENT + ' ' + this.SELECTORS.SECTIONUL; + selector += ' ' + this.SELECTORS.SLOT + this.SELECTORS.PAGEBREAK; + return Y.all(selector); + }, + + /** + * Retrieve the page break element item from the given slot. + * + * @method getPageBreak + * @param slot Slot node + * @return {Node|null} The Page Break Node. + */ + getPageBreak: function(slot) { + return Y.one(slot).one(this.SELECTORS.PAGEBREAK); + }, + + /** + * Add a page break and related elements to the list of slots. + * + * @method addPageBreak + * @param beforenode Int | Node | HTMLElement | String to add + * @return pagebreak PageBreak node + */ + addPageBreak: function(slot) { + var nodetext = M.mod_quiz.resource_toolbox.get('config').addpageiconhtml; + nodetext = nodetext.replace('%%SLOT%%', this.getNumber(slot)); + var pagebreak = Y.Node.create(nodetext); + slot.one('div').insert(pagebreak, 'after'); + return pagebreak; + }, + + /** + * Remove a pagebreak from the given slot. + * + * @method removePageBreak + * @param slot Slot node + * @return boolean + */ + removePageBreak: function(slot) { + var pagebreak = this.getPageBreak(slot); + if (!pagebreak) { + return false; + } + pagebreak.remove(); + return true; + }, + + /** + * Reorder each pagebreak by iterating through each related slot. + * + * @method reorderPageBreaks + * @return void + */ + reorderPageBreaks: function() { + // Get list of slot nodes. + var slots = this.getSlots(), slotnumber = 0; + // Loop through slots incrementing the number each time. + slots.each (function(slot, key) { + slotnumber++; + var pagebreak = this.getPageBreak(slot); + // Last slot won't have a page break. + if (!pagebreak && key === slots.size() - 1) { + return; + } + + // No pagebreak and not last slot. Add one. + if (!pagebreak && key !== slots.size() - 1) { + pagebreak = this.addPageBreak(slot); + } + + // Remove last page break if there is one. + if (pagebreak && key === slots.size() - 1) { + this.removePageBreak(slot); + } + + // Get page break anchor element. + var pagebreaklink = pagebreak.get('childNodes').item(0); + + // Get the correct title. + var action = '', iconname = ''; + if (Y.Moodle.mod_quiz.util.page.isPage(slot.next('li.activity'))) { + action = 'removepagebreak'; + iconname = 'e/remove_page_break'; + } else { + action = 'addpagebreak'; + iconname = 'e/insert_page_break'; + } + + // Update the link and image titles + pagebreaklink.set('title', M.util.get_string(action, 'quiz')); + pagebreaklink.setData('action', action); + // Update the image title. + var icon = pagebreaklink.one(this.SELECTORS.ICON); + icon.set('title', M.util.get_string(action, 'quiz')); + icon.set('alt', M.util.get_string(action, 'quiz')); + + // Update the image src. + icon.set('src', M.util.image_url(iconname)); + + // Get anchor url parameters as an associative array. + var params = Y.QueryString.parse(pagebreaklink.get('href')); + // Update slot number. + params.slot = slotnumber; + // Create the new url. + var newurl = ''; + for (var index in params) { + if (newurl.length) { + newurl += "&"; + } + newurl += index + "=" + params[index]; + } + // Update the anchor. + pagebreaklink.set('href', newurl); + }, this); } };