Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed subclass activity_class. The only logic in that class was for…

… handling of groupmode buttons. These are now handled in resource_class.prototype.init_buttons() and resource_class.prototype.toggle_groupmode().

We basially look at whether the button is present in the html output, and if it is, we add it to the ajax frontend. We do not make the distinction that activities should have the button (as opposed to resources). The advantage is that some activities might not have groupmode.

This fixes MDL-6916.
  • Loading branch information...
commit d500edf24365b0368adef381ea711851653043c4 1 parent b666f6f
vyshane authored
Showing with 112 additions and 94 deletions.
  1. +112 −94 lib/ajax/section_classes.js
View
206 lib/ajax/section_classes.js
@@ -83,6 +83,7 @@ section_class.prototype.init_buttons = function() {
//clear all but show only button
var commandContainerCount = commandContainer.childNodes.length;
+
for (var i=(commandContainerCount-1); i>0; i--) {
commandContainer.removeChild(commandContainer.childNodes[i])
}
@@ -101,7 +102,9 @@ section_class.prototype.init_buttons = function() {
section_class.prototype.add_handle = function() {
- var handleRef = main.mk_button('a', '/i/move_2d.gif', [['style','cursor:move']]);
+ var handleRef = main.mk_button('a', '/i/move_2d.gif',
+ [['style','cursor:move'], ['title', main.portal.strings['move']]]);
+
YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
this.handle = handleRef;
@@ -144,20 +147,13 @@ section_class.prototype.process_section = function() {
for (var i=0;i<resource_count;i++) {
var resource = this.resources_ul.getElementsByTagName('li')[i];
- if (YAHOO.util.Dom.hasClass(resource, 'resource')) {
- this.resources[this.resources.length] = new resource_class(resource.id, 'resources', null, this);
- if (this.debug) {
- YAHOO.log("Found resource");
- }
- } else {
- this.resources[this.resources.length] = new activity_class(resource.id, 'resources', null, this);
- }
+ this.resources[this.resources.length] = new resource_class(resource.id, 'resources', null, this);
}
this.summary = YAHOO.util.Dom.getElementsByClassName('summary', null, this.getEl())[0].firstChild.data || '';
}
-section_class.prototype.startDrag = function(x, y) {
+section_class.prototype.startDrag = function(x, y) {
//operates in point mode
YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
@@ -316,8 +312,8 @@ section_class.prototype.toggle_highlight = function() {
section_class.prototype.mk_marker = function() {
if (main.marker != this) {
main.update_marker(this);
-
- } else {//if currently the marker
+ } else {
+ // If currently the marker
main.marker = null;
main.connect('POST', 'class=course&field=marker', null, 'value=0');
@@ -468,11 +464,11 @@ section_class.prototype.write_sequence_list = function(toReturn) {
+
/**
* resource_class extends util.DDProxy
*/
function resource_class(id,group,config,parentObj) {
-
this.init_resource(id,group,config,parentObj);
}
@@ -487,6 +483,12 @@ resource_class.prototype.init_resource = function(id, group, config, parentObj)
YAHOO.log("Init resource, NO ID FOUND!", 'error');
return;
}
+
+ // Some constants.
+ this.NOGROUPS = 0;
+ this.SEPARATEGROUPS = 1;
+ this.VISIBLEGROUPS = 2;
+
this.is = 'resource';
this.init(id, group, config);
this.createFrame();
@@ -500,14 +502,17 @@ resource_class.prototype.init_resource = function(id, group, config, parentObj)
}
this.hiddenStored = null;
+ this.groupmode = null; // Can be null (i.e. does not apply), 0, 1 or 2.
+
this.linkContainer = this.getEl().getElementsByTagName('a')[0];
this.commandContainer = null;
this.viewButton = null;
- this.handle = null;
+ this.groupButton = null;
+ this.handle = null;
this.init_buttons();
- this.parentObj = parentObj;
+ this.parentObj = parentObj;
if (this.debug) {
YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
@@ -515,48 +520,101 @@ resource_class.prototype.init_resource = function(id, group, config, parentObj)
}
+/**
+ * The current strategy is to look at the DOM tree to get information on the
+ * resource and it's current mode. This is bad since we are dependant on
+ * the html that is output from serverside logic. Seemingly innocuous changes
+ * like changing the language string for the title of a button will break
+ * our JavaScript here. This is brittle.
+ *
+ * First, we clear the buttons container. Then:
+ * We need to add the new-style move handle.
+ * The old style move button (up/down) needs to be removed.
+ * Move left button (if any) needs an event handler.
+ * Move right button (if any) needs an event handler.
+ * Update button stays as it is. Add it back.
+ * Delete button needs an event handler.
+ * Visible button is a toggle. It needs an event handler too.
+ * Group mode button is a toggle. It needs an event handler too.
+ */
resource_class.prototype.init_buttons = function() {
- var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands', 'span', this.getEl())[0];
+
+ var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
+ 'span', this.getEl())[0];
+
if (commandContainer == null) {
YAHOO.log('Cannot find command container for '+this.getEl().id, 'error');
return;
}
+
+ // Language strings.
+ var strgroupsnone = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
+ var strgroupsseparate = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
+ var strgroupsvisible = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
+
this.commandContainer = commandContainer;
+ var buttons = commandContainer.getElementsByTagName('a');
- //find edit button
+ // Buttons that we might need to add back in.
+ var moveLeft = false;
+ var moveRight = false;
var updateButton = null;
- var buttons = commandContainer.getElementsByTagName('a');
for (var x=0; x<buttons.length; x++) {
- if (buttons[x].title == main.portal.strings['update']) {
+ if (buttons[x].title == main.portal.strings['moveleft']) {
+ moveLeft = true;
+ } else if (buttons[x].title == main.portal.strings['moveright']) {
+ moveRight = true;
+ } else if (buttons[x].title == main.portal.strings['update']) {
updateButton = buttons[x].cloneNode(true);
- }
+ } else if (buttons[x].title == strgroupsnone) {
+ this.groupmode = this.NOGROUPS;
+ } else if (buttons[x].title == strgroupsseparate) {
+ this.groupmode = this.SEPARATEGROUPS;
+ } else if (buttons[x].title == strgroupsvisible) {
+ this.groupmode = this.VISIBLEGROUPS;
+ }
}
if (updateButton == null) {
+ // Update button must always be present.
YAHOO.log('Cannot find updateButton for '+this.getEl().id, 'error');
}
+ // Clear all the buttons.
commandContainer.innerHTML = '';
- //add move-handle
+ // Add move-handle for drag and drop.
var handleRef = main.mk_button('a', '/i/move_2d.gif',
- [['style', 'cursor:move']], [['height', '11'], ['width', '11'],
- ['hspace', '2'], ['border', '0']]);
+ [['style', 'cursor:move'], ['title', main.portal.strings['move']]],
+ [['height', '11'], ['width', '11'], ['style', 'margin-right:3px; border:0;']]);
YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
this.handle = handleRef;
commandContainer.appendChild(handleRef);
this.setHandleElId(this.handle.id);
- //add edit button back in
- commandContainer.appendChild(updateButton);
+ // Add indentation buttons if needed (move left, move right).
+ if (moveLeft) {
+ var button = main.mk_button('a', '/t/left.gif', [['title', main.portal.strings['moveleft']]]);
+ YAHOO.util.Event.addListener(button, 'click', this.move_left_button, this, true);
+ commandContainer.appendChild(button);
+ }
+ if (moveRight) {
+ var button = main.mk_button('a', '/t/right.gif', [['title', main.portal.strings['moveright']]]);
+ YAHOO.util.Event.addListener(button, 'click', this.move_right_button, this, true);
+ commandContainer.appendChild(button);
+ }
+
+ // Add edit button back in.
+ commandContainer.appendChild(updateButton);
- //add rest
- var button = main.mk_button('a', '/t/delete.gif');
+ // Add the delete button.
+ var button = main.mk_button('a', '/t/delete.gif');
YAHOO.util.Event.addListener(button, 'click', this.delete_button, this, true);
commandContainer.appendChild(button);
+ // Add the hide or show button.
if (this.hidden) {
var button = main.mk_button('a', '/t/show.gif');
} else {
@@ -565,6 +623,20 @@ resource_class.prototype.init_buttons = function() {
YAHOO.util.Event.addListener(button, 'click', this.toggle_hide, this, true);
commandContainer.appendChild(button);
this.viewButton = button;
+
+ // Add the groupmode button if needed.
+ if (this.groupmode != null) {
+ if (this.groupmode == this.NOGROUPS) {
+ var button = main.mk_button('a', '/t/groupn.gif', [['title', strgroupsnone]]);
+ } else if (this.groupmode == this.SEPARATEGROUPS) {
+ var button = main.mk_button('a', '/t/groups.gif', [['title', strgroupsseparate]]);
+ } else {
+ var button = main.mk_button('a', '/t/groupv.gif', [['title', strgroupsvisible]]);
+ }
+ YAHOO.util.Event.addListener(button, 'click', this.toggle_groupmode, this, true);
+ commandContainer.appendChild(button);
+ this.groupButton = button;
+ }
}
@@ -575,7 +647,6 @@ resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
}
this.hidden = !force;
}
-
if (this.hidden) {
YAHOO.util.Dom.removeClass(this.linkContainer, 'dimmed');
this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
@@ -596,6 +667,19 @@ resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
}
+resource_class.prototype.groupImages = ['/t/groupn.gif', '/t/groups.gif', '/t/groupv.gif'];
+
+
+resource_class.prototype.toggle_groupmode = function() {
+ this.groupmode++;
+ if (this.groupmode > 2) {
+ this.groupmode = 0;
+ }
+ this.groupButton.getElementsByTagName('img')[0].src = main.portal.strings['pixpath']+this.groupImages[this.groupmode];
+ main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.groupmode+'&id='+this.id);
+}
+
+
resource_class.prototype.delete_button = function() {
if (this.debug) {
YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id);
@@ -693,69 +777,3 @@ resource_class.prototype.onDragDrop = function(e, ids) {YAHOO.log('onDragDrop');
resource_class.prototype.endDrag = function() {
// Eliminates default action
}
-
-
-
-/**
- * activity_class extends resource class
- */
-function activity_class(id, group, config, parentObj) {
- this.init_activity(id, group, config, parentObj);
-}
-
-YAHOO.extend(activity_class, resource_class);
-
-
-activity_class.prototype.init_activity = function(id, group, config, parentObj) {
- if (!id) {
- YAHOO.log("Init activity, NO ID FOUND!", 'error');
- return;
- }
- this.is = 'activity';
- this.currentGroup = this.get_current_group(id);
- this.init_resource(id, group, config, parentObj);
- this.groupButton= null;
- this.init_activity_button();
-
- if (this.debug) {
- YAHOO.log("--init_activity "+id);
- }
-}
-
-
-activity_class.prototype.groupImages = ['/t/groupn.gif', '/t/groups.gif', '/t/groupv.gif'];
-
-
-activity_class.prototype.init_activity_button = function() {
- var button = main.mk_button('a', this.groupImages[this.currentGroup]);
- YAHOO.util.Event.addListener(button,'click',this.toggle_group,this,true);
- this.commandContainer.appendChild(button);
- this.groupButton = button;
-}
-
-
-activity_class.prototype.get_current_group = function(id) {
- if (document.getElementById(id) == null) {
- return;
- }
- var groupNodeArray = document.getElementById(id).getElementsByTagName('a');
- var groupNode = groupNodeArray[groupNodeArray.length-1];
-
- for (var x=0;x<this.groupImages.length;x++) {
- if (main.portal.wwwroot+this.groupImages[x] == groupNode.getElementsByTagName('img')[0].src) {
- return x;
- }
- }
- return 0;
-}
-
-
-activity_class.prototype.toggle_group = function() {
- this.currentGroup++;
- if (this.currentGroup > 2) {
- this.currentGroup = 0;
- }
- this.groupButton.getElementsByTagName('img')[0].src = main.portal.wwwroot + this.groupImages[this.currentGroup];
-
- main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.currentGroup+'&id='+this.id);
-}
Please sign in to comment.
Something went wrong with that request. Please try again.