MDL-31830 course: improvements to JS coding style

This commit is contained in:
Sam Hemelryk
2013-10-07 10:22:51 +13:00
parent b488058f7d
commit c46996ea5a
8 changed files with 724 additions and 563 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@ YUI.add('moodle-course-management', function (Y, NAME) {
/**
* Provides drop down menus for list of action links.
*
* @module moodle-core_course-management
* @module moodle-course-management
*/
/**
@@ -11,7 +11,7 @@ YUI.add('moodle-course-management', function (Y, NAME) {
*
* Provides the organisation for course and category management JS.
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class Console
* @constructor
* @extends Y.Base
@@ -29,7 +29,7 @@ Console.ATTRS = {
*/
element : {
setter : function(node) {
if (typeof(node) === 'string') {
if (typeof node === 'string') {
node = Y.one('#'+node);
}
return node;
@@ -40,15 +40,21 @@ Console.ATTRS = {
* The category listing container node.
* @attribute categorylisting
* @type Node
* @default null
*/
categorylisting : {},
categorylisting : {
value : null
},
/**
* The course listing container node.
* @attribute courselisting
* @type Node
* @default null
*/
courselisting : {},
courselisting : {
value : null
},
/**
* The course details container node.
@@ -57,22 +63,28 @@ Console.ATTRS = {
* @default null
*/
coursedetails : {
value: null
value : null
},
/**
* The id of the currently active category.
* @attribute activecategoryid
* @type Int
* @type Number
* @default null
*/
activecategoryid : {},
activecategoryid : {
value : null
},
/**
* The id of the currently active course.
* @attribute activecourseid
* @type Int
* @type Number
* @default Null
*/
activecourseid : {},
activecourseid : {
value : null
},
/**
* The categories that are currently available through the management interface.
@@ -95,17 +107,12 @@ Console.ATTRS = {
/**
* The courses that are currently available through the management interface.
* @attribute courses
* @type Array
* @default []
* @type Course[]
* @default Array
*/
courses : {
setter : function(item, name) {
if (Y.Lang.isArray(item)) {
return item;
}
var items = this.get(name);
items.push(item);
return items;
validator : function(val) {
return Y.Lang.isArray(val);
},
value : []
},
@@ -113,7 +120,7 @@ Console.ATTRS = {
/**
* The currently displayed page of courses.
* @attribute page
* @type Int
* @type Number
* @default null
*/
page : {
@@ -130,7 +137,7 @@ Console.ATTRS = {
/**
* The total pages of courses that can be shown for this category.
* @attribute totalpages
* @type Int
* @type Number
* @default null
*/
totalpages : {
@@ -147,7 +154,7 @@ Console.ATTRS = {
/**
* The total number of courses belonging to this category.
* @attribute totalcourses
* @type Int
* @type Number
* @default null
*/
totalcourses : {
@@ -224,8 +231,8 @@ Console.prototype = {
if (selectedcourse) {
this.set('activecourseid', selectedcourse.getData('id'));
}
this.initialise_categories(categorylisting);
this.initialise_courses();
this.initialiseCategories(categorylisting);
this.initialiseCourses();
if (courselisting) {
// No need for dragdrop if we don't have a course listing.
@@ -235,11 +242,11 @@ Console.prototype = {
/**
* Initialises all the categories being shown.
* @method initialise_categories
* @method initialiseCategories
* @private
* @returns {boolean}
*/
initialise_categories : function(listing) {
initialiseCategories : function(listing) {
var count = 0;
if (!listing) {
return false;
@@ -252,7 +259,7 @@ Console.prototype = {
count++;
}, this);
if (!this.categoriesinit) {
this.get('categorylisting').delegate('click', this.handle_category_delegation, 'a[data-action]', this);
this.get('categorylisting').delegate('click', this.handleCategoryDelegation, 'a[data-action]', this);
this.categoriesinit = true;
} else {
}
@@ -260,99 +267,129 @@ Console.prototype = {
/**
* Initialises all the categories being shown.
* @method initialise_courses
* @method initialiseCourses
* @private
* @returns {boolean}
*/
initialise_courses : function() {
var category = this.get_category_by_id(this.get('activecategoryid')),
initialiseCourses : function() {
var category = this.getCategoryById(this.get('activecategoryid')),
listing = this.get('courselisting'),
count = 0;
if (!listing) {
return false;
}
if (!category) {
return false;
}
listing.all('.listitem[data-id]').each(function(node){
this.set('courses', new Course({
this.registerCourse(new Course({
node : node,
console : this,
category : category
}));
count++;
}, this);
listing.delegate('click', this.handle_course_delegation, 'a[data-action]', this);
listing.delegate('click', this.handleCourseDelegation, 'a[data-action]', this);
},
/**
* Registers a course within the management display.
* @method registerCourse
* @param {Course} course
*/
registerCourse : function(course) {
var courses = this.get('courses');
courses.push(course);
this.set('courses', courses);
},
/**
* Handles the event fired by a delegated course listener.
*
* @method handle_course_delegation
* @method handleCourseDelegation
* @protected
* @param {EventFacade} e
*/
handle_course_delegation : function(e) {
handleCourseDelegation : function(e) {
var target = e.currentTarget,
action = target.getData('action'),
courseid = target.ancestor('.listitem').getData('id'),
course = this.get_course_by_id(courseid);
course.handle(action, e);
course = this.getCourseById(courseid);
if (course) {
course.handle(action, e);
} else {
}
},
/**
* Handles the event fired by a delegated course listener.
*
* @method handle_category_delegation
* @method handleCategoryDelegation
* @protected
* @param {EventFacade} e
*/
handle_category_delegation : function(e) {
handleCategoryDelegation : function(e) {
var target = e.currentTarget,
action = target.getData('action'),
categoryid = target.ancestor('.listitem').getData('id'),
category = this.get_category_by_id(categoryid);
category.handle(action, e);
category = this.getCategoryById(categoryid);
if (category) {
category.handle(action, e);
} else {
}
},
/**
* Returns the category with the given ID.
* @method get_category_by_id
* @param {Int} id
* @returns {Category|Int} The category or the categoryid given if there is no matching category.
* @method getCategoryById
* @param {Number} id
* @returns {Category|Boolean} The category or false if it can't be found.
*/
get_category_by_id : function(id) {
var i, category, categories = this.get('categories'), length = categories.length;
getCategoryById : function(id) {
var i,
category,
categories = this.get('categories'),
length = categories.length;
for (i = 0; i < length; i++) {
category = categories[i];
if (category.get('categoryid') === id) {
return category;
}
}
return id;
},
/**
* Returns the course with the given id.
* @method get_course_by_id
* @param {Int} id
* @returns {Category|Int} The course or the courseid given if there is no matching category.
*/
get_course_by_id : function(id) {
var i, course, courses = this.get('courses'), length = courses.length;
for (i = 0; i < length; i++) {
course = courses[i];
if (course.get('courseid') === id) {
return course;
}
}
return false;
},
/**
* Removes the course with the given ID.
* @method remove_course_by_id
* @param {Int} id
* Returns the course with the given id.
* @method getCourseById
* @param {Number} id
* @returns {Course|Boolean} The course or false if not found/
*/
remove_course_by_id : function() {
getCourseById : function(id) {
var i,
course,
courses = this.get('courses'),
length = courses.length;
for (i = 0; i < length; i++) {
if (!courses.hadOwnPropery(i)) {
course = courses[i];
if (course.get('courseid') === id) {
return course;
}
}
}
return id;
},
/**
* Removes the course with the given ID.
* @method removeCourseById
* @param {Number} id
*/
removeCourseById : function() {
var courses = this.get('courses'),
length = courses.length,
course,
i;
for (i = 0; i < length; i++) {
course = courses[i];
@@ -366,13 +403,13 @@ Console.prototype = {
/**
* Performs an AJAX action.
*
* @method perform_ajax_action
* @method performAjaxAction
* @param {String} action The action to perform.
* @param {Object} args The arguments to pass through with teh request.
* @param {Function} callback The function to call when all is done.
* @param {Object} context The object to use as the context for the callback.
*/
perform_ajax_action : function(action, args, callback, context) {
performAjaxAction : function(action, args, callback, context) {
var io = new Y.IO();
args.action = action;
args.ajax = '1';
@@ -390,25 +427,21 @@ Console.prototype = {
};
Y.extend(Console, Y.Base, Console.prototype);
/**
* Course namespace.
* @static
* @namespace M
* @class course
*/
M.course = M.course || {};
M.course.management = M.course.management || {};
M.course.management.console = null;
/**
* Initalises the course management console.
* @static
* @param {Object} config
*/
M.course.init_management = function(config) {
M.course.console = new Console(config);
M.course.management.init = function(config) {
M.course.management.console = new Console(config);
};/**
* Drag and Drop handler
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class DragDrop
* @constructor
* @extends Y.Base
@@ -650,13 +683,14 @@ DragDrop.prototype = {
return false;
}
courseid = drag.getData('id');
course = console.get_course_by_id(courseid);
if (iscategory) {
categoryid = drop.ancestor('.listitem-category').getData('id');
category = console.get_category_by_id(categoryid);
category = console.getCategoryById(categoryid);
if (category) {
category.moveCourseTo(course);
course = console.getCourseById(courseid);
if (course) {
category.moveCourseTo(course);
}
}
} else if (iscourse || drop.ancestor('#course-listing')) {
previoussibling = drag.get('previousSibling');
@@ -672,7 +706,7 @@ DragDrop.prototype = {
Y.extend(DragDrop, Y.Base, DragDrop.prototype);/**
* A managed course.
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class Item
* @constructor
* @extends Y.Base
@@ -721,14 +755,14 @@ Item.prototype = {
/**
* Checks and parses an AJAX response for an item.
*
* @method check_ajax_response
* @method checkAjaxResponse
* @protected
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Object|Boolean}
*/
check_ajax_response : function(transactionid, response, args) {
checkAjaxResponse : function(transactionid, response, args) {
if (response.status !== 200) {
return false;
}
@@ -749,7 +783,7 @@ Item.prototype = {
* Moves an item up by one.
*
* @method moveup
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
@@ -762,7 +796,7 @@ Item.prototype = {
previousup,
previousdown,
tmpnode,
outcome = this.check_ajax_response(transactionid, response, args);
outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
return false;
}
@@ -800,7 +834,7 @@ Item.prototype = {
* Moves an item down by one.
*
* @method movedown
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
@@ -813,7 +847,7 @@ Item.prototype = {
nextup,
nextdown,
tmpnode,
outcome = this.check_ajax_response(transactionid, response, args);
outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
return false;
}
@@ -851,13 +885,13 @@ Item.prototype = {
* Makes an item visible.
*
* @method show
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
show : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args);
var outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
return false;
}
@@ -879,13 +913,13 @@ Item.prototype = {
* Hides an item.
*
* @method hide
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
hide : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args);
var outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
return false;
}
@@ -934,7 +968,7 @@ Item.prototype = {
Y.extend(Item, Y.Base, Item.prototype);/**
* A managed category.
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class Category
* @constructor
* @extends Item
@@ -948,9 +982,21 @@ Category.ATTRS = {
/**
* The category ID relating to this category.
* @attribute categoryid
* @type Int
* @type Number
* @writeOnce
* @default null
*/
categoryid : {},
categoryid : {
getter : function (value, name) {
if (value === null) {
value = this.get('node').getData('id');
this.set(name, value);
}
return value;
},
value : null,
writeOnce : true
},
/**
* True if this category is the currently selected category.
@@ -973,19 +1019,14 @@ Category.ATTRS = {
},
/**
* An array fo courses belonging to this category
* An array of courses belonging to this category.
* @attribute courses
* @type Course[]
* @default []
* @default Array
*/
courses : {
setter : function(item, name) {
if (Y.Lang.isArray(item)) {
return item;
}
var items = this.get(name);
items.push(item);
return items;
validator : function(val) {
return Y.Lang.isArray(val);
},
value : []
}
@@ -996,8 +1037,6 @@ Category.prototype = {
* @method initializer
*/
initializer : function() {
var node = this.get('node');
this.set('categoryid', node.getData('id'));
this.set('itemname', 'category');
},
@@ -1012,11 +1051,13 @@ Category.prototype = {
/**
* Registers a course as belonging to this category.
* @method register_course
* @method registerCourse
* @param {Course} course
*/
register_course : function(course) {
this.set('courses', course);
registerCourse : function(course) {
var courses = this.get('courses');
courses.push(course);
this.set('courses', courses);
},
/**
@@ -1031,31 +1072,31 @@ Category.prototype = {
var catarg = {categoryid : this.get('categoryid')};
switch (action) {
case 'moveup':
e.halt();
this.get('console').perform_ajax_action('movecategoryup', catarg, this.moveup, this);
e.preventDefault();
this.get('console').performAjaxAction('movecategoryup', catarg, this.moveup, this);
break;
case 'movedown':
e.halt();
this.get('console').perform_ajax_action('movecategorydown', catarg, this.movedown, this);
e.preventDefault();
this.get('console').performAjaxAction('movecategorydown', catarg, this.movedown, this);
break;
case 'show':
e.halt();
this.get('console').perform_ajax_action('showcategory', catarg, this.show, this);
e.preventDefault();
this.get('console').performAjaxAction('showcategory', catarg, this.show, this);
break;
case 'hide':
e.halt();
this.get('console').perform_ajax_action('hidecategory', catarg, this.hide, this);
e.preventDefault();
this.get('console').performAjaxAction('hidecategory', catarg, this.hide, this);
break;
case 'expand':
e.halt();
e.preventDefault();
if (this.get('node').getData('expanded') === '0') {
this.get('node').setData('expanded', true);
this.get('console').perform_ajax_action('getsubcategorieshtml', catarg, this.loadSubcategories, this);
this.get('node').setAttribute('data-expanded', '1').setData('expanded', 'true');
this.get('console').performAjaxAction('getsubcategorieshtml', catarg, this.loadSubcategories, this);
}
this.expand();
break;
case 'collapse':
e.halt();
e.preventDefault();
this.collapse();
break;
default:
@@ -1071,8 +1112,7 @@ Category.prototype = {
var node = this.get('node'),
action = node.one('a[data-action=expand]');
node.removeClass('collapsed');
action.setAttribute('data-action', 'collapse');
action.one('img').setAttrs({
action.setAttribute('data-action', 'collapse').one('img').setAttrs({
src : M.util.image_url('t/switch_minus', 'moodle'),
title : M.util.get_string('collapse', 'moodle'),
alt : M.util.get_string('collapse', 'moodle')
@@ -1087,8 +1127,7 @@ Category.prototype = {
var node = this.get('node'),
action = node.one('a[data-action=collapse]');
node.addClass('collapsed');
action.setAttribute('data-action', 'expand');
action.one('img').setAttrs({
action.setAttribute('data-action', 'expand').one('img').setAttrs({
src : M.util.image_url('t/switch_plus', 'moodle'),
title : M.util.get_string('expand', 'moodle'),
alt : M.util.get_string('expand', 'moodle')
@@ -1100,23 +1139,24 @@ Category.prototype = {
*
* @method loadSubcategories
* @protected
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
* @return {Boolean} Returns true on success - false otherwise.
*/
loadSubcategories : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args),
var outcome = this.checkAjaxResponse(transactionid, response, args),
node = this.get('node'),
console = this.get('console');
if (outcome === false) {
return false;
}
node.append(outcome.html);
console.initialise_categories(node);
console.initialiseCategories(node);
if (M.core && M.core.actionmenu && M.core.actionmenu.newDOMNode) {
M.core.actionmenu.newDOMNode(node);
}
return true;
},
/**
@@ -1140,7 +1180,7 @@ Category.prototype = {
confirm.on('complete-yes', function() {
confirm.hide();
confirm.destroy();
this.get('console').perform_ajax_action('movecourseintocategory', {
this.get('console').performAjaxAction('movecourseintocategory', {
categoryid : this.get('categoryid'),
courseid : course.get('courseid')
}, this.completeMoveCourse, this);
@@ -1153,18 +1193,21 @@ Category.prototype = {
* Completes moving a course to this category.
* @method completeMoveCourse
* @protected
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
completeMoveCourse : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args),
var outcome = this.checkAjaxResponse(transactionid, response, args),
course;
if (outcome === false) {
return false;
}
course = this.get('console').get_course_by_id(args.courseid);
course = this.get('console').getCourseById(args.courseid);
if (!course) {
return false;
}
this.highlight();
if (course) {
course.remove();
@@ -1176,13 +1219,13 @@ Category.prototype = {
* Makes an item visible.
*
* @method show
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
show : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args);
var outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
return false;
}
@@ -1201,13 +1244,13 @@ Category.prototype = {
* Hides an item.
*
* @method hide
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
hide : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args);
var outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
return false;
}
@@ -1224,6 +1267,7 @@ Category.prototype = {
/**
* Updates the visibility of child courses if required.
* @method updateCourseVisiblity
* @chainable
* @param courses
*/
updateCourseVisiblity : function(courses) {
@@ -1232,22 +1276,26 @@ Category.prototype = {
course;
try {
for (key in courses) {
course = console.get_course_by_id(courses[key].id);
if (course.get) {
if (courses[key].show === "1") {
course.markVisible();
} else {
course.markHidden();
if (courses.hasOwnProperty[key]) {
course = console.getCourseById(courses[key].id);
if (course) {
if (courses[key].show === "1") {
course.markVisible();
} else {
course.markHidden();
}
}
}
}
} catch (err) {
}
return this;
},
/**
* Updates the visibility of subcategories if required.
* @method updateChildVisibility
* @chainable
* @param categories
*/
updateChildVisibility : function(categories) {
@@ -1256,23 +1304,26 @@ Category.prototype = {
category;
try {
for (key in categories) {
category = console.get_category_by_id(categories[key].id);
if (category.get) {
if (categories[key].show === "1") {
category.markVisible();
} else {
category.markHidden();
if (categories.hasOwnProperty[key]) {
category = console.getCategoryById(categories[key].id);
if (category) {
if (categories[key].show === "1") {
category.markVisible();
} else {
category.markHidden();
}
}
}
}
} catch (err) {
}
return this;
}
};
Y.extend(Category, Item, Category.prototype);/**
* A managed course.
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class Course
* @constructor
* @extends Item
@@ -1287,7 +1338,7 @@ Course.ATTRS = {
/**
* The course ID of this course.
* @attribute courseid
* @type Int
* @type Number
*/
courseid : {},
@@ -1339,8 +1390,8 @@ Course.prototype = {
var node = this.get('node'),
category = this.get('category');
this.set('courseid', node.getData('id'));
if (category && category.register_course) {
category.register_course(this);
if (category && category.registerCourse) {
category.registerCourse(this);
}
this.set('itemname', 'course');
},
@@ -1367,19 +1418,19 @@ Course.prototype = {
switch (action) {
case 'moveup':
e.halt();
console.perform_ajax_action('movecourseup', args, this.moveup, this);
console.performAjaxAction('movecourseup', args, this.moveup, this);
break;
case 'movedown':
e.halt();
console.perform_ajax_action('movecoursedown', args, this.movedown, this);
console.performAjaxAction('movecoursedown', args, this.movedown, this);
break;
case 'show':
e.halt();
console.perform_ajax_action('showcourse', args, this.show, this);
console.performAjaxAction('showcourse', args, this.show, this);
break;
case 'hide':
e.halt();
console.perform_ajax_action('hidecourse', args, this.hide, this);
console.performAjaxAction('hidecourse', args, this.hide, this);
break;
default:
return false;
@@ -1391,7 +1442,7 @@ Course.prototype = {
* @method remove
*/
remove : function() {
this.get('console').remove_course_by_id(this.get('courseid'));
this.get('console').removeCourseById(this.get('courseid'));
this.get('node').remove();
},
@@ -1399,8 +1450,8 @@ Course.prototype = {
* Moves this course after another course.
*
* @method moveAfter
* @param {Int} moveaftercourse The course to move after or 0 to put it at the top.
* @param {Int} previousid the course it was previously after in case we need to revert.
* @param {Number} moveaftercourse The course to move after or 0 to put it at the top.
* @param {Number} previousid the course it was previously after in case we need to revert.
*/
moveAfter : function(moveaftercourse, previousid) {
var console = this.get('console'),
@@ -1409,7 +1460,7 @@ Course.prototype = {
moveafter : moveaftercourse,
previous : previousid
};
console.perform_ajax_action('movecourseafter', args, this.moveAfterResponse, this);
console.performAjaxAction('movecourseafter', args, this.moveAfterResponse, this);
},
/**
@@ -1417,13 +1468,13 @@ Course.prototype = {
*
* @method moveAfterResponse
* @protected
* @param {Int} transactionid The transaction ID for the request.
* @param {Number} transactionid The transaction ID for the request.
* @param {Object} response The response to the request.
* @param {Objects} args The arguments that were given with the request.
* @returns {Boolean}
*/
moveAfterResponse : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args),
var outcome = this.checkAjaxResponse(transactionid, response, args),
node = this.get('node'),
previous;
if (outcome === false) {
+86 -68
View File
@@ -1,7 +1,7 @@
/**
* A managed category.
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class Category
* @constructor
* @extends Item
@@ -15,9 +15,21 @@ Category.ATTRS = {
/**
* The category ID relating to this category.
* @attribute categoryid
* @type Int
* @type Number
* @writeOnce
* @default null
*/
categoryid : {},
categoryid : {
getter : function (value, name) {
if (value === null) {
value = this.get('node').getData('id');
this.set(name, value);
}
return value;
},
value : null,
writeOnce : true
},
/**
* True if this category is the currently selected category.
@@ -40,19 +52,14 @@ Category.ATTRS = {
},
/**
* An array fo courses belonging to this category
* An array of courses belonging to this category.
* @attribute courses
* @type Course[]
* @default []
* @default Array
*/
courses : {
setter : function(item, name) {
if (Y.Lang.isArray(item)) {
return item;
}
var items = this.get(name);
items.push(item);
return items;
validator : function(val) {
return Y.Lang.isArray(val);
},
value : []
}
@@ -63,8 +70,6 @@ Category.prototype = {
* @method initializer
*/
initializer : function() {
var node = this.get('node');
this.set('categoryid', node.getData('id'));
this.set('itemname', 'category');
},
@@ -79,11 +84,13 @@ Category.prototype = {
/**
* Registers a course as belonging to this category.
* @method register_course
* @method registerCourse
* @param {Course} course
*/
register_course : function(course) {
this.set('courses', course);
registerCourse : function(course) {
var courses = this.get('courses');
courses.push(course);
this.set('courses', courses);
},
/**
@@ -98,35 +105,35 @@ Category.prototype = {
var catarg = {categoryid : this.get('categoryid')};
switch (action) {
case 'moveup':
e.halt();
this.get('console').perform_ajax_action('movecategoryup', catarg, this.moveup, this);
e.preventDefault();
this.get('console').performAjaxAction('movecategoryup', catarg, this.moveup, this);
break;
case 'movedown':
e.halt();
this.get('console').perform_ajax_action('movecategorydown', catarg, this.movedown, this);
e.preventDefault();
this.get('console').performAjaxAction('movecategorydown', catarg, this.movedown, this);
break;
case 'show':
e.halt();
this.get('console').perform_ajax_action('showcategory', catarg, this.show, this);
e.preventDefault();
this.get('console').performAjaxAction('showcategory', catarg, this.show, this);
break;
case 'hide':
e.halt();
this.get('console').perform_ajax_action('hidecategory', catarg, this.hide, this);
e.preventDefault();
this.get('console').performAjaxAction('hidecategory', catarg, this.hide, this);
break;
case 'expand':
e.halt();
e.preventDefault();
if (this.get('node').getData('expanded') === '0') {
this.get('node').setData('expanded', true);
this.get('console').perform_ajax_action('getsubcategorieshtml', catarg, this.loadSubcategories, this);
this.get('node').setAttribute('data-expanded', '1').setData('expanded', 'true');
this.get('console').performAjaxAction('getsubcategorieshtml', catarg, this.loadSubcategories, this);
}
this.expand();
break;
case 'collapse':
e.halt();
e.preventDefault();
this.collapse();
break;
default:
Y.log('Invalid AJAX action requested of managed category.', 'warn', 'core_course');
Y.log('Invalid AJAX action requested of managed category.', 'warn', 'moodle-course-management');
return false;
}
},
@@ -139,8 +146,7 @@ Category.prototype = {
var node = this.get('node'),
action = node.one('a[data-action=expand]');
node.removeClass('collapsed');
action.setAttribute('data-action', 'collapse');
action.one('img').setAttrs({
action.setAttribute('data-action', 'collapse').one('img').setAttrs({
src : M.util.image_url('t/switch_minus', 'moodle'),
title : M.util.get_string('collapse', 'moodle'),
alt : M.util.get_string('collapse', 'moodle')
@@ -155,8 +161,7 @@ Category.prototype = {
var node = this.get('node'),
action = node.one('a[data-action=collapse]');
node.addClass('collapsed');
action.setAttribute('data-action', 'expand');
action.one('img').setAttrs({
action.setAttribute('data-action', 'expand').one('img').setAttrs({
src : M.util.image_url('t/switch_plus', 'moodle'),
title : M.util.get_string('expand', 'moodle'),
alt : M.util.get_string('expand', 'moodle')
@@ -168,25 +173,26 @@ Category.prototype = {
*
* @method loadSubcategories
* @protected
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
* @return {Boolean} Returns true on success - false otherwise.
*/
loadSubcategories : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args),
var outcome = this.checkAjaxResponse(transactionid, response, args),
node = this.get('node'),
console = this.get('console');
if (outcome === false) {
Y.log('AJAX failed to load sub categories for '+this.get('itemname'), 'warn', 'core_course');
Y.log('AJAX failed to load sub categories for '+this.get('itemname'), 'warn', 'moodle-course-management');
return false;
}
Y.log('AJAX loaded subcategories for '+this.get('itemname'), 'info', 'core_course');
Y.log('AJAX loaded subcategories for '+this.get('itemname'), 'info', 'moodle-course-management');
node.append(outcome.html);
console.initialise_categories(node);
console.initialiseCategories(node);
if (M.core && M.core.actionmenu && M.core.actionmenu.newDOMNode) {
M.core.actionmenu.newDOMNode(node);
}
return true;
},
/**
@@ -210,7 +216,7 @@ Category.prototype = {
confirm.on('complete-yes', function() {
confirm.hide();
confirm.destroy();
this.get('console').perform_ajax_action('movecourseintocategory', {
this.get('console').performAjaxAction('movecourseintocategory', {
categoryid : this.get('categoryid'),
courseid : course.get('courseid')
}, this.completeMoveCourse, this);
@@ -223,20 +229,24 @@ Category.prototype = {
* Completes moving a course to this category.
* @method completeMoveCourse
* @protected
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
completeMoveCourse : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args),
var outcome = this.checkAjaxResponse(transactionid, response, args),
course;
if (outcome === false) {
Y.log('AJAX failed to move courses into this category: '+this.get('itemname'), 'warn', 'core_course');
Y.log('AJAX failed to move courses into this category: '+this.get('itemname'), 'warn', 'moodle-course-management');
return false;
}
course = this.get('console').get_course_by_id(args.courseid);
Y.log('Moved the course ('+course.getName()+') into this category ('+this.getName()+')', 'info', 'core_course');
course = this.get('console').getCourseById(args.courseid);
if (!course) {
Y.log('Course was moved but the course listing could not be found to reflect this', 'warn', 'moodle-course-management');
return false;
}
Y.log('Moved the course ('+course.getName()+') into this category ('+this.getName()+')', 'info', 'moodle-course-management');
this.highlight();
if (course) {
course.remove();
@@ -248,15 +258,15 @@ Category.prototype = {
* Makes an item visible.
*
* @method show
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
show : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args);
var outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
Y.log('AJAX request to show '+this.get('itemname')+' by outcome.', 'warn', 'core_course');
Y.log('AJAX request to show '+this.get('itemname')+' by outcome.', 'warn', 'moodle-course-management');
return false;
}
@@ -268,22 +278,22 @@ Category.prototype = {
this.updateCourseVisiblity(outcome.coursevisibility);
}
this.updated();
Y.log('Success: category made visible by AJAX.', 'info', 'core_course');
Y.log('Success: category made visible by AJAX.', 'info', 'moodle-course-management');
},
/**
* Hides an item.
*
* @method hide
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
hide : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args);
var outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
Y.log('AJAX request to hide '+this.get('itemname')+' by outcome.', 'warn', 'core_course');
Y.log('AJAX request to hide '+this.get('itemname')+' by outcome.', 'warn', 'moodle-course-management');
return false;
}
this.markHidden();
@@ -294,12 +304,13 @@ Category.prototype = {
this.updateCourseVisiblity(outcome.coursevisibility);
}
this.updated();
Y.log('Success: '+this.get('itemname')+' made hidden by AJAX.', 'info', 'core_course');
Y.log('Success: '+this.get('itemname')+' made hidden by AJAX.', 'info', 'moodle-course-management');
},
/**
* Updates the visibility of child courses if required.
* @method updateCourseVisiblity
* @chainable
* @param courses
*/
updateCourseVisiblity : function(courses) {
@@ -308,23 +319,27 @@ Category.prototype = {
course;
try {
for (key in courses) {
course = console.get_course_by_id(courses[key].id);
if (course.get) {
if (courses[key].show === "1") {
course.markVisible();
} else {
course.markHidden();
if (courses.hasOwnProperty[key]) {
course = console.getCourseById(courses[key].id);
if (course) {
if (courses[key].show === "1") {
course.markVisible();
} else {
course.markHidden();
}
}
}
}
} catch (err) {
Y.log('Error trying to update course visibility: ' + err.message, 'warn', 'core_course');
Y.log('Error trying to update course visibility: ' + err.message, 'warn', 'moodle-course-management');
}
return this;
},
/**
* Updates the visibility of subcategories if required.
* @method updateChildVisibility
* @chainable
* @param categories
*/
updateChildVisibility : function(categories) {
@@ -333,18 +348,21 @@ Category.prototype = {
category;
try {
for (key in categories) {
category = console.get_category_by_id(categories[key].id);
if (category.get) {
if (categories[key].show === "1") {
category.markVisible();
} else {
category.markHidden();
if (categories.hasOwnProperty[key]) {
category = console.getCategoryById(categories[key].id);
if (category) {
if (categories[key].show === "1") {
category.markVisible();
} else {
category.markHidden();
}
}
}
}
} catch (err) {
Y.log('Error trying to update category visibility: ' + err.message, 'warn', 'core_course');
Y.log('Error trying to update category visibility: ' + err.message, 'warn', 'moodle-course-management');
}
return this;
}
};
Y.extend(Category, Item, Category.prototype);
+116 -80
View File
@@ -1,7 +1,7 @@
/**
* Provides drop down menus for list of action links.
*
* @module moodle-core_course-management
* @module moodle-course-management
*/
/**
@@ -9,7 +9,7 @@
*
* Provides the organisation for course and category management JS.
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class Console
* @constructor
* @extends Y.Base
@@ -27,7 +27,7 @@ Console.ATTRS = {
*/
element : {
setter : function(node) {
if (typeof(node) === 'string') {
if (typeof node === 'string') {
node = Y.one('#'+node);
}
return node;
@@ -38,15 +38,21 @@ Console.ATTRS = {
* The category listing container node.
* @attribute categorylisting
* @type Node
* @default null
*/
categorylisting : {},
categorylisting : {
value : null
},
/**
* The course listing container node.
* @attribute courselisting
* @type Node
* @default null
*/
courselisting : {},
courselisting : {
value : null
},
/**
* The course details container node.
@@ -55,22 +61,28 @@ Console.ATTRS = {
* @default null
*/
coursedetails : {
value: null
value : null
},
/**
* The id of the currently active category.
* @attribute activecategoryid
* @type Int
* @type Number
* @default null
*/
activecategoryid : {},
activecategoryid : {
value : null
},
/**
* The id of the currently active course.
* @attribute activecourseid
* @type Int
* @type Number
* @default Null
*/
activecourseid : {},
activecourseid : {
value : null
},
/**
* The categories that are currently available through the management interface.
@@ -93,17 +105,12 @@ Console.ATTRS = {
/**
* The courses that are currently available through the management interface.
* @attribute courses
* @type Array
* @default []
* @type Course[]
* @default Array
*/
courses : {
setter : function(item, name) {
if (Y.Lang.isArray(item)) {
return item;
}
var items = this.get(name);
items.push(item);
return items;
validator : function(val) {
return Y.Lang.isArray(val);
},
value : []
},
@@ -111,7 +118,7 @@ Console.ATTRS = {
/**
* The currently displayed page of courses.
* @attribute page
* @type Int
* @type Number
* @default null
*/
page : {
@@ -128,7 +135,7 @@ Console.ATTRS = {
/**
* The total pages of courses that can be shown for this category.
* @attribute totalpages
* @type Int
* @type Number
* @default null
*/
totalpages : {
@@ -145,7 +152,7 @@ Console.ATTRS = {
/**
* The total number of courses belonging to this category.
* @attribute totalcourses
* @type Int
* @type Number
* @default null
*/
totalcourses : {
@@ -200,7 +207,7 @@ Console.prototype = {
* @method initializer
*/
initializer : function() {
Y.log('Initialising course category management console', 'note', 'core_course');
Y.log('Initialising course category management console', 'info', 'moodle-course-management');
this.set('element', 'coursecat-management');
var element = this.get('element'),
categorylisting = element.one('#category-listing'),
@@ -223,8 +230,8 @@ Console.prototype = {
if (selectedcourse) {
this.set('activecourseid', selectedcourse.getData('id'));
}
this.initialise_categories(categorylisting);
this.initialise_courses();
this.initialiseCategories(categorylisting);
this.initialiseCourses();
if (courselisting) {
// No need for dragdrop if we don't have a course listing.
@@ -234,11 +241,11 @@ Console.prototype = {
/**
* Initialises all the categories being shown.
* @method initialise_categories
* @method initialiseCategories
* @private
* @returns {boolean}
*/
initialise_categories : function(listing) {
initialiseCategories : function(listing) {
var count = 0;
if (!listing) {
return false;
@@ -251,110 +258,143 @@ Console.prototype = {
count++;
}, this);
if (!this.categoriesinit) {
this.get('categorylisting').delegate('click', this.handle_category_delegation, 'a[data-action]', this);
this.get('categorylisting').delegate('click', this.handleCategoryDelegation, 'a[data-action]', this);
this.categoriesinit = true;
Y.log(count+' categories being managed', 'note', 'core_course');
Y.log(count+' categories being managed', 'info', 'moodle-course-management');
} else {
Y.log(count+' new categories being managed', 'note', 'core_course');
Y.log(count+' new categories being managed', 'info', 'moodle-course-management');
}
},
/**
* Initialises all the categories being shown.
* @method initialise_courses
* @method initialiseCourses
* @private
* @returns {boolean}
*/
initialise_courses : function() {
var category = this.get_category_by_id(this.get('activecategoryid')),
initialiseCourses : function() {
var category = this.getCategoryById(this.get('activecategoryid')),
listing = this.get('courselisting'),
count = 0;
if (!listing) {
return false;
}
if (!category) {
Y.log('Couldn\'t find the current category object.', 'warn', 'moodle-course-management');
return false;
}
listing.all('.listitem[data-id]').each(function(node){
this.set('courses', new Course({
this.registerCourse(new Course({
node : node,
console : this,
category : category
}));
count++;
}, this);
listing.delegate('click', this.handle_course_delegation, 'a[data-action]', this);
Y.log(count+' courses being managed', 'note', 'core_course');
listing.delegate('click', this.handleCourseDelegation, 'a[data-action]', this);
Y.log(count+' courses being managed', 'info', 'moodle-course-management');
},
/**
* Registers a course within the management display.
* @method registerCourse
* @param {Course} course
*/
registerCourse : function(course) {
var courses = this.get('courses');
courses.push(course);
this.set('courses', courses);
},
/**
* Handles the event fired by a delegated course listener.
*
* @method handle_course_delegation
* @method handleCourseDelegation
* @protected
* @param {EventFacade} e
*/
handle_course_delegation : function(e) {
handleCourseDelegation : function(e) {
var target = e.currentTarget,
action = target.getData('action'),
courseid = target.ancestor('.listitem').getData('id'),
course = this.get_course_by_id(courseid);
course.handle(action, e);
course = this.getCourseById(courseid);
if (course) {
course.handle(action, e);
} else {
Y.log('Course with ID '+courseid+' could not be found for delegation', 'error', 'moodle-course-management');
}
},
/**
* Handles the event fired by a delegated course listener.
*
* @method handle_category_delegation
* @method handleCategoryDelegation
* @protected
* @param {EventFacade} e
*/
handle_category_delegation : function(e) {
handleCategoryDelegation : function(e) {
var target = e.currentTarget,
action = target.getData('action'),
categoryid = target.ancestor('.listitem').getData('id'),
category = this.get_category_by_id(categoryid);
category.handle(action, e);
category = this.getCategoryById(categoryid);
if (category) {
category.handle(action, e);
} else {
Y.log('Could not find category to delegate to.', 'error', 'moodle-course-management');
}
},
/**
* Returns the category with the given ID.
* @method get_category_by_id
* @param {Int} id
* @returns {Category|Int} The category or the categoryid given if there is no matching category.
* @method getCategoryById
* @param {Number} id
* @returns {Category|Boolean} The category or false if it can't be found.
*/
get_category_by_id : function(id) {
var i, category, categories = this.get('categories'), length = categories.length;
getCategoryById : function(id) {
var i,
category,
categories = this.get('categories'),
length = categories.length;
for (i = 0; i < length; i++) {
category = categories[i];
if (category.get('categoryid') === id) {
return category;
}
}
return id;
},
/**
* Returns the course with the given id.
* @method get_course_by_id
* @param {Int} id
* @returns {Category|Int} The course or the courseid given if there is no matching category.
*/
get_course_by_id : function(id) {
var i, course, courses = this.get('courses'), length = courses.length;
for (i = 0; i < length; i++) {
course = courses[i];
if (course.get('courseid') === id) {
return course;
}
}
return false;
},
/**
* Removes the course with the given ID.
* @method remove_course_by_id
* @param {Int} id
* Returns the course with the given id.
* @method getCourseById
* @param {Number} id
* @returns {Course|Boolean} The course or false if not found/
*/
remove_course_by_id : function() {
getCourseById : function(id) {
var i,
course,
courses = this.get('courses'),
length = courses.length;
for (i = 0; i < length; i++) {
if (!courses.hadOwnPropery(i)) {
course = courses[i];
if (course.get('courseid') === id) {
return course;
}
}
}
return id;
},
/**
* Removes the course with the given ID.
* @method removeCourseById
* @param {Number} id
*/
removeCourseById : function() {
var courses = this.get('courses'),
length = courses.length,
course,
i;
for (i = 0; i < length; i++) {
course = courses[i];
@@ -368,13 +408,13 @@ Console.prototype = {
/**
* Performs an AJAX action.
*
* @method perform_ajax_action
* @method performAjaxAction
* @param {String} action The action to perform.
* @param {Object} args The arguments to pass through with teh request.
* @param {Function} callback The function to call when all is done.
* @param {Object} context The object to use as the context for the callback.
*/
perform_ajax_action : function(action, args, callback, context) {
performAjaxAction : function(action, args, callback, context) {
var io = new Y.IO();
args.action = action;
args.ajax = '1';
@@ -392,19 +432,15 @@ Console.prototype = {
};
Y.extend(Console, Y.Base, Console.prototype);
/**
* Course namespace.
* @static
* @namespace M
* @class course
*/
M.course = M.course || {};
M.course.management = M.course.management || {};
M.course.management.console = null;
/**
* Initalises the course management console.
* @static
* @param {Object} config
*/
M.course.init_management = function(config) {
M.course.console = new Console(config);
M.course.management.init = function(config) {
M.course.management.console = new Console(config);
};
+17 -17
View File
@@ -1,7 +1,7 @@
/**
* A managed course.
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class Course
* @constructor
* @extends Item
@@ -16,7 +16,7 @@ Course.ATTRS = {
/**
* The course ID of this course.
* @attribute courseid
* @type Int
* @type Number
*/
courseid : {},
@@ -68,8 +68,8 @@ Course.prototype = {
var node = this.get('node'),
category = this.get('category');
this.set('courseid', node.getData('id'));
if (category && category.register_course) {
category.register_course(this);
if (category && category.registerCourse) {
category.registerCourse(this);
}
this.set('itemname', 'course');
},
@@ -96,22 +96,22 @@ Course.prototype = {
switch (action) {
case 'moveup':
e.halt();
console.perform_ajax_action('movecourseup', args, this.moveup, this);
console.performAjaxAction('movecourseup', args, this.moveup, this);
break;
case 'movedown':
e.halt();
console.perform_ajax_action('movecoursedown', args, this.movedown, this);
console.performAjaxAction('movecoursedown', args, this.movedown, this);
break;
case 'show':
e.halt();
console.perform_ajax_action('showcourse', args, this.show, this);
console.performAjaxAction('showcourse', args, this.show, this);
break;
case 'hide':
e.halt();
console.perform_ajax_action('hidecourse', args, this.hide, this);
console.performAjaxAction('hidecourse', args, this.hide, this);
break;
default:
Y.log('Invalid AJAX action requested of managed course.', 'warn', 'core_course');
Y.log('Invalid AJAX action requested of managed course.', 'warn', 'moodle-course-management');
return false;
}
},
@@ -121,7 +121,7 @@ Course.prototype = {
* @method remove
*/
remove : function() {
this.get('console').remove_course_by_id(this.get('courseid'));
this.get('console').removeCourseById(this.get('courseid'));
this.get('node').remove();
},
@@ -129,8 +129,8 @@ Course.prototype = {
* Moves this course after another course.
*
* @method moveAfter
* @param {Int} moveaftercourse The course to move after or 0 to put it at the top.
* @param {Int} previousid the course it was previously after in case we need to revert.
* @param {Number} moveaftercourse The course to move after or 0 to put it at the top.
* @param {Number} previousid the course it was previously after in case we need to revert.
*/
moveAfter : function(moveaftercourse, previousid) {
var console = this.get('console'),
@@ -139,7 +139,7 @@ Course.prototype = {
moveafter : moveaftercourse,
previous : previousid
};
console.perform_ajax_action('movecourseafter', args, this.moveAfterResponse, this);
console.performAjaxAction('movecourseafter', args, this.moveAfterResponse, this);
},
/**
@@ -147,18 +147,18 @@ Course.prototype = {
*
* @method moveAfterResponse
* @protected
* @param {Int} transactionid The transaction ID for the request.
* @param {Number} transactionid The transaction ID for the request.
* @param {Object} response The response to the request.
* @param {Objects} args The arguments that were given with the request.
* @returns {Boolean}
*/
moveAfterResponse : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args),
var outcome = this.checkAjaxResponse(transactionid, response, args),
node = this.get('node'),
previous;
if (outcome === false) {
previous = node.ancestor('ul').one('li[data-id='+args.previous+']');
Y.log('AJAX failed to move this course after the requested course', 'warn', 'core_course');
Y.log('AJAX failed to move this course after the requested course', 'warn', 'moodle-course-management');
if (previous) {
// After the last previous.
previous.insertAfter(node, 'after');
@@ -168,7 +168,7 @@ Course.prototype = {
}
return false;
}
Y.log('AJAX successfully moved course ('+this.getName()+')', 'info', 'core_course');
Y.log('AJAX successfully moved course ('+this.getName()+')', 'info', 'moodle-course-management');
this.highlight();
}
};
+8 -7
View File
@@ -1,7 +1,7 @@
/**
* Drag and Drop handler
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class DragDrop
* @constructor
* @extends Y.Base
@@ -239,19 +239,20 @@ DragDrop.prototype = {
previousid;
if (!drag.test('.listitem-course')) {
Y.log('Wasn\'t what I expected', 'warn', 'core_course');
Y.log('Wasn\'t what I expected', 'warn', 'moodle-course-management');
alert(drag);
return false;
}
courseid = drag.getData('id');
course = console.get_course_by_id(courseid);
if (iscategory) {
categoryid = drop.ancestor('.listitem-category').getData('id');
Y.log('Course ' + courseid + ' dragged into category ' + categoryid);
category = console.get_category_by_id(categoryid);
category = console.getCategoryById(categoryid);
if (category) {
category.moveCourseTo(course);
course = console.getCourseById(courseid);
if (course) {
category.moveCourseTo(course);
}
}
} else if (iscourse || drop.ancestor('#course-listing')) {
previoussibling = drag.get('previousSibling');
@@ -261,7 +262,7 @@ DragDrop.prototype = {
course.moveAfter(aftercourseid, previousid);
}
} else {
Y.log('Course dropped over unhandled target.', 'info', 'core_course');
Y.log('Course dropped over unhandled target.', 'info', 'moodle-course-management');
}
}
};
+26 -26
View File
@@ -1,7 +1,7 @@
/**
* A managed course.
*
* @namespace M.core_course.management
* @namespace M.course.management
* @class Item
* @constructor
* @extends Y.Base
@@ -50,20 +50,20 @@ Item.prototype = {
/**
* Checks and parses an AJAX response for an item.
*
* @method check_ajax_response
* @method checkAjaxResponse
* @protected
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Object|Boolean}
*/
check_ajax_response : function(transactionid, response, args) {
checkAjaxResponse : function(transactionid, response, args) {
if (response.status !== 200) {
Y.log('Error: AJAX response resulted in non 200 status.', 'error', 'Item.check_ajax_response');
Y.log('Error: AJAX response resulted in non 200 status.', 'error', 'Item.checkAjaxResponse');
return false;
}
if (transactionid === null || args === null) {
Y.log('Error: Invalid AJAX response details provided.', 'error', 'Item.check_ajax_response');
Y.log('Error: Invalid AJAX response details provided.', 'error', 'Item.checkAjaxResponse');
return false;
}
var outcome = Y.JSON.parse(response.responseText);
@@ -80,7 +80,7 @@ Item.prototype = {
* Moves an item up by one.
*
* @method moveup
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
@@ -93,9 +93,9 @@ Item.prototype = {
previousup,
previousdown,
tmpnode,
outcome = this.check_ajax_response(transactionid, response, args);
outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
Y.log('AJAX request to move '+this.get('itemname')+' up failed by outcome.', 'warn', 'core_course');
Y.log('AJAX request to move '+this.get('itemname')+' up failed by outcome.', 'warn', 'moodle-course-management');
return false;
}
node = this.get('node');
@@ -124,9 +124,9 @@ Item.prototype = {
}
}
this.updated(true);
Y.log('Success: '+this.get('itemname')+' moved up by AJAX.', 'info', 'core_course');
Y.log('Success: '+this.get('itemname')+' moved up by AJAX.', 'info', 'moodle-course-management');
} else {
Y.log(this.get('itemname')+' cannot be moved up as its the top item', 'warn', 'core_course');
Y.log(this.get('itemname')+' cannot be moved up as its the top item', 'warn', 'moodle-course-management');
}
},
@@ -134,7 +134,7 @@ Item.prototype = {
* Moves an item down by one.
*
* @method movedown
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
@@ -147,9 +147,9 @@ Item.prototype = {
nextup,
nextdown,
tmpnode,
outcome = this.check_ajax_response(transactionid, response, args);
outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
Y.log('AJAX request to move '+this.get('itemname')+' down failed by outcome.', 'warn', 'core_course');
Y.log('AJAX request to move '+this.get('itemname')+' down failed by outcome.', 'warn', 'moodle-course-management');
return false;
}
node = this.get('node');
@@ -178,9 +178,9 @@ Item.prototype = {
}
}
this.updated(true);
Y.log('Success: '+this.get('itemname')+' moved down by AJAX.', 'info', 'core_course');
Y.log('Success: '+this.get('itemname')+' moved down by AJAX.', 'info', 'moodle-course-management');
} else {
Y.log(this.get('itemname')+' cannot be moved down as its the last item', 'warn', 'core_course');
Y.log(this.get('itemname')+' cannot be moved down as its the last item', 'warn', 'moodle-course-management');
}
},
@@ -188,21 +188,21 @@ Item.prototype = {
* Makes an item visible.
*
* @method show
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
show : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args);
var outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
Y.log('AJAX request to show '+this.get('itemname')+' by outcome.', 'warn', 'core_course');
Y.log('AJAX request to show '+this.get('itemname')+' by outcome.', 'warn', 'moodle-course-management');
return false;
}
this.markVisible();
this.updated();
Y.log('Success: '+this.get('itemname')+' made visible by AJAX.', 'info', 'core_course');
Y.log('Success: '+this.get('itemname')+' made visible by AJAX.', 'info', 'moodle-course-management');
},
/**
@@ -211,7 +211,7 @@ Item.prototype = {
*/
markVisible : function() {
this.get('node').setAttribute('data-visible', '1');
Y.log('Marked '+this.get('itemname')+' as visible', 'note', 'core_course');
Y.log('Marked '+this.get('itemname')+' as visible', 'info', 'moodle-course-management');
return true;
},
@@ -219,20 +219,20 @@ Item.prototype = {
* Hides an item.
*
* @method hide
* @param {Int} transactionid The transaction ID of the AJAX request (unique)
* @param {Number} transactionid The transaction ID of the AJAX request (unique)
* @param {Object} response The response from the AJAX request.
* @param {Object} args The arguments given to the request.
* @returns {Boolean}
*/
hide : function(transactionid, response, args) {
var outcome = this.check_ajax_response(transactionid, response, args);
var outcome = this.checkAjaxResponse(transactionid, response, args);
if (outcome === false) {
Y.log('AJAX request to hide '+this.get('itemname')+' by outcome.', 'warn', 'core_course');
Y.log('AJAX request to hide '+this.get('itemname')+' by outcome.', 'warn', 'moodle-course-management');
return false;
}
this.markHidden();
this.updated();
Y.log('Success: '+this.get('itemname')+' made hidden by AJAX.', 'info', 'core_course');
Y.log('Success: '+this.get('itemname')+' made hidden by AJAX.', 'info', 'moodle-course-management');
},
/**
@@ -241,7 +241,7 @@ Item.prototype = {
*/
markHidden : function() {
this.get('node').setAttribute('data-visible', '0');
Y.log('Marked '+this.get('itemname')+' as hidden', 'note', 'core_course');
Y.log('Marked '+this.get('itemname')+' as hidden', 'info', 'moodle-course-management');
return true;
},