Skip to content

Commit

Permalink
Merge branch 'MDL-32652_master' of git://github.com/pauln/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jan 21, 2013
2 parents 2f61796 + d7c29c2 commit 94abbef
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
10 changes: 0 additions & 10 deletions course/lib.php
Expand Up @@ -3760,16 +3760,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',
Expand Down
14 changes: 14 additions & 0 deletions lib/ajax/blocks.php
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions lib/outputrequirementslib.php
Expand Up @@ -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);
}
}

/**
Expand Down
13 changes: 12 additions & 1 deletion lib/yui/blocks/blocks.js
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down

0 comments on commit 94abbef

Please sign in to comment.