Skip to content

Commit

Permalink
Merge branch 'MDL-34328-MOODLE_23_STABLE-2' of git://git.luns.net.uk/…
Browse files Browse the repository at this point in the history
…moodle into MOODLE_23_STABLE
  • Loading branch information
danpoltawski committed Sep 25, 2012
2 parents 790ad23 + cffbc80 commit 2d39f72
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 102 deletions.
87 changes: 49 additions & 38 deletions course/yui/dragdrop/dragdrop.js
Expand Up @@ -41,6 +41,26 @@ YUI.add('moodle-course-dragdrop', function(Y) {
if (this.sectionlistselector) { if (this.sectionlistselector) {
this.sectionlistselector = '.'+CSS.COURSECONTENT+' '+this.sectionlistselector; this.sectionlistselector = '.'+CSS.COURSECONTENT+' '+this.sectionlistselector;
this.setup_for_section(this.sectionlistselector); this.setup_for_section(this.sectionlistselector);

// Make each li element in the lists of sections draggable
var nodeselector = this.sectionlistselector.slice(CSS.COURSECONTENT.length+2);
var del = new Y.DD.Delegate({
container: '.'+CSS.COURSECONTENT,
nodes: nodeselector,
target: true,
handles: ['.'+CSS.LEFT],
dragConfig: {groups: this.groups}
});
del.dd.plug(Y.Plugin.DDProxy, {
// Don't move the node at the end of the drag
moveOnEnd: false
});
del.dd.plug(Y.Plugin.DDConstrained, {
// Keep it inside the .course-content
constrain: '#'+CSS.PAGECONTENT,
stickY: true
});
del.dd.plug(Y.Plugin.DDWinScroll);
} }
}, },


