MDL-40811 JavaScript: Use the new moodle-course-util functions
This commit is contained in:
Vendored
+8
-20
@@ -73,7 +73,7 @@ YUI.add('moodle-course-dragdrop', function(Y) {
|
||||
setup_for_section : function(baseselector) {
|
||||
Y.Node.all(baseselector).each(function(sectionnode) {
|
||||
// Determine the section ID
|
||||
var sectionid = this.get_section_id(sectionnode);
|
||||
var sectionid = Y.Moodle.core_course.util.section.getId(sectionnode);
|
||||
|
||||
// We skip the top section as it is not draggable
|
||||
if (sectionid > 0) {
|
||||
@@ -100,10 +100,6 @@ YUI.add('moodle-course-dragdrop', function(Y) {
|
||||
}, this);
|
||||
},
|
||||
|
||||
get_section_id : function(node) {
|
||||
return Number(node.get('id').replace(/section-/i, ''));
|
||||
},
|
||||
|
||||
/*
|
||||
* Drag-dropping related functions
|
||||
*/
|
||||
@@ -135,8 +131,8 @@ YUI.add('moodle-course-dragdrop', function(Y) {
|
||||
var dragnode = drag.get('node');
|
||||
var dropnode = e.drop.get('node');
|
||||
// Prepare some variables
|
||||
var dragnodeid = Number(this.get_section_id(dragnode));
|
||||
var dropnodeid = Number(this.get_section_id(dropnode));
|
||||
var dragnodeid = Number(Y.Moodle.core_course.util.section.getId(dragnode));
|
||||
var dropnodeid = Number(Y.Moodle.core_course.util.section.getId(dropnode));
|
||||
|
||||
var loopstart = dragnodeid;
|
||||
var loopend = dropnodeid;
|
||||
@@ -195,7 +191,7 @@ YUI.add('moodle-course-dragdrop', function(Y) {
|
||||
do {
|
||||
var swapped = false;
|
||||
for (var i = loopstart; i <= loopend; i++) {
|
||||
if (this.get_section_id(sectionlist.item(i-1)) > this.get_section_id(sectionlist.item(i))) {
|
||||
if (Y.Moodle.core_course.util.section.getId(sectionlist.item(i-1)) > Y.Moodle.core_course.util.section.getId(sectionlist.item(i))) {
|
||||
// Swap section id
|
||||
var sectionid = sectionlist.item(i-1).get('id');
|
||||
sectionlist.item(i-1).set('id', sectionlist.item(i).get('id'));
|
||||
@@ -323,14 +319,6 @@ YUI.add('moodle-course-dragdrop', function(Y) {
|
||||
}, this);
|
||||
},
|
||||
|
||||
get_section_id : function(node) {
|
||||
return Number(node.get('id').replace(/section-/i, ''));
|
||||
},
|
||||
|
||||
get_resource_id : function(node) {
|
||||
return Number(node.get('id').replace(/module-/i, ''));
|
||||
},
|
||||
|
||||
drag_start : function(e) {
|
||||
// Get our drag object
|
||||
var drag = e.target;
|
||||
@@ -367,11 +355,11 @@ YUI.add('moodle-course-dragdrop', function(Y) {
|
||||
params.courseId = this.get('courseid');
|
||||
params['class'] = 'resource';
|
||||
params.field = 'move';
|
||||
params.id = Number(this.get_resource_id(dragnode));
|
||||
params.sectionId = this.get_section_id(dropnode.ancestor(M.course.format.get_section_wrapper(Y), true));
|
||||
params.id = Number(Y.Moodle.core_course.util.cm.getId(dragnode));
|
||||
params.sectionId = Y.Moodle.core_course.util.section.getId(dropnode.ancestor(M.course.format.get_section_wrapper(Y), true));
|
||||
|
||||
if (dragnode.next()) {
|
||||
params.beforeId = Number(this.get_resource_id(dragnode.next()));
|
||||
params.beforeId = Number(Y.Moodle.core_course.util.cm.getId(dragnode.next()));
|
||||
}
|
||||
|
||||
// Do AJAX request
|
||||
@@ -426,4 +414,4 @@ YUI.add('moodle-course-dragdrop', function(Y) {
|
||||
M.course.init_section_dragdrop = function(params) {
|
||||
new DRAGSECTION(params);
|
||||
}
|
||||
}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-core-notification', 'moodle-course-coursebase']});
|
||||
}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-core-notification', 'moodle-course-coursebase', 'moodle-course-util']});
|
||||
|
||||
Vendored
+12
-44
@@ -123,38 +123,6 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
// Send the request
|
||||
Y.io(uri, config);
|
||||
return responsetext;
|
||||
},
|
||||
/**
|
||||
* Return the name of the activity instance
|
||||
*
|
||||
* If activity has no name (for example label) null is returned
|
||||
*
|
||||
* @param element The <li> element to determine a name for
|
||||
* @return string|null Instance name
|
||||
*/
|
||||
get_instance_name : function(target) {
|
||||
if (target.one(SELECTOR.INSTANCENAME)) {
|
||||
return target.one(SELECTOR.INSTANCENAME).get('firstChild').get('data');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
/**
|
||||
* Return the module ID for the specified element
|
||||
*
|
||||
* @param element The <li> element to determine a module-id number for
|
||||
* @return string The module ID
|
||||
*/
|
||||
get_element_id : function(element) {
|
||||
return element.get('id').replace(CSS.MODULEIDPREFIX, '');
|
||||
},
|
||||
/**
|
||||
* Return the module ID for the specified element
|
||||
*
|
||||
* @param element The <li> element to determine a module-id number for
|
||||
* @return string The module ID
|
||||
*/
|
||||
get_section_id : function(section) {
|
||||
return section.get('id').replace(CSS.SECTIONIDPREFIX, '');
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -343,7 +311,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
'class' : 'resource',
|
||||
'field' : 'indent',
|
||||
'value' : newindent,
|
||||
'id' : this.get_element_id(activity)
|
||||
'id' : Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
var commands = activity.one(SELECTOR.COMMANDSPAN);
|
||||
var spinner = M.util.add_spinner(Y, commands).setStyles({
|
||||
@@ -395,8 +363,8 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
var plugindata = {
|
||||
type : M.util.get_string('pluginname', element.getAttribute('class').match(/modtype_([^\s]*)/)[1])
|
||||
}
|
||||
if (this.get_instance_name(element) != null) {
|
||||
plugindata.name = this.get_instance_name(element)
|
||||
if (Y.Moodle.core_course.util.cm.getName(element) != null) {
|
||||
plugindata.name = Y.Moodle.core_course.util.cm.getName(element)
|
||||
confirmstring = M.util.get_string('deletechecktypename', 'moodle', plugindata);
|
||||
} else {
|
||||
confirmstring = M.util.get_string('deletechecktype', 'moodle', plugindata)
|
||||
@@ -412,7 +380,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
var data = {
|
||||
'class' : 'resource',
|
||||
'action' : 'DELETE',
|
||||
'id' : this.get_element_id(element)
|
||||
'id' : Y.Moodle.core_course.util.cm.getId(element)
|
||||
};
|
||||
this.send_request(data);
|
||||
if (M.core.actionmenu && M.core.actionmenu.instance) {
|
||||
@@ -450,7 +418,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
'class' : 'resource',
|
||||
'field' : 'visible',
|
||||
'value' : value,
|
||||
'id' : this.get_element_id(element)
|
||||
'id' : Y.Moodle.core_course.util.cm.getId(element)
|
||||
};
|
||||
var spinner = M.util.add_spinner(Y, element.one(SELECTOR.COMMANDSPAN));
|
||||
this.send_request(data, spinner);
|
||||
@@ -484,7 +452,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
button.setData('action', newstatus);
|
||||
|
||||
// If activity is conditionally hidden, then don't toggle.
|
||||
if (this.get_instance_name(activity) == null) {
|
||||
if (Y.Moodle.core_course.util.cm.getName(activity) == null) {
|
||||
toggleclass = CSS.DIMMEDTEXT;
|
||||
dimarea = activity.all(SELECTOR.MODINDENTDIV + ' > div').item(1);
|
||||
}
|
||||
@@ -554,7 +522,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
'class' : 'resource',
|
||||
'field' : 'groupmode',
|
||||
'value' : groupmode,
|
||||
'id' : this.get_element_id(activity)
|
||||
'id' : Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
|
||||
spinner = M.util.add_spinner(Y, activity.one(SELECTOR.COMMANDSPAN));
|
||||
@@ -575,7 +543,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
*/
|
||||
edit_title : function(ev, button, activity) {
|
||||
// Get the element we're working on
|
||||
var activityid = this.get_element_id(activity),
|
||||
var activityid = Y.Moodle.core_course.util.cm.getId(activity),
|
||||
instancename = activity.one(SELECTOR.INSTANCENAME),
|
||||
currenttitle = instancename.get('firstChild'),
|
||||
oldtitle = currenttitle.get('data'),
|
||||
@@ -652,7 +620,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
'class' : 'resource',
|
||||
'field' : 'updatetitle',
|
||||
'title' : newtitle,
|
||||
'id' : this.get_element_id(activity)
|
||||
'id' : Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
var response = this.send_request(data, spinner);
|
||||
if (response.instancename) {
|
||||
@@ -811,7 +779,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
var data = {
|
||||
'class' : 'section',
|
||||
'field' : 'visible',
|
||||
'id' : this.get_section_id(section.ancestor(M.course.format.get_section_wrapper(Y), true)),
|
||||
'id' : Y.Moodle.core_course.util.section.getId(section.ancestor(M.course.format.get_section_wrapper(Y), true)),
|
||||
'value' : value
|
||||
};
|
||||
|
||||
@@ -827,7 +795,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
} else {
|
||||
var button = node.one(SELECTOR.HIDE);
|
||||
}
|
||||
var activityid = this.get_element_id(node);
|
||||
var activityid = Y.Moodle.core_course.util.cm.getId(node);
|
||||
|
||||
if (Y.Array.indexOf(response.resourcestotoggle, activityid) != -1) {
|
||||
node.getData('toolbox').handle_resource_dim(button, node, oldstatus);
|
||||
@@ -864,7 +832,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
|
||||
// Then add it if required to the selected section
|
||||
if (!togglestatus) {
|
||||
section.addClass('current');
|
||||
value = this.get_section_id(section.ancestor(M.course.format.get_section_wrapper(Y), true));
|
||||
value = Y.Moodle.core_course.util.section.getId(section.ancestor(M.course.format.get_section_wrapper(Y), true));
|
||||
var new_string = M.util.get_string('markedthistopic', 'moodle');
|
||||
button
|
||||
.set('title', new_string);
|
||||
|
||||
Reference in New Issue
Block a user