[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/quiz/amd/src/ -> preflightcheck.js (source)

   1  // This file is part of Moodle - http://moodle.org/
   2  //
   3  // Moodle is free software: you can redistribute it and/or modify
   4  // it under the terms of the GNU General Public License as published by
   5  // the Free Software Foundation, either version 3 of the License, or
   6  // (at your option) any later version.
   7  //
   8  // Moodle is distributed in the hope that it will be useful,
   9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11  // GNU General Public License for more details.
  12  //
  13  // You should have received a copy of the GNU General Public License
  14  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  15  
  16  /**
  17   * This class manages the confirmation pop-up (also called the pre-flight check)
  18   * that is sometimes shown when a use clicks the start attempt button.
  19   *
  20   * This is also responsible for opening the pop-up window, if the quiz requires to be in one.
  21   *
  22   * @module    mod_quiz/preflightcheck
  23   * @class     preflightcheck
  24   * @package   mod_quiz
  25   * @copyright 2016 The Open University
  26   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   * @since     3.1
  28   */
  29  define(['jquery', 'core/yui'], function($, Y) {
  30  
  31      /**
  32       * @alias module:mod_quiz/preflightcheck
  33       */
  34      var t = {
  35          confirmDialogue: null,
  36  
  37          /**
  38           * Initialise the start attempt button.
  39           *
  40           * @param {String} startButton the id of the start attempt button that we will be enhancing.
  41           * @param {String} confirmationTitle the title of the dialogue.
  42           * @param {String} confirmationForm selector for the confirmation form to show in the dialogue.
  43           * @param {String} popupoptions If not null, the quiz should be launced in a pop-up.
  44           */
  45          init: function(startButton, confirmationTitle, confirmationForm, popupoptions) {
  46              var finalStartButton = startButton;
  47  
  48              Y.use('moodle-core-notification', 'moodle-core-formchangechecker', 'io-form', function() {
  49                  if (Y.one(confirmationForm)) {
  50                      t.confirmDialogue = new M.core.dialogue({
  51                          headerContent: confirmationTitle,
  52                          bodyContent: Y.one(confirmationForm),
  53                          draggable: true,
  54                          visible: false,
  55                          center: true,
  56                          modal: true,
  57                          width: null,
  58                          extraClasses: ['mod_quiz_preflight_popup']
  59                      });
  60  
  61                      Y.one(startButton).on('click', t.displayDialogue);
  62                      Y.one('#id_cancel').on('click', t.hideDialogue);
  63  
  64                      finalStartButton = t.confirmDialogue.get('boundingBox').one('[name="submitbutton"]');
  65                  }
  66  
  67                  if (popupoptions) {
  68                      Y.one(finalStartButton).on('click', t.launchQuizPopup, t, popupoptions);
  69                  }
  70              });
  71          },
  72  
  73          /**
  74           * Display the dialogue.
  75           * @param {Y.EventFacade} e the event being responded to, if any.
  76           */
  77          displayDialogue: function(e) {
  78              if (e) {
  79                  e.halt();
  80              }
  81              t.confirmDialogue.show();
  82          },
  83  
  84          /**
  85           * Hide the dialogue.
  86           * @param {Y.EventFacade} e the event being responded to, if any.
  87           */
  88          hideDialogue: function(e) {
  89              if (e) {
  90                  e.halt();
  91              }
  92              t.confirmDialogue.hide(e);
  93          },
  94  
  95          /**
  96           * Event handler for the quiz start attempt button.
  97            * @param {Event} e the event being responded to
  98            * @param {Object} popupoptions
  99           */
 100          launchQuizPopup: function(e, popupoptions) {
 101              e.halt();
 102              M.core_formchangechecker.reset_form_dirty_state();
 103              var form = e.target.ancestor('form');
 104              window.openpopup(e, {
 105                  url: form.get('action') + '?' + Y.IO.stringify(form).replace(/\bcancel=/, 'x='),
 106                  windowname: 'quizpopup',
 107                  options: popupoptions,
 108                  fullscreen: true,
 109              });
 110          }
 111      };
 112  
 113      return t;
 114  });


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1