)), 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',
$courseid = required_param('courseid', PARAM_INT);
$pagelayout = required_param('pagelayout', PARAM_ALPHAEXT);
$pagetype = required_param('pagetype', PARAM_ALPHAEXT);
+$contextid = required_param('contextid', PARAM_INT);
$subpage = optional_param('subpage', '', PARAM_ALPHANUMEXT);
$cmid = optional_param('cmid', null, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
require_login($courseid, false, $cm);
require_sesskey();
+// Set context from ID, so we don't have to guess it from other info.
+$PAGE->set_context(context::instance_by_id($contextid));
+
// 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 'my':
+ // My Home page needs to have 'content' block region set up.
+ $PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
+ $PAGE->blocks->add_region('content');
+ break;
+ case 'user':
+ if ($pagelayout == 'mydashboard') {
+ // User profile pages also need the 'content' block region set up.
+ $PAGE->blocks->add_region('content');
+ // If it's not the current user's profile, we need a different capability.
+ if ($PAGE->context->contextlevel == CONTEXT_USER && $PAGE->context->instanceid != $USER->id) {
+ $PAGE->set_blocks_editing_capability('moodle/user:manageblocks');
+ } else {
+ $PAGE->set_blocks_editing_capability('moodle/user:manageownblocks');
+ }
+ }
+ break;
+}
+
echo $OUTPUT->header(); // send headers
switch ($action) {
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(),
+ 'contextid' => $page->context->id,
+ );
+ 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);
+ }
}
/**
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() {
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);
var regioncontent = Y.Node.create('<div></div>')
.addClass(CSS.REGIONCONTENT);
blockregion.appendChild(regioncontent);
+ var pre = blockregionlist.filter('#region-pre');
+ var post = blockregionlist.filter('#region-post');
- var regionid = this.get_region_id(blockregionlist.item(0));
- if (regionid === 'post') {
+ if (pre.size() === 0 && post.size() === 1) {
// pre block is missing, instert it before post
blockregion.setAttrs({id : 'region-pre'});
- blockregionlist.item(0).insert(blockregion, 'before');
+ post.item(0).insert(blockregion, 'before');
blockregionlist.unshift(blockregion);
- } else {
+ } else if (post.size() === 0 && pre.size() === 1) {
// post block is missing, instert it after pre
blockregion.setAttrs({id : 'region-post'});
- blockregionlist.item(0).insert(blockregion, 'after');
+ pre.item(0).insert(blockregion, 'after');
blockregionlist.push(blockregion);
}
}
pagelayout : this.get('pagelayout'),
pagetype : this.get('pagetype'),
subpage : this.get('subpage'),
+ contextid : this.get('contextid'),
action : 'move',
bui_moveid : this.get_block_id(dragnode),
bui_newregion : this.get_block_region(dropnode)
cmid : {
value : null
},
+ contextid : {
+ value : null
+ },
pagelayout : {
value : null
},
echo "</table></div></div>";
-
+echo '<div id="region-content" class="block-region"><div class="region-content">';
echo $OUTPUT->blocks_for_region('content');
+echo '</div></div>';
// Print messaging link if allowed
if (isloggedin() && has_capability('moodle/site:sendmessage', $context)