Merge branch 'wip-mdl-36619' of git://github.com/rajeshtaneja/moodle

This commit is contained in:
Sam Hemelryk 2013-01-29 10:50:14 +13:00
commit 3178ae6f09
7 changed files with 110 additions and 141 deletions

View file

@ -85,9 +85,6 @@ class block_course_overview extends block_base {
// For each course, build category cache. // For each course, build category cache.
$this->content->text .= $renderer->course_overview($sortedcourses, $overviews); $this->content->text .= $renderer->course_overview($sortedcourses, $overviews);
$this->content->text .= $renderer->hidden_courses($totalcourses - count($sortedcourses)); $this->content->text .= $renderer->hidden_courses($totalcourses - count($sortedcourses));
if ($this->page->user_is_editing() && ajaxenabled()) {
$this->page->requires->js_init_call('M.block_course_overview.add_handles');
}
} }
return $this->content; return $this->content;

View file

@ -37,7 +37,11 @@ $string['hiddencoursecount'] = 'You have {$a} hidden course';
$string['hiddencoursecountplural'] = 'You have {$a} hidden courses'; $string['hiddencoursecountplural'] = 'You have {$a} hidden courses';
$string['message'] = 'message'; $string['message'] = 'message';
$string['messages'] = 'messages'; $string['messages'] = 'messages';
$string['movecourse'] = 'Move course: {$a}';
$string['movecoursehere'] = 'Move course here'; $string['movecoursehere'] = 'Move course here';
$string['movetofirst'] = 'Move {$a} course to top';
$string['moveafterhere'] = 'Move {$a->movingcoursename} course after {$a->currentcoursename}';
$string['movingcourse'] = 'You are moving: {$a->fullname} ({$a->cancellink})';
$string['numtodisplay'] = 'Number of courses to display: '; $string['numtodisplay'] = 'Number of courses to display: ';
$string['otherexpanded'] = 'Other Courses Expanded'; $string['otherexpanded'] = 'Other Courses Expanded';
$string['pluginname'] = 'Course overview'; $string['pluginname'] = 'Course overview';

View file

