Permalink
Browse files

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.
  • Loading branch information...
1 parent ca48fe5 commit d7c29c22572314680350ccdcf801f188aca541e4 @pauln pauln committed Jan 15, 2013
Showing with 41 additions and 11 deletions.
  1. +0 −10 course/lib.php
  2. +14 −0 lib/ajax/blocks.php
  3. +15 −0 lib/outputrequirementslib.php
  4. +12 −1 lib/yui/blocks/blocks.js
View
@@ -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',
View
@@ -53,6 +53,20 @@
// 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 @@ protected function init_requirements_data(moodle_page $page, core_renderer $rend
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);
+ }
}
/**
@@ -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);

0 comments on commit d7c29c2

Please sign in to comment.