From 6bafb66c349ab0277792a037fd7b167d2ba32288 Mon Sep 17 00:00:00 2001 From: M Kassaei Date: Tue, 30 Oct 2018 16:25:15 +0000 Subject: [PATCH] MDL-63825 Quiz: convert quiz repaginate.js from YUI to AMD --- mod/quiz/amd/build/repaginate.min.js | 1 + mod/quiz/amd/src/repaginate.js | 48 +++++++++++ mod/quiz/classes/output/edit_renderer.php | 3 +- .../moodle-mod_quiz-repaginate-debug.js | 85 ------------------- .../moodle-mod_quiz-repaginate-min.js | 1 - .../moodle-mod_quiz-repaginate.js | 85 ------------------- mod/quiz/yui/src/repaginate/build.json | 10 --- mod/quiz/yui/src/repaginate/js/repaginate.js | 80 ----------------- .../yui/src/repaginate/meta/repaginate.json | 11 --- 9 files changed, 50 insertions(+), 274 deletions(-) create mode 100644 mod/quiz/amd/build/repaginate.min.js create mode 100644 mod/quiz/amd/src/repaginate.js delete mode 100644 mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate-debug.js delete mode 100644 mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate-min.js delete mode 100644 mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate.js delete mode 100644 mod/quiz/yui/src/repaginate/build.json delete mode 100644 mod/quiz/yui/src/repaginate/js/repaginate.js delete mode 100644 mod/quiz/yui/src/repaginate/meta/repaginate.json diff --git a/mod/quiz/amd/build/repaginate.min.js b/mod/quiz/amd/build/repaginate.min.js new file mode 100644 index 00000000000..cd9d3a2d1f7 --- /dev/null +++ b/mod/quiz/amd/build/repaginate.min.js @@ -0,0 +1 @@ +define(["jquery","core/modal_factory"],function(a,b){var c={REPAGINATECOMMAND:"#repaginatecommand",HEADER:"header",BODY:"form"},d=function(){b.create({title:a(c.REPAGINATECOMMAND).data(c.HEADER),body:a(c.REPAGINATECOMMAND).data(c.BODY),large:!1},a(c.REPAGINATECOMMAND))};return{init:d}}); \ No newline at end of file diff --git a/mod/quiz/amd/src/repaginate.js b/mod/quiz/amd/src/repaginate.js new file mode 100644 index 00000000000..77203032acb --- /dev/null +++ b/mod/quiz/amd/src/repaginate.js @@ -0,0 +1,48 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Initialise the repaginate dialogue on quiz editing page. + * + * @module mod_quiz/repaginate + * @package mod_quiz + * @copyright 2019 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +define(['jquery', 'core/modal_factory'], function($, ModalFactory) { + + var SELECTORS = { + REPAGINATECOMMAND: '#repaginatecommand', + HEADER: 'header', + BODY: 'form' + }; + + /** + * Initialise the repaginate button and add the event listener. + */ + var init = function() { + ModalFactory.create( + { + title: $(SELECTORS.REPAGINATECOMMAND).data(SELECTORS.HEADER), + body: $(SELECTORS.REPAGINATECOMMAND).data(SELECTORS.BODY), + large: false, + }, + $(SELECTORS.REPAGINATECOMMAND) + ); + }; + return { + init: init + }; +}); diff --git a/mod/quiz/classes/output/edit_renderer.php b/mod/quiz/classes/output/edit_renderer.php index 021a19fb4a8..d1d12063d63 100644 --- a/mod/quiz/classes/output/edit_renderer.php +++ b/mod/quiz/classes/output/edit_renderer.php @@ -193,7 +193,6 @@ class edit_renderer extends \plugin_renderer_base { * @return string HTML to output. */ protected function repaginate_button(structure $structure, \moodle_url $pageurl) { - $header = html_writer::tag('span', get_string('repaginatecommand', 'quiz'), array('class' => 'repaginatecommand')); $form = $this->repaginate_form($structure, $pageurl); @@ -209,7 +208,7 @@ class edit_renderer extends \plugin_renderer_base { if (!$structure->can_be_repaginated()) { $buttonoptions['disabled'] = 'disabled'; } else { - $this->page->requires->yui_module('moodle-mod_quiz-repaginate', 'M.mod_quiz.repaginate.init'); + $this->page->requires->js_call_amd('mod_quiz/repaginate', 'init'); } return html_writer::empty_tag('input', $buttonoptions); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate-debug.js b/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate-debug.js deleted file mode 100644 index ad23f7a040d..00000000000 --- a/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate-debug.js +++ /dev/null @@ -1,85 +0,0 @@ -YUI.add('moodle-mod_quiz-repaginate', function (Y, NAME) { - -// This file is part of Moodle - http://moodle.org/ -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - - -/** - * Repaginate functionality for a popup in quiz editing page. - * - * @package mod_quiz - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -var CSS = { - REPAGINATECOMMAND: '#repaginatecommand' -}; - -var PARAMS = { - CMID: 'cmid', - HEADER: 'header', - FORM: 'form' -}; - -var POPUP = function() { - POPUP.superclass.constructor.apply(this, arguments); -}; - -Y.extend(POPUP, Y.Base, { - header: null, - body: null, - - initializer: function() { - var repaginatebutton = Y.one(CSS.REPAGINATECOMMAND); - - // Set popup header and body. - this.header = repaginatebutton.getData(PARAMS.HEADER); - this.body = repaginatebutton.getData(PARAMS.FORM); - repaginatebutton.on('click', this.display_dialog, this); - }, - - display_dialog: function(e) { - e.preventDefault(); - - // Configure the popup. - var config = { - headerContent: this.header, - bodyContent: this.body, - draggable: true, - modal: true, - zIndex: 1000, - context: [CSS.REPAGINATECOMMAND, 'tr', 'br', ['beforeShow']], - centered: false, - width: '30em', - visible: false, - postmethod: 'form', - footerContent: null - }; - - var popup = {dialog: null}; - popup.dialog = new M.core.dialogue(config); - popup.dialog.show(); - } -}); - -M.mod_quiz = M.mod_quiz || {}; -M.mod_quiz.repaginate = M.mod_quiz.repaginate || {}; -M.mod_quiz.repaginate.init = function() { - return new POPUP(); -}; - - -}, '@VERSION@', {"requires": ["base", "event", "node", "io", "moodle-core-notification-dialogue"]}); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate-min.js b/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate-min.js deleted file mode 100644 index 9830b4a01b8..00000000000 --- a/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate-min.js +++ /dev/null @@ -1 +0,0 @@ -YUI.add("moodle-mod_quiz-repaginate",function(e,t){var n={REPAGINATECOMMAND:"#repaginatecommand"},r={CMID:"cmid",HEADER:"header",FORM:"form"},i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,e.Base,{header:null,body:null,initializer:function(){var t=e.one(n.REPAGINATECOMMAND);this.header=t.getData(r.HEADER),this.body=t.getData(r.FORM),t.on("click",this.display_dialog,this)},display_dialog:function(e){e.preventDefault();var t={headerContent:this.header,bodyContent:this.body,draggable:!0,modal:!0,zIndex:1e3,context:[n.REPAGINATECOMMAND,"tr","br",["beforeShow"]],centered:!1,width:"30em",visible:!1,postmethod:"form",footerContent:null},r={dialog:null};r.dialog=new M.core.dialogue(t),r.dialog.show()}}),M.mod_quiz=M.mod_quiz||{},M.mod_quiz.repaginate=M.mod_quiz.repaginate||{},M.mod_quiz.repaginate.init=function(){return new i}},"@VERSION@",{requires:["base","event","node","io","moodle-core-notification-dialogue"]}); diff --git a/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate.js b/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate.js deleted file mode 100644 index ad23f7a040d..00000000000 --- a/mod/quiz/yui/build/moodle-mod_quiz-repaginate/moodle-mod_quiz-repaginate.js +++ /dev/null @@ -1,85 +0,0 @@ -YUI.add('moodle-mod_quiz-repaginate', function (Y, NAME) { - -// This file is part of Moodle - http://moodle.org/ -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - - -/** - * Repaginate functionality for a popup in quiz editing page. - * - * @package mod_quiz - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -var CSS = { - REPAGINATECOMMAND: '#repaginatecommand' -}; - -var PARAMS = { - CMID: 'cmid', - HEADER: 'header', - FORM: 'form' -}; - -var POPUP = function() { - POPUP.superclass.constructor.apply(this, arguments); -}; - -Y.extend(POPUP, Y.Base, { - header: null, - body: null, - - initializer: function() { - var repaginatebutton = Y.one(CSS.REPAGINATECOMMAND); - - // Set popup header and body. - this.header = repaginatebutton.getData(PARAMS.HEADER); - this.body = repaginatebutton.getData(PARAMS.FORM); - repaginatebutton.on('click', this.display_dialog, this); - }, - - display_dialog: function(e) { - e.preventDefault(); - - // Configure the popup. - var config = { - headerContent: this.header, - bodyContent: this.body, - draggable: true, - modal: true, - zIndex: 1000, - context: [CSS.REPAGINATECOMMAND, 'tr', 'br', ['beforeShow']], - centered: false, - width: '30em', - visible: false, - postmethod: 'form', - footerContent: null - }; - - var popup = {dialog: null}; - popup.dialog = new M.core.dialogue(config); - popup.dialog.show(); - } -}); - -M.mod_quiz = M.mod_quiz || {}; -M.mod_quiz.repaginate = M.mod_quiz.repaginate || {}; -M.mod_quiz.repaginate.init = function() { - return new POPUP(); -}; - - -}, '@VERSION@', {"requires": ["base", "event", "node", "io", "moodle-core-notification-dialogue"]}); diff --git a/mod/quiz/yui/src/repaginate/build.json b/mod/quiz/yui/src/repaginate/build.json deleted file mode 100644 index fc6e1f7d235..00000000000 --- a/mod/quiz/yui/src/repaginate/build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "moodle-mod_quiz-repaginate", - "builds": { - "moodle-mod_quiz-repaginate": { - "jsfiles": [ - "repaginate.js" - ] - } - } -} diff --git a/mod/quiz/yui/src/repaginate/js/repaginate.js b/mod/quiz/yui/src/repaginate/js/repaginate.js deleted file mode 100644 index c7a75d88838..00000000000 --- a/mod/quiz/yui/src/repaginate/js/repaginate.js +++ /dev/null @@ -1,80 +0,0 @@ -// This file is part of Moodle - http://moodle.org/ -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - - -/** - * Repaginate functionality for a popup in quiz editing page. - * - * @package mod_quiz - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -var CSS = { - REPAGINATECOMMAND: '#repaginatecommand' -}; - -var PARAMS = { - CMID: 'cmid', - HEADER: 'header', - FORM: 'form' -}; - -var POPUP = function() { - POPUP.superclass.constructor.apply(this, arguments); -}; - -Y.extend(POPUP, Y.Base, { - header: null, - body: null, - - initializer: function() { - var repaginatebutton = Y.one(CSS.REPAGINATECOMMAND); - - // Set popup header and body. - this.header = repaginatebutton.getData(PARAMS.HEADER); - this.body = repaginatebutton.getData(PARAMS.FORM); - repaginatebutton.on('click', this.display_dialog, this); - }, - - display_dialog: function(e) { - e.preventDefault(); - - // Configure the popup. - var config = { - headerContent: this.header, - bodyContent: this.body, - draggable: true, - modal: true, - zIndex: 1000, - context: [CSS.REPAGINATECOMMAND, 'tr', 'br', ['beforeShow']], - centered: false, - width: '30em', - visible: false, - postmethod: 'form', - footerContent: null - }; - - var popup = {dialog: null}; - popup.dialog = new M.core.dialogue(config); - popup.dialog.show(); - } -}); - -M.mod_quiz = M.mod_quiz || {}; -M.mod_quiz.repaginate = M.mod_quiz.repaginate || {}; -M.mod_quiz.repaginate.init = function() { - return new POPUP(); -}; diff --git a/mod/quiz/yui/src/repaginate/meta/repaginate.json b/mod/quiz/yui/src/repaginate/meta/repaginate.json deleted file mode 100644 index c97b768fab6..00000000000 --- a/mod/quiz/yui/src/repaginate/meta/repaginate.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "moodle-mod_quiz-repaginate": { - "requires": [ - "base", - "event", - "node", - "io", - "moodle-core-notification-dialogue" - ] - } -}