@ -2,12 +2,23 @@ M.block_course_overview = {}
M.block_course_overview.add_handles = function(Y) { M.block_course_overview.add_handles = function(Y) {
M.block_course_overview.Y = Y; M.block_course_overview.Y = Y;
var MOVEICON = {
pix: "i/move_2d",
component: 'moodle'
};
YUI().use('dd-constrain', 'dd-proxy', 'dd-drop', 'dd-plugin', function(Y) { YUI().use('dd-constrain', 'dd-proxy', 'dd-drop', 'dd-plugin', function(Y) {
//Static Vars //Static Vars
var goingUp = false, lastY = 0; var goingUp = false, lastY = 0;
var list = Y.Node.all('#course_list .coursebox'); var list = Y.Node.all('.course_list .coursebox');
list.each(function(v, k) { list.each(function(v, k) {
// Replace move link and image with move_2d image.
var imagenode = v.one('.course_title .move a img');
imagenode.setAttribute('src', M.util.image_url(MOVEICON.pix, MOVEICON.component));
imagenode.addClass('cursor');
v.one('.course_title .move a').replace(imagenode);
var dd = new Y.DD.Drag({ var dd = new Y.DD.Drag({
node: v, node: v,
target: { target: {
@ -16,18 +27,11 @@ M.block_course_overview.add_handles = function(Y) {
}).plug(Y.Plugin.DDProxy, { }).plug(Y.Plugin.DDProxy, {
moveOnEnd: false moveOnEnd: false
}).plug(Y.Plugin.DDConstrained, { }).plug(Y.Plugin.DDConstrained, {
constrain2node: '#course_list' constrain2node: '.course_list'
}); });
dd.addHandle('.course_title .move'); dd.addHandle('.course_title .move');
}); });
var drops = Y.Node.all('#coursebox');
drops.each(function(v, k) {
var tar = new Y.DD.Drop({
node: v
});
});
Y.DD.DDM.on('drag:start', function(e) { Y.DD.DDM.on('drag:start', function(e) {
//Get our drag object //Get our drag object
var drag = e.target; var drag = e.target;
@ -101,7 +105,7 @@ M.block_course_overview.add_handles = function(Y) {
M.block_course_overview.save = function() { M.block_course_overview.save = function() {
var Y = M.block_course_overview.Y; var Y = M.block_course_overview.Y;
var sortorder = Y.one('#course_list').get('children').getAttribute('id'); var sortorder = Y.one('.course_list').get('children').getAttribute('id');
for (var i = 0; i < sortorder.length; i++) { for (var i = 0; i < sortorder.length; i++) {
sortorder[i] = sortorder[i].substring(7); sortorder[i] = sortorder[i].substring(7);
} }

View file

@ -27,47 +27,34 @@ require_once(dirname(__FILE__) . '/locallib.php');
require_sesskey(); require_sesskey();
require_login(); require_login();
$source = required_param('source', PARAM_INT); $coursetomove = required_param('courseid', PARAM_INT);
$move = required_param('move', PARAM_INT); $moveto = required_param('moveto', PARAM_INT);
list($courses_sorted, $sitecourses, $coursecount) = block_course_overview_get_sorted_courses(); list($courses, $sitecourses, $coursecount) = block_course_overview_get_sorted_courses();
$sortorder = array_keys($courses_sorted); $sortedcourses = array_keys($courses);
// Now resort based on new weight for chosen course.
$neworder = array();
$sourcekey = array_search($source, $sortorder); $currentcourseindex = array_search($coursetomove, $sortedcourses);
if ($sourcekey === false) { // If coursetomove is not found or moveto < 0 or > count($sortedcourses) then throw error.
print_error("invalidcourseid", null, null, $source); if ($currentcourseindex === false) {
print_error("invalidcourseid", null, null, $coursetomove);
} else if (($moveto < 0) || ($moveto >= count($sortedcourses))) {
print_error("invalidaction");
} }
$destination = $sourcekey + $move; // If current course index is same as destination index then don't do anything.
if ($destination < 0) { if ($currentcourseindex === $moveto) {
print_error("listcantmoveup"); redirect(new moodle_url('/my/index.php'));
} else if ($destination >= count($courses_sorted)) {
print_error("listcantmovedown");
} }
// Create neworder list for courses. // Create neworder list for courses.
unset($sortorder[$sourcekey]); $neworder = array();
if ($move == -1) {
if ($destination > 0) {
$neworder = array_slice($sortorder, 0, $destination, true);
}
$neworder[] = $source;
$remaningcourses = array_slice($sortorder, $destination);
foreach ($remaningcourses as $courseid) {
$neworder[] = $courseid;
}
} else if (($move == 1)) {
$neworder = array_slice($sortorder, 0, $destination);
$neworder[] = $source;
if (($destination) < count($courses_sorted)) {
$remaningcourses = array_slice($sortorder, $destination);
foreach ($remaningcourses as $courseid) {
$neworder[] = $courseid;
}
}
}
block_course_overview_update_myorder($neworder); unset($sortedcourses[$currentcourseindex]);
$neworder = array_slice($sortedcourses, 0, $moveto, true);
$neworder[] = $coursetomove;
$remaningcourses = array_slice($sortedcourses, $moveto);
foreach ($remaningcourses as $courseid) {
$neworder[] = $courseid;
}
block_course_overview_update_myorder(array_values($neworder));
redirect(new moodle_url('/my/index.php')); redirect(new moodle_url('/my/index.php'));

View file

@ -41,67 +41,64 @@ class block_course_overview_renderer extends plugin_renderer_base {
public function course_overview($courses, $overviews) { public function course_overview($courses, $overviews) {
$html = ''; $html = '';
$config = get_config('block_course_overview'); $config = get_config('block_course_overview');
$ismovingcourse = false;
$html .= html_writer::start_tag('div', array('id' => 'course_list'));
$courseordernumber = 0; $courseordernumber = 0;
$maxcourses = count($courses); $maxcourses = count($courses);
// Intialize string/icon etc if user is editing. $userediting = false;
$url = null; // Intialise string/icon etc if user is editing and courses > 1
$moveicon = null; if ($this->page->user_is_editing() && (count($courses) > 1)) {
$moveup[] = null; $userediting = true;
$movedown[] = null; // If ajaxenabled then include DND JS and replace link with move image.
if ($this->page->user_is_editing()) {
if (ajaxenabled()) { if (ajaxenabled()) {
$moveicon = html_writer::tag('div', $this->page->requires->js_init_call('M.block_course_overview.add_handles');
html_writer::empty_tag('img',
array('src' => $this->pix_url('i/move_2d')->out(false),
'alt' => get_string('move'), 'class' => 'cursor',
'title' => get_string('move'))
), array('class' => 'move')
);
} else {
$url = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey()));
$moveup['str'] = get_string('moveup');
$moveup['icon'] = $this->pix_url('t/up');
$movedown['str'] = get_string('movedown');
$movedown['icon'] = $this->pix_url('t/down');
} }
// Check if course is moving
$ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL);
$movingcourseid = optional_param('courseid', 0, PARAM_INT);
}
// Render first movehere icon.
if ($ismovingcourse) {
// Remove movecourse param from url.
$this->page->ensure_param_not_in_url('movecourse');
// Show moving course notice, so user knows what is being moved.
$html .= $this->output->box_start('notice');
$a = new stdClass();
$a->fullname = $courses[$movingcourseid]->fullname;
$a->cancellink = html_writer::link($this->page->url, get_string('cancel'));
$html .= get_string('movingcourse', 'block_course_overview', $a);
$html .= $this->output->box_end();
$moveurl = new moodle_url('/blocks/course_overview/move.php',
array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid));
// Create move icon, so it can be used.
$movetofirsticon = html_writer::empty_tag('img',
array('src' => $this->output->pix_url('movehere'),
'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname),
'title' => get_string('movehere')));
$moveurl = html_writer::link($moveurl, $movetofirsticon);
$html .= html_writer::tag('div', $moveurl, array('class' => 'movehere'));
} }
foreach ($courses as $key => $course) { foreach ($courses as $key => $course) {
// If moving course, then don't show course which needs to be moved.
if ($ismovingcourse && ($course->id == $movingcourseid)) {
continue;
}
$html .= $this->output->box_start('coursebox', "course-{$course->id}"); $html .= $this->output->box_start('coursebox', "course-{$course->id}");
$html .= html_writer::start_tag('div', array('class' => 'course_title')); $html .= html_writer::start_tag('div', array('class' => 'course_title'));
// Ajax enabled then add moveicon html // If user is editing, then add move icons.
if (!is_null($moveicon)) { if ($userediting && !$ismovingcourse) {
$html .= $moveicon; $moveicon = html_writer::empty_tag('img',
} else if (!is_null($url)) { array('src' => $this->pix_url('t/move')->out(false),
// Add course id to move link 'alt' => get_string('movecourse', 'block_course_overview', $course->fullname),
$url->param('source', $course->id); 'title' => get_string('move')));
$html .= html_writer::start_tag('div', array('class' => 'moveicons')); $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id));
// Add an arrow to move course up. $moveurl = html_writer::link($moveurl, $moveicon);
if ($courseordernumber > 0) { $html .= html_writer::tag('div', $moveurl, array('class' => 'move'));
$url->param('move', -1);
$html .= html_writer::link($url,
html_writer::empty_tag('img', array('src' => $moveup['icon'],
'class' => 'up', 'alt' => $moveup['str'])),
array('title' => $moveup['str'], 'class' => 'moveup'));
} else {
// Add a spacer to keep keep down arrow icons at right position.
$html .= html_writer::empty_tag('img', array('src' => $this->pix_url('spacer'),
'class' => 'movedownspacer'));
}
// Add an arrow to move course down.
if ($courseordernumber <= $maxcourses-2) {
$url->param('move', 1);
$html .= html_writer::link($url, html_writer::empty_tag('img',
array('src' => $movedown['icon'], 'class' => 'down', 'alt' => $movedown['str'])),
array('title' => $movedown['str'], 'class' => 'movedown'));
} else {
// Add a spacer to keep keep up arrow icons at right position.
$html .= html_writer::empty_tag('img', array('src' => $this->pix_url('spacer'),
'class' => 'moveupspacer'));
}
$html .= html_writer::end_tag('div');
} }
$attributes = array('title' => s($course->fullname)); $attributes = array('title' => s($course->fullname));
@ -125,17 +122,30 @@ class block_course_overview_renderer extends plugin_renderer_base {
} }
} }
if (isset($overviews[$course->id])) { // If user is moving courses, then down't show overview.
if (isset($overviews[$course->id]) && !$ismovingcourse) {
$html .= $this->activity_display($course->id, $overviews[$course->id]); $html .= $this->activity_display($course->id, $overviews[$course->id]);
} }
$html .= $this->output->box('', 'flush'); $html .= $this->output->box('', 'flush');
$html .= $this->output->box_end(); $html .= $this->output->box_end();
$courseordernumber++; $courseordernumber++;
if ($ismovingcourse) {
$moveurl = new moodle_url('/blocks/course_overview/move.php',
array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid));
$a = new stdClass();
$a->movingcoursename = $courses[$movingcourseid]->fullname;
$a->currentcoursename = $course->fullname;
$movehereicon = html_writer::empty_tag('img',
array('src' => $this->output->pix_url('movehere'),
'alt' => get_string('moveafterhere', 'block_course_overview', $a),
'title' => get_string('movehere')));
$moveurl = html_writer::link($moveurl, $movehereicon);
$html .= html_writer::tag('div', $moveurl, array('class' => 'movehere'));
} }
$html .= html_writer::end_tag('div'); }
// Wrap course list in a div and return.
return $html; return html_writer::tag('div', $html, array('class' => 'course_list'));
} }
/** /**

View file

@ -64,36 +64,7 @@
padding: 2px 10px; padding: 2px 10px;
} }
.editing .block_course_overview .moveicons { .block_course_overview .course_list {
display: block;
float: left;
padding-right: 5px;
}
.dir-rtl.editing .block_course_overview .moveicons {
float:right;
}
.editing .block_course_overview .moveup {
padding-right: 5px;
}
.editing .block_course_overview .movedownspacer {
float: left;
width: 14px;
}
.dir-rtl.editing .block_course_overview .movedownspacer {
float:right;
}
.editing .block_course_overview .moveupspacer {
float: right;
width: 14px;
}
.dir-rtl.editing .block_course_overview .moveupspacer {
float:left;
}
.block_course_overview #course_list {
width: 100%; width: 100%;
} }
@ -122,10 +93,6 @@
text-align: right; text-align: right;
} }
.block_course_overview .coursemovetarget { .block_course_overview .content .course_list .movehere{
display: block; margin-bottom: 15px;
height: 1em;
margin-bottom: 1em;
border-width: 2px;
border-style: dashed;
} }

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2012121000; // The current plugin version (Date: YYYYMMDDXX) $plugin->version = 2013012300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012112900; // Requires this Moodle version $plugin->requires = 2012112900; // Requires this Moodle version
$plugin->component = 'block_course_overview'; // Full name of the plugin (used for diagnostics) $plugin->component = 'block_course_overview'; // Full name of the plugin (used for diagnostics)