//clear all but show only button
var commandContainerCount = commandContainer.childNodes.length;
+
for (var i=(commandContainerCount-1); i>0; i--) {
commandContainer.removeChild(commandContainer.childNodes[i])
}
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;
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;
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');
+
/**
* resource_class extends util.DDProxy
*/
function resource_class(id,group,config,parentObj) {
-
this.init_resource(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();
}
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);
}
+/**
+ * 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 {
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;
+ }
}
}
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');
}
+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);
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);
-}