mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-32652 - Make block drag-drop work throughout Moodle
Other than shifting the initialisation from course/lib.php to lib/outputrequirementslib.php, some workarounds/tweaks were required in order to make it work correctly on admin pages and My Home.
This commit is contained in:
parent
ca48fe5f97
commit
d7c29c2257
@ -4503,16 +4503,6 @@ function include_course_ajax($course, $usedmodules = array(), $enabledmodules =
|
||||
)), null, true);
|
||||
}
|
||||
|
||||
// Include blocks dragdrop
|
||||
$params = array(
|
||||
'courseid' => $course->id,
|
||||
'pagetype' => $PAGE->pagetype,
|
||||
'pagelayout' => $PAGE->pagelayout,
|
||||
'subpage' => $PAGE->subpage,
|
||||
'regions' => $PAGE->blocks->get_regions(),
|
||||
);
|
||||
$PAGE->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true);
|
||||
|
||||
// Require various strings for the command toolbox
|
||||
$PAGE->requires->strings_for_js(array(
|
||||
'moveleft',
|
||||
|
@ -53,6 +53,20 @@ require_sesskey();
|
||||
// Setting layout to replicate blocks configuration for the page we edit
|
||||
$PAGE->set_pagelayout($pagelayout);
|
||||
$PAGE->set_subpage($subpage);
|
||||
$pagetype = explode('-', $pagetype);
|
||||
switch ($pagetype[0]) {
|
||||
case 'admin':
|
||||
// Admin pages need to be in the system context, not Site Course context.
|
||||
$PAGE->set_context(context_system::instance());
|
||||
break;
|
||||
case 'my':
|
||||
// My Home page needs to be in user context, and to have 'content' block region set up.
|
||||
$PAGE->set_context(context_user::instance($USER->id));
|
||||
$PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
|
||||
$PAGE->blocks->add_region('content');
|
||||
break;
|
||||
}
|
||||
|
||||
echo $OUTPUT->header(); // send headers
|
||||
|
||||
switch ($action) {
|
||||
|
@ -282,6 +282,21 @@ class page_requirements_manager {
|
||||
if ($page->pagelayout === 'frametop') {
|
||||
$this->js_init_call('M.util.init_frametop');
|
||||
}
|
||||
|
||||
// Include block drag/drop if editing is on
|
||||
if ($page->user_is_editing()) {
|
||||
$params = array(
|
||||
'courseid' => $page->course->id,
|
||||
'pagetype' => $page->pagetype,
|
||||
'pagelayout' => $page->pagelayout,
|
||||
'subpage' => $page->subpage,
|
||||
'regions' => $page->blocks->get_regions(),
|
||||
);
|
||||
if (!empty($page->cm->id)) {
|
||||
$params['cmid'] = $page->cm->id;
|
||||
}
|
||||
$page->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
13
lib/yui/blocks/blocks.js
vendored
13
lib/yui/blocks/blocks.js
vendored
@ -10,7 +10,9 @@ YUI.add('moodle-core-blocks', function(Y) {
|
||||
LIGHTBOX : 'lightbox',
|
||||
REGIONCONTENT : 'region-content',
|
||||
SKIPBLOCK : 'skip-block',
|
||||
SKIPBLOCKTO : 'skip-block-to'
|
||||
SKIPBLOCKTO : 'skip-block-to',
|
||||
MYINDEX : 'page-my-index',
|
||||
REGIONMAIN : 'region-main'
|
||||
}
|
||||
|
||||
var DRAGBLOCK = function() {
|
||||
@ -26,6 +28,15 @@ YUI.add('moodle-core-blocks', function(Y) {
|
||||
this.samenodeclass = CSS.BLOCK;
|
||||
this.parentnodeclass = CSS.REGIONCONTENT;
|
||||
|
||||
// Add relevant classes and ID to 'content' block region on My Home page.
|
||||
var myhomecontent = Y.Node.all('body#'+CSS.MYINDEX+' #'+CSS.REGIONMAIN+' > .'+CSS.REGIONCONTENT);
|
||||
if (myhomecontent.size() > 0) {
|
||||
var contentregion = myhomecontent.item(0);
|
||||
contentregion.addClass(CSS.BLOCKREGION);
|
||||
contentregion.set('id', CSS.REGIONCONTENT);
|
||||
contentregion.one('div').addClass(CSS.REGIONCONTENT);
|
||||
}
|
||||
|
||||
// Initialise blocks dragging
|
||||
// Find all block regions on the page
|
||||
var blockregionlist = Y.Node.all('div.'+CSS.BLOCKREGION);
|
||||
|
Loading…
x
Reference in New Issue
Block a user