MDL-42629 course: moving a course now updates counts and pagination totals

This commit is contained in:
Sam Hemelryk 2013-10-31 15:07:46 +08:00
parent 83886a49a0
commit bd7ee7ada4
5 changed files with 103 additions and 8 deletions

View file

@ -54,7 +54,27 @@ switch ($action) {
case 'movecourseintocategory': case 'movecourseintocategory':
$courseid = required_param('courseid', PARAM_INT); $courseid = required_param('courseid', PARAM_INT);
$categoryid = required_param('categoryid', PARAM_INT); $categoryid = required_param('categoryid', PARAM_INT);
$outcome->outcome = \core_course\management\helper::move_courses_into_category($categoryid, $courseid); $course = get_course($courseid);
$oldcategory = coursecat::get($course->category);
$category = coursecat::get($categoryid);
$outcome->outcome = \core_course\management\helper::move_courses_into_category($category, $courseid);
$perpage = (int)get_user_preferences('coursecat_management_perpage', $CFG->coursesperpage);
$totalcourses = $oldcategory->get_courses_count();
$totalpages = ceil($totalcourses / $perpage);
if ($totalpages == 0) {
$str = get_string('nocoursesyet');
} else if ($totalpages == 1) {
$str = get_string('showingacourses', 'moodle', $totalcourses);
} else {
$a = new stdClass;
$a->start = ($page * $perpage) + 1;
$a->end = min((($page + 1) * $perpage), $totalcourses);
$a->total = $totalcourses;
$str = get_string('showingxofycourses', 'moodle', $a);
}
$outcome->newcatcourses = $category->get_courses_count();
$outcome->oldcatcourses = $totalcourses;
$outcome->paginationtotals = $str;
break; break;
case 'movecourseafter' : case 'movecourseafter' :
$courseid = required_param('courseid', PARAM_INT); $courseid = required_param('courseid', PARAM_INT);

View file

@ -1246,12 +1246,15 @@ Category.prototype = {
*/ */
completeMoveCourse : function(transactionid, response, args) { completeMoveCourse : function(transactionid, response, args) {
var outcome = this.checkAjaxResponse(transactionid, response, args), var outcome = this.checkAjaxResponse(transactionid, response, args),
course; console = this.get('console'),
category,
course,
totals;
if (outcome === false) { if (outcome === false) {
Y.log('AJAX failed to move courses into this category: '+this.get('itemname'), 'warn', 'moodle-course-management'); Y.log('AJAX failed to move courses into this category: '+this.get('itemname'), 'warn', 'moodle-course-management');
return false; return false;
} }
course = this.get('console').getCourseById(args.courseid); course = console.getCourseById(args.courseid);
if (!course) { if (!course) {
Y.log('Course was moved but the course listing could not be found to reflect this', 'warn', 'moodle-course-management'); Y.log('Course was moved but the course listing could not be found to reflect this', 'warn', 'moodle-course-management');
return false; return false;
@ -1259,6 +1262,28 @@ Category.prototype = {
Y.log('Moved the course ('+course.getName()+') into this category ('+this.getName()+')', 'info', 'moodle-course-management'); Y.log('Moved the course ('+course.getName()+') into this category ('+this.getName()+')', 'info', 'moodle-course-management');
this.highlight(); this.highlight();
if (course) { if (course) {
if (outcome.paginationtotals) {
totals = console.get('courselisting').one('.listing-pagination-totals');
if (totals) {
totals.set('innerHTML', outcome.paginationtotals);
}
}
if (outcome.newcatcourses !== 'undefined') {
totals = this.get('node').one('.course-count');
if (totals) {
totals.set('innerHTML', totals.get('innerHTML').replace(/^\d+/, outcome.newcatcourses));
}
}
if (outcome.oldcatcourses !== 'undefined') {
category = console.get('activecategoryid');
category = console.getCategoryById(category);
if (category) {
totals = category.get('node').one('.course-count');
if (totals) {
totals.set('innerHTML', totals.get('innerHTML').replace(/^\d+/, outcome.oldcatcourses));
}
}
}
course.remove(); course.remove();
} }
return true; return true;

File diff suppressed because one or more lines are too long

View file

@ -1218,16 +1218,41 @@ Category.prototype = {
*/ */
completeMoveCourse : function(transactionid, response, args) { completeMoveCourse : function(transactionid, response, args) {
var outcome = this.checkAjaxResponse(transactionid, response, args), var outcome = this.checkAjaxResponse(transactionid, response, args),
course; console = this.get('console'),
category,
course,
totals;
if (outcome === false) { if (outcome === false) {
return false; return false;
} }
course = this.get('console').getCourseById(args.courseid); course = console.getCourseById(args.courseid);
if (!course) { if (!course) {
return false; return false;
} }
this.highlight(); this.highlight();
if (course) { if (course) {
if (outcome.paginationtotals) {
totals = console.get('courselisting').one('.listing-pagination-totals');
if (totals) {
totals.set('innerHTML', outcome.paginationtotals);
}
}
if (outcome.newcatcourses !== 'undefined') {
totals = this.get('node').one('.course-count');
if (totals) {
totals.set('innerHTML', totals.get('innerHTML').replace(/^\d+/, outcome.newcatcourses));
}
}
if (outcome.oldcatcourses !== 'undefined') {
category = console.get('activecategoryid');
category = console.getCategoryById(category);
if (category) {
totals = category.get('node').one('.course-count');
if (totals) {
totals.set('innerHTML', totals.get('innerHTML').replace(/^\d+/, outcome.oldcatcourses));
}
}
}
course.remove(); course.remove();
} }
return true; return true;

View file

@ -242,12 +242,15 @@ Category.prototype = {
*/ */
completeMoveCourse : function(transactionid, response, args) { completeMoveCourse : function(transactionid, response, args) {
var outcome = this.checkAjaxResponse(transactionid, response, args), var outcome = this.checkAjaxResponse(transactionid, response, args),
course; console = this.get('console'),
category,
course,
totals;
if (outcome === false) { if (outcome === false) {
Y.log('AJAX failed to move courses into this category: '+this.get('itemname'), 'warn', 'moodle-course-management'); Y.log('AJAX failed to move courses into this category: '+this.get('itemname'), 'warn', 'moodle-course-management');
return false; return false;
} }
course = this.get('console').getCourseById(args.courseid); course = console.getCourseById(args.courseid);
if (!course) { if (!course) {
Y.log('Course was moved but the course listing could not be found to reflect this', 'warn', 'moodle-course-management'); Y.log('Course was moved but the course listing could not be found to reflect this', 'warn', 'moodle-course-management');
return false; return false;
@ -255,6 +258,28 @@ Category.prototype = {
Y.log('Moved the course ('+course.getName()+') into this category ('+this.getName()+')', 'info', 'moodle-course-management'); Y.log('Moved the course ('+course.getName()+') into this category ('+this.getName()+')', 'info', 'moodle-course-management');
this.highlight(); this.highlight();
if (course) { if (course) {
if (outcome.paginationtotals) {
totals = console.get('courselisting').one('.listing-pagination-totals');
if (totals) {
totals.set('innerHTML', outcome.paginationtotals);
}
}
if (outcome.newcatcourses !== 'undefined') {
totals = this.get('node').one('.course-count');
if (totals) {
totals.set('innerHTML', totals.get('innerHTML').replace(/^\d+/, outcome.newcatcourses));
}
}
if (outcome.oldcatcourses !== 'undefined') {
category = console.get('activecategoryid');
category = console.getCategoryById(category);
if (category) {
totals = category.get('node').one('.course-count');
if (totals) {
totals.set('innerHTML', totals.get('innerHTML').replace(/^\d+/, outcome.oldcatcourses));
}
}
}
course.remove(); course.remove();
} }
return true; return true;