Expand Down Expand Up @@ -76,22 +96,6 @@ YUI.add('moodle-course-dragdrop', function(Y) {
if (movedown) { if (movedown) {
movedown.remove(); movedown.remove();
} }

// Make each li element in the lists of sections draggable
var dd = new Y.DD.Drag({
node: sectionnode,
// Make each li a Drop target too
groups: this.groups,
target: true,
handles: ['.'+CSS.LEFT]
}).plug(Y.Plugin.DDProxy, {
// Don't move the node at the end of the drag
moveOnEnd: false
}).plug(Y.Plugin.DDConstrained, {
// Keep it inside the .course-content
constrain: '#'+CSS.PAGECONTENT,
stickY: true
}).plug(Y.Plugin.DDWinScroll);
} }
} }
}, this); }, this);
Expand Down Expand Up @@ -244,12 +248,33 @@ YUI.add('moodle-course-dragdrop', function(Y) {
this.groups = ['resource']; this.groups = ['resource'];
this.samenodeclass = CSS.ACTIVITY; this.samenodeclass = CSS.ACTIVITY;
this.parentnodeclass = CSS.SECTION; this.parentnodeclass = CSS.SECTION;
this.resourcedraghandle = this.get_drag_handle(M.str.moodle.move, CSS.EDITINGMOVE, CSS.ICONCLASS);


// Go through all sections // Go through all sections
var sectionlistselector = M.course.format.get_section_selector(Y); var sectionlistselector = M.course.format.get_section_selector(Y);
if (sectionlistselector) { if (sectionlistselector) {
sectionlistselector = '.'+CSS.COURSECONTENT+' '+sectionlistselector; sectionlistselector = '.'+CSS.COURSECONTENT+' '+sectionlistselector;
this.setup_for_section(sectionlistselector); this.setup_for_section(sectionlistselector);

// Initialise drag & drop for all resources/activities
var nodeselector = sectionlistselector.slice(CSS.COURSECONTENT.length+2)+' li.'+CSS.ACTIVITY;
var del = new Y.DD.Delegate({
container: '.'+CSS.COURSECONTENT,
nodes: nodeselector,
target: true,
handles: ['.' + CSS.EDITINGMOVE],
dragConfig: {groups: this.groups}
});
del.dd.plug(Y.Plugin.DDProxy, {
// Don't move the node at the end of the drag
moveOnEnd: false
});
del.dd.plug(Y.Plugin.DDConstrained, {
// Keep it inside the .course-content
constrain: '#'+CSS.PAGECONTENT
});
del.dd.plug(Y.Plugin.DDWinScroll);

M.course.coursebase.register_module(this); M.course.coursebase.register_module(this);
M.course.dragres = this; M.course.dragres = this;
} }
Expand All @@ -269,15 +294,15 @@ YUI.add('moodle-course-dragdrop', function(Y) {
var resources = Y.Node.create('<ul></ul>'); var resources = Y.Node.create('<ul></ul>');
resources.addClass(CSS.SECTION); resources.addClass(CSS.SECTION);
sectionnode.one('.'+CSS.CONTENT+' div.'+CSS.SUMMARY).insert(resources, 'after'); sectionnode.one('.'+CSS.CONTENT+' div.'+CSS.SUMMARY).insert(resources, 'after');
// Define empty ul as droptarget, so that item could be moved to empty list
var tar = new Y.DD.Drop({
node: resources,
groups: this.groups,
padding: '20 0 20 0'
});
} }


// Define each ul as droptarget, so that item could be moved to empty list // Initialise each resource/activity in this section
var tar = new Y.DD.Drop({
node: resources,
groups: this.groups,
padding: '20 0 20 0'
});
// Go through each li element and make them draggable
this.setup_for_resource('#'+sectionnode.get('id')+' li.'+CSS.ACTIVITY); this.setup_for_resource('#'+sectionnode.get('id')+' li.'+CSS.ACTIVITY);
}, this); }, this);
}, },
Expand All @@ -292,21 +317,7 @@ YUI.add('moodle-course-dragdrop', function(Y) {
// Replace move icons // Replace move icons
var move = resourcesnode.one('a.'+CSS.EDITINGMOVE); var move = resourcesnode.one('a.'+CSS.EDITINGMOVE);
if (move) { if (move) {
move.replace(this.get_drag_handle(M.str.moodle.move, CSS.EDITINGMOVE, CSS.ICONCLASS)); move.replace(this.resourcedraghandle.cloneNode(true));
// Make each li element in the lists of sections draggable
var dd = new Y.DD.Drag({
node: resourcesnode,
groups: this.groups,
// Make each li a Drop target too
target: true,
handles: ['.' + CSS.EDITINGMOVE]
}).plug(Y.Plugin.DDProxy, {
// Don't move the node at the end of the drag
moveOnEnd: false
}).plug(Y.Plugin.DDConstrained, {
// Keep it inside the .course-content
constrain: '#'+CSS.PAGECONTENT
}).plug(Y.Plugin.DDWinScroll);
} }
}, this); }, this);
}, },
Expand Down
85 changes: 33 additions & 52 deletions course/yui/toolboxes/toolboxes.js
Expand Up @@ -49,32 +49,9 @@ YUI.add('moodle-course-toolboxes', function(Y) {


Y.extend(TOOLBOX, Y.Base, { Y.extend(TOOLBOX, Y.Base, {
/** /**
* Replace the button click at the selector with the specified * Toggle the visibility and availability for the specified
* callback * resource show/hide button
*
* @param toolboxtarget The selector of the working area
* @param selector The 'button' to replace
* @param callback The callback to apply
* @param cursor An optional cursor style to apply
*/ */
replace_button : function(toolboxtarget, selector, callback, cursor) {
if (!cursor) {
// Set the default cursor type to pointer to match the
// anchor
cursor = 'pointer';
}
var button = Y.one(toolboxtarget).all(selector)
.setStyle('cursor', cursor);

// on isn't chainable and will return an event
button.on('click', callback, this);

return button;
},
/**
* Toggle the visibility and availability for the specified
* resource show/hide button
*/
toggle_hide_resource_ui : function(button) { toggle_hide_resource_ui : function(button) {
var element = button.ancestor(CSS.ACTIVITYLI); var element = button.ancestor(CSS.ACTIVITYLI);
var hideicon = button.one('img'); var hideicon = button.one('img');
Expand Down Expand Up @@ -241,6 +218,17 @@ YUI.add('moodle-course-toolboxes', function(Y) {
initializer : function(config) { initializer : function(config) {
this.setup_for_resource(); this.setup_for_resource();
M.course.coursebase.register_module(this); M.course.coursebase.register_module(this);

var prefix = CSS.ACTIVITYLI + ' ' + CSS.COMMANDSPAN + ' ';
Y.delegate('click', this.edit_resource_title, CSS.PAGECONTENT, prefix + CSS.EDITTITLE, this);
Y.delegate('click', this.move_left, CSS.PAGECONTENT, prefix + CSS.MOVELEFT, this);
Y.delegate('click', this.move_right, CSS.PAGECONTENT, prefix + CSS.MOVERIGHT, this);
Y.delegate('click', this.delete_resource, CSS.PAGECONTENT, prefix + CSS.DELETE, this);
Y.delegate('click', this.toggle_hide_resource, CSS.PAGECONTENT, prefix + CSS.HIDE, this);
Y.delegate('click', this.toggle_hide_resource, CSS.PAGECONTENT, prefix + CSS.SHOW, this);
Y.delegate('click', this.toggle_groupmode, CSS.PAGECONTENT, prefix + CSS.GROUPSNONE, this);
Y.delegate('click', this.toggle_groupmode, CSS.PAGECONTENT, prefix + CSS.GROUPSSEPARATE, this);
Y.delegate('click', this.toggle_groupmode, CSS.PAGECONTENT, prefix + CSS.GROUPSVISIBLE, this);
}, },


/** /**
Expand All @@ -252,43 +240,32 @@ YUI.add('moodle-course-toolboxes', function(Y) {
*/ */
setup_for_resource : function(baseselector) { setup_for_resource : function(baseselector) {
if (!baseselector) { if (!baseselector) {
var baseselector = CSS.PAGECONTENT + ' ' + CSS.ACTIVITYLI;; var baseselector = CSS.PAGECONTENT + ' ' + CSS.ACTIVITYLI;
} }


Y.all(baseselector).each(this._setup_for_resource, this); Y.all(baseselector).each(this._setup_for_resource, this);
}, },
_setup_for_resource : function(toolboxtarget) { _setup_for_resource : function(toolboxtarget) {
// Edit Title toolboxtarget = Y.one(toolboxtarget);
this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.EDITTITLE, this.edit_resource_title); // "Disable" show/hide icons (change cursor to not look clickable) if section is hidden

var showhide = toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.HIDE);
// Move left and right showhide.concat(toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.SHOW));
this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.MOVELEFT, this.move_left);
this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.MOVERIGHT, this.move_right);

// Delete
this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.DELETE, this.delete_resource);

// Show/Hide
var showhide = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.HIDE, this.toggle_hide_resource);
var shown = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.SHOW, this.toggle_hide_resource);

showhide = showhide.concat(shown);
showhide.each(function(node) { showhide.each(function(node) {
var section = node.ancestor(CSS.SECTIONLI); var section = node.ancestor(CSS.SECTIONLI);
if (section && section.hasClass(CSS.SECTIONHIDDENCLASS)) { if (section && section.hasClass(CSS.SECTIONHIDDENCLASS)) {
node.setStyle('cursor', 'auto'); node.setStyle('cursor', 'auto');
} }
}); });


// Change Group Mode // Set groupmode attribute for use by this.toggle_groupmode()
var groups; var groups;
groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSNONE, this.toggle_groupmode); groups = toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.GROUPSNONE);
groups.setAttribute('groupmode', this.GROUPS_NONE); groups.setAttribute('groupmode', this.GROUPS_NONE);


groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSSEPARATE, this.toggle_groupmode); groups = toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.GROUPSSEPARATE);
groups.setAttribute('groupmode', this.GROUPS_SEPARATE); groups.setAttribute('groupmode', this.GROUPS_SEPARATE);


groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSVISIBLE, this.toggle_groupmode); groups = toolboxtarget.all(CSS.COMMANDSPAN + ' ' + CSS.GROUPSVISIBLE);
groups.setAttribute('groupmode', this.GROUPS_VISIBLE); groups.setAttribute('groupmode', this.GROUPS_VISIBLE);
}, },
move_left : function(e) { move_left : function(e) {
Expand Down Expand Up @@ -405,6 +382,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
}; };
var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN)); var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN));
this.send_request(data, spinner); this.send_request(data, spinner);
return false; // Need to return false to stop the delegate for the new state firing
}, },
toggle_groupmode : function(e) { toggle_groupmode : function(e) {
// Prevent the default button action // Prevent the default button action
Expand Down Expand Up @@ -460,6 +438,7 @@ YUI.add('moodle-course-toolboxes', function(Y) {
}; };
var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN)); var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN));
this.send_request(data, spinner); this.send_request(data, spinner);
return false; // Need to return false to stop the delegate for the new state firing
}, },
/** /**
* Add the moveleft button * Add the moveleft button
Expand Down Expand Up @@ -632,6 +611,11 @@ YUI.add('moodle-course-toolboxes', function(Y) {
initializer : function(config) { initializer : function(config) {
this.setup_for_section(); this.setup_for_section();
M.course.coursebase.register_module(this); M.course.coursebase.register_module(this);

// Section Highlighting
Y.delegate('click', this.toggle_highlight, CSS.PAGECONTENT, CSS.SECTIONLI + ' ' + CSS.HIGHLIGHT, this);
// Section Visibility
Y.delegate('click', this.toggle_hide_section, CSS.PAGECONTENT, CSS.SECTIONLI + ' ' + CSS.SHOWHIDE, this);
}, },
/** /**
* Update any section areas within the scope of the specified * Update any section areas within the scope of the specified
Expand All @@ -641,18 +625,15 @@ YUI.add('moodle-course-toolboxes', function(Y) {
* @return void * @return void
*/ */
setup_for_section : function(baseselector) { setup_for_section : function(baseselector) {
if (!baseselector) { // Left here for potential future use - not currently needed due to YUI delegation in initializer()
/*if (!baseselector) {
var baseselector = CSS.PAGECONTENT; var baseselector = CSS.PAGECONTENT;
} }
Y.all(baseselector).each(this._setup_for_section, this); Y.all(baseselector).each(this._setup_for_section, this);*/
}, },
_setup_for_section : function(toolboxtarget) { _setup_for_section : function(toolboxtarget) {
// Section Highlighting // Left here for potential future use - not currently needed due to YUI delegation in initializer()
this.replace_button(toolboxtarget, CSS.RIGHTSIDE + ' ' + CSS.HIGHLIGHT, this.toggle_highlight);

// Section Visibility
this.replace_button(toolboxtarget, CSS.RIGHTSIDE + ' ' + CSS.SHOWHIDE, this.toggle_hide_section);
}, },
toggle_hide_section : function(e) { toggle_hide_section : function(e) {
// Prevent the default button action // Prevent the default button action
Expand Down
26 changes: 15 additions & 11 deletions lib/yui/blocks/blocks.js
Expand Up @@ -68,23 +68,27 @@ YUI.add('moodle-core-blocks', function(Y) {
padding: '40 240 40 240' padding: '40 240 40 240'
}); });


// Make each div element in the list of blocks draggable
var del = new Y.DD.Delegate({
container: blockregionnode,
nodes: '.'+CSS.BLOCK,
target: true,
handles: ['.'+CSS.HEADER],
invalid: '.block-hider-hide, .block-hider-show, .moveto',
dragConfig: {groups: this.groups}
});
del.dd.plug(Y.Plugin.DDProxy, {
// Don't move the node at the end of the drag
moveOnEnd: false
});
del.dd.plug(Y.Plugin.DDWinScroll);

var blocklist = blockregionnode.all('.'+CSS.BLOCK); var blocklist = blockregionnode.all('.'+CSS.BLOCK);
blocklist.each(function(blocknode) { blocklist.each(function(blocknode) {
var move = blocknode.one('a.'+CSS.EDITINGMOVE); var move = blocknode.one('a.'+CSS.EDITINGMOVE);
if (move) { if (move) {
move.remove(); move.remove();
blocknode.one('.'+CSS.HEADER).setStyle('cursor', 'move'); blocknode.one('.'+CSS.HEADER).setStyle('cursor', 'move');
// Make each div element in the list of blocks draggable
var dd = new Y.DD.Drag({
node: blocknode,
groups: this.groups,
// Make each div a Drop target too
target: true,
handles: ['.'+CSS.HEADER]
}).plug(Y.Plugin.DDProxy, {
// Don't move the node at the end of the drag
moveOnEnd: false
}).plug(Y.Plugin.DDWinScroll);
} }
}, this); }, this);
}, this); }, this);
Expand Down
2 changes: 1 addition & 1 deletion lib/yui/dragdrop/dragdrop.js
Expand Up @@ -167,11 +167,11 @@ YUI.add('moodle-core-dragdrop', function(Y) {
// we substitute them for the ease of use. For e.drop we use, // we substitute them for the ease of use. For e.drop we use,
// this.lastdroptarget (ghost node we use for indicating where to drop) // this.lastdroptarget (ghost node we use for indicating where to drop)
e.drag = e.target; e.drag = e.target;
e.drop = this.lastdroptarget;
// Check that drop object belong to correct group // Check that drop object belong to correct group
if (!e.drop || !e.drop.inGroup(this.groups)) { if (!e.drop || !e.drop.inGroup(this.groups)) {
return; return;
} }
e.drop = this.lastdroptarget;
this.drag_dropmiss(e); this.drag_dropmiss(e);
}, },


Expand Down

0 comments on commit 2d39f72

Please sign in to comment.