[ Index ]

PHP Cross Reference of Moodle 310

title

Body

[close]

/lib/amd/src/ -> addblockmodal.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   * Show an add block modal instead of doing it on a separate page.
  18   *
  19   * @module     core/addblockmodal
  20   * @copyright  2016 Damyon Wiese <damyon@moodle.com>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  define(['jquery', 'core/modal_factory', 'core/templates', 'core/str', 'core/notification'],
  24         function($, ModalFactory, Templates, Str, Notification) {
  25  
  26  
  27      return /** @alias module:core/addblockmodal */ {
  28          /**
  29           * Global init function for this module.
  30           *
  31           * @method init
  32           * @param {Object} context The template context for rendering this modal body.
  33           */
  34          init: function(context) {
  35              var addblocklink = $('[data-key=addblock]');
  36  
  37              // We need the fetch the names of the blocks. It was too much to send in the page.
  38              var titlerequests = context.blocks.map(function(blockName) {
  39                  return {
  40                      key: 'pluginname',
  41                      component: 'block_' + blockName,
  42                  };
  43              });
  44  
  45              var bodyPromise = Str.get_strings(titlerequests)
  46              .then(function(titles) {
  47                  return titles.map(function(title, index) {
  48                      return {
  49                          name: context.blocks[index],
  50                          title: title,
  51                      };
  52                  });
  53              })
  54              .then(function(blocks) {
  55                  context.blocks = blocks;
  56                  return Templates.render('core/add_block_body', context);
  57              })
  58              .fail(Notification.exception);
  59  
  60              var titlePromise = Str.get_string('addblock')
  61              .fail(Notification.exception);
  62  
  63              ModalFactory.create({
  64                  title: titlePromise,
  65                  body: bodyPromise,
  66                  type: 'CANCEL',
  67              }, addblocklink);
  68          }
  69      };
  70  });


Generated: Wed Jan 22 11:59:49 2025 Cross-referenced by PHPXref 0.7.1