mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
MDL-4782 course: substitute YUI with AMD and rest.php with calling WS
This commit is contained in:
parent
4529327a22
commit
4b6728e431
1
course/amd/build/actions.min.js
vendored
Normal file
1
course/amd/build/actions.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
594
course/amd/src/actions.js
Normal file
594
course/amd/src/actions.js
Normal file
@ -0,0 +1,594 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Various actions on modules and sections in the editing mode - hiding, duplicating, deleting, etc.
|
||||
*
|
||||
* @module core_course/actions
|
||||
* @package core
|
||||
* @copyright 2016 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 3.3
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str', 'core/url', 'core/yui'],
|
||||
function($, ajax, templates, notification, str, url, Y) {
|
||||
var CSS = {
|
||||
EDITINPROGRESS: 'editinprogress',
|
||||
SECTIONDRAGGABLE: 'sectiondraggable',
|
||||
EDITINGMOVE: 'editing_move'
|
||||
};
|
||||
var SELECTOR = {
|
||||
ACTIVITYLI: 'li.activity',
|
||||
ACTIONAREA: '.actions',
|
||||
ACTIVITYACTION: 'a.cm-edit-action',
|
||||
MENU: '.moodle-actionmenu[data-enhance=moodle-core-actionmenu]',
|
||||
TOGGLE: '.toggle-display,.dropdown-toggle',
|
||||
SECTIONLI: 'li.section',
|
||||
SECTIONACTIONMENU: '.section_action_menu'
|
||||
};
|
||||
|
||||
Y.use('moodle-course-coursebase', function() {
|
||||
var courseformatselector = M.course.format.get_section_selector();
|
||||
if (courseformatselector) {
|
||||
SELECTOR.SECTIONLI = courseformatselector;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Wrapper for Y.Moodle.core_course.util.cm.getId
|
||||
*
|
||||
* @param {JQuery} element
|
||||
* @returns {Integer}
|
||||
*/
|
||||
var getModuleId = function(element) {
|
||||
var id;
|
||||
Y.use('moodle-course-util', function(Y) {
|
||||
id = Y.Moodle.core_course.util.cm.getId(Y.Node(element.get(0)));
|
||||
});
|
||||
return id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for Y.Moodle.core_course.util.cm.getName
|
||||
*
|
||||
* @param {JQuery} element
|
||||
* @returns {String}
|
||||
*/
|
||||
var getModuleName = function(element) {
|
||||
var name;
|
||||
Y.use('moodle-course-util', function(Y) {
|
||||
name = Y.Moodle.core_course.util.cm.getName(Y.Node(element.get(0)));
|
||||
});
|
||||
return name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for M.util.add_spinner for an activity
|
||||
*
|
||||
* @param {JQuery} activity
|
||||
* @returns {Node}
|
||||
*/
|
||||
var addActivitySpinner = function(activity) {
|
||||
activity.addClass(CSS.EDITINPROGRESS);
|
||||
var actionarea = activity.find(SELECTOR.ACTIONAREA).get(0);
|
||||
if (actionarea) {
|
||||
var spinner = M.util.add_spinner(Y, Y.Node(actionarea));
|
||||
spinner.show();
|
||||
return spinner;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for M.util.add_spinner for a section
|
||||
*
|
||||
* @param {JQuery} sectionelement
|
||||
* @returns {Node}
|
||||
*/
|
||||
var addSectionSpinner = function(sectionelement) {
|
||||
sectionelement.addClass(CSS.EDITINPROGRESS);
|
||||
var actionarea = sectionelement.find(SELECTOR.SECTIONACTIONMENU).get(0);
|
||||
if (actionarea) {
|
||||
var spinner = M.util.add_spinner(Y, Y.Node(actionarea));
|
||||
spinner.show();
|
||||
return spinner;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for M.util.add_lightbox
|
||||
*
|
||||
* @param {JQuery} sectionelement
|
||||
* @returns {Node}
|
||||
*/
|
||||
var addSectionLightbox = function(sectionelement) {
|
||||
var lightbox = M.util.add_lightbox(Y, Y.Node(sectionelement.get(0)));
|
||||
lightbox.show();
|
||||
return lightbox;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the spinner element
|
||||
*
|
||||
* @param {JQuery} element
|
||||
* @param {Node} spinner
|
||||
* @param {Number} delay
|
||||
*/
|
||||
var removeSpinner = function(element, spinner, delay) {
|
||||
window.setTimeout(function() {
|
||||
element.removeClass(CSS.EDITINPROGRESS);
|
||||
if (spinner) {
|
||||
spinner.hide();
|
||||
}
|
||||
}, delay);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the lightbox element
|
||||
*
|
||||
* @param {Node} lightbox lighbox YUI element returned by addSectionLightbox
|
||||
* @param {Number} delay
|
||||
*/
|
||||
var removeLightbox = function(lightbox, delay) {
|
||||
if (lightbox) {
|
||||
window.setTimeout(function() {
|
||||
lightbox.hide();
|
||||
}, delay);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise action menu for the element (section or module)
|
||||
*
|
||||
* @param {String} elementid CSS id attribute of the element
|
||||
* @param {Boolean} openmenu whether to open menu - this can be used when re-initiating menu after indent action was pressed
|
||||
*/
|
||||
var initActionMenu = function(elementid, openmenu) {
|
||||
// Initialise action menu in the new activity.
|
||||
Y.use('moodle-course-coursebase', function() {
|
||||
M.course.coursebase.invoke_function('setup_for_resource', '#' + elementid);
|
||||
});
|
||||
if (M.core.actionmenu && M.core.actionmenu.newDOMNode) {
|
||||
M.core.actionmenu.newDOMNode(Y.one('#' + elementid));
|
||||
}
|
||||
// Open action menu if the original element had data-keepopen.
|
||||
if (openmenu) {
|
||||
// We must use YUI click simulate here so the toggle works in Clean theme. This toggle is not
|
||||
// needed in Boost because we use standard bootstrapbase action menu.
|
||||
var toggle = Y.one('#' + elementid + ' ' + SELECTOR.MENU).one(SELECTOR.TOGGLE);
|
||||
if (toggle && toggle.simulate) {
|
||||
toggle.simulate('click');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns focus to the element that was clicked or "Edit" link if element is no longer visible.
|
||||
*
|
||||
* @param {String} elementId CSS id attribute of the element
|
||||
* @param {String} action data-action property of the element that was clicked
|
||||
*/
|
||||
var focusActionItem = function(elementId, action) {
|
||||
var mainelement = $('#' + elementId);
|
||||
var selector = '[data-action=' + action + ']';
|
||||
if (action === 'groupsseparate' || action === 'groupsvisible' || action === 'groupsnone') {
|
||||
// New element will have different data-action.
|
||||
selector = '[data-action=groupsseparate],[data-action=groupsvisible],[data-action=groupsnone]';
|
||||
}
|
||||
if (mainelement.find(selector).is(':visible')) {
|
||||
mainelement.find(selector).focus();
|
||||
} else {
|
||||
// Element not visible, focus the "Edit" link.
|
||||
mainelement.find(SELECTOR.MENU).find(SELECTOR.TOGGLE).focus();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Find next <a> after the element
|
||||
*
|
||||
* @param {JQuery} mainElement element that is about to be deleted
|
||||
* @returns {JQuery}
|
||||
*/
|
||||
var findNextFocusable = function(mainElement) {
|
||||
var tabables = $("a:visible");
|
||||
var isInside = false, foundElement = null;
|
||||
tabables.each(function() {
|
||||
if ($.contains(mainElement[0], this)) {
|
||||
isInside = true;
|
||||
} else if (isInside) {
|
||||
foundElement = this;
|
||||
return false; // Returning false in .each() is equivalent to "break;" inside the loop in php.
|
||||
}
|
||||
});
|
||||
return foundElement;
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs an action on a module (moving, deleting, duplicating, hiding, etc.)
|
||||
*
|
||||
* @param {JQuery} moduleElement activity element we perform action on
|
||||
* @param {Number} cmid
|
||||
* @param {JQuery} target the element (menu item) that was clicked
|
||||
*/
|
||||
var editModule = function(moduleElement, cmid, target) {
|
||||
var keepopen = target.attr('data-keepopen'),
|
||||
action = target.attr('data-action');
|
||||
var spinner = addActivitySpinner(moduleElement);
|
||||
var promises = ajax.call([{
|
||||
methodname: 'core_course_edit_module',
|
||||
args: {id: cmid,
|
||||
action: action,
|
||||
sectionreturn: target.attr('data-sectionreturn') ? target.attr('data-sectionreturn') : 0
|
||||
}
|
||||
}], true);
|
||||
|
||||
var lightbox;
|
||||
if (action === 'duplicate') {
|
||||
lightbox = addSectionLightbox(target.closest(SELECTOR.SECTIONLI));
|
||||
}
|
||||
$.when.apply($, promises)
|
||||
.done(function(data) {
|
||||
var elementToFocus = findNextFocusable(moduleElement);
|
||||
moduleElement.replaceWith(data);
|
||||
// Initialise action menu for activity(ies) added as a result of this.
|
||||
$('<div>' + data + '</div>').find(SELECTOR.ACTIVITYLI).each(function(index) {
|
||||
initActionMenu($(this).attr('id'), keepopen);
|
||||
if (index === 0) {
|
||||
focusActionItem($(this).attr('id'), action);
|
||||
elementToFocus = null;
|
||||
}
|
||||
});
|
||||
// In case of activity deletion focus the next focusable element.
|
||||
if (elementToFocus) {
|
||||
elementToFocus.focus();
|
||||
}
|
||||
// Remove spinner and lightbox with a delay.
|
||||
removeSpinner(moduleElement, spinner, 400);
|
||||
removeLightbox(lightbox, 400);
|
||||
// Trigger event that can be observed by course formats.
|
||||
moduleElement.trigger($.Event('coursemoduleedited', {ajaxreturn: data, action: action}));
|
||||
}).fail(function(ex) {
|
||||
// Remove spinner and lightbox.
|
||||
removeSpinner(moduleElement, spinner);
|
||||
removeLightbox(lightbox);
|
||||
// Trigger event that can be observed by course formats.
|
||||
var e = $.Event('coursemoduleeditfailed', {exception: ex, action: action});
|
||||
moduleElement.trigger(e);
|
||||
if (!e.isDefaultPrevented()) {
|
||||
notification.exception(ex);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Requests html for the module via WS core_course_get_module and updates the module on the course page
|
||||
*
|
||||
* Used after d&d of the module to another section
|
||||
*
|
||||
* @param {JQuery} activityElement
|
||||
* @param {Number} cmid
|
||||
* @param {Number} sectionreturn
|
||||
*/
|
||||
var refreshModule = function(activityElement, cmid, sectionreturn) {
|
||||
var spinner = addActivitySpinner(activityElement);
|
||||
var promises = ajax.call([{
|
||||
methodname: 'core_course_get_module',
|
||||
args: {id: cmid, sectionreturn: sectionreturn}
|
||||
}], true);
|
||||
|
||||
$.when.apply($, promises)
|
||||
.done(function(data) {
|
||||
removeSpinner(activityElement, spinner, 400);
|
||||
replaceActivityHtmlWith(data);
|
||||
}).fail(function() {
|
||||
removeSpinner(activityElement, spinner);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Displays the delete confirmation to delete a module
|
||||
*
|
||||
* @param {JQuery} mainelement activity element we perform action on
|
||||
* @param {function} onconfirm function to execute on confirm
|
||||
*/
|
||||
var confirmDeleteModule = function(mainelement, onconfirm) {
|
||||
var modtypename = mainelement.attr('class').match(/modtype_([^\s]*)/)[1];
|
||||
var modulename = getModuleName(mainelement);
|
||||
|
||||
str.get_string('pluginname', modtypename).done(function(pluginname) {
|
||||
var plugindata = {
|
||||
type: pluginname,
|
||||
name: modulename
|
||||
};
|
||||
str.get_strings([
|
||||
{key: 'confirm'},
|
||||
{key: modulename === null ? 'deletechecktype' : 'deletechecktypename', param: plugindata},
|
||||
{key: 'yes'},
|
||||
{key: 'no'}
|
||||
]).done(function(s) {
|
||||
notification.confirm(s[0], s[1], s[2], s[3], onconfirm);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Displays the delete confirmation to delete a section
|
||||
*
|
||||
* @param {String} message confirmation message
|
||||
* @param {function} onconfirm function to execute on confirm
|
||||
*/
|
||||
var confirmEditSection = function(message, onconfirm) {
|
||||
str.get_strings([
|
||||
{key: 'confirm'}, // TODO link text
|
||||
{key: 'yes'},
|
||||
{key: 'no'}
|
||||
]).done(function(s) {
|
||||
notification.confirm(s[0], message, s[1], s[2], onconfirm);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaces an action menu item with another one (for example Show->Hide, Set marker->Remove marker)
|
||||
*
|
||||
* @param {JQuery} actionitem
|
||||
* @param {String} image new image name ("i/show", "i/hide", etc.)
|
||||
* @param {String} stringname new string for the action menu item
|
||||
* @param {String} stringcomponent
|
||||
* @param {String} titlestr string for "title" attribute (if different from stringname)
|
||||
* @param {String} titlecomponent
|
||||
* @param {String} newaction new value for data-action attribute of the link
|
||||
*/
|
||||
var replaceActionItem = function(actionitem, image, stringname,
|
||||
stringcomponent, titlestr, titlecomponent, newaction) {
|
||||
actionitem.find('img').attr('src', url.imageUrl(image, 'core'));
|
||||
str.get_string(stringname, stringcomponent).done(function(newstring) {
|
||||
actionitem.find('span.menu-action-text').html(newstring);
|
||||
actionitem.attr('title', newstring);
|
||||
});
|
||||
if (titlestr) {
|
||||
str.get_string(titlestr, titlecomponent).done(function(newtitle) {
|
||||
actionitem.attr('title', newtitle);
|
||||
});
|
||||
}
|
||||
actionitem.attr('data-action', newaction);
|
||||
};
|
||||
|
||||
/**
|
||||
* Default post-processing for section AJAX edit actions.
|
||||
*
|
||||
* This can be overridden in course formats by listening to event coursesectionedited:
|
||||
*
|
||||
* $('body').on('coursesectionedited', 'li.section', function(e) {
|
||||
* var action = e.action,
|
||||
* sectionElement = $(e.target),
|
||||
* data = e.ajaxreturn;
|
||||
* // ... Do some processing here.
|
||||
* e.preventDefault(); // Prevent default handler.
|
||||
* });
|
||||
*
|
||||
* @param {JQuery} sectionElement
|
||||
* @param {JQuery} actionItem
|
||||
* @param {Object} data
|
||||
* @param {String} courseformat
|
||||
*/
|
||||
var defaultEditSectionHandler = function(sectionElement, actionItem, data, courseformat) {
|
||||
var action = actionItem.attr('data-action');
|
||||
if (action === 'hide' || action === 'show') {
|
||||
if (action === 'hide') {
|
||||
sectionElement.addClass('hidden');
|
||||
replaceActionItem(actionItem, 'i/show',
|
||||
'showfromothers', 'format_' + courseformat, null, null, 'show');
|
||||
} else {
|
||||
sectionElement.removeClass('hidden');
|
||||
replaceActionItem(actionItem, 'i/hide',
|
||||
'hidefromothers', 'format_' + courseformat, null, null, 'hide');
|
||||
}
|
||||
// Replace the modules with new html (that indicates that they are now hidden or not hidden).
|
||||
if (data.modules !== undefined) {
|
||||
for (var i in data.modules) {
|
||||
replaceActivityHtmlWith(data.modules[i]);
|
||||
}
|
||||
}
|
||||
// Replace the section availability information.
|
||||
if (data.section_availability !== undefined) {
|
||||
sectionElement.find('.section_availability').first().replaceWith(data.section_availability);
|
||||
}
|
||||
} else if (action === 'setmarker') {
|
||||
var oldmarker = $(SELECTOR.SECTIONLI + '.current'),
|
||||
oldActionItem = oldmarker.find(SELECTOR.SECTIONACTIONMENU + ' ' + 'a[data-action=removemarker]');
|
||||
oldmarker.removeClass('current');
|
||||
replaceActionItem(oldActionItem, 'i/marker',
|
||||
'highlight', 'core', 'markthistopic', 'core', 'setmarker');
|
||||
sectionElement.addClass('current');
|
||||
replaceActionItem(actionItem, 'i/marked',
|
||||
'highlightoff', 'core', 'markedthistopic', 'core', 'removemarker');
|
||||
} else if (action === 'removemarker') {
|
||||
sectionElement.removeClass('current');
|
||||
replaceActionItem(actionItem, 'i/marker',
|
||||
'highlight', 'core', 'markthistopic', 'core', 'setmarker');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaces the course module with the new html (used to update module after it was edited or its visibility was changed).
|
||||
*
|
||||
* @param {String} activityHTML
|
||||
*/
|
||||
var replaceActivityHtmlWith = function(activityHTML) {
|
||||
$('<div>' + activityHTML + '</div>').find(SELECTOR.ACTIVITYLI).each(function() {
|
||||
// Extract id from the new activity html.
|
||||
var id = $(this).attr('id');
|
||||
// Find the existing element with the same id and replace its contents with new html.
|
||||
$(SELECTOR.ACTIVITYLI + '#' + id).replaceWith(activityHTML);
|
||||
// Initialise action menu.
|
||||
initActionMenu(id, false);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs an action on a module (moving, deleting, duplicating, hiding, etc.)
|
||||
*
|
||||
* @param {JQuery} sectionElement section element we perform action on
|
||||
* @param {Nunmber} sectionid
|
||||
* @param {JQuery} target the element (menu item) that was clicked
|
||||
* @param {String} courseformat
|
||||
*/
|
||||
var editSection = function(sectionElement, sectionid, target, courseformat) {
|
||||
var action = target.attr('data-action'),
|
||||
sectionreturn = target.attr('data-sectionreturn') ? target.attr('data-sectionreturn') : 0;
|
||||
var spinner = addSectionSpinner(sectionElement);
|
||||
var promises = ajax.call([{
|
||||
methodname: 'core_course_edit_section',
|
||||
args: {id: sectionid, action: action, sectionreturn: sectionreturn}
|
||||
}], true);
|
||||
|
||||
var lightbox = addSectionLightbox(sectionElement);
|
||||
$.when.apply($, promises)
|
||||
.done(function(dataencoded) {
|
||||
var data = $.parseJSON(dataencoded);
|
||||
removeSpinner(sectionElement, spinner);
|
||||
removeLightbox(lightbox);
|
||||
sectionElement.find(SELECTOR.SECTIONACTIONMENU).find(SELECTOR.TOGGLE).focus();
|
||||
// Trigger event that can be observed by course formats.
|
||||
var e = $.Event('coursesectionedited', {ajaxreturn: data, action: action});
|
||||
sectionElement.trigger(e);
|
||||
if (!e.isDefaultPrevented()) {
|
||||
defaultEditSectionHandler(sectionElement, target, data, courseformat);
|
||||
}
|
||||
}).fail(function(ex) {
|
||||
// Remove spinner and lightbox.
|
||||
removeSpinner(sectionElement, spinner);
|
||||
removeLightbox(lightbox);
|
||||
// Trigger event that can be observed by course formats.
|
||||
var e = $.Event('coursesectioneditfailed', {exception: ex, action: action});
|
||||
sectionElement.trigger(e);
|
||||
if (!e.isDefaultPrevented()) {
|
||||
notification.exception(ex);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Register a function to be executed after D&D of an activity.
|
||||
Y.use('moodle-course-coursebase', function() {
|
||||
M.course.coursebase.register_module({
|
||||
// Ignore camelcase eslint rule for the next line because it is an expected name of the callback.
|
||||
// eslint-disable-next-line camelcase
|
||||
set_visibility_resource_ui: function(args) {
|
||||
var mainelement = $(args.element.getDOMNode());
|
||||
var cmid = getModuleId(mainelement);
|
||||
if (cmid) {
|
||||
var sectionreturn = mainelement.find('.' + CSS.EDITINGMOVE).attr('data-sectionreturn');
|
||||
refreshModule(mainelement, cmid, sectionreturn);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return /** @alias module:core_course/actions */ {
|
||||
|
||||
/**
|
||||
* Initialises course page
|
||||
*
|
||||
* @method init
|
||||
* @param {String} courseformat name of the current course format (for fetching strings)
|
||||
*/
|
||||
initCoursePage: function(courseformat) {
|
||||
|
||||
// Add a handler for course module actions.
|
||||
$('body').on('click keypress', SELECTOR.ACTIVITYLI + ' ' +
|
||||
SELECTOR.ACTIVITYACTION + '[data-action]', function(e) {
|
||||
if (e.type === 'keypress' && e.keyCode !== 13) {
|
||||
return;
|
||||
}
|
||||
var actionItem = $(this),
|
||||
moduleElement = actionItem.closest(SELECTOR.ACTIVITYLI),
|
||||
action = actionItem.attr('data-action'),
|
||||
moduleId = getModuleId(moduleElement);
|
||||
switch (action) {
|
||||
case 'moveleft':
|
||||
case 'moveright':
|
||||
case 'delete':
|
||||
case 'duplicate':
|
||||
case 'hide':
|
||||
case 'stealth':
|
||||
case 'show':
|
||||
case 'groupsseparate':
|
||||
case 'groupsvisible':
|
||||
case 'groupsnone':
|
||||
break;
|
||||
default:
|
||||
// Nothing to do here!
|
||||
return;
|
||||
}
|
||||
if (!moduleId) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
if (action === 'delete') {
|
||||
// Deleting requires confirmation.
|
||||
confirmDeleteModule(moduleElement, function() {
|
||||
editModule(moduleElement, moduleId, actionItem);
|
||||
});
|
||||
} else {
|
||||
editModule(moduleElement, moduleId, actionItem);
|
||||
}
|
||||
});
|
||||
|
||||
// Add a handler for section show/hide actions.
|
||||
$('body').on('click keypress', SELECTOR.SECTIONLI + ' ' +
|
||||
SELECTOR.SECTIONACTIONMENU + '[data-sectionid] ' +
|
||||
'a[data-action]', function(e) {
|
||||
if (e.type === 'keypress' && e.keyCode !== 13) {
|
||||
return;
|
||||
}
|
||||
var actionItem = $(this),
|
||||
sectionElement = actionItem.closest(SELECTOR.SECTIONLI),
|
||||
sectionId = actionItem.closest(SELECTOR.SECTIONACTIONMENU).attr('data-sectionid');
|
||||
e.preventDefault();
|
||||
if (actionItem.attr('data-confirm')) {
|
||||
// Action requires confirmation.
|
||||
confirmEditSection(actionItem.attr('data-confirm'), function() {
|
||||
editSection(sectionElement, sectionId, actionItem, courseformat);
|
||||
});
|
||||
} else {
|
||||
editSection(sectionElement, sectionId, actionItem, courseformat);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Replaces a section action menu item with another one (for example Show->Hide, Set marker->Remove marker)
|
||||
*
|
||||
* This method can be used by course formats in their listener to the coursesectionedited event
|
||||
*
|
||||
* @param {JQuery} sectionelement
|
||||
* @param {String} selector CSS selector inside the section element, for example "a[data-action=show]"
|
||||
* @param {String} image new image name ("i/show", "i/hide", etc.)
|
||||
* @param {String} stringname new string for the action menu item
|
||||
* @param {String} stringcomponent
|
||||
* @param {String} titlestr string for "title" attribute (if different from stringname)
|
||||
* @param {String} titlecomponent
|
||||
* @param {String} newaction new value for data-action attribute of the link
|
||||
*/
|
||||
replaceSectionActionItem: function(sectionelement, selector, image, stringname,
|
||||
stringcomponent, titlestr, titlecomponent, newaction) {
|
||||
var actionitem = sectionelement.find(SELECTOR.SECTIONACTIONMENU + ' ' + selector);
|
||||
replaceActionItem(actionitem, image, stringname, stringcomponent, titlestr, titlecomponent, newaction);
|
||||
}
|
||||
};
|
||||
});
|
145
course/rest.php
145
course/rest.php
@ -33,17 +33,10 @@ require_once($CFG->dirroot.'/course/lib.php');
|
||||
$courseid = required_param('courseId', PARAM_INT);
|
||||
$class = required_param('class', PARAM_ALPHA);
|
||||
$field = optional_param('field', '', PARAM_ALPHA);
|
||||
$instanceid = optional_param('instanceId', 0, PARAM_INT);
|
||||
$sectionid = optional_param('sectionId', 0, PARAM_INT);
|
||||
$beforeid = optional_param('beforeId', 0, PARAM_INT);
|
||||
$value = optional_param('value', 0, PARAM_INT);
|
||||
$column = optional_param('column', 0, PARAM_ALPHA);
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$summary = optional_param('summary', '', PARAM_RAW);
|
||||
$sequence = optional_param('sequence', '', PARAM_SEQUENCE);
|
||||
$visible = optional_param('visible', 0, PARAM_INT);
|
||||
$pageaction = optional_param('action', '', PARAM_ALPHA); // Used to simulate a DELETE command
|
||||
$title = optional_param('title', '', PARAM_TEXT);
|
||||
|
||||
$PAGE->set_url('/course/rest.php', array('courseId'=>$courseid,'class'=>$class));
|
||||
|
||||
@ -63,113 +56,33 @@ require_sesskey();
|
||||
|
||||
echo $OUTPUT->header(); // send headers
|
||||
|
||||
// OK, now let's process the parameters and do stuff
|
||||
// MDL-10221 the DELETE method is not allowed on some web servers, so we simulate it with the action URL param
|
||||
$requestmethod = $_SERVER['REQUEST_METHOD'];
|
||||
if ($pageaction == 'DELETE') {
|
||||
$requestmethod = 'DELETE';
|
||||
}
|
||||
|
||||
switch($requestmethod) {
|
||||
case 'POST':
|
||||
|
||||
switch ($class) {
|
||||
case 'section':
|
||||
|
||||
if (!$DB->record_exists('course_sections', array('course'=>$course->id, 'section'=>$id))) {
|
||||
throw new moodle_exception('AJAX commands.php: Bad Section ID '.$id);
|
||||
}
|
||||
|
||||
switch ($field) {
|
||||
case 'visible':
|
||||
require_capability('moodle/course:sectionvisibility', $coursecontext);
|
||||
$resourcestotoggle = set_section_visible($course->id, $id, $value);
|
||||
echo json_encode(array('resourcestotoggle' => $resourcestotoggle));
|
||||
break;
|
||||
|
||||
case 'move':
|
||||
require_capability('moodle/course:movesections', $coursecontext);
|
||||
move_section_to($course, $id, $value);
|
||||
// See if format wants to do something about it
|
||||
$response = course_get_format($course)->ajax_section_move();
|
||||
if ($response !== null) {
|
||||
echo json_encode($response);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'resource':
|
||||
switch ($field) {
|
||||
case 'visible':
|
||||
require_capability('moodle/course:activityvisibility', $modcontext);
|
||||
set_coursemodule_visible($cm->id, $value);
|
||||
\core\event\course_module_updated::create_from_cm($cm, $modcontext)->trigger();
|
||||
break;
|
||||
|
||||
case 'duplicate':
|
||||
require_capability('moodle/course:manageactivities', $coursecontext);
|
||||
require_capability('moodle/backup:backuptargetimport', $coursecontext);
|
||||
require_capability('moodle/restore:restoretargetimport', $coursecontext);
|
||||
if (!course_allowed_module($course, $cm->modname)) {
|
||||
throw new moodle_exception('No permission to create that activity');
|
||||
}
|
||||
$sr = optional_param('sr', null, PARAM_INT);
|
||||
$result = mod_duplicate_activity($course, $cm, $sr);
|
||||
echo json_encode($result);
|
||||
break;
|
||||
|
||||
case 'groupmode':
|
||||
require_capability('moodle/course:manageactivities', $modcontext);
|
||||
set_coursemodule_groupmode($cm->id, $value);
|
||||
\core\event\course_module_updated::create_from_cm($cm, $modcontext)->trigger();
|
||||
break;
|
||||
|
||||
case 'indent':
|
||||
require_capability('moodle/course:manageactivities', $modcontext);
|
||||
$cm->indent = $value;
|
||||
if ($cm->indent >= 0) {
|
||||
$DB->update_record('course_modules', $cm);
|
||||
rebuild_course_cache($cm->course);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'move':
|
||||
require_capability('moodle/course:manageactivities', $modcontext);
|
||||
if (!$section = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>$sectionid))) {
|
||||
throw new moodle_exception('AJAX commands.php: Bad section ID '.$sectionid);
|
||||
}
|
||||
|
||||
if ($beforeid > 0){
|
||||
$beforemod = get_coursemodule_from_id('', $beforeid, $course->id);
|
||||
$beforemod = $DB->get_record('course_modules', array('id'=>$beforeid));
|
||||
} else {
|
||||
$beforemod = NULL;
|
||||
}
|
||||
|
||||
$isvisible = moveto_module($cm, $section, $beforemod);
|
||||
echo json_encode(array('visible' => (bool) $isvisible));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'course':
|
||||
switch($field) {
|
||||
case 'marker':
|
||||
require_capability('moodle/course:setcurrentsection', $coursecontext);
|
||||
course_set_marker($course->id, $value);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
switch ($class) {
|
||||
case 'resource':
|
||||
require_capability('moodle/course:manageactivities', $modcontext);
|
||||
course_delete_module($cm->id, true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
if ($class === 'section' && $field === 'move') {
|
||||
if (!$DB->record_exists('course_sections', array('course' => $course->id, 'section' => $id))) {
|
||||
throw new moodle_exception('AJAX commands.php: Bad Section ID ' . $id);
|
||||
}
|
||||
|
||||
require_capability('moodle/course:movesections', $coursecontext);
|
||||
move_section_to($course, $id, $value);
|
||||
// See if format wants to do something about it.
|
||||
$response = course_get_format($course)->ajax_section_move();
|
||||
if ($response !== null) {
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
} else if ($class === 'resource' && $field === 'move') {
|
||||
|
||||
require_capability('moodle/course:manageactivities', $modcontext);
|
||||
if (!$section = $DB->get_record('course_sections', array('course' => $course->id, 'section' => $sectionid))) {
|
||||
throw new moodle_exception('AJAX commands.php: Bad section ID '.$sectionid);
|
||||
}
|
||||
|
||||
if ($beforeid > 0) {
|
||||
$beforemod = get_coursemodule_from_id('', $beforeid, $course->id);
|
||||
$beforemod = $DB->get_record('course_modules', array('id' => $beforeid));
|
||||
} else {
|
||||
$beforemod = null;
|
||||
}
|
||||
|
||||
$isvisible = moveto_module($cm, $section, $beforemod);
|
||||
echo json_encode(array('visible' => (bool) $isvisible));
|
||||
}
|
||||
|
@ -423,7 +423,8 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, {
|
||||
// Replace move icons
|
||||
var move = resourcesnode.one('a.' + CSS.EDITINGMOVE);
|
||||
if (move) {
|
||||
move.replace(this.resourcedraghandle.cloneNode(true));
|
||||
var sr = move.getData('sr');
|
||||
move.replace(this.resourcedraghandle.cloneNode(true).setAttribute('data-sectionreturn', sr));
|
||||
}
|
||||
}, this);
|
||||
},
|
||||
|
File diff suppressed because one or more lines are too long
@ -419,7 +419,8 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, {
|
||||
// Replace move icons
|
||||
var move = resourcesnode.one('a.' + CSS.EDITINGMOVE);
|
||||
if (move) {
|
||||
move.replace(this.resourcedraghandle.cloneNode(true));
|
||||
var sr = move.getData('sr');
|
||||
move.replace(this.resourcedraghandle.cloneNode(true).setAttribute('data-sectionreturn', sr));
|
||||
}
|
||||
}, this);
|
||||
},
|
||||
|
@ -1,947 +0,0 @@
|
||||
YUI.add('moodle-course-toolboxes', function (Y, NAME) {
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
// The CSS classes we use.
|
||||
var CSS = {
|
||||
ACTIVITYINSTANCE: 'activityinstance',
|
||||
AVAILABILITYINFODIV: 'div.availabilityinfo',
|
||||
CONTENTWITHOUTLINK: 'contentwithoutlink',
|
||||
CONDITIONALHIDDEN: 'conditionalhidden',
|
||||
DIMCLASS: 'dimmed',
|
||||
DIMMEDTEXT: 'dimmed_text',
|
||||
EDITINSTRUCTIONS: 'editinstructions',
|
||||
HIDE: 'hide',
|
||||
MODINDENTCOUNT: 'mod-indent-',
|
||||
MODINDENTHUGE: 'mod-indent-huge',
|
||||
MODULEIDPREFIX: 'module-',
|
||||
SECTIONHIDDENCLASS: 'hidden',
|
||||
SECTIONIDPREFIX: 'section-',
|
||||
SHOW: 'editing_show'
|
||||
},
|
||||
// The CSS selectors we use.
|
||||
SELECTOR = {
|
||||
ACTIONAREA: '.actions',
|
||||
ACTIONLINKTEXT: '.actionlinktext',
|
||||
ACTIVITYACTION: 'a.cm-edit-action[data-action]',
|
||||
ACTIVITYICON: 'img.activityicon',
|
||||
ACTIVITYINSTANCE: '.' + CSS.ACTIVITYINSTANCE,
|
||||
ACTIVITYLINK: '.' + CSS.ACTIVITYINSTANCE + ' > a, .' + CSS.ACTIVITYINSTANCE +
|
||||
' > span[data-inplaceeditable] > a:not([data-inplaceeditablelink])',
|
||||
ACTIVITYLI: 'li.activity',
|
||||
COMMANDSPAN: '.commands',
|
||||
CONTENTAFTERLINK: 'div.contentafterlink',
|
||||
CONTENTWITHOUTLINK: 'div.contentwithoutlink',
|
||||
GROUPINGLABEL: '.' + CSS.ACTIVITYINSTANCE + ' .groupinglabel',
|
||||
HIDE: 'a.editing_hide',
|
||||
HIGHLIGHT: 'a.editing_highlight',
|
||||
INSTANCENAME: 'span.instancename',
|
||||
MODINDENTDIV: '.mod-indent',
|
||||
MODINDENTOUTER: '.mod-indent-outer',
|
||||
PAGECONTENT: 'body',
|
||||
SECTIONLI: 'li.section',
|
||||
SHOW: 'a.' + CSS.SHOW,
|
||||
SHOWHIDE: 'a.editing_showhide'
|
||||
},
|
||||
INDENTLIMITS = {
|
||||
MIN: 0,
|
||||
MAX: 16
|
||||
},
|
||||
BODY = Y.one(document.body);
|
||||
|
||||
// Setup the basic namespace.
|
||||
M.course = M.course || {};
|
||||
|
||||
/**
|
||||
* The toolbox class is a generic class which should never be directly
|
||||
* instantiated. Please extend it instead.
|
||||
*
|
||||
* @class toolbox
|
||||
* @constructor
|
||||
* @protected
|
||||
* @extends Base
|
||||
*/
|
||||
var TOOLBOX = function() {
|
||||
TOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(TOOLBOX, Y.Base, {
|
||||
/**
|
||||
* Send a request using the REST API
|
||||
*
|
||||
* @method send_request
|
||||
* @param {Object} data The data to submit with the AJAX request
|
||||
* @param {Node} [statusspinner] A statusspinner which may contain a section loader
|
||||
* @param {Function} success_callback The callback to use on success
|
||||
* @param {Object} [optionalconfig] Any additional configuration to submit
|
||||
* @chainable
|
||||
*/
|
||||
send_request: function(data, statusspinner, success_callback, optionalconfig) {
|
||||
// Default data structure
|
||||
if (!data) {
|
||||
data = {};
|
||||
}
|
||||
// Handle any variables which we must pass back through to
|
||||
var pageparams = this.get('config').pageparams,
|
||||
varname;
|
||||
for (varname in pageparams) {
|
||||
data[varname] = pageparams[varname];
|
||||
}
|
||||
|
||||
data.sesskey = M.cfg.sesskey;
|
||||
data.courseId = this.get('courseid');
|
||||
|
||||
var uri = M.cfg.wwwroot + this.get('ajaxurl');
|
||||
|
||||
// Define the configuration to send with the request
|
||||
var responsetext = [];
|
||||
var config = {
|
||||
method: 'POST',
|
||||
data: data,
|
||||
on: {
|
||||
success: function(tid, response) {
|
||||
try {
|
||||
responsetext = Y.JSON.parse(response.responseText);
|
||||
if (responsetext.error) {
|
||||
new M.core.ajaxException(responsetext);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore.
|
||||
}
|
||||
|
||||
// Run the callback if we have one.
|
||||
if (success_callback) {
|
||||
Y.bind(success_callback, this, responsetext)();
|
||||
}
|
||||
|
||||
if (statusspinner) {
|
||||
window.setTimeout(function() {
|
||||
statusspinner.hide();
|
||||
}, 400);
|
||||
}
|
||||
},
|
||||
failure: function(tid, response) {
|
||||
if (statusspinner) {
|
||||
statusspinner.hide();
|
||||
}
|
||||
new M.core.ajaxException(response);
|
||||
}
|
||||
},
|
||||
context: this
|
||||
};
|
||||
|
||||
// Apply optional config
|
||||
if (optionalconfig) {
|
||||
for (varname in optionalconfig) {
|
||||
config[varname] = optionalconfig[varname];
|
||||
}
|
||||
}
|
||||
|
||||
if (statusspinner) {
|
||||
statusspinner.show();
|
||||
}
|
||||
|
||||
// Send the request
|
||||
Y.io(uri, config);
|
||||
return this;
|
||||
}
|
||||
},
|
||||
{
|
||||
NAME: 'course-toolbox',
|
||||
ATTRS: {
|
||||
/**
|
||||
* The ID of the Moodle Course being edited.
|
||||
*
|
||||
* @attribute courseid
|
||||
* @default 0
|
||||
* @type Number
|
||||
*/
|
||||
courseid: {
|
||||
'value': 0
|
||||
},
|
||||
|
||||
/**
|
||||
* The Moodle course format.
|
||||
*
|
||||
* @attribute format
|
||||
* @default 'topics'
|
||||
* @type String
|
||||
*/
|
||||
format: {
|
||||
'value': 'topics'
|
||||
},
|
||||
/**
|
||||
* The URL to use when submitting requests.
|
||||
* @attribute ajaxurl
|
||||
* @default null
|
||||
* @type String
|
||||
*/
|
||||
ajaxurl: {
|
||||
'value': null
|
||||
},
|
||||
/**
|
||||
* Any additional configuration passed when creating the instance.
|
||||
*
|
||||
* @attribute config
|
||||
* @default {}
|
||||
* @type Object
|
||||
*/
|
||||
config: {
|
||||
'value': {}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
/* global TOOLBOX, BODY, SELECTOR, INDENTLIMITS */
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This is a class extending TOOLBOX containing code specific to resources
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @class resources
|
||||
* @constructor
|
||||
* @extends M.course.toolboxes.toolbox
|
||||
*/
|
||||
var RESOURCETOOLBOX = function() {
|
||||
RESOURCETOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(RESOURCETOOLBOX, TOOLBOX, {
|
||||
/**
|
||||
* No groups are being used.
|
||||
*
|
||||
* @property GROUPS_NONE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_NONE: 0,
|
||||
|
||||
/**
|
||||
* Separate groups are being used.
|
||||
*
|
||||
* @property GROUPS_SEPARATE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_SEPARATE: 1,
|
||||
|
||||
/**
|
||||
* Visible groups are being used.
|
||||
*
|
||||
* @property GROUPS_VISIBLE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_VISIBLE: 2,
|
||||
|
||||
/**
|
||||
* Initialize the resource toolbox
|
||||
*
|
||||
* For each activity the commands are updated and a reference to the activity is attached.
|
||||
* This way it doesn't matter where the commands are going to called from they have a reference to the
|
||||
* activity that they relate to.
|
||||
* This is essential as some of the actions are displayed in an actionmenu which removes them from the
|
||||
* page flow.
|
||||
*
|
||||
* This function also creates a single event delegate to manage all AJAX actions for all activities on
|
||||
* the page.
|
||||
*
|
||||
* @method initializer
|
||||
* @protected
|
||||
*/
|
||||
initializer: function() {
|
||||
M.course.coursebase.register_module(this);
|
||||
BODY.delegate('key', this.handle_data_action, 'down:enter', SELECTOR.ACTIVITYACTION, this);
|
||||
Y.delegate('click', this.handle_data_action, BODY, SELECTOR.ACTIVITYACTION, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the delegation event. When this is fired someone has triggered an action.
|
||||
*
|
||||
* Note not all actions will result in an AJAX enhancement.
|
||||
*
|
||||
* @protected
|
||||
* @method handle_data_action
|
||||
* @param {EventFacade} ev The event that was triggered.
|
||||
* @return {boolean}
|
||||
*/
|
||||
handle_data_action: function(ev) {
|
||||
// We need to get the anchor element that triggered this event.
|
||||
var node = ev.target;
|
||||
if (!node.test('a')) {
|
||||
node = node.ancestor(SELECTOR.ACTIVITYACTION);
|
||||
}
|
||||
|
||||
// From the anchor we can get both the activity (added during initialisation) and the action being
|
||||
// performed (added by the UI as a data attribute).
|
||||
var action = node.getData('action'),
|
||||
activity = node.ancestor(SELECTOR.ACTIVITYLI);
|
||||
|
||||
if (!node.test('a') || !action || !activity) {
|
||||
// It wasn't a valid action node.
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch based upon the action and do the desired thing.
|
||||
switch (action) {
|
||||
case 'moveleft':
|
||||
case 'moveright':
|
||||
// The user changing the indent of the activity.
|
||||
this.change_indent(ev, node, activity, action);
|
||||
break;
|
||||
case 'delete':
|
||||
// The user is deleting the activity.
|
||||
this.delete_with_confirmation(ev, node, activity, action);
|
||||
break;
|
||||
case 'duplicate':
|
||||
// The user is duplicating the activity.
|
||||
this.duplicate(ev, node, activity, action);
|
||||
break;
|
||||
case 'hide':
|
||||
case 'show':
|
||||
// The user is changing the visibility of the activity.
|
||||
this.change_visibility(ev, node, activity, action);
|
||||
break;
|
||||
case 'groupsseparate':
|
||||
case 'groupsvisible':
|
||||
case 'groupsnone':
|
||||
// The user is changing the group mode.
|
||||
this.change_groupmode(ev, node, activity, action);
|
||||
break;
|
||||
case 'move':
|
||||
case 'update':
|
||||
case 'assignroles':
|
||||
break;
|
||||
default:
|
||||
// Nothing to do here!
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a loading icon to the specified activity.
|
||||
*
|
||||
* The icon is added within the action area.
|
||||
*
|
||||
* @method add_spinner
|
||||
* @param {Node} activity The activity to add a loading icon to
|
||||
* @return {Node|null} The newly created icon, or null if the action area was not found.
|
||||
*/
|
||||
add_spinner: function(activity) {
|
||||
var actionarea = activity.one(SELECTOR.ACTIONAREA);
|
||||
if (actionarea) {
|
||||
return M.util.add_spinner(Y, actionarea);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the indent of the activity or resource.
|
||||
*
|
||||
* @method change_indent
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action The action that has been requested. Will be 'moveleft' or 'moveright'.
|
||||
*/
|
||||
change_indent: function(ev, button, activity, action) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
var direction = (action === 'moveleft') ? -1 : 1;
|
||||
|
||||
// And we need to determine the current and new indent level
|
||||
var indentdiv = activity.one(SELECTOR.MODINDENTDIV),
|
||||
indent = indentdiv.getAttribute('class').match(/mod-indent-(\d{1,})/),
|
||||
oldindent = 0,
|
||||
newindent;
|
||||
|
||||
if (indent) {
|
||||
oldindent = parseInt(indent[1], 10);
|
||||
}
|
||||
newindent = oldindent + parseInt(direction, 10);
|
||||
|
||||
if (newindent < INDENTLIMITS.MIN || newindent > INDENTLIMITS.MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (indent) {
|
||||
indentdiv.removeClass(indent[0]);
|
||||
}
|
||||
|
||||
// Perform the move
|
||||
indentdiv.addClass(CSS.MODINDENTCOUNT + newindent);
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'indent',
|
||||
'value': newindent,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
var spinner = this.add_spinner(activity);
|
||||
this.send_request(data, spinner);
|
||||
|
||||
var remainingmove;
|
||||
|
||||
// Handle removal/addition of the moveleft button.
|
||||
if (newindent === INDENTLIMITS.MIN) {
|
||||
button.addClass('hidden');
|
||||
remainingmove = activity.one('.editing_moveright');
|
||||
} else if (newindent > INDENTLIMITS.MIN && oldindent === INDENTLIMITS.MIN) {
|
||||
button.ancestor('.menu').one('[data-action=moveleft]').removeClass('hidden');
|
||||
}
|
||||
|
||||
if (newindent === INDENTLIMITS.MAX) {
|
||||
button.addClass('hidden');
|
||||
remainingmove = activity.one('.editing_moveleft');
|
||||
} else if (newindent < INDENTLIMITS.MAX && oldindent === INDENTLIMITS.MAX) {
|
||||
button.ancestor('.menu').one('[data-action=moveright]').removeClass('hidden');
|
||||
}
|
||||
|
||||
// Handle massive indentation to match non-ajax display
|
||||
var hashugeclass = indentdiv.hasClass(CSS.MODINDENTHUGE);
|
||||
if (newindent > 15 && !hashugeclass) {
|
||||
indentdiv.addClass(CSS.MODINDENTHUGE);
|
||||
} else if (newindent <= 15 && hashugeclass) {
|
||||
indentdiv.removeClass(CSS.MODINDENTHUGE);
|
||||
}
|
||||
|
||||
if (ev.type && ev.type === "key" && remainingmove) {
|
||||
remainingmove.focus();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Deletes the given activity or resource after confirmation.
|
||||
*
|
||||
* @protected
|
||||
* @method delete_with_confirmation
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
delete_with_confirmation: function(ev, button, activity) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity,
|
||||
// Create confirm string (different if element has or does not have name)
|
||||
confirmstring = '',
|
||||
plugindata = {
|
||||
type: M.util.get_string('pluginname', element.getAttribute('class').match(/modtype_([^\s]*)/)[1])
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
// Create the confirmation dialogue.
|
||||
var confirm = new M.core.confirm({
|
||||
question: confirmstring,
|
||||
modal: true,
|
||||
visible: false
|
||||
});
|
||||
confirm.show();
|
||||
|
||||
// If it is confirmed.
|
||||
confirm.on('complete-yes', function() {
|
||||
|
||||
// Actually remove the element.
|
||||
element.remove();
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'action': 'DELETE',
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element)
|
||||
};
|
||||
this.send_request(data);
|
||||
if (M.core.actionmenu && M.core.actionmenu.instance) {
|
||||
M.core.actionmenu.instance.hideMenu(ev);
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Duplicates the activity.
|
||||
*
|
||||
* @method duplicate
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
duplicate: function(ev, button, activity) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity;
|
||||
|
||||
// Add the lightbox.
|
||||
var section = activity.ancestor(M.course.format.get_section_selector(Y)),
|
||||
lightbox = M.util.add_lightbox(Y, section).show();
|
||||
|
||||
// Build and send the request.
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'duplicate',
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element),
|
||||
'sr': button.getData('sr')
|
||||
};
|
||||
this.send_request(data, lightbox, function(response) {
|
||||
var newcm = Y.Node.create(response.fullcontent);
|
||||
|
||||
// Append to the section?
|
||||
activity.insert(newcm, 'after');
|
||||
Y.use('moodle-course-coursebase', function() {
|
||||
M.course.coursebase.invoke_function('setup_for_resource', newcm);
|
||||
});
|
||||
if (M.core.actionmenu && M.core.actionmenu.newDOMNode) {
|
||||
M.core.actionmenu.newDOMNode(newcm);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the visibility of this activity or resource.
|
||||
*
|
||||
* @method change_visibility
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action The action that has been requested.
|
||||
* @chainable
|
||||
*/
|
||||
change_visibility: function(ev, button, activity, action) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity;
|
||||
var value = this.handle_resource_dim(button, activity, action);
|
||||
|
||||
// Send the request
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'visible',
|
||||
'value': value,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element)
|
||||
};
|
||||
var spinner = this.add_spinner(element);
|
||||
this.send_request(data, spinner);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the UI aspect of dimming the activity or resource.
|
||||
*
|
||||
* @method handle_resource_dim
|
||||
* @protected
|
||||
* @param {Node} button The button that triggered the action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action 'show' or 'hide'.
|
||||
* @return {Number} 1 if we changed to visible, 0 if we were hiding.
|
||||
*/
|
||||
handle_resource_dim: function(button, activity, action) {
|
||||
var toggleclass = CSS.DIMCLASS,
|
||||
dimarea = activity.one([
|
||||
SELECTOR.ACTIVITYLINK,
|
||||
SELECTOR.CONTENTWITHOUTLINK
|
||||
].join(', ')),
|
||||
availabilityinfo = activity.one(CSS.AVAILABILITYINFODIV),
|
||||
nextaction = (action === 'hide') ? 'show' : 'hide',
|
||||
buttontext = button.one('span'),
|
||||
newstring = M.util.get_string(nextaction, 'moodle'),
|
||||
buttonimg = button.one('img');
|
||||
|
||||
// Update button info.
|
||||
buttonimg.setAttrs({
|
||||
'src': M.util.image_url('t/' + nextaction)
|
||||
});
|
||||
|
||||
if (Y.Lang.trim(button.getAttribute('title'))) {
|
||||
button.setAttribute('title', newstring);
|
||||
}
|
||||
|
||||
if (Y.Lang.trim(buttonimg.getAttribute('alt'))) {
|
||||
buttonimg.setAttribute('alt', newstring);
|
||||
}
|
||||
|
||||
button.replaceClass('editing_' + action, 'editing_' + nextaction);
|
||||
button.setData('action', nextaction);
|
||||
if (buttontext) {
|
||||
buttontext.set('text', newstring);
|
||||
}
|
||||
|
||||
if (activity.one(SELECTOR.CONTENTWITHOUTLINK)) {
|
||||
dimarea = activity.one(SELECTOR.CONTENTWITHOUTLINK);
|
||||
toggleclass = CSS.DIMMEDTEXT;
|
||||
}
|
||||
|
||||
// If activity is conditionally hidden, then don't toggle.
|
||||
if (!dimarea.hasClass(CSS.CONDITIONALHIDDEN)) {
|
||||
if (action === 'hide') {
|
||||
// Change the UI.
|
||||
dimarea.addClass(toggleclass);
|
||||
// We need to toggle dimming on the description too.
|
||||
activity.all(SELECTOR.CONTENTAFTERLINK).addClass(CSS.DIMMEDTEXT);
|
||||
activity.all(SELECTOR.GROUPINGLABEL).addClass(CSS.DIMMEDTEXT);
|
||||
} else {
|
||||
// Change the UI.
|
||||
dimarea.removeClass(toggleclass);
|
||||
// We need to toggle dimming on the description too.
|
||||
activity.all(SELECTOR.CONTENTAFTERLINK).removeClass(CSS.DIMMEDTEXT);
|
||||
activity.all(SELECTOR.GROUPINGLABEL).removeClass(CSS.DIMMEDTEXT);
|
||||
}
|
||||
}
|
||||
// Toggle availablity info for conditional activities.
|
||||
if (availabilityinfo) {
|
||||
availabilityinfo.toggleClass(CSS.HIDE);
|
||||
}
|
||||
return (action === 'hide') ? 0 : 1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the groupmode of the activity to the next groupmode in the sequence.
|
||||
*
|
||||
* @method change_groupmode
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
change_groupmode: function(ev, button, activity) {
|
||||
// Prevent the default button action.
|
||||
ev.preventDefault();
|
||||
|
||||
// Current Mode
|
||||
var groupmode = parseInt(button.getData('nextgroupmode'), 10),
|
||||
newtitle = '',
|
||||
iconsrc = '',
|
||||
newtitlestr,
|
||||
data,
|
||||
spinner,
|
||||
nextgroupmode = groupmode + 1,
|
||||
buttonimg = button.one('img');
|
||||
|
||||
if (nextgroupmode > 2) {
|
||||
nextgroupmode = 0;
|
||||
}
|
||||
|
||||
if (groupmode === this.GROUPS_NONE) {
|
||||
newtitle = 'groupsnone';
|
||||
iconsrc = M.util.image_url('i/groupn', 'moodle');
|
||||
} else if (groupmode === this.GROUPS_SEPARATE) {
|
||||
newtitle = 'groupsseparate';
|
||||
iconsrc = M.util.image_url('i/groups', 'moodle');
|
||||
} else if (groupmode === this.GROUPS_VISIBLE) {
|
||||
newtitle = 'groupsvisible';
|
||||
iconsrc = M.util.image_url('i/groupv', 'moodle');
|
||||
}
|
||||
newtitlestr = M.util.get_string('clicktochangeinbrackets', 'moodle', M.util.get_string(newtitle, 'moodle'));
|
||||
|
||||
// Change the UI
|
||||
var oldAction = button.getData('action');
|
||||
button.replaceClass('editing_' + oldAction, 'editing_' + newtitle);
|
||||
buttonimg.setAttrs({
|
||||
'src': iconsrc
|
||||
});
|
||||
if (Y.Lang.trim(button.getAttribute('title'))) {
|
||||
button.setAttribute('title', newtitlestr).setData('action', newtitle).setData('nextgroupmode', nextgroupmode);
|
||||
}
|
||||
|
||||
if (Y.Lang.trim(buttonimg.getAttribute('alt'))) {
|
||||
buttonimg.setAttribute('alt', newtitlestr);
|
||||
}
|
||||
|
||||
// And send the request
|
||||
data = {
|
||||
'class': 'resource',
|
||||
'field': 'groupmode',
|
||||
'value': groupmode,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
|
||||
spinner = this.add_spinner(activity);
|
||||
this.send_request(data, spinner);
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the visibility of the specified resource to match the visible parameter.
|
||||
*
|
||||
* Note: This is not a toggle function and only changes the visibility
|
||||
* in the browser (no ajax update is performed).
|
||||
*
|
||||
* @method set_visibility_resource_ui
|
||||
* @param {object} args An object containing the required information to trigger a change.
|
||||
* @param {Node} args.element The resource to toggle
|
||||
* @param {Boolean} args.visible The target visibility
|
||||
*/
|
||||
set_visibility_resource_ui: function(args) {
|
||||
var element = args.element,
|
||||
buttonnode = element.one(SELECTOR.HIDE),
|
||||
// By default we assume that the item is visible and we're going to hide it.
|
||||
currentVisibility = true,
|
||||
targetVisibility = false;
|
||||
|
||||
if (!buttonnode) {
|
||||
// If the buttonnode was not found, try to find the HIDE button
|
||||
// and change the target visibility setting to false.
|
||||
buttonnode = element.one(SELECTOR.SHOW);
|
||||
currentVisibility = false;
|
||||
targetVisibility = true;
|
||||
}
|
||||
|
||||
if (typeof args.visible !== 'undefined') {
|
||||
// If we were provided with a visibility argument, use that instead.
|
||||
targetVisibility = args.visible;
|
||||
}
|
||||
|
||||
// Only trigger a change if necessary.
|
||||
if (currentVisibility !== targetVisibility) {
|
||||
var action = 'hide';
|
||||
if (targetVisibility) {
|
||||
action = 'show';
|
||||
}
|
||||
|
||||
this.handle_resource_dim(buttonnode, element, action);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
NAME: 'course-resource-toolbox',
|
||||
ATTRS: {
|
||||
}
|
||||
});
|
||||
|
||||
M.course.resource_toolbox = null;
|
||||
M.course.init_resource_toolbox = function(config) {
|
||||
M.course.resource_toolbox = new RESOURCETOOLBOX(config);
|
||||
return M.course.resource_toolbox;
|
||||
};
|
||||
/* global SELECTOR, TOOLBOX */
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Section toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with sections
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @class section
|
||||
* @constructor
|
||||
* @extends M.course.toolboxes.toolbox
|
||||
*/
|
||||
var SECTIONTOOLBOX = function() {
|
||||
SECTIONTOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(SECTIONTOOLBOX, TOOLBOX, {
|
||||
/**
|
||||
* Initialize the section toolboxes module.
|
||||
*
|
||||
* Updates all span.commands with relevant handlers and other required changes.
|
||||
*
|
||||
* @method initializer
|
||||
* @protected
|
||||
*/
|
||||
initializer: function() {
|
||||
M.course.coursebase.register_module(this);
|
||||
|
||||
// Section Highlighting.
|
||||
Y.delegate('click', this.toggle_highlight, SELECTOR.PAGECONTENT, SELECTOR.SECTIONLI + ' ' + SELECTOR.HIGHLIGHT, this);
|
||||
|
||||
// Section Visibility.
|
||||
Y.delegate('click', this.toggle_hide_section, SELECTOR.PAGECONTENT, SELECTOR.SECTIONLI + ' ' + SELECTOR.SHOWHIDE, this);
|
||||
},
|
||||
|
||||
toggle_hide_section: function(e) {
|
||||
// Prevent the default button action.
|
||||
e.preventDefault();
|
||||
|
||||
// Get the section we're working on.
|
||||
var section = e.target.ancestor(M.course.format.get_section_selector(Y)),
|
||||
button = e.target.ancestor('a', true),
|
||||
hideicon = button.one('img'),
|
||||
buttontext = button.one('span'),
|
||||
|
||||
// The value to submit
|
||||
value,
|
||||
|
||||
// The text for strings and images. Also determines the icon to display.
|
||||
action,
|
||||
nextaction;
|
||||
|
||||
if (!section.hasClass(CSS.SECTIONHIDDENCLASS)) {
|
||||
section.addClass(CSS.SECTIONHIDDENCLASS);
|
||||
value = 0;
|
||||
action = 'hide';
|
||||
nextaction = 'show';
|
||||
} else {
|
||||
section.removeClass(CSS.SECTIONHIDDENCLASS);
|
||||
value = 1;
|
||||
action = 'show';
|
||||
nextaction = 'hide';
|
||||
}
|
||||
|
||||
var newstring = M.util.get_string(nextaction + 'fromothers', 'format_' + this.get('format'));
|
||||
hideicon.setAttrs({
|
||||
'alt': newstring,
|
||||
'src': M.util.image_url('i/' + nextaction)
|
||||
});
|
||||
button.set('title', newstring);
|
||||
if (buttontext) {
|
||||
buttontext.set('text', newstring);
|
||||
}
|
||||
|
||||
// Change the show/hide status
|
||||
var data = {
|
||||
'class': 'section',
|
||||
'field': 'visible',
|
||||
'id': Y.Moodle.core_course.util.section.getId(section.ancestor(M.course.format.get_section_wrapper(Y), true)),
|
||||
'value': value
|
||||
};
|
||||
|
||||
var lightbox = M.util.add_lightbox(Y, section);
|
||||
lightbox.show();
|
||||
|
||||
this.send_request(data, lightbox, function(response) {
|
||||
var activities = section.all(SELECTOR.ACTIVITYLI);
|
||||
activities.each(function(node) {
|
||||
var button;
|
||||
if (node.one(SELECTOR.SHOW)) {
|
||||
button = node.one(SELECTOR.SHOW);
|
||||
} else {
|
||||
button = node.one(SELECTOR.HIDE);
|
||||
}
|
||||
var activityid = Y.Moodle.core_course.util.cm.getId(node);
|
||||
|
||||
// NOTE: resourcestotoggle is returned as a string instead
|
||||
// of a Number so we must cast our activityid to a String.
|
||||
if (Y.Array.indexOf(response.resourcestotoggle, "" + activityid) !== -1) {
|
||||
M.course.resource_toolbox.handle_resource_dim(button, node, action);
|
||||
}
|
||||
}, this);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle highlighting the current section.
|
||||
*
|
||||
* @method toggle_highlight
|
||||
* @param {EventFacade} e
|
||||
*/
|
||||
toggle_highlight: function(e) {
|
||||
// Prevent the default button action.
|
||||
e.preventDefault();
|
||||
|
||||
// Get the section we're working on.
|
||||
var section = e.target.ancestor(M.course.format.get_section_selector(Y));
|
||||
var button = e.target.ancestor('a', true);
|
||||
var buttonicon = button.one('img');
|
||||
var buttontext = button.one('span');
|
||||
|
||||
// Determine whether the marker is currently set.
|
||||
var togglestatus = section.hasClass('current');
|
||||
var value = 0;
|
||||
|
||||
// Set the current highlighted item text.
|
||||
var old_string = M.util.get_string('markthistopic', 'moodle');
|
||||
|
||||
var selectedpage = Y.one(SELECTOR.PAGECONTENT);
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT)
|
||||
.set('title', old_string);
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT + ' span')
|
||||
.set('text', M.util.get_string('highlight', 'moodle'));
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT + ' img')
|
||||
.set('alt', old_string)
|
||||
.set('src', M.util.image_url('i/marker'));
|
||||
|
||||
// Remove the highlighting from all sections.
|
||||
selectedpage.all(M.course.format.get_section_selector(Y))
|
||||
.removeClass('current');
|
||||
|
||||
// Then add it if required to the selected section.
|
||||
if (!togglestatus) {
|
||||
section.addClass('current');
|
||||
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);
|
||||
buttonicon
|
||||
.set('alt', new_string)
|
||||
.set('src', M.util.image_url('i/marked'));
|
||||
if (buttontext) {
|
||||
buttontext
|
||||
.set('text', M.util.get_string('highlightoff', 'moodle'));
|
||||
}
|
||||
}
|
||||
|
||||
// Change the highlight status.
|
||||
var data = {
|
||||
'class': 'course',
|
||||
'field': 'marker',
|
||||
'value': value
|
||||
};
|
||||
var lightbox = M.util.add_lightbox(Y, section);
|
||||
lightbox.show();
|
||||
this.send_request(data, lightbox);
|
||||
}
|
||||
}, {
|
||||
NAME: 'course-section-toolbox',
|
||||
ATTRS: {
|
||||
}
|
||||
});
|
||||
|
||||
M.course.init_section_toolbox = function(config) {
|
||||
return new SECTIONTOOLBOX(config);
|
||||
};
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["node", "base", "event-key", "node", "io", "moodle-course-coursebase", "moodle-course-util"]});
|
File diff suppressed because one or more lines are too long
@ -1,947 +0,0 @@
|
||||
YUI.add('moodle-course-toolboxes', function (Y, NAME) {
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
// The CSS classes we use.
|
||||
var CSS = {
|
||||
ACTIVITYINSTANCE: 'activityinstance',
|
||||
AVAILABILITYINFODIV: 'div.availabilityinfo',
|
||||
CONTENTWITHOUTLINK: 'contentwithoutlink',
|
||||
CONDITIONALHIDDEN: 'conditionalhidden',
|
||||
DIMCLASS: 'dimmed',
|
||||
DIMMEDTEXT: 'dimmed_text',
|
||||
EDITINSTRUCTIONS: 'editinstructions',
|
||||
HIDE: 'hide',
|
||||
MODINDENTCOUNT: 'mod-indent-',
|
||||
MODINDENTHUGE: 'mod-indent-huge',
|
||||
MODULEIDPREFIX: 'module-',
|
||||
SECTIONHIDDENCLASS: 'hidden',
|
||||
SECTIONIDPREFIX: 'section-',
|
||||
SHOW: 'editing_show'
|
||||
},
|
||||
// The CSS selectors we use.
|
||||
SELECTOR = {
|
||||
ACTIONAREA: '.actions',
|
||||
ACTIONLINKTEXT: '.actionlinktext',
|
||||
ACTIVITYACTION: 'a.cm-edit-action[data-action]',
|
||||
ACTIVITYICON: 'img.activityicon',
|
||||
ACTIVITYINSTANCE: '.' + CSS.ACTIVITYINSTANCE,
|
||||
ACTIVITYLINK: '.' + CSS.ACTIVITYINSTANCE + ' > a, .' + CSS.ACTIVITYINSTANCE +
|
||||
' > span[data-inplaceeditable] > a:not([data-inplaceeditablelink])',
|
||||
ACTIVITYLI: 'li.activity',
|
||||
COMMANDSPAN: '.commands',
|
||||
CONTENTAFTERLINK: 'div.contentafterlink',
|
||||
CONTENTWITHOUTLINK: 'div.contentwithoutlink',
|
||||
GROUPINGLABEL: '.' + CSS.ACTIVITYINSTANCE + ' .groupinglabel',
|
||||
HIDE: 'a.editing_hide',
|
||||
HIGHLIGHT: 'a.editing_highlight',
|
||||
INSTANCENAME: 'span.instancename',
|
||||
MODINDENTDIV: '.mod-indent',
|
||||
MODINDENTOUTER: '.mod-indent-outer',
|
||||
PAGECONTENT: 'body',
|
||||
SECTIONLI: 'li.section',
|
||||
SHOW: 'a.' + CSS.SHOW,
|
||||
SHOWHIDE: 'a.editing_showhide'
|
||||
},
|
||||
INDENTLIMITS = {
|
||||
MIN: 0,
|
||||
MAX: 16
|
||||
},
|
||||
BODY = Y.one(document.body);
|
||||
|
||||
// Setup the basic namespace.
|
||||
M.course = M.course || {};
|
||||
|
||||
/**
|
||||
* The toolbox class is a generic class which should never be directly
|
||||
* instantiated. Please extend it instead.
|
||||
*
|
||||
* @class toolbox
|
||||
* @constructor
|
||||
* @protected
|
||||
* @extends Base
|
||||
*/
|
||||
var TOOLBOX = function() {
|
||||
TOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(TOOLBOX, Y.Base, {
|
||||
/**
|
||||
* Send a request using the REST API
|
||||
*
|
||||
* @method send_request
|
||||
* @param {Object} data The data to submit with the AJAX request
|
||||
* @param {Node} [statusspinner] A statusspinner which may contain a section loader
|
||||
* @param {Function} success_callback The callback to use on success
|
||||
* @param {Object} [optionalconfig] Any additional configuration to submit
|
||||
* @chainable
|
||||
*/
|
||||
send_request: function(data, statusspinner, success_callback, optionalconfig) {
|
||||
// Default data structure
|
||||
if (!data) {
|
||||
data = {};
|
||||
}
|
||||
// Handle any variables which we must pass back through to
|
||||
var pageparams = this.get('config').pageparams,
|
||||
varname;
|
||||
for (varname in pageparams) {
|
||||
data[varname] = pageparams[varname];
|
||||
}
|
||||
|
||||
data.sesskey = M.cfg.sesskey;
|
||||
data.courseId = this.get('courseid');
|
||||
|
||||
var uri = M.cfg.wwwroot + this.get('ajaxurl');
|
||||
|
||||
// Define the configuration to send with the request
|
||||
var responsetext = [];
|
||||
var config = {
|
||||
method: 'POST',
|
||||
data: data,
|
||||
on: {
|
||||
success: function(tid, response) {
|
||||
try {
|
||||
responsetext = Y.JSON.parse(response.responseText);
|
||||
if (responsetext.error) {
|
||||
new M.core.ajaxException(responsetext);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore.
|
||||
}
|
||||
|
||||
// Run the callback if we have one.
|
||||
if (success_callback) {
|
||||
Y.bind(success_callback, this, responsetext)();
|
||||
}
|
||||
|
||||
if (statusspinner) {
|
||||
window.setTimeout(function() {
|
||||
statusspinner.hide();
|
||||
}, 400);
|
||||
}
|
||||
},
|
||||
failure: function(tid, response) {
|
||||
if (statusspinner) {
|
||||
statusspinner.hide();
|
||||
}
|
||||
new M.core.ajaxException(response);
|
||||
}
|
||||
},
|
||||
context: this
|
||||
};
|
||||
|
||||
// Apply optional config
|
||||
if (optionalconfig) {
|
||||
for (varname in optionalconfig) {
|
||||
config[varname] = optionalconfig[varname];
|
||||
}
|
||||
}
|
||||
|
||||
if (statusspinner) {
|
||||
statusspinner.show();
|
||||
}
|
||||
|
||||
// Send the request
|
||||
Y.io(uri, config);
|
||||
return this;
|
||||
}
|
||||
},
|
||||
{
|
||||
NAME: 'course-toolbox',
|
||||
ATTRS: {
|
||||
/**
|
||||
* The ID of the Moodle Course being edited.
|
||||
*
|
||||
* @attribute courseid
|
||||
* @default 0
|
||||
* @type Number
|
||||
*/
|
||||
courseid: {
|
||||
'value': 0
|
||||
},
|
||||
|
||||
/**
|
||||
* The Moodle course format.
|
||||
*
|
||||
* @attribute format
|
||||
* @default 'topics'
|
||||
* @type String
|
||||
*/
|
||||
format: {
|
||||
'value': 'topics'
|
||||
},
|
||||
/**
|
||||
* The URL to use when submitting requests.
|
||||
* @attribute ajaxurl
|
||||
* @default null
|
||||
* @type String
|
||||
*/
|
||||
ajaxurl: {
|
||||
'value': null
|
||||
},
|
||||
/**
|
||||
* Any additional configuration passed when creating the instance.
|
||||
*
|
||||
* @attribute config
|
||||
* @default {}
|
||||
* @type Object
|
||||
*/
|
||||
config: {
|
||||
'value': {}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
/* global TOOLBOX, BODY, SELECTOR, INDENTLIMITS */
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This is a class extending TOOLBOX containing code specific to resources
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @class resources
|
||||
* @constructor
|
||||
* @extends M.course.toolboxes.toolbox
|
||||
*/
|
||||
var RESOURCETOOLBOX = function() {
|
||||
RESOURCETOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(RESOURCETOOLBOX, TOOLBOX, {
|
||||
/**
|
||||
* No groups are being used.
|
||||
*
|
||||
* @property GROUPS_NONE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_NONE: 0,
|
||||
|
||||
/**
|
||||
* Separate groups are being used.
|
||||
*
|
||||
* @property GROUPS_SEPARATE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_SEPARATE: 1,
|
||||
|
||||
/**
|
||||
* Visible groups are being used.
|
||||
*
|
||||
* @property GROUPS_VISIBLE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_VISIBLE: 2,
|
||||
|
||||
/**
|
||||
* Initialize the resource toolbox
|
||||
*
|
||||
* For each activity the commands are updated and a reference to the activity is attached.
|
||||
* This way it doesn't matter where the commands are going to called from they have a reference to the
|
||||
* activity that they relate to.
|
||||
* This is essential as some of the actions are displayed in an actionmenu which removes them from the
|
||||
* page flow.
|
||||
*
|
||||
* This function also creates a single event delegate to manage all AJAX actions for all activities on
|
||||
* the page.
|
||||
*
|
||||
* @method initializer
|
||||
* @protected
|
||||
*/
|
||||
initializer: function() {
|
||||
M.course.coursebase.register_module(this);
|
||||
BODY.delegate('key', this.handle_data_action, 'down:enter', SELECTOR.ACTIVITYACTION, this);
|
||||
Y.delegate('click', this.handle_data_action, BODY, SELECTOR.ACTIVITYACTION, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the delegation event. When this is fired someone has triggered an action.
|
||||
*
|
||||
* Note not all actions will result in an AJAX enhancement.
|
||||
*
|
||||
* @protected
|
||||
* @method handle_data_action
|
||||
* @param {EventFacade} ev The event that was triggered.
|
||||
* @return {boolean}
|
||||
*/
|
||||
handle_data_action: function(ev) {
|
||||
// We need to get the anchor element that triggered this event.
|
||||
var node = ev.target;
|
||||
if (!node.test('a')) {
|
||||
node = node.ancestor(SELECTOR.ACTIVITYACTION);
|
||||
}
|
||||
|
||||
// From the anchor we can get both the activity (added during initialisation) and the action being
|
||||
// performed (added by the UI as a data attribute).
|
||||
var action = node.getData('action'),
|
||||
activity = node.ancestor(SELECTOR.ACTIVITYLI);
|
||||
|
||||
if (!node.test('a') || !action || !activity) {
|
||||
// It wasn't a valid action node.
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch based upon the action and do the desired thing.
|
||||
switch (action) {
|
||||
case 'moveleft':
|
||||
case 'moveright':
|
||||
// The user changing the indent of the activity.
|
||||
this.change_indent(ev, node, activity, action);
|
||||
break;
|
||||
case 'delete':
|
||||
// The user is deleting the activity.
|
||||
this.delete_with_confirmation(ev, node, activity, action);
|
||||
break;
|
||||
case 'duplicate':
|
||||
// The user is duplicating the activity.
|
||||
this.duplicate(ev, node, activity, action);
|
||||
break;
|
||||
case 'hide':
|
||||
case 'show':
|
||||
// The user is changing the visibility of the activity.
|
||||
this.change_visibility(ev, node, activity, action);
|
||||
break;
|
||||
case 'groupsseparate':
|
||||
case 'groupsvisible':
|
||||
case 'groupsnone':
|
||||
// The user is changing the group mode.
|
||||
this.change_groupmode(ev, node, activity, action);
|
||||
break;
|
||||
case 'move':
|
||||
case 'update':
|
||||
case 'assignroles':
|
||||
break;
|
||||
default:
|
||||
// Nothing to do here!
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a loading icon to the specified activity.
|
||||
*
|
||||
* The icon is added within the action area.
|
||||
*
|
||||
* @method add_spinner
|
||||
* @param {Node} activity The activity to add a loading icon to
|
||||
* @return {Node|null} The newly created icon, or null if the action area was not found.
|
||||
*/
|
||||
add_spinner: function(activity) {
|
||||
var actionarea = activity.one(SELECTOR.ACTIONAREA);
|
||||
if (actionarea) {
|
||||
return M.util.add_spinner(Y, actionarea);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the indent of the activity or resource.
|
||||
*
|
||||
* @method change_indent
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action The action that has been requested. Will be 'moveleft' or 'moveright'.
|
||||
*/
|
||||
change_indent: function(ev, button, activity, action) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
var direction = (action === 'moveleft') ? -1 : 1;
|
||||
|
||||
// And we need to determine the current and new indent level
|
||||
var indentdiv = activity.one(SELECTOR.MODINDENTDIV),
|
||||
indent = indentdiv.getAttribute('class').match(/mod-indent-(\d{1,})/),
|
||||
oldindent = 0,
|
||||
newindent;
|
||||
|
||||
if (indent) {
|
||||
oldindent = parseInt(indent[1], 10);
|
||||
}
|
||||
newindent = oldindent + parseInt(direction, 10);
|
||||
|
||||
if (newindent < INDENTLIMITS.MIN || newindent > INDENTLIMITS.MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (indent) {
|
||||
indentdiv.removeClass(indent[0]);
|
||||
}
|
||||
|
||||
// Perform the move
|
||||
indentdiv.addClass(CSS.MODINDENTCOUNT + newindent);
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'indent',
|
||||
'value': newindent,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
var spinner = this.add_spinner(activity);
|
||||
this.send_request(data, spinner);
|
||||
|
||||
var remainingmove;
|
||||
|
||||
// Handle removal/addition of the moveleft button.
|
||||
if (newindent === INDENTLIMITS.MIN) {
|
||||
button.addClass('hidden');
|
||||
remainingmove = activity.one('.editing_moveright');
|
||||
} else if (newindent > INDENTLIMITS.MIN && oldindent === INDENTLIMITS.MIN) {
|
||||
button.ancestor('.menu').one('[data-action=moveleft]').removeClass('hidden');
|
||||
}
|
||||
|
||||
if (newindent === INDENTLIMITS.MAX) {
|
||||
button.addClass('hidden');
|
||||
remainingmove = activity.one('.editing_moveleft');
|
||||
} else if (newindent < INDENTLIMITS.MAX && oldindent === INDENTLIMITS.MAX) {
|
||||
button.ancestor('.menu').one('[data-action=moveright]').removeClass('hidden');
|
||||
}
|
||||
|
||||
// Handle massive indentation to match non-ajax display
|
||||
var hashugeclass = indentdiv.hasClass(CSS.MODINDENTHUGE);
|
||||
if (newindent > 15 && !hashugeclass) {
|
||||
indentdiv.addClass(CSS.MODINDENTHUGE);
|
||||
} else if (newindent <= 15 && hashugeclass) {
|
||||
indentdiv.removeClass(CSS.MODINDENTHUGE);
|
||||
}
|
||||
|
||||
if (ev.type && ev.type === "key" && remainingmove) {
|
||||
remainingmove.focus();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Deletes the given activity or resource after confirmation.
|
||||
*
|
||||
* @protected
|
||||
* @method delete_with_confirmation
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
delete_with_confirmation: function(ev, button, activity) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity,
|
||||
// Create confirm string (different if element has or does not have name)
|
||||
confirmstring = '',
|
||||
plugindata = {
|
||||
type: M.util.get_string('pluginname', element.getAttribute('class').match(/modtype_([^\s]*)/)[1])
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
// Create the confirmation dialogue.
|
||||
var confirm = new M.core.confirm({
|
||||
question: confirmstring,
|
||||
modal: true,
|
||||
visible: false
|
||||
});
|
||||
confirm.show();
|
||||
|
||||
// If it is confirmed.
|
||||
confirm.on('complete-yes', function() {
|
||||
|
||||
// Actually remove the element.
|
||||
element.remove();
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'action': 'DELETE',
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element)
|
||||
};
|
||||
this.send_request(data);
|
||||
if (M.core.actionmenu && M.core.actionmenu.instance) {
|
||||
M.core.actionmenu.instance.hideMenu(ev);
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Duplicates the activity.
|
||||
*
|
||||
* @method duplicate
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
duplicate: function(ev, button, activity) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity;
|
||||
|
||||
// Add the lightbox.
|
||||
var section = activity.ancestor(M.course.format.get_section_selector(Y)),
|
||||
lightbox = M.util.add_lightbox(Y, section).show();
|
||||
|
||||
// Build and send the request.
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'duplicate',
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element),
|
||||
'sr': button.getData('sr')
|
||||
};
|
||||
this.send_request(data, lightbox, function(response) {
|
||||
var newcm = Y.Node.create(response.fullcontent);
|
||||
|
||||
// Append to the section?
|
||||
activity.insert(newcm, 'after');
|
||||
Y.use('moodle-course-coursebase', function() {
|
||||
M.course.coursebase.invoke_function('setup_for_resource', newcm);
|
||||
});
|
||||
if (M.core.actionmenu && M.core.actionmenu.newDOMNode) {
|
||||
M.core.actionmenu.newDOMNode(newcm);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the visibility of this activity or resource.
|
||||
*
|
||||
* @method change_visibility
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action The action that has been requested.
|
||||
* @chainable
|
||||
*/
|
||||
change_visibility: function(ev, button, activity, action) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity;
|
||||
var value = this.handle_resource_dim(button, activity, action);
|
||||
|
||||
// Send the request
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'visible',
|
||||
'value': value,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element)
|
||||
};
|
||||
var spinner = this.add_spinner(element);
|
||||
this.send_request(data, spinner);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the UI aspect of dimming the activity or resource.
|
||||
*
|
||||
* @method handle_resource_dim
|
||||
* @protected
|
||||
* @param {Node} button The button that triggered the action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action 'show' or 'hide'.
|
||||
* @return {Number} 1 if we changed to visible, 0 if we were hiding.
|
||||
*/
|
||||
handle_resource_dim: function(button, activity, action) {
|
||||
var toggleclass = CSS.DIMCLASS,
|
||||
dimarea = activity.one([
|
||||
SELECTOR.ACTIVITYLINK,
|
||||
SELECTOR.CONTENTWITHOUTLINK
|
||||
].join(', ')),
|
||||
availabilityinfo = activity.one(CSS.AVAILABILITYINFODIV),
|
||||
nextaction = (action === 'hide') ? 'show' : 'hide',
|
||||
buttontext = button.one('span'),
|
||||
newstring = M.util.get_string(nextaction, 'moodle'),
|
||||
buttonimg = button.one('img');
|
||||
|
||||
// Update button info.
|
||||
buttonimg.setAttrs({
|
||||
'src': M.util.image_url('t/' + nextaction)
|
||||
});
|
||||
|
||||
if (Y.Lang.trim(button.getAttribute('title'))) {
|
||||
button.setAttribute('title', newstring);
|
||||
}
|
||||
|
||||
if (Y.Lang.trim(buttonimg.getAttribute('alt'))) {
|
||||
buttonimg.setAttribute('alt', newstring);
|
||||
}
|
||||
|
||||
button.replaceClass('editing_' + action, 'editing_' + nextaction);
|
||||
button.setData('action', nextaction);
|
||||
if (buttontext) {
|
||||
buttontext.set('text', newstring);
|
||||
}
|
||||
|
||||
if (activity.one(SELECTOR.CONTENTWITHOUTLINK)) {
|
||||
dimarea = activity.one(SELECTOR.CONTENTWITHOUTLINK);
|
||||
toggleclass = CSS.DIMMEDTEXT;
|
||||
}
|
||||
|
||||
// If activity is conditionally hidden, then don't toggle.
|
||||
if (!dimarea.hasClass(CSS.CONDITIONALHIDDEN)) {
|
||||
if (action === 'hide') {
|
||||
// Change the UI.
|
||||
dimarea.addClass(toggleclass);
|
||||
// We need to toggle dimming on the description too.
|
||||
activity.all(SELECTOR.CONTENTAFTERLINK).addClass(CSS.DIMMEDTEXT);
|
||||
activity.all(SELECTOR.GROUPINGLABEL).addClass(CSS.DIMMEDTEXT);
|
||||
} else {
|
||||
// Change the UI.
|
||||
dimarea.removeClass(toggleclass);
|
||||
// We need to toggle dimming on the description too.
|
||||
activity.all(SELECTOR.CONTENTAFTERLINK).removeClass(CSS.DIMMEDTEXT);
|
||||
activity.all(SELECTOR.GROUPINGLABEL).removeClass(CSS.DIMMEDTEXT);
|
||||
}
|
||||
}
|
||||
// Toggle availablity info for conditional activities.
|
||||
if (availabilityinfo) {
|
||||
availabilityinfo.toggleClass(CSS.HIDE);
|
||||
}
|
||||
return (action === 'hide') ? 0 : 1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the groupmode of the activity to the next groupmode in the sequence.
|
||||
*
|
||||
* @method change_groupmode
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
change_groupmode: function(ev, button, activity) {
|
||||
// Prevent the default button action.
|
||||
ev.preventDefault();
|
||||
|
||||
// Current Mode
|
||||
var groupmode = parseInt(button.getData('nextgroupmode'), 10),
|
||||
newtitle = '',
|
||||
iconsrc = '',
|
||||
newtitlestr,
|
||||
data,
|
||||
spinner,
|
||||
nextgroupmode = groupmode + 1,
|
||||
buttonimg = button.one('img');
|
||||
|
||||
if (nextgroupmode > 2) {
|
||||
nextgroupmode = 0;
|
||||
}
|
||||
|
||||
if (groupmode === this.GROUPS_NONE) {
|
||||
newtitle = 'groupsnone';
|
||||
iconsrc = M.util.image_url('i/groupn', 'moodle');
|
||||
} else if (groupmode === this.GROUPS_SEPARATE) {
|
||||
newtitle = 'groupsseparate';
|
||||
iconsrc = M.util.image_url('i/groups', 'moodle');
|
||||
} else if (groupmode === this.GROUPS_VISIBLE) {
|
||||
newtitle = 'groupsvisible';
|
||||
iconsrc = M.util.image_url('i/groupv', 'moodle');
|
||||
}
|
||||
newtitlestr = M.util.get_string('clicktochangeinbrackets', 'moodle', M.util.get_string(newtitle, 'moodle'));
|
||||
|
||||
// Change the UI
|
||||
var oldAction = button.getData('action');
|
||||
button.replaceClass('editing_' + oldAction, 'editing_' + newtitle);
|
||||
buttonimg.setAttrs({
|
||||
'src': iconsrc
|
||||
});
|
||||
if (Y.Lang.trim(button.getAttribute('title'))) {
|
||||
button.setAttribute('title', newtitlestr).setData('action', newtitle).setData('nextgroupmode', nextgroupmode);
|
||||
}
|
||||
|
||||
if (Y.Lang.trim(buttonimg.getAttribute('alt'))) {
|
||||
buttonimg.setAttribute('alt', newtitlestr);
|
||||
}
|
||||
|
||||
// And send the request
|
||||
data = {
|
||||
'class': 'resource',
|
||||
'field': 'groupmode',
|
||||
'value': groupmode,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
|
||||
spinner = this.add_spinner(activity);
|
||||
this.send_request(data, spinner);
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the visibility of the specified resource to match the visible parameter.
|
||||
*
|
||||
* Note: This is not a toggle function and only changes the visibility
|
||||
* in the browser (no ajax update is performed).
|
||||
*
|
||||
* @method set_visibility_resource_ui
|
||||
* @param {object} args An object containing the required information to trigger a change.
|
||||
* @param {Node} args.element The resource to toggle
|
||||
* @param {Boolean} args.visible The target visibility
|
||||
*/
|
||||
set_visibility_resource_ui: function(args) {
|
||||
var element = args.element,
|
||||
buttonnode = element.one(SELECTOR.HIDE),
|
||||
// By default we assume that the item is visible and we're going to hide it.
|
||||
currentVisibility = true,
|
||||
targetVisibility = false;
|
||||
|
||||
if (!buttonnode) {
|
||||
// If the buttonnode was not found, try to find the HIDE button
|
||||
// and change the target visibility setting to false.
|
||||
buttonnode = element.one(SELECTOR.SHOW);
|
||||
currentVisibility = false;
|
||||
targetVisibility = true;
|
||||
}
|
||||
|
||||
if (typeof args.visible !== 'undefined') {
|
||||
// If we were provided with a visibility argument, use that instead.
|
||||
targetVisibility = args.visible;
|
||||
}
|
||||
|
||||
// Only trigger a change if necessary.
|
||||
if (currentVisibility !== targetVisibility) {
|
||||
var action = 'hide';
|
||||
if (targetVisibility) {
|
||||
action = 'show';
|
||||
}
|
||||
|
||||
this.handle_resource_dim(buttonnode, element, action);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
NAME: 'course-resource-toolbox',
|
||||
ATTRS: {
|
||||
}
|
||||
});
|
||||
|
||||
M.course.resource_toolbox = null;
|
||||
M.course.init_resource_toolbox = function(config) {
|
||||
M.course.resource_toolbox = new RESOURCETOOLBOX(config);
|
||||
return M.course.resource_toolbox;
|
||||
};
|
||||
/* global SELECTOR, TOOLBOX */
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Section toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with sections
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @class section
|
||||
* @constructor
|
||||
* @extends M.course.toolboxes.toolbox
|
||||
*/
|
||||
var SECTIONTOOLBOX = function() {
|
||||
SECTIONTOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(SECTIONTOOLBOX, TOOLBOX, {
|
||||
/**
|
||||
* Initialize the section toolboxes module.
|
||||
*
|
||||
* Updates all span.commands with relevant handlers and other required changes.
|
||||
*
|
||||
* @method initializer
|
||||
* @protected
|
||||
*/
|
||||
initializer: function() {
|
||||
M.course.coursebase.register_module(this);
|
||||
|
||||
// Section Highlighting.
|
||||
Y.delegate('click', this.toggle_highlight, SELECTOR.PAGECONTENT, SELECTOR.SECTIONLI + ' ' + SELECTOR.HIGHLIGHT, this);
|
||||
|
||||
// Section Visibility.
|
||||
Y.delegate('click', this.toggle_hide_section, SELECTOR.PAGECONTENT, SELECTOR.SECTIONLI + ' ' + SELECTOR.SHOWHIDE, this);
|
||||
},
|
||||
|
||||
toggle_hide_section: function(e) {
|
||||
// Prevent the default button action.
|
||||
e.preventDefault();
|
||||
|
||||
// Get the section we're working on.
|
||||
var section = e.target.ancestor(M.course.format.get_section_selector(Y)),
|
||||
button = e.target.ancestor('a', true),
|
||||
hideicon = button.one('img'),
|
||||
buttontext = button.one('span'),
|
||||
|
||||
// The value to submit
|
||||
value,
|
||||
|
||||
// The text for strings and images. Also determines the icon to display.
|
||||
action,
|
||||
nextaction;
|
||||
|
||||
if (!section.hasClass(CSS.SECTIONHIDDENCLASS)) {
|
||||
section.addClass(CSS.SECTIONHIDDENCLASS);
|
||||
value = 0;
|
||||
action = 'hide';
|
||||
nextaction = 'show';
|
||||
} else {
|
||||
section.removeClass(CSS.SECTIONHIDDENCLASS);
|
||||
value = 1;
|
||||
action = 'show';
|
||||
nextaction = 'hide';
|
||||
}
|
||||
|
||||
var newstring = M.util.get_string(nextaction + 'fromothers', 'format_' + this.get('format'));
|
||||
hideicon.setAttrs({
|
||||
'alt': newstring,
|
||||
'src': M.util.image_url('i/' + nextaction)
|
||||
});
|
||||
button.set('title', newstring);
|
||||
if (buttontext) {
|
||||
buttontext.set('text', newstring);
|
||||
}
|
||||
|
||||
// Change the show/hide status
|
||||
var data = {
|
||||
'class': 'section',
|
||||
'field': 'visible',
|
||||
'id': Y.Moodle.core_course.util.section.getId(section.ancestor(M.course.format.get_section_wrapper(Y), true)),
|
||||
'value': value
|
||||
};
|
||||
|
||||
var lightbox = M.util.add_lightbox(Y, section);
|
||||
lightbox.show();
|
||||
|
||||
this.send_request(data, lightbox, function(response) {
|
||||
var activities = section.all(SELECTOR.ACTIVITYLI);
|
||||
activities.each(function(node) {
|
||||
var button;
|
||||
if (node.one(SELECTOR.SHOW)) {
|
||||
button = node.one(SELECTOR.SHOW);
|
||||
} else {
|
||||
button = node.one(SELECTOR.HIDE);
|
||||
}
|
||||
var activityid = Y.Moodle.core_course.util.cm.getId(node);
|
||||
|
||||
// NOTE: resourcestotoggle is returned as a string instead
|
||||
// of a Number so we must cast our activityid to a String.
|
||||
if (Y.Array.indexOf(response.resourcestotoggle, "" + activityid) !== -1) {
|
||||
M.course.resource_toolbox.handle_resource_dim(button, node, action);
|
||||
}
|
||||
}, this);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle highlighting the current section.
|
||||
*
|
||||
* @method toggle_highlight
|
||||
* @param {EventFacade} e
|
||||
*/
|
||||
toggle_highlight: function(e) {
|
||||
// Prevent the default button action.
|
||||
e.preventDefault();
|
||||
|
||||
// Get the section we're working on.
|
||||
var section = e.target.ancestor(M.course.format.get_section_selector(Y));
|
||||
var button = e.target.ancestor('a', true);
|
||||
var buttonicon = button.one('img');
|
||||
var buttontext = button.one('span');
|
||||
|
||||
// Determine whether the marker is currently set.
|
||||
var togglestatus = section.hasClass('current');
|
||||
var value = 0;
|
||||
|
||||
// Set the current highlighted item text.
|
||||
var old_string = M.util.get_string('markthistopic', 'moodle');
|
||||
|
||||
var selectedpage = Y.one(SELECTOR.PAGECONTENT);
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT)
|
||||
.set('title', old_string);
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT + ' span')
|
||||
.set('text', M.util.get_string('highlight', 'moodle'));
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT + ' img')
|
||||
.set('alt', old_string)
|
||||
.set('src', M.util.image_url('i/marker'));
|
||||
|
||||
// Remove the highlighting from all sections.
|
||||
selectedpage.all(M.course.format.get_section_selector(Y))
|
||||
.removeClass('current');
|
||||
|
||||
// Then add it if required to the selected section.
|
||||
if (!togglestatus) {
|
||||
section.addClass('current');
|
||||
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);
|
||||
buttonicon
|
||||
.set('alt', new_string)
|
||||
.set('src', M.util.image_url('i/marked'));
|
||||
if (buttontext) {
|
||||
buttontext
|
||||
.set('text', M.util.get_string('highlightoff', 'moodle'));
|
||||
}
|
||||
}
|
||||
|
||||
// Change the highlight status.
|
||||
var data = {
|
||||
'class': 'course',
|
||||
'field': 'marker',
|
||||
'value': value
|
||||
};
|
||||
var lightbox = M.util.add_lightbox(Y, section);
|
||||
lightbox.show();
|
||||
this.send_request(data, lightbox);
|
||||
}
|
||||
}, {
|
||||
NAME: 'course-section-toolbox',
|
||||
ATTRS: {
|
||||
}
|
||||
});
|
||||
|
||||
M.course.init_section_toolbox = function(config) {
|
||||
return new SECTIONTOOLBOX(config);
|
||||
};
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["node", "base", "event-key", "node", "io", "moodle-course-coursebase", "moodle-course-util"]});
|
3
course/yui/src/dragdrop/js/resource.js
vendored
3
course/yui/src/dragdrop/js/resource.js
vendored
@ -108,7 +108,8 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, {
|
||||
// Replace move icons
|
||||
var move = resourcesnode.one('a.' + CSS.EDITINGMOVE);
|
||||
if (move) {
|
||||
move.replace(this.resourcedraghandle.cloneNode(true));
|
||||
var sr = move.getData('sr');
|
||||
move.replace(this.resourcedraghandle.cloneNode(true).setAttribute('data-sectionreturn', sr));
|
||||
}
|
||||
}, this);
|
||||
},
|
||||
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
"name": "moodle-course-toolboxes",
|
||||
"builds": {
|
||||
"moodle-course-toolboxes": {
|
||||
"jsfiles": [
|
||||
"toolbox.js",
|
||||
"resource.js",
|
||||
"section.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
552
course/yui/src/toolboxes/js/resource.js
vendored
552
course/yui/src/toolboxes/js/resource.js
vendored
@ -1,552 +0,0 @@
|
||||
/* global TOOLBOX, BODY, SELECTOR, INDENTLIMITS */
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This is a class extending TOOLBOX containing code specific to resources
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @class resources
|
||||
* @constructor
|
||||
* @extends M.course.toolboxes.toolbox
|
||||
*/
|
||||
var RESOURCETOOLBOX = function() {
|
||||
RESOURCETOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(RESOURCETOOLBOX, TOOLBOX, {
|
||||
/**
|
||||
* No groups are being used.
|
||||
*
|
||||
* @property GROUPS_NONE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_NONE: 0,
|
||||
|
||||
/**
|
||||
* Separate groups are being used.
|
||||
*
|
||||
* @property GROUPS_SEPARATE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_SEPARATE: 1,
|
||||
|
||||
/**
|
||||
* Visible groups are being used.
|
||||
*
|
||||
* @property GROUPS_VISIBLE
|
||||
* @protected
|
||||
* @type Number
|
||||
*/
|
||||
GROUPS_VISIBLE: 2,
|
||||
|
||||
/**
|
||||
* Initialize the resource toolbox
|
||||
*
|
||||
* For each activity the commands are updated and a reference to the activity is attached.
|
||||
* This way it doesn't matter where the commands are going to called from they have a reference to the
|
||||
* activity that they relate to.
|
||||
* This is essential as some of the actions are displayed in an actionmenu which removes them from the
|
||||
* page flow.
|
||||
*
|
||||
* This function also creates a single event delegate to manage all AJAX actions for all activities on
|
||||
* the page.
|
||||
*
|
||||
* @method initializer
|
||||
* @protected
|
||||
*/
|
||||
initializer: function() {
|
||||
M.course.coursebase.register_module(this);
|
||||
BODY.delegate('key', this.handle_data_action, 'down:enter', SELECTOR.ACTIVITYACTION, this);
|
||||
Y.delegate('click', this.handle_data_action, BODY, SELECTOR.ACTIVITYACTION, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the delegation event. When this is fired someone has triggered an action.
|
||||
*
|
||||
* Note not all actions will result in an AJAX enhancement.
|
||||
*
|
||||
* @protected
|
||||
* @method handle_data_action
|
||||
* @param {EventFacade} ev The event that was triggered.
|
||||
* @return {boolean}
|
||||
*/
|
||||
handle_data_action: function(ev) {
|
||||
// We need to get the anchor element that triggered this event.
|
||||
var node = ev.target;
|
||||
if (!node.test('a')) {
|
||||
node = node.ancestor(SELECTOR.ACTIVITYACTION);
|
||||
}
|
||||
|
||||
// From the anchor we can get both the activity (added during initialisation) and the action being
|
||||
// performed (added by the UI as a data attribute).
|
||||
var action = node.getData('action'),
|
||||
activity = node.ancestor(SELECTOR.ACTIVITYLI);
|
||||
|
||||
if (!node.test('a') || !action || !activity) {
|
||||
// It wasn't a valid action node.
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch based upon the action and do the desired thing.
|
||||
switch (action) {
|
||||
case 'moveleft':
|
||||
case 'moveright':
|
||||
// The user changing the indent of the activity.
|
||||
this.change_indent(ev, node, activity, action);
|
||||
break;
|
||||
case 'delete':
|
||||
// The user is deleting the activity.
|
||||
this.delete_with_confirmation(ev, node, activity, action);
|
||||
break;
|
||||
case 'duplicate':
|
||||
// The user is duplicating the activity.
|
||||
this.duplicate(ev, node, activity, action);
|
||||
break;
|
||||
case 'hide':
|
||||
case 'show':
|
||||
// The user is changing the visibility of the activity.
|
||||
this.change_visibility(ev, node, activity, action);
|
||||
break;
|
||||
case 'groupsseparate':
|
||||
case 'groupsvisible':
|
||||
case 'groupsnone':
|
||||
// The user is changing the group mode.
|
||||
this.change_groupmode(ev, node, activity, action);
|
||||
break;
|
||||
case 'move':
|
||||
case 'update':
|
||||
case 'assignroles':
|
||||
break;
|
||||
default:
|
||||
// Nothing to do here!
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a loading icon to the specified activity.
|
||||
*
|
||||
* The icon is added within the action area.
|
||||
*
|
||||
* @method add_spinner
|
||||
* @param {Node} activity The activity to add a loading icon to
|
||||
* @return {Node|null} The newly created icon, or null if the action area was not found.
|
||||
*/
|
||||
add_spinner: function(activity) {
|
||||
var actionarea = activity.one(SELECTOR.ACTIONAREA);
|
||||
if (actionarea) {
|
||||
return M.util.add_spinner(Y, actionarea);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the indent of the activity or resource.
|
||||
*
|
||||
* @method change_indent
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action The action that has been requested. Will be 'moveleft' or 'moveright'.
|
||||
*/
|
||||
change_indent: function(ev, button, activity, action) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
var direction = (action === 'moveleft') ? -1 : 1;
|
||||
|
||||
// And we need to determine the current and new indent level
|
||||
var indentdiv = activity.one(SELECTOR.MODINDENTDIV),
|
||||
indent = indentdiv.getAttribute('class').match(/mod-indent-(\d{1,})/),
|
||||
oldindent = 0,
|
||||
newindent;
|
||||
|
||||
if (indent) {
|
||||
oldindent = parseInt(indent[1], 10);
|
||||
}
|
||||
newindent = oldindent + parseInt(direction, 10);
|
||||
|
||||
if (newindent < INDENTLIMITS.MIN || newindent > INDENTLIMITS.MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (indent) {
|
||||
indentdiv.removeClass(indent[0]);
|
||||
}
|
||||
|
||||
// Perform the move
|
||||
indentdiv.addClass(CSS.MODINDENTCOUNT + newindent);
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'indent',
|
||||
'value': newindent,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
var spinner = this.add_spinner(activity);
|
||||
this.send_request(data, spinner);
|
||||
|
||||
var remainingmove;
|
||||
|
||||
// Handle removal/addition of the moveleft button.
|
||||
if (newindent === INDENTLIMITS.MIN) {
|
||||
button.addClass('hidden');
|
||||
remainingmove = activity.one('.editing_moveright');
|
||||
} else if (newindent > INDENTLIMITS.MIN && oldindent === INDENTLIMITS.MIN) {
|
||||
button.ancestor('.menu').one('[data-action=moveleft]').removeClass('hidden');
|
||||
}
|
||||
|
||||
if (newindent === INDENTLIMITS.MAX) {
|
||||
button.addClass('hidden');
|
||||
remainingmove = activity.one('.editing_moveleft');
|
||||
} else if (newindent < INDENTLIMITS.MAX && oldindent === INDENTLIMITS.MAX) {
|
||||
button.ancestor('.menu').one('[data-action=moveright]').removeClass('hidden');
|
||||
}
|
||||
|
||||
// Handle massive indentation to match non-ajax display
|
||||
var hashugeclass = indentdiv.hasClass(CSS.MODINDENTHUGE);
|
||||
if (newindent > 15 && !hashugeclass) {
|
||||
indentdiv.addClass(CSS.MODINDENTHUGE);
|
||||
} else if (newindent <= 15 && hashugeclass) {
|
||||
indentdiv.removeClass(CSS.MODINDENTHUGE);
|
||||
}
|
||||
|
||||
if (ev.type && ev.type === "key" && remainingmove) {
|
||||
remainingmove.focus();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Deletes the given activity or resource after confirmation.
|
||||
*
|
||||
* @protected
|
||||
* @method delete_with_confirmation
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
delete_with_confirmation: function(ev, button, activity) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity,
|
||||
// Create confirm string (different if element has or does not have name)
|
||||
confirmstring = '',
|
||||
plugindata = {
|
||||
type: M.util.get_string('pluginname', element.getAttribute('class').match(/modtype_([^\s]*)/)[1])
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
// Create the confirmation dialogue.
|
||||
var confirm = new M.core.confirm({
|
||||
question: confirmstring,
|
||||
modal: true,
|
||||
visible: false
|
||||
});
|
||||
confirm.show();
|
||||
|
||||
// If it is confirmed.
|
||||
confirm.on('complete-yes', function() {
|
||||
|
||||
// Actually remove the element.
|
||||
element.remove();
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'action': 'DELETE',
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element)
|
||||
};
|
||||
this.send_request(data);
|
||||
if (M.core.actionmenu && M.core.actionmenu.instance) {
|
||||
M.core.actionmenu.instance.hideMenu(ev);
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Duplicates the activity.
|
||||
*
|
||||
* @method duplicate
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
duplicate: function(ev, button, activity) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity;
|
||||
|
||||
// Add the lightbox.
|
||||
var section = activity.ancestor(M.course.format.get_section_selector(Y)),
|
||||
lightbox = M.util.add_lightbox(Y, section).show();
|
||||
|
||||
// Build and send the request.
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'duplicate',
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element),
|
||||
'sr': button.getData('sr')
|
||||
};
|
||||
this.send_request(data, lightbox, function(response) {
|
||||
var newcm = Y.Node.create(response.fullcontent);
|
||||
|
||||
// Append to the section?
|
||||
activity.insert(newcm, 'after');
|
||||
Y.use('moodle-course-coursebase', function() {
|
||||
M.course.coursebase.invoke_function('setup_for_resource', newcm);
|
||||
});
|
||||
if (M.core.actionmenu && M.core.actionmenu.newDOMNode) {
|
||||
M.core.actionmenu.newDOMNode(newcm);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the visibility of this activity or resource.
|
||||
*
|
||||
* @method change_visibility
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action The action that has been requested.
|
||||
* @chainable
|
||||
*/
|
||||
change_visibility: function(ev, button, activity, action) {
|
||||
// Prevent the default button action
|
||||
ev.preventDefault();
|
||||
|
||||
// Get the element we're working on
|
||||
var element = activity;
|
||||
var value = this.handle_resource_dim(button, activity, action);
|
||||
|
||||
// Send the request
|
||||
var data = {
|
||||
'class': 'resource',
|
||||
'field': 'visible',
|
||||
'value': value,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(element)
|
||||
};
|
||||
var spinner = this.add_spinner(element);
|
||||
this.send_request(data, spinner);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the UI aspect of dimming the activity or resource.
|
||||
*
|
||||
* @method handle_resource_dim
|
||||
* @protected
|
||||
* @param {Node} button The button that triggered the action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @param {String} action 'show' or 'hide'.
|
||||
* @return {Number} 1 if we changed to visible, 0 if we were hiding.
|
||||
*/
|
||||
handle_resource_dim: function(button, activity, action) {
|
||||
var toggleclass = CSS.DIMCLASS,
|
||||
dimarea = activity.one([
|
||||
SELECTOR.ACTIVITYLINK,
|
||||
SELECTOR.CONTENTWITHOUTLINK
|
||||
].join(', ')),
|
||||
availabilityinfo = activity.one(CSS.AVAILABILITYINFODIV),
|
||||
nextaction = (action === 'hide') ? 'show' : 'hide',
|
||||
buttontext = button.one('span'),
|
||||
newstring = M.util.get_string(nextaction, 'moodle'),
|
||||
buttonimg = button.one('img');
|
||||
|
||||
// Update button info.
|
||||
buttonimg.setAttrs({
|
||||
'src': M.util.image_url('t/' + nextaction)
|
||||
});
|
||||
|
||||
if (Y.Lang.trim(button.getAttribute('title'))) {
|
||||
button.setAttribute('title', newstring);
|
||||
}
|
||||
|
||||
if (Y.Lang.trim(buttonimg.getAttribute('alt'))) {
|
||||
buttonimg.setAttribute('alt', newstring);
|
||||
}
|
||||
|
||||
button.replaceClass('editing_' + action, 'editing_' + nextaction);
|
||||
button.setData('action', nextaction);
|
||||
if (buttontext) {
|
||||
buttontext.set('text', newstring);
|
||||
}
|
||||
|
||||
if (activity.one(SELECTOR.CONTENTWITHOUTLINK)) {
|
||||
dimarea = activity.one(SELECTOR.CONTENTWITHOUTLINK);
|
||||
toggleclass = CSS.DIMMEDTEXT;
|
||||
}
|
||||
|
||||
// If activity is conditionally hidden, then don't toggle.
|
||||
if (!dimarea.hasClass(CSS.CONDITIONALHIDDEN)) {
|
||||
if (action === 'hide') {
|
||||
// Change the UI.
|
||||
dimarea.addClass(toggleclass);
|
||||
// We need to toggle dimming on the description too.
|
||||
activity.all(SELECTOR.CONTENTAFTERLINK).addClass(CSS.DIMMEDTEXT);
|
||||
activity.all(SELECTOR.GROUPINGLABEL).addClass(CSS.DIMMEDTEXT);
|
||||
} else {
|
||||
// Change the UI.
|
||||
dimarea.removeClass(toggleclass);
|
||||
// We need to toggle dimming on the description too.
|
||||
activity.all(SELECTOR.CONTENTAFTERLINK).removeClass(CSS.DIMMEDTEXT);
|
||||
activity.all(SELECTOR.GROUPINGLABEL).removeClass(CSS.DIMMEDTEXT);
|
||||
}
|
||||
}
|
||||
// Toggle availablity info for conditional activities.
|
||||
if (availabilityinfo) {
|
||||
availabilityinfo.toggleClass(CSS.HIDE);
|
||||
}
|
||||
return (action === 'hide') ? 0 : 1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the groupmode of the activity to the next groupmode in the sequence.
|
||||
*
|
||||
* @method change_groupmode
|
||||
* @protected
|
||||
* @param {EventFacade} ev The event that was fired.
|
||||
* @param {Node} button The button that triggered this action.
|
||||
* @param {Node} activity The activity node that this action will be performed on.
|
||||
* @chainable
|
||||
*/
|
||||
change_groupmode: function(ev, button, activity) {
|
||||
// Prevent the default button action.
|
||||
ev.preventDefault();
|
||||
|
||||
// Current Mode
|
||||
var groupmode = parseInt(button.getData('nextgroupmode'), 10),
|
||||
newtitle = '',
|
||||
iconsrc = '',
|
||||
newtitlestr,
|
||||
data,
|
||||
spinner,
|
||||
nextgroupmode = groupmode + 1,
|
||||
buttonimg = button.one('img');
|
||||
|
||||
if (nextgroupmode > 2) {
|
||||
nextgroupmode = 0;
|
||||
}
|
||||
|
||||
if (groupmode === this.GROUPS_NONE) {
|
||||
newtitle = 'groupsnone';
|
||||
iconsrc = M.util.image_url('i/groupn', 'moodle');
|
||||
} else if (groupmode === this.GROUPS_SEPARATE) {
|
||||
newtitle = 'groupsseparate';
|
||||
iconsrc = M.util.image_url('i/groups', 'moodle');
|
||||
} else if (groupmode === this.GROUPS_VISIBLE) {
|
||||
newtitle = 'groupsvisible';
|
||||
iconsrc = M.util.image_url('i/groupv', 'moodle');
|
||||
}
|
||||
newtitlestr = M.util.get_string('clicktochangeinbrackets', 'moodle', M.util.get_string(newtitle, 'moodle'));
|
||||
|
||||
// Change the UI
|
||||
var oldAction = button.getData('action');
|
||||
button.replaceClass('editing_' + oldAction, 'editing_' + newtitle);
|
||||
buttonimg.setAttrs({
|
||||
'src': iconsrc
|
||||
});
|
||||
if (Y.Lang.trim(button.getAttribute('title'))) {
|
||||
button.setAttribute('title', newtitlestr).setData('action', newtitle).setData('nextgroupmode', nextgroupmode);
|
||||
}
|
||||
|
||||
if (Y.Lang.trim(buttonimg.getAttribute('alt'))) {
|
||||
buttonimg.setAttribute('alt', newtitlestr);
|
||||
}
|
||||
|
||||
// And send the request
|
||||
data = {
|
||||
'class': 'resource',
|
||||
'field': 'groupmode',
|
||||
'value': groupmode,
|
||||
'id': Y.Moodle.core_course.util.cm.getId(activity)
|
||||
};
|
||||
|
||||
spinner = this.add_spinner(activity);
|
||||
this.send_request(data, spinner);
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the visibility of the specified resource to match the visible parameter.
|
||||
*
|
||||
* Note: This is not a toggle function and only changes the visibility
|
||||
* in the browser (no ajax update is performed).
|
||||
*
|
||||
* @method set_visibility_resource_ui
|
||||
* @param {object} args An object containing the required information to trigger a change.
|
||||
* @param {Node} args.element The resource to toggle
|
||||
* @param {Boolean} args.visible The target visibility
|
||||
*/
|
||||
set_visibility_resource_ui: function(args) {
|
||||
var element = args.element,
|
||||
buttonnode = element.one(SELECTOR.HIDE),
|
||||
// By default we assume that the item is visible and we're going to hide it.
|
||||
currentVisibility = true,
|
||||
targetVisibility = false;
|
||||
|
||||
if (!buttonnode) {
|
||||
// If the buttonnode was not found, try to find the HIDE button
|
||||
// and change the target visibility setting to false.
|
||||
buttonnode = element.one(SELECTOR.SHOW);
|
||||
currentVisibility = false;
|
||||
targetVisibility = true;
|
||||
}
|
||||
|
||||
if (typeof args.visible !== 'undefined') {
|
||||
// If we were provided with a visibility argument, use that instead.
|
||||
targetVisibility = args.visible;
|
||||
}
|
||||
|
||||
// Only trigger a change if necessary.
|
||||
if (currentVisibility !== targetVisibility) {
|
||||
var action = 'hide';
|
||||
if (targetVisibility) {
|
||||
action = 'show';
|
||||
}
|
||||
|
||||
this.handle_resource_dim(buttonnode, element, action);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
NAME: 'course-resource-toolbox',
|
||||
ATTRS: {
|
||||
}
|
||||
});
|
||||
|
||||
M.course.resource_toolbox = null;
|
||||
M.course.init_resource_toolbox = function(config) {
|
||||
M.course.resource_toolbox = new RESOURCETOOLBOX(config);
|
||||
return M.course.resource_toolbox;
|
||||
};
|
189
course/yui/src/toolboxes/js/section.js
vendored
189
course/yui/src/toolboxes/js/section.js
vendored
@ -1,189 +0,0 @@
|
||||
/* global SELECTOR, TOOLBOX */
|
||||
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Section toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with sections
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @class section
|
||||
* @constructor
|
||||
* @extends M.course.toolboxes.toolbox
|
||||
*/
|
||||
var SECTIONTOOLBOX = function() {
|
||||
SECTIONTOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(SECTIONTOOLBOX, TOOLBOX, {
|
||||
/**
|
||||
* Initialize the section toolboxes module.
|
||||
*
|
||||
* Updates all span.commands with relevant handlers and other required changes.
|
||||
*
|
||||
* @method initializer
|
||||
* @protected
|
||||
*/
|
||||
initializer: function() {
|
||||
M.course.coursebase.register_module(this);
|
||||
|
||||
// Section Highlighting.
|
||||
Y.delegate('click', this.toggle_highlight, SELECTOR.PAGECONTENT, SELECTOR.SECTIONLI + ' ' + SELECTOR.HIGHLIGHT, this);
|
||||
|
||||
// Section Visibility.
|
||||
Y.delegate('click', this.toggle_hide_section, SELECTOR.PAGECONTENT, SELECTOR.SECTIONLI + ' ' + SELECTOR.SHOWHIDE, this);
|
||||
},
|
||||
|
||||
toggle_hide_section: function(e) {
|
||||
// Prevent the default button action.
|
||||
e.preventDefault();
|
||||
|
||||
// Get the section we're working on.
|
||||
var section = e.target.ancestor(M.course.format.get_section_selector(Y)),
|
||||
button = e.target.ancestor('a', true),
|
||||
hideicon = button.one('img'),
|
||||
buttontext = button.one('span'),
|
||||
|
||||
// The value to submit
|
||||
value,
|
||||
|
||||
// The text for strings and images. Also determines the icon to display.
|
||||
action,
|
||||
nextaction;
|
||||
|
||||
if (!section.hasClass(CSS.SECTIONHIDDENCLASS)) {
|
||||
section.addClass(CSS.SECTIONHIDDENCLASS);
|
||||
value = 0;
|
||||
action = 'hide';
|
||||
nextaction = 'show';
|
||||
} else {
|
||||
section.removeClass(CSS.SECTIONHIDDENCLASS);
|
||||
value = 1;
|
||||
action = 'show';
|
||||
nextaction = 'hide';
|
||||
}
|
||||
|
||||
var newstring = M.util.get_string(nextaction + 'fromothers', 'format_' + this.get('format'));
|
||||
hideicon.setAttrs({
|
||||
'alt': newstring,
|
||||
'src': M.util.image_url('i/' + nextaction)
|
||||
});
|
||||
button.set('title', newstring);
|
||||
if (buttontext) {
|
||||
buttontext.set('text', newstring);
|
||||
}
|
||||
|
||||
// Change the show/hide status
|
||||
var data = {
|
||||
'class': 'section',
|
||||
'field': 'visible',
|
||||
'id': Y.Moodle.core_course.util.section.getId(section.ancestor(M.course.format.get_section_wrapper(Y), true)),
|
||||
'value': value
|
||||
};
|
||||
|
||||
var lightbox = M.util.add_lightbox(Y, section);
|
||||
lightbox.show();
|
||||
|
||||
this.send_request(data, lightbox, function(response) {
|
||||
var activities = section.all(SELECTOR.ACTIVITYLI);
|
||||
activities.each(function(node) {
|
||||
var button;
|
||||
if (node.one(SELECTOR.SHOW)) {
|
||||
button = node.one(SELECTOR.SHOW);
|
||||
} else {
|
||||
button = node.one(SELECTOR.HIDE);
|
||||
}
|
||||
var activityid = Y.Moodle.core_course.util.cm.getId(node);
|
||||
|
||||
// NOTE: resourcestotoggle is returned as a string instead
|
||||
// of a Number so we must cast our activityid to a String.
|
||||
if (Y.Array.indexOf(response.resourcestotoggle, "" + activityid) !== -1) {
|
||||
M.course.resource_toolbox.handle_resource_dim(button, node, action);
|
||||
}
|
||||
}, this);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle highlighting the current section.
|
||||
*
|
||||
* @method toggle_highlight
|
||||
* @param {EventFacade} e
|
||||
*/
|
||||
toggle_highlight: function(e) {
|
||||
// Prevent the default button action.
|
||||
e.preventDefault();
|
||||
|
||||
// Get the section we're working on.
|
||||
var section = e.target.ancestor(M.course.format.get_section_selector(Y));
|
||||
var button = e.target.ancestor('a', true);
|
||||
var buttonicon = button.one('img');
|
||||
var buttontext = button.one('span');
|
||||
|
||||
// Determine whether the marker is currently set.
|
||||
var togglestatus = section.hasClass('current');
|
||||
var value = 0;
|
||||
|
||||
// Set the current highlighted item text.
|
||||
var old_string = M.util.get_string('markthistopic', 'moodle');
|
||||
|
||||
var selectedpage = Y.one(SELECTOR.PAGECONTENT);
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT)
|
||||
.set('title', old_string);
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT + ' span')
|
||||
.set('text', M.util.get_string('highlight', 'moodle'));
|
||||
selectedpage
|
||||
.all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT + ' img')
|
||||
.set('alt', old_string)
|
||||
.set('src', M.util.image_url('i/marker'));
|
||||
|
||||
// Remove the highlighting from all sections.
|
||||
selectedpage.all(M.course.format.get_section_selector(Y))
|
||||
.removeClass('current');
|
||||
|
||||
// Then add it if required to the selected section.
|
||||
if (!togglestatus) {
|
||||
section.addClass('current');
|
||||
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);
|
||||
buttonicon
|
||||
.set('alt', new_string)
|
||||
.set('src', M.util.image_url('i/marked'));
|
||||
if (buttontext) {
|
||||
buttontext
|
||||
.set('text', M.util.get_string('highlightoff', 'moodle'));
|
||||
}
|
||||
}
|
||||
|
||||
// Change the highlight status.
|
||||
var data = {
|
||||
'class': 'course',
|
||||
'field': 'marker',
|
||||
'value': value
|
||||
};
|
||||
var lightbox = M.util.add_lightbox(Y, section);
|
||||
lightbox.show();
|
||||
this.send_request(data, lightbox);
|
||||
}
|
||||
}, {
|
||||
NAME: 'course-section-toolbox',
|
||||
ATTRS: {
|
||||
}
|
||||
});
|
||||
|
||||
M.course.init_section_toolbox = function(config) {
|
||||
return new SECTIONTOOLBOX(config);
|
||||
};
|
0
course/yui/src/toolboxes/js/shared.js
vendored
0
course/yui/src/toolboxes/js/shared.js
vendored
201
course/yui/src/toolboxes/js/toolbox.js
vendored
201
course/yui/src/toolboxes/js/toolbox.js
vendored
@ -1,201 +0,0 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
/**
|
||||
* Resource and activity toolbox class.
|
||||
*
|
||||
* This class is responsible for managing AJAX interactions with activities and resources
|
||||
* when viewing a course in editing mode.
|
||||
*
|
||||
* @module moodle-course-toolboxes
|
||||
* @namespace M.course.toolboxes
|
||||
*/
|
||||
|
||||
// The CSS classes we use.
|
||||
var CSS = {
|
||||
ACTIVITYINSTANCE: 'activityinstance',
|
||||
AVAILABILITYINFODIV: 'div.availabilityinfo',
|
||||
CONTENTWITHOUTLINK: 'contentwithoutlink',
|
||||
CONDITIONALHIDDEN: 'conditionalhidden',
|
||||
DIMCLASS: 'dimmed',
|
||||
DIMMEDTEXT: 'dimmed_text',
|
||||
EDITINSTRUCTIONS: 'editinstructions',
|
||||
HIDE: 'hide',
|
||||
MODINDENTCOUNT: 'mod-indent-',
|
||||
MODINDENTHUGE: 'mod-indent-huge',
|
||||
MODULEIDPREFIX: 'module-',
|
||||
SECTIONHIDDENCLASS: 'hidden',
|
||||
SECTIONIDPREFIX: 'section-',
|
||||
SHOW: 'editing_show'
|
||||
},
|
||||
// The CSS selectors we use.
|
||||
SELECTOR = {
|
||||
ACTIONAREA: '.actions',
|
||||
ACTIONLINKTEXT: '.actionlinktext',
|
||||
ACTIVITYACTION: 'a.cm-edit-action[data-action]',
|
||||
ACTIVITYICON: 'img.activityicon',
|
||||
ACTIVITYINSTANCE: '.' + CSS.ACTIVITYINSTANCE,
|
||||
ACTIVITYLINK: '.' + CSS.ACTIVITYINSTANCE + ' > a, .' + CSS.ACTIVITYINSTANCE +
|
||||
' > span[data-inplaceeditable] > a:not([data-inplaceeditablelink])',
|
||||
ACTIVITYLI: 'li.activity',
|
||||
COMMANDSPAN: '.commands',
|
||||
CONTENTAFTERLINK: 'div.contentafterlink',
|
||||
CONTENTWITHOUTLINK: 'div.contentwithoutlink',
|
||||
GROUPINGLABEL: '.' + CSS.ACTIVITYINSTANCE + ' .groupinglabel',
|
||||
HIDE: 'a.editing_hide',
|
||||
HIGHLIGHT: 'a.editing_highlight',
|
||||
INSTANCENAME: 'span.instancename',
|
||||
MODINDENTDIV: '.mod-indent',
|
||||
MODINDENTOUTER: '.mod-indent-outer',
|
||||
PAGECONTENT: 'body',
|
||||
SECTIONLI: 'li.section',
|
||||
SHOW: 'a.' + CSS.SHOW,
|
||||
SHOWHIDE: 'a.editing_showhide'
|
||||
},
|
||||
INDENTLIMITS = {
|
||||
MIN: 0,
|
||||
MAX: 16
|
||||
},
|
||||
BODY = Y.one(document.body);
|
||||
|
||||
// Setup the basic namespace.
|
||||
M.course = M.course || {};
|
||||
|
||||
/**
|
||||
* The toolbox class is a generic class which should never be directly
|
||||
* instantiated. Please extend it instead.
|
||||
*
|
||||
* @class toolbox
|
||||
* @constructor
|
||||
* @protected
|
||||
* @extends Base
|
||||
*/
|
||||
var TOOLBOX = function() {
|
||||
TOOLBOX.superclass.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
Y.extend(TOOLBOX, Y.Base, {
|
||||
/**
|
||||
* Send a request using the REST API
|
||||
*
|
||||
* @method send_request
|
||||
* @param {Object} data The data to submit with the AJAX request
|
||||
* @param {Node} [statusspinner] A statusspinner which may contain a section loader
|
||||
* @param {Function} success_callback The callback to use on success
|
||||
* @param {Object} [optionalconfig] Any additional configuration to submit
|
||||
* @chainable
|
||||
*/
|
||||
send_request: function(data, statusspinner, success_callback, optionalconfig) {
|
||||
// Default data structure
|
||||
if (!data) {
|
||||
data = {};
|
||||
}
|
||||
// Handle any variables which we must pass back through to
|
||||
var pageparams = this.get('config').pageparams,
|
||||
varname;
|
||||
for (varname in pageparams) {
|
||||
data[varname] = pageparams[varname];
|
||||
}
|
||||
|
||||
data.sesskey = M.cfg.sesskey;
|
||||
data.courseId = this.get('courseid');
|
||||
|
||||
var uri = M.cfg.wwwroot + this.get('ajaxurl');
|
||||
|
||||
// Define the configuration to send with the request
|
||||
var responsetext = [];
|
||||
var config = {
|
||||
method: 'POST',
|
||||
data: data,
|
||||
on: {
|
||||
success: function(tid, response) {
|
||||
try {
|
||||
responsetext = Y.JSON.parse(response.responseText);
|
||||
if (responsetext.error) {
|
||||
new M.core.ajaxException(responsetext);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore.
|
||||
}
|
||||
|
||||
// Run the callback if we have one.
|
||||
if (success_callback) {
|
||||
Y.bind(success_callback, this, responsetext)();
|
||||
}
|
||||
|
||||
if (statusspinner) {
|
||||
window.setTimeout(function() {
|
||||
statusspinner.hide();
|
||||
}, 400);
|
||||
}
|
||||
},
|
||||
failure: function(tid, response) {
|
||||
if (statusspinner) {
|
||||
statusspinner.hide();
|
||||
}
|
||||
new M.core.ajaxException(response);
|
||||
}
|
||||
},
|
||||
context: this
|
||||
};
|
||||
|
||||
// Apply optional config
|
||||
if (optionalconfig) {
|
||||
for (varname in optionalconfig) {
|
||||
config[varname] = optionalconfig[varname];
|
||||
}
|
||||
}
|
||||
|
||||
if (statusspinner) {
|
||||
statusspinner.show();
|
||||
}
|
||||
|
||||
// Send the request
|
||||
Y.io(uri, config);
|
||||
return this;
|
||||
}
|
||||
},
|
||||
{
|
||||
NAME: 'course-toolbox',
|
||||
ATTRS: {
|
||||
/**
|
||||
* The ID of the Moodle Course being edited.
|
||||
*
|
||||
* @attribute courseid
|
||||
* @default 0
|
||||
* @type Number
|
||||
*/
|
||||
courseid: {
|
||||
'value': 0
|
||||
},
|
||||
|
||||
/**
|
||||
* The Moodle course format.
|
||||
*
|
||||
* @attribute format
|
||||
* @default 'topics'
|
||||
* @type String
|
||||
*/
|
||||
format: {
|
||||
'value': 'topics'
|
||||
},
|
||||
/**
|
||||
* The URL to use when submitting requests.
|
||||
* @attribute ajaxurl
|
||||
* @default null
|
||||
* @type String
|
||||
*/
|
||||
ajaxurl: {
|
||||
'value': null
|
||||
},
|
||||
/**
|
||||
* Any additional configuration passed when creating the instance.
|
||||
*
|
||||
* @attribute config
|
||||
* @default {}
|
||||
* @type Object
|
||||
*/
|
||||
config: {
|
||||
'value': {}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
@ -1,13 +0,0 @@
|
||||
{
|
||||
"moodle-course-toolboxes": {
|
||||
"requires": [
|
||||
"node",
|
||||
"base",
|
||||
"event-key",
|
||||
"node",
|
||||
"io",
|
||||
"moodle-course-coursebase",
|
||||
"moodle-course-util"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user